GeezerVison is showing github.com — fix: robust subagent completion propagation by ASidorenkoCode · Pull Request #13321 · anomalyco/opencode
Conversation
Summary
Fixes parent session hanging indefinitely when a subagent (Task tool) completes but SessionPrompt.prompt() never resolves. Fixes #9003, #10802, #11865, #6792.
Three targeted changes:
await the prune() call (prompt.ts:653) — was fire-and-forget, racing with the immediately following MessageV2.stream() reads.
- Diagnostic logging (
prompt.ts:305-312) — the loop exit condition silently continued when assistant finished but user message ID was newer. Now logs a warning so this case is visible.
- Event-driven recovery (
task.ts) — subscribe to child MessageV2.Event.Updated; if the child reaches a terminal state (finish or error) but the prompt doesn't resolve within 3s, force-cancel to unblock the parent. Not a timeout — only fires with positive proof of completion.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
lightsofapollo, ahom, felixzsh, manalkaff, DenchikBY, cantalupo555, will-ks, mpiton, dottharun, tbrandenburg, and 8 more reacted with thumbs up emoji
Fixes parent session hanging when a subagent completes but the prompt
loop doesn't exit. Three changes:
1. `await` the `SessionCompaction.prune()` call that was fire-and-forget,
eliminating a race between prune writes and the following stream reads.
2. Add diagnostic logging when the loop exit condition fails (assistant
finished but user message ID is newer), making stuck loops visible.
3. Add event-driven recovery in the task tool: subscribe to child message
updates, and if the child's assistant message reaches a terminal state
(finish or error) but the prompt doesn't resolve within 3s, force-cancel
to unblock the parent.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Thanks for your contribution!
This PR doesn't have a linked issue. All PRs must reference an existing issue.
Please:
- Open an issue describing the bug/feature (if one doesn't exist)
- Add
Fixes #<number> or Closes #<number> to this PR description
See CONTRIBUTING.md for details.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reproduction & verification
Simulating the stuck condition
To reliably reproduce the race condition, I injected an abort-aware delay in prompt.ts at the child session's loop break point (after processor.process() returns "stop", before break). This only triggers for child sessions (session.parentID is set), simulating the condition where the child's loop doesn't exit after completion:
if (result === "stop") {
if (session.parentID) {
log.warn("INJECTED DELAY: child loop stuck after processor returned stop", { sessionID })
await new Promise<void>((resolve) => {
const timer = setTimeout(resolve, 120_000)
abort.addEventListener("abort", () => { clearTimeout(timer); resolve() }, { once: true })
})
}
break
}
The delay is abort-aware so that SessionPrompt.cancel() can interrupt it, mirroring real stuck conditions which wait on abort-aware I/O.
Before (without fix, with injected delay)
=== BEFORE TEST ===
• quick test Explore Agent
I'll launch an explore agent...
--- 60s elapsed ---
RESULT: STILL RUNNING = HUNG (parent blocked by stuck child)
Log confirmed the child was stuck:
WARN service=session.prompt sessionID=ses_... INJECTED DELAY: child loop stuck after processor returned stop
Parent waited forever — had to be killed.
After (with fix, no injected delay)
=== AFTER TEST ===
• list top-level files Explore Agent
✓ list top-level files Explore Agent
(full directory listing...)
## Top-Level Files & Directories Report
(parent produced final summary and exited cleanly)
Log confirmed clean exit:
INFO service=session.prompt sessionID=ses_... exiting loop
INFO service=session.prompt sessionID=ses_... cancel
Additional finding
During testing, discovered that processor errors set error on the assistant message but NOT finish. Updated the recovery mechanism to detect both terminal states (finish and error), covering both clean completions and error exits.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
The following comment was made by an LLM, it may be inaccurate:
No duplicate PRs found
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Mar 20, 2026
|
Please merge this, its just unusable without this fix
|
acoyfellow, dottharun, halabooda, Burdis28, apmcodes, lukacsi, and gf-mse reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Subagents seem to 100% hang every time on the parent Agent.
|
tbrandenburg, x44ylan, apmcodes, lukacsi, and mrgaturus reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Opencode is getting stucked often with subagents...please merge this
|
yajo reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Is there an update on this? This is still very relevant.
|
gf-mse, mrgaturus, halabooda, dben, shubhambansal013, MaxRehnberg, and Fctoni reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2.
— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊
|
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.
Assignees
No one assigned
Milestone
No milestone
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.
|