Repository navigation
feat(sdk): opt-in oom_score_adj for the Copilot runtime - #447
Open
ChrisKrawczyk wants to merge 2 commits into
Open
ChrisKrawczyk wants to merge 2 commits into
ChrisKrawczyk wants to merge 2 commits into
Conversation
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
This was referenced Dec 2, 2026
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #441
What
New opt-in worker setting:
copilotRuntimeOomScoreAdj, or envPILOTSWARM_COPILOT_RUNTIME_OOM_SCORE_ADJwhen the option isn't set. A whole number from -999 to 1000. Unset by default; nothing is written.CopilotRuntimeMonitor.bind()writes the value to the runtime's/proc/<pid>/oom_score_adjas 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./procis its own PID namespace (NStgid), checked before each write, and never creates or truncates the file.Copilot runtime exitedline 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)
memory.oom.group=1, the Kubernetes 1.28+ default on cgroup v2), it does not help at the container's own limit, and in a node-wide shortage a runtime at 1000 can make the kernel take the whole worker container.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
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.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.runtime-loss3/3,copilot-runtime-idle-stop5/5. Lint passes.TLA+ is not required: no durable step, transaction, lock, timer or retry changes.