GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: robust subagent completion propagation by ASidorenkoCode · Pull Request #13321 · anomalyco/opencode

Conversation

@ASidorenkoCode

@ASidorenkoCode ASidorenkoCode commented Feb 12, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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:

  1. await the prune() call (prompt.ts:653) — was fire-and-forget, racing with the immediately following MessageV2.stream() reads.
  2. 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.
  3. 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
All reactions
  • 👍 18 reactions
ASidorenkoCode
fix: robust subagent completion propagation
005201e
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]>
@github-actions github-actions Bot added the needs:issue label Feb 12, 2026
@github-actions

github-actions Bot commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ASidorenkoCode

ASidorenkoCode commented Feb 12, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed the needs:issue label Feb 12, 2026
@github-actions github-actions Bot mentioned this pull request Feb 13, 2026
fix(opencode): propagate subagent errors to parent session #13422
Closed
This was referenced Mar 20, 2026
fix: Fixes race conditions and missing error handling that cause subagents to hang indefinitely when errors occur. #18389
Closed
fix(tui): surface sub-agent provider errors in parent task flow #18444
Closed
fix(task): propagate subagent provider errors to orchestrator #18509
Closed
@manalkaff

manalkaff commented Mar 26, 2026

Copy link
Copy Markdown

Please merge this, its just unusable without this fix

acoyfellow, dottharun, halabooda, Burdis28, apmcodes, lukacsi, and gf-mse reacted with thumbs up emoji
All reactions
  • 👍 7 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@manalkaff manalkaff mentioned this pull request Mar 26, 2026
main agent hangs because of subagent (explore) #9003
Closed
@acoyfellow

acoyfellow commented Apr 11, 2026

Copy link
Copy Markdown

Subagents seem to 100% hang every time on the parent Agent.

tbrandenburg, x44ylan, apmcodes, lukacsi, and mrgaturus reacted with thumbs up emoji
All reactions
  • 👍 5 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@opencode-agent
opencode-agent Bot force-pushed the dev branch from 2f2ed11 to 9f201d6 Compare April 16, 2026 21:55
@halabooda halabooda mentioned this pull request Apr 19, 2026
[BUG] The whole workflow stalls if any sub-agent is aborted. #23415
Closed
@github-actions github-actions Bot mentioned this pull request May 23, 2026
fix(session): use parent link for loop exit #29032
Closed
@henrique-barreto

henrique-barreto commented May 27, 2026

Copy link
Copy Markdown

Opencode is getting stucked often with subagents...please merge this

yajo reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Jun 8, 2026
fix(task): propagate subagent errors to prevent infinite hang #31299
Closed
3 of 6 tasks
@lukacsi

lukacsi commented Jun 16, 2026

Copy link
Copy Markdown

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
All reactions
  • 👍 7 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gf-mse gf-mse mentioned this pull request Jun 20, 2026
reopening #9003 #33066
Closed
@thdxr

thdxr commented Oct 10, 2026

Copy link
Copy Markdown
Member

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 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thdxr thdxr closed this Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

main agent hangs because of subagent (explore)

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@ASidorenkoCode @manalkaff @acoyfellow @henrique-barreto @lukacsi @thdxr
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.