diff --git a/packages/opencode/src/tool/task.ts b/packages/opencode/src/tool/task.ts index 94fca0e99d15..605aea7a7333 100644 --- a/packages/opencode/src/tool/task.ts +++ b/packages/opencode/src/tool/task.ts @@ -386,7 +386,10 @@ export const TaskTool = Tool.define( }), (_, exit) => Effect.gen(function* () { - if (Exit.hasInterrupts(exit)) + // Cancel on any abnormal exit (interrupt, fail, or die). Limiting cleanup to + // interrupts left subagent sessions orphaned when Effect.orDie converted tool + // errors into defects, so the parent continued while the child kept running. + if (Exit.isFailure(exit)) yield* Effect.all([cancel, background.cancel(nextSession.id)], { discard: true }) }).pipe( Effect.ensuring(