Repository navigation
Conversation
li-xiu-qi
marked this pull request as ready for review
October 27, 2026 08:17
li-xiu-qi
requested review from
MelodyVAR,
Uking-xxx,
ZouR-Ma and
liuedcson
as code owners
October 27, 2026 08:17
li-xiu-qi
marked this pull request as draft
October 27, 2026 09:10
li-xiu-qi
force-pushed
the
fix/307-compact-aborts-subagents
branch
from
October 27, 2026 10:20
7f3bd67 to
6e3227e
Compare
li-xiu-qi
marked this pull request as ready for review
October 27, 2026 10:28
li-xiu-qi
marked this pull request as draft
October 27, 2026 11:50
li-xiu-qi
marked this pull request as ready for review
October 27, 2026 12:16
li-xiu-qi
marked this pull request as draft
October 27, 2026 14:02
li-xiu-qi
marked this pull request as ready for review
October 27, 2026 14:06
li-xiu-qi
marked this pull request as draft
October 27, 2026 14:24
li-xiu-qi
marked this pull request as ready for review
October 27, 2026 14:33
li-xiu-qi
marked this pull request as draft
October 27, 2026 15:35
li-xiu-qi
force-pushed
the
fix/307-compact-aborts-subagents
branch
from
October 27, 2026 15:35
cb7c8f7 to
3d872ed
Compare
li-xiu-qi
marked this pull request as ready for review
October 27, 2026 15:44
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 #307
Summary
Manual
/compactused to abort the active run, so a foregroundsubagentchild was killed before compaction finished. This PR makes compaction safe for subagents and lets manual compaction hand a running foreground subagent to a background lane instead of waiting for it. Automatic compaction already used the non-aborting path and is unchanged.Problem
AgentSession.compact()calledabort()on the active run. A foregroundsubagentcall shares the agent-run abort signal, so its child process was torn down when the user ran/compact. The reported order was: subagent aborted, parent error, compaction completed.The earlier commit in this PR removed that abort, but manual compaction then waited for the active run to settle. A foreground subagent therefore blocked
/compactuntil it finished, even though compaction only needs to rewrite the parent session context.Automatic threshold/overflow compaction did not abort the run. This PR keeps that behavior and makes the survival contract explicit for both paths: neither manual nor automatic compaction may kill subagents.
Design
The session core does not know what foreground work a host is running. It only knows that a run is active. So manual compaction does not call into subagent code directly. It broadcasts a detach offer before it waits, and the owner of the foreground work decides whether to claim it.
AgentSession.compact()emitssession_detach_foregroundbeforewaitForIdle().subagentcalls. Each call runs inside a detachable runner that races the real child run against the detach request.adoptForegroundRun()hands the in-flight run to the existing background-lane lifecycle. The lane owns the original promise and AbortController; the child process keeps running.<agent-notification>.This indirection is deliberate:
AgentSessionmust not know about subagents, lanes, or child processes. The event lets the owner of the foreground work decide how to hand it off, and lets other extensions reuse the same hook for their own foreground work.Automatic compaction keeps its existing path.
_runAutoCompaction()does not abort the agent run and does not stop background lanes, so subagents survive automatic compaction as well. The detach event is manual-only because automatic compaction is dispatched at assistant-message/prompt boundaries, not while the session is blocked on a foreground tool call.Changes
session_detach_foregroundextension event and emit it fromAgentSession.compact()beforewaitForIdle().step-subagent.ts.adoptForegroundRun()to the lane lifecycle and extract sharedattachRunPromise()final handling for started and adopted lanes.run_in_background, plus the running-lane limit; fall back to waiting when detach is unavailable.docs/extensions.md.blocking.Behavior and compatibility
/compactwith a foreground subagent and available lanes: the subagent is handed to a background lane, compaction proceeds, and the subagent reports back when it finishes./compactwithout available lanes: compaction waits for the foreground subagent, but does not abort it.Validation
Local platform: Windows 11 with Node.js 24.21.0.
pnpm exec vitest --run test/suite/regressions/307-compact-aborts-subagent.test.ts: 2 passed.pnpm exec vitest --run test/compaction-extensions.test.ts test/extensions-runner.test.ts test/suite/agent-session-compaction.test.ts test/suite/agent-session-auto-clm.test.ts: passed.pnpm exec vitest --run test/subagent-lane-notifications.test.ts test/subagent-background-tui.test.ts: passed.pnpm exec vitest --run test/step-subagent-events.test.ts -t "a detached foreground subagent keeps its child session id for later replies": passed; reverting the session-id fix makes it fail.pnpm exec tsgo --noEmit: passed.pnpm exec biome check --error-on-warningson changed files: passed.pnpm run check:public-boundaryandpnpm run check:coding-agent-entry-freeze: passed.build-check-testandCheck commit attributionare green for head3d872ed.Known unrelated local failures on Windows:
test/step-subagent-events.test.tshas one output-path formatting failure, andtest/subagent-invocation.test.tshits a localspawnSynctimeout/EPERM; neither exercises the compaction or lane-adoption paths changed here.Limitations