You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A subagent that ends a turn while it still has pending background work (shell or nested subagent with background: true) is reported to its parent as completed at that first idle. The subagent job settled as soon as sessions.resume(child) returned, so the parent received the child's early reply; when the pending work later woke the child and it produced its real result, nothing delivered it.
SubagentCompletion.finalText runs the child to quiescence before reading its response: while the child still owns pending background notifications that will wake it, it waits for their delivery and resumes again.
New Job.awaitBackground(notificationID) resolves when the notification is admitted (its durable marker clears). Waiting for job settlement alone races that asynchronous delivery.
Live subagent jobs and restart recovery share the same body, so recovered jobs behave identically.
How did you verify your code works?
cd packages/core && bun test test/job.test.ts test/tool-subagent.test.ts — the new regression test (waits for pending child background work before notifying the parent) fails when run against the un-fixed source (Expected "running", Received "completed") and passes with the fix.
Reproduced the original failure on v2: the parent was notified with SHELL_STARTED while the child's background shell was still running, and the child's later WOKEN_RESULT_COLLECTED stayed stranded in the child session.
The description now follows the PR template section for section and the compliance check passes:
### Issue for this PR — Closes #48826
### Type of change — bug fix checked
### What does this PR do?
### How did you verify your code works?
### Screenshots / recordings — not a UI change
### Checklist — both items checked
One note for maintainers on the remaining needs:issue label: it can't clear itself for PRs targeting v2. The pull_request_target run uses the workflow copy without the v2 body fallback, so it only reads closingIssuesReferences, and GitHub returns 0 closing references for PRs that don't target the default branch. Other v2 PRs with a Closes reference (e.g. #48928, #49295) carry the same label. The issue link is present in the description.
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
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 #48826
Type of change
What does this PR do?
A subagent that ends a turn while it still has pending background work (
shellor nestedsubagentwithbackground: true) is reported to its parent ascompletedat that first idle. The subagent job settled as soon assessions.resume(child)returned, so the parent received the child's early reply; when the pending work later woke the child and it produced its real result, nothing delivered it.SubagentCompletion.finalTextruns the child to quiescence before reading its response: while the child still owns pending background notifications that will wake it, it waits for their delivery and resumes again.Job.awaitBackground(notificationID)resolves when the notification is admitted (its durable marker clears). Waiting for job settlement alone races that asynchronous delivery.How did you verify your code works?
cd packages/core && bun test test/job.test.ts test/tool-subagent.test.ts— the new regression test (waits for pending child background work before notifying the parent) fails when run against the un-fixed source (Expected "running", Received "completed") and passes with the fix.Reproduced the original failure on v2: the parent was notified with
SHELL_STARTEDwhile the child's background shell was still running, and the child's laterWOKEN_RESULT_COLLECTEDstayed stranded in the child session.Screenshots / recordings
Not a UI change.
Checklist