Skip to content

Commit 43dfdcc

Browse files
saphidclaudemaria-rcks
authored
fix(opencode): tools stopped mid-run show as interrupted, not failed (pingdotgg#29762)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 8dbf262 commit 43dfdcc

2 files changed

Lines changed: 67 additions & 15 deletions

File tree

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

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -784,26 +784,70 @@ describe("OpenCodeAdapterV2", () => {
784784
error: "Command failed",
785785
time: { start: 3, end: 4 },
786786
},
787+
{
788+
status: "error",
789+
input: { command: "sleep 60" },
790+
error: "Interrupted",
791+
metadata: { interrupted: true },
792+
time: { start: 5, end: 6 },
793+
},
794+
// OpenCode 1.3 reports a stopped tool only through this message.
795+
{
796+
status: "error",
797+
input: { command: "sleep 90" },
798+
error: "Tool execution aborted",
799+
time: { start: 6, end: 7 },
800+
},
787801
] satisfies ReadonlyArray<ToolPart["state"]>;
788802
for (const state of states) {
803+
const callID =
804+
state.status === "error" ? `call-ended-${state.time.start}` : "call-working";
789805
yield* Effect.promise(() =>
790806
nativeEvents.push({
791807
type: "message.part.updated",
792808
properties: {
793809
sessionID: nativeSessionId,
794810
part: {
795-
id: state.status === "error" ? "part-failed" : "part-working",
811+
id: `part-${callID}`,
796812
sessionID: nativeSessionId,
797813
messageID: "late-assistant",
798814
type: "tool",
799-
callID: state.status === "error" ? "call-failed" : "call-working",
815+
callID,
800816
tool: "bash",
801817
state,
802818
},
803819
},
804820
}),
805821
);
806822
}
823+
for (const error of ["Task cancelled", "Task failed"]) {
824+
yield* Effect.promise(() =>
825+
nativeEvents.push({
826+
type: "message.part.updated",
827+
properties: {
828+
sessionID: nativeSessionId,
829+
part: {
830+
id: `part-${error}`,
831+
sessionID: nativeSessionId,
832+
messageID: "late-assistant",
833+
type: "tool",
834+
callID: `call-${error}`,
835+
tool: "task",
836+
state: {
837+
status: "error",
838+
input: {
839+
description: "Sleep task",
840+
prompt: "sleep 120",
841+
subagent_type: "general",
842+
},
843+
error,
844+
time: { start: 7, end: 8 },
845+
},
846+
},
847+
},
848+
}),
849+
);
850+
}
807851
yield* Effect.promise(() =>
808852
nativeEvents.push({
809853
type: "message.part.updated",
@@ -902,21 +946,31 @@ describe("OpenCodeAdapterV2", () => {
902946
const commands = items.filter((item) => item.type === "command_execution");
903947
assert.deepEqual(
904948
commands.map((item) => item.status),
905-
["pending", "running", "completed", "failed", "failed"],
949+
["pending", "running", "completed", "failed", "interrupted", "interrupted", "failed"],
906950
);
907951
assert.deepEqual(
908952
commands.map((item) => item.input),
909-
["pwd", "pwd", "pwd", "pwd", "vp test"],
953+
["pwd", "pwd", "pwd", "pwd", "sleep 60", "sleep 90", "vp test"],
910954
);
911955
assert.equal(commands[2]?.output, "/repo\n");
912956
assert.equal(commands[3]?.output, "Command failed");
913-
assert.equal(commands[4]?.exitCode, 1);
957+
assert.equal(commands[6]?.exitCode, 1);
914958
assert.equal(
915959
events
916960
.flatMap((event) => (event.type === "node.updated" ? [event.node] : []))
917-
.findLast((node) => node.id === commands[4]?.nodeId)?.status,
961+
.findLast((node) => node.id === commands[6]?.nodeId)?.status,
918962
"failed",
919963
);
964+
assert.deepEqual(
965+
items.filter((item) => item.type === "subagent").map((item) => item.status),
966+
["interrupted", "failed"],
967+
);
968+
assert.deepEqual(
969+
events.flatMap((event) =>
970+
event.type === "subagent.updated" ? [event.subagent.status] : [],
971+
),
972+
["interrupted", "failed"],
973+
);
920974
assert.isTrue(
921975
events.some(
922976
(event) =>

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,12 @@ function toolStatus(part: ToolPart): {
747747
? { node: "failed", item: "failed" }
748748
: { node: "completed", item: "completed" };
749749
case "error":
750-
return { node: "failed", item: "failed" };
750+
// Stop marks in-flight tools this way; OpenCode's own UI shows them as cancelled.
751+
return part.state.metadata?.["interrupted"] === true ||
752+
part.state.error === "Tool execution aborted" ||
753+
(part.tool === "task" && part.state.error === "Task cancelled")
754+
? { node: "interrupted", item: "interrupted" }
755+
: { node: "failed", item: "failed" };
751756
}
752757
}
753758

@@ -1439,14 +1444,7 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
14391444
if (part.state.status === "completed" && output !== undefined) context.result = output;
14401445
const status = toolStatus(part);
14411446
const completedAt = toolCompletedAt(part, now);
1442-
const subagentStatus: OrchestrationV2Subagent["status"] =
1443-
status.item === "failed"
1444-
? "failed"
1445-
: status.item === "completed"
1446-
? "completed"
1447-
: status.item === "pending"
1448-
? "pending"
1449-
: "running";
1447+
const subagentStatus: OrchestrationV2Subagent["status"] = status.item;
14501448
const subagent: OrchestrationV2Subagent = {
14511449
id: nodeId,
14521450
threadId: turn.threadId,

0 commit comments

Comments
 (0)