fix(opencode): a tool killed for memory no longer stops every OpenCode thread #19367
main fromrefs/pull/19367/head·merged by juliusmarminge View on GitHubAn OOM-killed tool could stop the shared OpenCode server and disconnect every thread using it. Shared agent scopes now request OOMPolicy=continue when the systemd manager supports it. OpenCode's server launch opts in; per-thread policy and older-systemd fallback retain their existing behavior.
Based on @t3dotgg's work in #19367, with original commits retained and current main merged. This addresses the blast-radius requirement in #19164. Provider-death/user-interrupt attribution remains tracked separately in #16110. The broader suggestion to change per-thread scopes is outside this focused fix.
Live proof on this Linux machine (systemd 255): the real agentScopeCommand wrapper launched a stand-in server and allocating tool in a separate temporary scope, capped at 128 MiB with swap disabled. No running T3 agent scope was modified. The tool requested 256 MiB.
Before, OOMPolicy=stop:
server-terminated
server exit status 143
After, OOMPolicy=continue:
tool-exit -9
server-survived
server exit status 0
The temporary scopes and slice were cleaned up. This verifies systemd's process behavior with a stand-in, not a live OpenCode model turn. Screenshots are not applicable to this launch-policy change. macOS, Windows, iOS, Android and Electron desktop were not run. Human approval of the changed shared-server default remains required; no merge performed.
Verification: the single PR regression is rewritten in the existing agentScope.test.ts (1 before → 1 after; file remains 9 cases). Ten focused scope/wrapper tests pass; disabling only shared policy selection makes the regression fail immediately with stop instead of continue, then passes after byte-for-byte restoration. Older-manager and non-Linux fallback paths were inspected, not run.
All 48 tests across five focused scope, launch-wrapper, OpenCode runtime, server-owner and OpenCode2Server suites pass, including the real fixture-server subprocess cases. Scoped shared, provider-opencode and server typechecks, four-file lint and formatting pass.
Implementation/test harness: T3 Code with Codex GPT-6.1-Sol (high) and GPT-6-Astra (high); adversarial reviews with Claude Opus 5.5 and Codex GPT-6-Sol.
One full adversarial review round with Claude Opus 5.5 and Codex GPT-6-Sol found no code blockers. The issue-closing wording was corrected to keep the partially addressed issue open. Current-head CI and human policy approval remain required before merging.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
juliusmarminge added labelsmacroscope-review
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Team
- Run ID:
0af2e0ac-038f-4ce5-99d7-081b531d9f20
📥 Commits
-
Reviewing files that changed from the base of the PR and between ad43a51b32b313efe5518b2e3edc3b05e83e8c12 and f6db8217c23eb4daff651ef47a9c823d8d3d762d.
📒 Files selected for processing: 2
-
apps/server/src/process/agentScope.test.tspackages/provider-opencode/src/server/OpenCodeRuntime.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
-
📝 Walkthrough
-
The OpenCode server launch now passes the shared flag to
agentScope.wrap. An integration test checks that supported systemd OOM policy arguments usecontinuefor shared scopes andstopfor ordinary agent scopes.Changes: Shared scope behavior
Layer / File(s) Summary Mark and verify the shared server scope
packages/provider-opencode/src/server/OpenCodeRuntime.ts,apps/server/src/process/agentScope.test.tsThe OpenCode server launch is marked as shared. The test checks the expected OOM policy arguments for shared and ordinary agent scopes when systemd supports the option. Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~8 minutes
Change: Bug fix
Suggested reviewers:
maria-rcks,juliusmarminge
Merge Risk: ⚪ Minimal · up to
f6db8-
The shared server is protected from propagating a tool OOM to other OpenCode threads, and no verified merge-blocking issue remains.
Pre-merge checks:
4-
Check name Status Explanation Title check The title clearly identifies the OpenCode OOM isolation fix and uses a concise conventional-commit format. Description check The description covers the problem, change, scope, verification, limitations, related issues, and implementation attribution. It provides detailed test results and clearly states that human approval a… Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Full details: Description check
-
Explanation
The description covers the problem, change, scope, verification, limitations, related issues, and implementation attribution. It provides detailed test results and clearly states that human approval and current-head CI remain required.
-
✨ Finishing Touches
-
📝 Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Codex Live turn WebSocket decoded 20.9 KiB 20.9 KiB 0 B (0.0%) 29.3 KiB ✅ Codex Live turn messages 2 2 0 (0.0%) 8 ✅ Claude Total thread wire 5.0 KiB 5.0 KiB +31 B (+0.6%) 6.8 KiB ✅ Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB +31 B (+2.6%) 2.0 KiB ✅ Claude Live turn WebSocket decoded 21.2 KiB 21.2 KiB +41 B (+0.2%) 29.3 KiB ✅ Claude Live turn messages 1 2 +1 (+100.0%) 8 ✅ Baseline:
143ab16· PR result:f6db821· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
- Codex decoded thread snapshot: 108.5 KiB
- Claude decoded thread snapshot: 108.8 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
The per-thread scopes this PR keeps on
OOMPolicy=stophit the same problem, at the scale of one thread. A Claude thread's scope holds the CLI, every subagent it runs (background ones included), and all their tool commands. So one runaway command ends the whole conversation, though the kernel already killed only that command.From 0.0.46-nightly.20261014.3093 on systemd 261: a background subagent's
cargo testbinary grew to 45 GB while the parent was idle. The kernel killed only that binary. The CLI received the tool result,Exit code 137, at 08:59:34.5. Three seconds later systemd stopped the scope and the CLI with it:08:59:34 kernel: oom-kill:constraint=CONSTRAINT_NONE,...,global_oom,task_memcg=/.../app-t3code-agents.slice/t3code-claude-b3f6e302.scope,task=annotation_appe,pid=638787,uid=1000 08:59:34 kernel: Out of memory: Killed process 638787 (annotation_appe) total-vm:102101288kB, anon-rss:45390088kB, ... oom_score_adj:800 08:59:37 systemd[1256]: t3code-claude-b3f6e302.scope: Failed with result 'oom-kill'.With
continue, the agent would have read the exit code and carried on, as it does when a test dies any other way. Instead the subagent lost its work, and its thread still shows it working hours later (a separate bug, #19440). It reproduces the way you tested the shared scope:systemctl --user set-property --runtime <scope> MemoryMax=1G MemorySwapMax=0on a Claude thread's scope, then a background subagent allocates 2 GiB. The kernel kills onlypython3, then the scope fails withoom-killand the CLI is gone.The "Killed: out of memory" label may not need
stopeither:readScopealready reads the scope'soom_killcounter frommemory.events, so a turn that fails because the CLI itself was killed could still be labelled from it. Could per-thread scopes usecontinuetoo, or is there a case wherestopdoes something the counter can't?juliusmarminge assignedjuliusmarminge
Taking over this one for batch other-providers-01. I will merge current main, verify the shared-server OOM policy and push to this branch.
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:S
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XS
juliusmarminge merged thised2ca82
juliusmarminge closed this
Sign in to join this conversation.
Approvability#
Verdict: Needs Human Approval
Macroscope's review found this PR requires human approval — This focused fix changes OpenCode server launches to use shared-scope OOM continuation so one tool's memory kill no longer disconnects other threads, with coverage for shared and per-thread policies. Because this alters the product's default server launch behavior, it requires human review.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).