Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 60 additions & 6 deletions packages/provider-opencode/src/server/adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -783,26 +783,70 @@ describe("OpenCodeAdapterV2", () => {
error: "Command failed",
time: { start: 3, end: 4 },
},
{
status: "error",
input: { command: "sleep 60" },
error: "Interrupted",
metadata: { interrupted: true },
time: { start: 5, end: 6 },
},
// OpenCode 1.3 reports a stopped tool only through this message.
{
status: "error",
input: { command: "sleep 90" },
error: "Tool execution aborted",
time: { start: 6, end: 7 },
},
] satisfies ReadonlyArray<ToolPart["state"]>;
for (const state of states) {
const callID =
state.status === "error" ? `call-ended-${state.time.start}` : "call-working";
yield* Effect.promise(() =>
nativeEvents.push({
type: "message.part.updated",
properties: {
sessionID: nativeSessionId,
part: {
id: state.status === "error" ? "part-failed" : "part-working",
id: `part-${callID}`,
sessionID: nativeSessionId,
messageID: "late-assistant",
type: "tool",
callID: state.status === "error" ? "call-failed" : "call-working",
callID,
tool: "bash",
state,
},
},
}),
);
}
for (const error of ["Task cancelled", "Task failed"]) {
yield* Effect.promise(() =>
nativeEvents.push({
type: "message.part.updated",
Comment thread
saphid marked this conversation as resolved.
Resolved
properties: {
sessionID: nativeSessionId,
part: {
id: `part-${error}`,
sessionID: nativeSessionId,
messageID: "late-assistant",
type: "tool",
callID: `call-${error}`,
tool: "task",
state: {
status: "error",
input: {
description: "Sleep task",
prompt: "sleep 120",
subagent_type: "general",
},
error,
time: { start: 7, end: 8 },
},
},
},
}),
);
}
yield* Effect.promise(() =>
nativeEvents.push({
type: "message.part.updated",
Expand Down Expand Up @@ -901,21 +945,31 @@ describe("OpenCodeAdapterV2", () => {
const commands = items.filter((item) => item.type === "command_execution");
assert.deepEqual(
commands.map((item) => item.status),
["pending", "running", "completed", "failed", "failed"],
["pending", "running", "completed", "failed", "interrupted", "interrupted", "failed"],
);
assert.deepEqual(
commands.map((item) => item.input),
["pwd", "pwd", "pwd", "pwd", "vp test"],
["pwd", "pwd", "pwd", "pwd", "sleep 60", "sleep 90", "vp test"],
);
assert.equal(commands[2]?.output, "/repo\n");
assert.equal(commands[3]?.output, "Command failed");
assert.equal(commands[4]?.exitCode, 1);
assert.equal(commands[6]?.exitCode, 1);
assert.equal(
events
.flatMap((event) => (event.type === "node.updated" ? [event.node] : []))
.findLast((node) => node.id === commands[4]?.nodeId)?.status,
.findLast((node) => node.id === commands[6]?.nodeId)?.status,
"failed",
);
assert.deepEqual(
items.filter((item) => item.type === "subagent").map((item) => item.status),
["interrupted", "failed"],
);
assert.deepEqual(
events.flatMap((event) =>
event.type === "subagent.updated" ? [event.subagent.status] : [],
),
["interrupted", "failed"],
);
assert.isTrue(
events.some(
(event) =>
Expand Down
16 changes: 7 additions & 9 deletions packages/provider-opencode/src/server/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,12 @@ function toolStatus(part: ToolPart): {
? { node: "failed", item: "failed" }
: { node: "completed", item: "completed" };
case "error":
return { node: "failed", item: "failed" };
// Stop marks in-flight tools this way; OpenCode's own UI shows them as cancelled.
return part.state.metadata?.["interrupted"] === true ||
part.state.error === "Tool execution aborted" ||
(part.tool === "task" && part.state.error === "Task cancelled")
? { node: "interrupted", item: "interrupted" }
: { node: "failed", item: "failed" };
}
}

Expand Down Expand Up @@ -1438,14 +1443,7 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
if (part.state.status === "completed" && output !== undefined) context.result = output;
const status = toolStatus(part);
const completedAt = toolCompletedAt(part, now);
const subagentStatus: OrchestrationV2Subagent["status"] =
status.item === "failed"
? "failed"
: status.item === "completed"
? "completed"
: status.item === "pending"
? "pending"
: "running";
const subagentStatus: OrchestrationV2Subagent["status"] = status.item;
const subagent: OrchestrationV2Subagent = {
id: nodeId,
threadId: turn.threadId,
Expand Down
Loading