Skip to content

fix(opencode): fail task when child turn ends with an orphaned interrupted tool - #18

Closed
PierrotAWB wants to merge 1 commit into
devfrom
claude/task-fail-on-orphaned-interrupted-tool
Closed

fix(opencode): fail task when child turn ends with an orphaned interrupted tool#18
PierrotAWB wants to merge 1 commit into
devfrom
claude/task-fail-on-orphaned-interrupted-tool

Conversation

@PierrotAWB

@PierrotAWBPierrotAWB commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Issue for this PR

Closes REPL-30868 (Linear — GitHub issues are disabled on this fork, so no # issue exists to link; flagging per the bot's "let a maintainer know" instruction).

Type of change

  • Bug fix

What does this PR do?

When a subagent's LLM stream dies exactly as it opens a tool call (finish=unknown, zero input deltas), cleanup() marks the orphaned tool_use as error + metadata.interrupted and the run loop exits cleanly (upstream anomalyco#26178 behavior, logging WARN "loop exit with orphaned interrupted tool"). The task tool then packaged the dead child as state="completed" with its last mid-work narration as the task_result, so the parent agent treated truncated work as successful.

Real-world impact (replohq/andytown REPL-30868): a write-business-md subagent's stream was severed as it began its final write call; the task returned completed with "…Let me compose the BUSINESS.md briefing.", the parent told the user brand extraction succeeded, and the file never existed — the extracted brand was invisible in Brand Studio.

Fix: runTask in packages/opencode/src/tool/task.ts now inspects the child's final assistant message; if it carries an orphaned interrupted tool part (the exact predicate the run loop's WARN uses), the task fails with an error naming the severed tool and including the partial text. This works because both consumption paths already handle task failure honestly — foreground surfaces a tool error to the parent model, background injects state="error" — so the parent sees a real error and can re-run the task. Detection is scoped to the final message only, so a mid-turn stream retry that recovered (leaving an orphan on an earlier message) does not false-positive.

How did you verify your code works?

  • New test in packages/opencode/test/tool/task.test.ts: a stubbed child turn ending with an orphaned interrupted write tool part makes execute fail, with the error naming the tool and carrying the partial output.
  • bun test test/tool/task.test.ts: 19 pass, 0 fail. bun run typecheck (tsgo) clean in packages/opencode.
  • Note on CI: the failing Truncate > cleanup > deletes files older than 7 days test in test/tool/truncation.test.ts also fails on a clean checkout of dev (verified locally) — pre-existing, unrelated to this change.

Checklist

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

🤖 Generated with Claude Code

…upted tool
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

github-actionsBot commented Aug 19, 2026

Copy link
Copy Markdown

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • No issue referenced. Please add Closes #<number> linking to the relevant issue.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown

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.

@github-actions

Copy link
Copy Markdown

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

@cubic-dev-aicubic-dev-aiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

@github-actions

Copy link
Copy Markdown

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@PierrotAWB