Skip to content

fix(task): propagate subagent errors to prevent infinite hang#31299

Open
iloli-25 wants to merge 1 commit into
anomalyco:devfrom
iloli-25:fix/subagent-error-propagation
Open

fix(task): propagate subagent errors to prevent infinite hang#31299
iloli-25 wants to merge 1 commit into
anomalyco:devfrom
iloli-25:fix/subagent-error-propagation

Conversation

@iloli-25
Copy link
Copy Markdown

@iloli-25 iloli-25 commented Jun 8, 2026

Subscribe to Session.Event.Error before prompt starts to avoid race condition. Race prompt against error events and 120s timeout, interrupt error fiber on completion to prevent leaks.

Issue for this PR

Closes #5204

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When a subagent hits a quota/rate limit error, the error fires as a
Session.Event.Error bus event but the parent agent hangs indefinitely
because ops.prompt() has no error listener and no timeout.

Fix: subscribe to Session.Event.Error before calling ops.prompt() to
eliminate the race window where an early error is missed. Race the
prompt against the error listener and a 120s idle timeout. Use
Effect.ensuring(Fiber.interrupt(errorFiber)) to clean up the subscriber
regardless of which branch wins.

How did you verify your code works?

Added a unit test in task.test.ts: mocks ops.prompt() as a never-resolving
promise, publishes a Session.Event.Error on the subagent session after
500ms, and asserts the task fails with the error message rather than
hanging. All 19 existing tests continue to pass.

Screenshots / recordings

If this is a UI change, please include a screenshot or recording.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

If you do not follow this template your PR will be automatically rejected.

Subscribe to Session.Event.Error before prompt starts to avoid
race condition. Race prompt against error events and 120s timeout,
interrupt error fiber on completion to prevent leaks.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 8, 2026

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

Potential Duplicate Found

PR #13321: "fix: robust subagent completion propagation"

This PR appears related as it also addresses subagent error/completion propagation issues. It may have overlapping scope with PR #31299, though it's unclear if it specifically addresses the timeout and race condition aspects.

All other search results returned PR #31299 (the current PR itself), which is expected and not a duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error messages from model provider during a subagent don't make way to primary agent

1 participant