Repository navigation
fix(core): wait for subagent background jobs before completing - #57132
Draft
kitlangton wants to merge 1 commit into
Draft
kitlangton wants to merge 1 commit into
kitlangton wants to merge 1 commit into
Conversation
This was referenced Oct 29, 2026
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.
Issue for this PR
Closes #
Type of change
What does this PR do?
When a subagent launches a background shell (
shellwithbackground: true),BACKGROUND_INSTRUCTIONinpackages/core/src/tool/plugin/shell.tstells it:SubagentJob.start(packages/core/src/session/subagent-job.ts) andSessionRestart.recoverSubagent(packages/core/src/session/execution/restart.ts) only waited for a singlesessions.resume(recovery.childSessionID)busy period before settling the subagent job and delivering<subagent state="completed">to the parent. When a subagent started a background shell and ended its turn as instructed—for example replying "The script is still working through the worktrees (1 of 48 done). I'll pick this up when it completes" or "Waiting for the before/after recording on mini before I write the todo note"—the parent immediately receivedstate="completed"with that interim promise, and when the background shell later finished and woke the child session, no subagent job or observer was left to deliver the final result to the parent.This adds
Job.awaitBackground(sessionID)(packages/core/src/job.ts), which resolves when any in-flight background job whose completion notifiessessionIDacknowledgescompleteBackground(aftersessions.synthetichas enqueued the notification and wokensessionID).SubagentJobandSessionRestart.recoverSubagentnow loop until the child session is idle and owns no pending background notifications before reading its final assistant response and settling the subagent job.How did you verify your code works?
packages/core/test/tool-subagent.test.tswhere a child subagent starts abackground: trueshell, ends its turn with an interim message while the shell is still running, gets woken when the shell finishes, and delivers its final response to the parent.bun run script/test.ts test/tool-subagent.test.ts test/subagent-lifetime.test.ts test/job.test.ts test/session-execution.test.tsandbun typecheckinpackages/core.Screenshots / recordings
N/A
Checklist