From 2474be429e62f19e6b00e5710870b766177e65bf Mon Sep 17 00:00:00 2001 From: CreatorGhost Date: Sun, 12 Jul 2026 00:52:51 +0530 Subject: [PATCH] fix(task): cancel subagent on any abnormal tool exit Ported from upstream anomalyco/opencode#36358. --- packages/opencode/src/tool/task.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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(