GeezerVison is showing github.com — feat(server): OpenCode 2 subagents and background wake-ups by juliusmarminge · Pull Request #14474 · pingdotgg/t3code
Conversation
Layer 6 of the OpenCode 2 stack. Layer 4 kept sessions off the subagent tool because a background child wakes its parent in an execution T3 never asked for. This layer adds real subagent support and removes that deny rule.
Only a user Stop stops background subagents. The orchestrator also interrupts a turn to restart it with new input. That restart used to stop the thread's background subagents too, and the interrupted turn's end then settled them as interrupted. Only ProviderTurnControlService.interrupt passes requestRuntimeRestart: true, so the adapter now stops background children only then. Two adapter tests cover it; the restart one fails without the fix.
Review fixes.
- A subagent's permission ask is shown on its parent's turn. "Allow this session" and the stop after an undeliverable answer now both target the subagent's own session, not the parent's.
- A Stop in the gap between OpenCode announcing a background child (
session.created{parentID}) and the call naming it now interrupts that child too.
- A background subagent's report, queued before OpenCode starts the follow-up for it, now counts as pending work. A Stop is accepted in that gap, and idle unload keeps the session.
- A Stop marks each stopped background child on the session that called it, so a nested child's report stops its own caller's follow-up instead of opening another subagent turn.
- An execution start this build can't decode (
unreadable.execution.started) now starts a subagent's turn or a background follow-up, like a readable start. The subagent and background replays run again with that start made undecodable.
- A background subagent whose Stop failed or timed out stays tracked instead of being settled as interrupted. The session is not released under it, and the next Stop tries again.
- A subagent's form T3 can't show is declined on the subagent's own session. Only that subagent's turn ends; a failed cancel stops the subagent, not the parent.
- A running subagent gets the thread's rules when the thread's mode changes, and so does a subagent the model resumes by session id. A new child session already inherits them from OpenCode.
- A resumed subagent keeps counting its turns, so its next execution no longer replaces its first turn.
Each has a test that fails without its fix.
What changed
OpenCode2AdapterV2.ts, building on layer 5's childOwners map:
- Foreground subagents. A
subagent call is the parent turn's subagent item, node and row. Its child session, announced by session.created{parentID} and named by tool.progress{metadata.sessionID}, becomes a subagent thread under that item. Each execution of the child is a runless turn on that thread, with the delegated prompt as its user message. The child's tools and text stay there, and tool ids get a per-session prefix because the model names them. The result is the child's answer without OpenCode's <subagent …> wrapper. The parent turn's usage stays its own and sets hasSubagents.
- Background subagents.
background: true returns at launch while the child runs on. The item stays running, and the thread's provider-thread roster lists it as typed subagent work (no string matching), so the run waits on it and Stop can reach it. hasPendingBackgroundWork is true while any owned child session is busy, a background call is open, or a wake is held; the ForThread probe checks only that thread's own calls and wakes. The synthetic inbox report OpenCode queues for the parent (metadata.source: "subagent", childID, state) settles the call.
- The server-started follow-up turn. When the child ends, OpenCode starts a new parent execution by itself. The adapter holds that execution's events, including any subagent it starts, and offers a continuation through
ProviderContinuationRequests. The notification names the subagent, as backgroundWorkNotification does for Claude and Grok. The continuation turn replays the held events and ends with that execution, so the wake's output always reaches a turn that terminates. A user prompt sent while the wake runs joins that execution (OpenCode steers it in), so the user's turn takes the wake and its continuation offer is dropped.
- Stop. Checked live on 2.0.18, since DESIGN.md left it open: a parent Stop interrupts a foreground child server-side, but a background child keeps running, and interrupting an idle parent returns
{interrupted:false}. When the child finishes, it still wakes the parent. So Stop now interrupts the thread's background children, marks them interrupted, and stops the execution OpenCode starts to report them, which leaves no continuation behind. It works on a settled run too, because the roster makes Stop reach it. A lost event stream fails every open call and drops held wakes.
- Approvals from children. A child's
permission.asked and form.created land on the parent thread's running turn. For a background child, whose parent turn may have ended, they land on the turn that launched it, whose run is still waiting on the child. Requests from a background child survive that turn completing. approvalsCanOriginateFromSubagents is now true.
- Nesting. A refused call is a failed subagent carrying OpenCode's message, for example
Subagent depth limit reached (1). Increase "experimental.subagent_depth"… (seen live).
- Rules.
rule("subagent", "deny") is removed from sessionRules. A session created by an earlier build with that rule gets its rules rewritten on resume, through layer 5's existing writeRules.
- Capabilities:
supportsSubagents, exposesSubagentThreadIds, emitsSubagentLifecycle and canWaitForSubagents are true. Close and fork of subagent threads stay false.
Verification
All server tests ran inside unshare -U --map-current-user -p -f --mount-proc, as targeted files only.
-
Replay fixtures through the orchestrator, converted from the spike recordings:
opencode2_subagent (subagent.ndjson): a foreground explore child becomes a child thread. Its read/glob calls and answer stay there, one app run, and the item is completed with the answer.
opencode2_background (background.ndjson, with the continuation worker): run 1 ends at waiting while the child runs. The subagent completes after that, and only then does run 2 start as an agent:provider continuation. Its notification says Subagent "Sleep and reply" finished and links the child thread, and the wake's reply lands in run 2, which completes. Nothing stays running or waiting, and the shell roster is empty.
- Both fixtures fail on layer 5's adapter: the subagent fixture on its assertions, and the background one never reaches run 2.
-
OrchestratorReplayFixtures.integration.test.ts -t "opencode|OpenCode", OpenCode2OrchestratorV2.integration.test.ts and OpenCode2AdapterV2.test.ts: 52 passed. Two existing resume tests now start from a session that still has the old deny rule.
-
Live on OpenCode 2.0.18 with openrouter/deepseek/deepseek-v4-flash (OpenCode2OrchestratorV2.live.test.ts -t "runs subagents", real driver, spawned server, continuation worker), one thread per case:
- A foreground subagent: the child thread has
FG_CHILD_OK, and the run completes.
- A background subagent (
sleep 8): run 1 completes, and the wake becomes run 2 (agent:provider), which completes with the parent's reply.
- Stop while a background child runs
sleep 60: the subagent is interrupted, the child thread shows nothing running, no wake run appears, and the thread stays settled 5 s later. OpenCode's own database records the child's outcome as interrupted.
The live run also caught a real bug that replay could not: without the roster entry, Stop on a settled run with a running background child was refused.
-
tsc --noEmit -p apps/server exits 0. vp lint is clean on the touched files (one pre-existing unused helper in shared.ts is not mine). vp run knip:check passes, and the namespace audit shows no violations in lines I changed.
Not run: repo-wide checks, which CI covers; the free opencode/big-pickle model, since deepseek was more reliable at following the tool instructions; and restart reconciliation of held wakes, which is layer 9.
Model: Claude Opus 5.5 (Claude Code)
🤖 Generated with Claude Code

Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Approvability
Verdict: Not approved
Macroscope's review found this PR not approvable — This PR introduces a large production orchestration feature covering subagent threads, background execution, continuation runs, approvals, and Stop semantics. It also changes the default OpenCode session rules to allow subagents, so the scope and default-behavior impact require human review.
No code changes detected at d6c331c. Prior analysis still applies.
You can add or adjust custom eligibility rules. Learn more.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Thread transfer impact
✅ Thread transfer remains within every enforced ceiling.
ℹ️ No successful main baseline artifact is available yet. This run establishes the initial measurement.
| Provider |
Metric |
Main baseline |
This PR |
Impact |
PR ceiling |
|
| Codex |
Total thread wire |
— |
4.9 KiB |
— |
6.8 KiB |
✅ |
| Codex |
Thread snapshot wire |
— |
3.7 KiB |
— |
4.9 KiB |
✅ |
| Codex |
Live turn WebSocket wire |
— |
1.2 KiB |
— |
2.0 KiB |
✅ |
| Codex |
Live turn WebSocket decoded |
— |
20.4 KiB |
— |
29.3 KiB |
✅ |
| Codex |
Live turn messages |
— |
2 |
— |
8 |
✅ |
| Claude |
Total thread wire |
— |
4.9 KiB |
— |
6.8 KiB |
✅ |
| Claude |
Thread snapshot wire |
— |
3.7 KiB |
— |
4.9 KiB |
✅ |
| Claude |
Live turn WebSocket wire |
— |
1.2 KiB |
— |
2.0 KiB |
✅ |
| Claude |
Live turn WebSocket decoded |
— |
20.8 KiB |
— |
29.3 KiB |
✅ |
| Claude |
Live turn messages |
— |
2 |
— |
8 |
✅ |
Baseline: unavailable · PR result: d6c331c · Source CI: success
Scenario 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: 106.1 KiB
- Claude decoded thread snapshot: 106.4 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
A `subagent` call runs in a child session. Each child becomes a subagent
thread under the call's item, and each of its executions is a runless
turn there, so its tools and answer stay out of the parent. The parent
turn's usage stays its own and notes that a subagent ran.
A background call returns at launch while the child keeps running. Its
item stays running and it is listed on the provider thread's roster as
`subagent` work, so the run waits on it and a Stop reaches it. The
report OpenCode queues for the parent settles it. Then OpenCode starts a
parent execution nobody asked for. The adapter holds that execution's
events, offers a continuation turn naming the subagent, and replays
them into it, so the wake's output reaches a turn that ends. A user
prompt sent while the wake runs joins it instead.
OpenCode stops a foreground child with its parent but not a background
one (checked live on 2.0.18), so Stop interrupts the thread's background
children itself and stops the execution OpenCode starts to report them.
A child's permission asks and forms go to the parent thread's turn, or
for a background child to the turn that launched it. Refused calls (such
as the nesting limit) end as failed subagents. The `subagent` deny rule
is gone, and resuming a session made with it rewrites its rules.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…nts running
The orchestrator interrupts a turn both for a user Stop and to restart it
with new input. Only a Stop (`requestRuntimeRestart`) should reach the
thread's background subagents; a restart stopped them too, and the
interrupted turn's end then settled them as interrupted.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…its call names it
OpenCode announces a subagent's session before the call's progress names
it. A Stop in that gap settled the call but interrupted nothing, so the
child ran on untracked. The Stop now interrupts the caller's announced
children too.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…s own session
A subagent's permission ask is shown on its parent's turn, but the grant
for "allow this session" and the stop after an undeliverable answer both
went to the parent session. The grant now goes into the subagent's own
rules, and the subagent's session is the one stopped.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ndecodable start
A newer OpenCode may change an execution start's shape, which the client
then reads as `unreadable.execution.started`. That event only marked a
running turn, so a subagent's execution or a background follow-up that
started with it never got a turn, and lost its text, tools and end. It
now starts them like a readable start. The subagent and background
replays run again with that start made undecodable.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…work
Between a background subagent's report and the follow-up execution
OpenCode starts for it, the thread looked idle: a Stop was refused and
the idle lifecycle could unload the session, losing the report and its
continuation. Queued reports now count as pending background work. A
Stop in that gap marks them stopped, so their follow-up is stopped too,
and a lost stream drops them.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… on its own parent
A Stop marked every stopped child on the thread's own state, but a nested
background subagent reports to the subagent that called it. That
subagent's report then found no marker, and its wake ran as a new child
turn. The Stop now marks each child on its caller's state; a subagent's
execution that only answers stopped children is stopped, not run; and a
nested child's queued report counts as the thread's pending work.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…te on failures
- A background subagent whose interrupt failed or timed out stays tracked
instead of being settled as interrupted: it is still running, so the
session is not released under it and the next Stop tries it again.
- A subagent's form T3 can't show is declined on the subagent's own
session: that turn ends, not its parent's, and a cancel that fails stops
the subagent rather than the parent.
- A subagent's session gets the thread's rules when it can hold others:
a running subagent when the thread's mode changes between turns, and a
subagent resumed by session id, whose session OpenCode made earlier.
A new subagent session inherits its parent's rules from OpenCode.
- A resumed subagent keeps counting its turns, so its next execution gets
its own native turn id instead of replacing its first turn's.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
size:XXL
1,000+ changed lines (additions + deletions).
vouch:trusted
Author is trusted by repo permissions or the VOUCHED list.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|