Skip to content

Commit 0eab160

Browse files
committed
fix(opencode): mark cancelled native tasks interrupted
1 parent 9eaff78 commit 0eab160

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

‎packages/provider-opencode/src/server/adapter.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,34 @@ describe("OpenCodeAdapterV2", () => {
812812
}),
813813
);
814814
}
815+
for (const error of ["Task cancelled", "Task failed"]) {
816+
yield* Effect.promise(() =>
817+
nativeEvents.push({
818+
type: "message.part.updated",
819+
properties: {
820+
sessionID: nativeSessionId,
821+
part: {
822+
id: `part-${error}`,
823+
sessionID: nativeSessionId,
824+
messageID: "late-assistant",
825+
type: "tool",
826+
callID: `call-${error}`,
827+
tool: "task",
828+
state: {
829+
status: "error",
830+
input: {
831+
description: "Sleep task",
832+
prompt: "sleep 120",
833+
subagent_type: "general",
834+
},
835+
error,
836+
time: { start: 7, end: 8 },
837+
},
838+
},
839+
},
840+
}),
841+
);
842+
}
815843
yield* Effect.promise(() =>
816844
nativeEvents.push({
817845
type: "message.part.updated",
@@ -894,6 +922,16 @@ describe("OpenCodeAdapterV2", () => {
894922
);
895923
assert.equal(commands[2]?.output, "/repo\n");
896924
assert.equal(commands[3]?.output, "Command failed");
925+
assert.deepEqual(
926+
items.filter((item) => item.type === "subagent").map((item) => item.status),
927+
["interrupted", "failed"],
928+
);
929+
assert.deepEqual(
930+
events.flatMap((event) =>
931+
event.type === "subagent.updated" ? [event.subagent.status] : [],
932+
),
933+
["interrupted", "failed"],
934+
);
897935
assert.isTrue(
898936
events.some(
899937
(event) =>

‎packages/provider-opencode/src/server/adapter.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,8 @@ function toolStatus(part: ToolPart): {
745745
case "error":
746746
// Stop marks in-flight tools this way; OpenCode's own UI shows them as cancelled.
747747
return part.state.metadata?.["interrupted"] === true ||
748-
part.state.error === "Tool execution aborted"
748+
part.state.error === "Tool execution aborted" ||
749+
(part.tool === "task" && part.state.error === "Task cancelled")
749750
? { node: "interrupted", item: "interrupted" }
750751
: { node: "failed", item: "failed" };
751752
}

0 commit comments

Comments
 (0)