Skip to content

fix(opencode): transition subagent ToolPart to error state on RunErrorEvent - #93

Closed
Million-mo wants to merge 2 commits into
develop/agenticfrom
feature/fix-subagent-interupt
Closed

fix(opencode): transition subagent ToolPart to error state on RunErrorEvent#93
Million-mo wants to merge 2 commits into
develop/agenticfrom
feature/fix-subagent-interupt

Conversation

@Million-mo

Copy link
Copy Markdown
Owner

Summary

  • Bug: When a subagent fails (emits RunErrorEvent), the parent session's ToolPart stays in ToolStateRunning forever, making the UI show the subagent as perpetually "running" even after it crashed
  • Root cause: EventProcessor.process() had no match arm for RunErrorEvent — it was silently dropped. The _process_subagent_event() method only handled StreamCompleteEvent (happy path)
  • Fix: Added RunErrorEvent handler in _process_subagent_event() that transitions ToolPart to ToolStateError, emits SessionErrorEvent for the child session, and prevents subsequent StreamCompleteEvent from overriding the error state

Changes

File Change
event_processor.py Add RunErrorEvent + SessionErrorEvent imports; add step 8 handler for RunErrorEvent in _process_subagent_event(); guard StreamCompleteEvent with is_errored check
event_processor_context.py Add is_errored: bool field to prevent error state override
test_subagent_error_state.py New TDD test file with 3 tests

Test plan

  • test_subagent_run_error_transitions_toolpart_to_error — RunErrorEvent transitions ToolPart to ToolStateError with correct error message, emits SessionErrorEvent
  • test_subagent_run_error_without_prior_spawn — RunErrorEvent as first event still creates context and transitions to error
  • test_subagent_stream_complete_after_run_error_stays_error — Error state is terminal, late StreamCompleteEvent doesn't override
  • All 510 existing opencode_server tests pass (0 regressions)

备份迁移自 SRC-PR#24 · 作者 @Leoyzen · 创建于 2026-04-23T14:09:01Z · head=feature/fix-subagent-interupt base=develop/agentic
源状态: merged · merge_commit_sha=4ba3d75148f1cb1694863891af5c382751ea2e08

Leoyzen and others added 2 commits April 23, 2026 22:08
…rEvent

When a subagent fails, it emits RunErrorEvent which was silently dropped
by EventProcessor.process() - no match arm existed for it. The parent
session's ToolPart stayed in ToolStateRunning forever, making the UI show
the subagent as perpetually running even after it crashed.

Changes:
- Add RunErrorEvent handler in _process_subagent_event() that transitions
  ToolPart from ToolStateRunning to ToolStateError with error message
- Emit SessionErrorEvent for child session (matching TS client behavior)
- Add is_errored flag to EventProcessorContext to prevent subsequent
  StreamCompleteEvent from overriding the error state
- Add TDD tests: error transition, error without prior spawn, error
  state terminal (not overridden by late StreamCompleteEvent)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@Million-mo Million-mo closed this Aug 22, 2026
This was referenced Aug 22, 2026
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.

2 participants