@devries-cameron20 / t3code Mirror · read-only / commits / 43dfdcc84e
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 03:15 UTC

fix(opencode): tools stopped mid-run show as interrupted, not failed (#29762)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>

Alex Southwell committed Nov 6, 2026 at 04:24 UTC 43dfdcc84eb2f0bddeca9e4e1659c6c35e8fcf03
2 files changed +67 -15
packages/provider-opencode/src/server/adapter.test.ts
+60 -6
@@ -784,19 +784,35 @@ describe("OpenCodeAdapterV2", () => {
784 error: "Command failed",
785 time: { start: 3, end: 4 },
786 },
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 + },
801 ] satisfies ReadonlyArray<ToolPart["state"]>;
802 for (const state of states) {
803 + const callID =
804 + state.status === "error" ? `call-ended-${state.time.start}` : "call-working";
805 yield* Effect.promise(() =>
806 nativeEvents.push({
807 type: "message.part.updated",
808 properties: {
809 sessionID: nativeSessionId,
810 part: {
795 - id: state.status === "error" ? "part-failed" : "part-working",
811 + id: `part-${callID}`,
812 sessionID: nativeSessionId,
813 messageID: "late-assistant",
814 type: "tool",
799 - callID: state.status === "error" ? "call-failed" : "call-working",
815 + callID,
816 tool: "bash",
817 state,
818 },
@@ -804,6 +820,34 @@ describe("OpenCodeAdapterV2", () => {
820 }),
821 );
822 }
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 + }
851 yield* Effect.promise(() =>
852 nativeEvents.push({
853 type: "message.part.updated",
@@ -902,21 +946,31 @@ describe("OpenCodeAdapterV2", () => {
946 const commands = items.filter((item) => item.type === "command_execution");
947 assert.deepEqual(
948 commands.map((item) => item.status),
905 - ["pending", "running", "completed", "failed", "failed"],
949 + ["pending", "running", "completed", "failed", "interrupted", "interrupted", "failed"],
950 );
951 assert.deepEqual(
952 commands.map((item) => item.input),
909 - ["pwd", "pwd", "pwd", "pwd", "vp test"],
953 + ["pwd", "pwd", "pwd", "pwd", "sleep 60", "sleep 90", "vp test"],
954 );
955 assert.equal(commands[2]?.output, "/repo\n");
956 assert.equal(commands[3]?.output, "Command failed");
913 - assert.equal(commands[4]?.exitCode, 1);
957 + assert.equal(commands[6]?.exitCode, 1);
958 assert.equal(
959 events
960 .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,
962 "failed",
963 );
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 + );
974 assert.isTrue(
975 events.some(
976 (event) =>
packages/provider-opencode/src/server/adapter.ts
+7 -9
@@ -747,7 +747,12 @@ function toolStatus(part: ToolPart): {
747 ? { node: "failed", item: "failed" }
748 : { node: "completed", item: "completed" };
749 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" };
756 }
757 }
758
@@ -1439,14 +1444,7 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
1444 if (part.state.status === "completed" && output !== undefined) context.result = output;
1445 const status = toolStatus(part);
1446 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;
1448 const subagent: OrchestrationV2Subagent = {
1449 id: nodeId,
1450 threadId: turn.threadId,