Skip to content

Commit b27bd8b

Browse files
MarcoDotIOclaude
andcommitted
fix(opencode): cancelled todos no longer keep the todo list running
OpenCode marks dropped todos "cancelled". The OpenCode adapter mapped that status to "pending", so a cancelled item looked like outstanding work and a list whose other items were all done never completed. Drop cancelled todos, as the Cursor and Muse adapters already do. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 680152e commit b27bd8b

2 files changed

Lines changed: 75 additions & 11 deletions

File tree

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,62 @@ describe("OpenCodeAdapterV2", () => {
840840
),
841841
);
842842

843+
it.effect("drops cancelled OpenCode todos so a finished list completes", () =>
844+
Effect.gen(function* () {
845+
const nativeEvents = asyncEventStream();
846+
const nativeSessionId = "native-opencode-todos";
847+
const harness = yield* makeOpenCodeRuntimeHarness("todos", nativeSessionId, {
848+
event: {
849+
subscribe: async (_input: unknown, options: { signal?: AbortSignal }) => {
850+
options.signal?.addEventListener("abort", () => nativeEvents.close(), { once: true });
851+
return { stream: nativeEvents.stream };
852+
},
853+
},
854+
mcp: { status: async () => ({ data: {} }) },
855+
session: {
856+
create: async () => ({
857+
data: { id: nativeSessionId, time: { created: 1, updated: 1 } },
858+
}),
859+
promptAsync: async () => ({ data: true }),
860+
},
861+
});
862+
yield* harness.startTurn();
863+
const received = yield* harness.runtime.events.pipe(
864+
Stream.takeUntil((event) => event.type === "plan.updated"),
865+
Stream.runCollect,
866+
Effect.forkScoped,
867+
);
868+
yield* Effect.promise(() =>
869+
nativeEvents.push({
870+
type: "todo.updated",
871+
properties: {
872+
sessionID: nativeSessionId,
873+
todos: [
874+
{ content: "Write the fix", status: "completed", priority: "high" },
875+
{ content: "Try another approach", status: "cancelled", priority: "low" },
876+
{ content: "Add a test", status: "completed", priority: "medium" },
877+
],
878+
},
879+
}),
880+
);
881+
const plan = (yield* Fiber.join(received)).flatMap((event) =>
882+
event.type === "plan.updated" ? [event.plan] : [],
883+
)[0];
884+
assert.ok(plan?.kind === "todo_list");
885+
assert.deepEqual(
886+
plan.steps.map((step) => ({ text: step.text, status: step.status })),
887+
[
888+
{ text: "Write the fix", status: "completed" },
889+
{ text: "Add a test", status: "completed" },
890+
],
891+
);
892+
assert.equal(plan.status, "completed");
893+
}).pipe(
894+
Effect.provide(Layer.merge(IdAllocator.layer, McpProviderSessions.layer)),
895+
Effect.scoped,
896+
),
897+
);
898+
843899
it.effect("presents OpenCode MCP calls without treating remote tools as local edits", () =>
844900
Effect.gen(function* () {
845901
const output =

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,17 +1665,25 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
16651665
driver: OPENCODE_PROVIDER,
16661666
nativeItemId,
16671667
});
1668-
const steps: Array<OrchestrationV2PlanStep> = todos.map((todo, index) => ({
1669-
id: `${nativeItemId}:${index + 1}`,
1670-
text: todo.content.trim() || `Todo ${index + 1}`,
1671-
status:
1672-
todo.status === "completed"
1673-
? "completed"
1674-
: todo.status === "in_progress"
1675-
? "running"
1676-
: "pending",
1677-
}));
1678-
const completed = steps.length > 0 && steps.every((step) => step.status === "completed");
1668+
// A cancelled todo is not outstanding work, and plan steps have no
1669+
// cancelled status, so drop it rather than show it as pending.
1670+
const steps: Array<OrchestrationV2PlanStep> = todos.flatMap((todo, index) =>
1671+
todo.status === "cancelled"
1672+
? []
1673+
: [
1674+
{
1675+
id: `${nativeItemId}:${index + 1}`,
1676+
text: todo.content.trim() || `Todo ${index + 1}`,
1677+
status:
1678+
todo.status === "completed"
1679+
? "completed"
1680+
: todo.status === "in_progress"
1681+
? "running"
1682+
: "pending",
1683+
},
1684+
],
1685+
);
1686+
const completed = todos.length > 0 && steps.every((step) => step.status === "completed");
16791687
yield* emitProviderEvent({
16801688
type: "node.updated",
16811689
driver: OPENCODE_PROVIDER,

0 commit comments

Comments
 (0)