Skip to content

[BUG] task.ts: Effect.orDie orphans subagent sessions after tool error → double processing #31787

Closed as not planned

Description

@hmannekomimi-ctrl2

Description

When task.ts (subagent/subtask tool) encounters an error after starting the subagent session, Effect.orDie silently swallows the error, and the subagent session continues running orphaned in the background while the main agent proceeds with an empty tool result — causing double processing.

Root Cause Chain

1. tool.ts:145 — Framework-level Effect.orDie

All V1 tool executions are wrapped by Effect.orDie in the wrap() function. Any Effect.fail(...) from the tool's execute function becomes a defect instead of a visible error. The main agent receives an empty/malformed result.

2. task.ts — Cleanup only on interrupt, not on defect

The acquireUseRelease block only cancels the subagent on interruption. When Effect.orDie converts an error to a defect, the fiber exit is not an interrupt — it's a defect failure. Exit.hasInterrupts(exit) returns false, so background.cancel(nextSession.id) is never called. The subagent session continues running.

3. runner/llm.ts — Tool fiber failure propagates as run() failure

In the SessionRunner, the tool fiber failure propagates up and causes run() to fail. The orchestrator may retry run(), starting a new main-agent turn while the orphaned subagent is still working → double processing.

Impact

  • Subagent sessions become orphaned background processes
  • Main agent proceeds as if the subtask finished (empty result) or observes a failure
  • Both agents modify the same files/topics simultaneously
  • Token waste from duplicate work
  • Potential data corruption from concurrent file edits

Affected Version

OpenCode v1.17.3 (root cause dates to commit 3910a6e, Apr 23, 2026)

Related Issues

Suggested Fix

Either:

  1. Remove Effect.orDie from tool.ts wrap() so errors propagate visibly (fixes [BUG] V1 tool errors silently swallowed by Effect.orDie - AI never sees error messages #31772)
  2. Or in task.ts, expand cleanup to also handle defect/error exits, not just interrupts:
    • background.cancel(nextSession.id) should run on ANY abnormal exit

Note: This issue was drafted with AI assistance (OpenCode + GLM-5.1) and reviewed by the human reporter.

Activity

  1. github-actions commented on Aug 10, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions