Skip to content

feat(sdk): opt-in oom_score_adj for the Copilot runtime - #447

Open
ChrisKrawczyk wants to merge 2 commits into
mainfrom
feat/441-runtime-oom-score
Open

ChrisKrawczyk wants to merge 2 commits into
mainfrom
feat/441-runtime-oom-score

Conversation

@ChrisKrawczyk

@ChrisKrawczyk ChrisKrawczyk commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #441

What

New opt-in worker setting: copilotRuntimeOomScoreAdj, or env PILOTSWARM_COPILOT_RUNTIME_OOM_SCORE_ADJ when the option isn't set. A whole number from -999 to 1000. Unset by default; nothing is written.

  • On Linux, CopilotRuntimeMonitor.bind() writes the value to the runtime's /proc/<pid>/oom_score_adj as the runtime starts. Processes the runtime starts afterwards, including its tools, inherit it. The worker's own score never changes.
  • -1000 (never kill) is refused. A value below the worker's own score is not written, so no privilege is needed and a runtime is never harder to kill than its worker.
  • The worker writes only when /proc is its own PID namespace (NStgid), checked before each write, and never creates or truncates the file.
  • A failed write logs a warning (repeats are counted) and the runtime keeps its score.
  • The startup log shows the configured value and the worker's own score, and warns when the runtime would get no preference. The Copilot runtime exited line includes the runtime's score.

With 1000, an out-of-memory kill usually takes a runtime, which the worker replaces (#329), instead of the worker, which drops every session.

Limits (in configuration.md)

Review

A five-reviewer debate review found one must-fix (the docs claimed no effect under group kill, which was wrong) and nine should-fix items. All are in the second commit: the range and floor, the PID-namespace check, no create/truncate, deduplicated warnings, the exit listener attached before scoring, the startup check, safe handling of odd inputs, the docs, and test isolation from the real env var.

Tests

  • Unit, test/unit/copilot-runtime-oom-score.test.mjs (10 tests): parsing and range; the real env var; Linux-only writes, never to the worker; the namespace check (nested, wrong pid, missing, unreadable); the floor; deduplicated warnings; a throwing setting or writer; and, on Linux, the kernel gives the runtime and its tools the score while the worker keeps its own.
  • Linux e2e, runtime-loss.test.js: the runtime has the score and the worker doesn't; after a SIGKILL the exit log names the score; the next turn runs on a fresh runtime with the same score. The Linux tests skip with a reason if the worker is already at 1000.
  • Linux: all SDK unit tests (3188 passed, 0 failed), runtime-loss 3/3, copilot-runtime-idle-stop 5/5. Lint passes.
  • Before the review fixes, the full local suite on Linux: 4776 passed, 2 failed, 27 skipped. Neither failure touched this change and both pass alone: one is the hand-off deadline that test(sdk): give lossy-replay turns time for the worker hand-off #448 fixes; the other was the model not asking for consent.

TLA+ is not required: no durable step, transaction, lock, timer or retry changes.

New worker option copilotRuntimeOomScoreAdj (env
PILOTSWARM_COPILOT_RUNTIME_OOM_SCORE_ADJ), a whole number from -1000 to
1000. Unset changes nothing.

- On Linux, the runtime monitor writes the value to
  /proc/<pid>/oom_score_adj of each runtime it binds, before the
  client's start resolves, so the runtime's tools inherit it. The
  worker's own score never changes; other platforms are skipped.
- A failed write (EACCES below the floor, ENOENT after an exit) logs
  one warning and the runtime keeps its score.
- The worker logs the setting at startup, and the "Copilot runtime
  exited" warning names the score the runtime had.
- Docs: configuration, .env.example, design and CHANGELOG, with the
  limits (a preference only; no effect with memory.oom.group=1).

Fixes #441

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cc944a13-3e0b-43de-8040-5863182bbdb0
- Accept -999..1000; refuse -1000 (OOM-immune). Never write a value below
  the worker's own score; if that score is unreadable, write only values
  of 0 or more.
- Write only when /proc is the worker's own PID namespace (NStgid), checked
  before every write. Write to the existing /proc file without creating or
  truncating it.
- Count repeated write failures per reason instead of warning per spawn.
- Attach the exit listener before scoring, and warn when the setting or
  writer throws.
- Log the configured value and the worker's own score at startup, and warn
  when the runtime would get no preference.
- Treat a blank env value as unset; never throw while describing an invalid
  value.
- Docs: correct the group-kill claim, state the node-wide risk, the retry
  side effects and what the setting does not cover.
- Tests: isolate the real env var, cover the namespace check, the floor and
  the deduplication; skip the Linux tests with a reason when the worker is
  already at 1000.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cc944a13-3e0b-43de-8040-5863182bbdb0

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Option to make the Copilot runtime the preferred OOM victim (oom_score_adj)

2 participants