Skip to content
TypeScript

fix(cursor): avoid reporting unfinished tool calls as successful (#21448)

Victor Vogel481ff3ea89c7
diff --git a/packages/provider-cursor/src/server/adapter.test.ts b/packages/provider-cursor/src/server/adapter.test.ts
index 790dd0e4415..5318e160f61 100644
--- a/packages/provider-cursor/src/server/adapter.test.ts
+++ b/packages/provider-cursor/src/server/adapter.test.ts
@@ -43,7 +43,7 @@ describe("CursorAdapterV2", () => {
{ status: "finished", model: undefined, lateModel: "gpt-6-sol" },
{ status: "finished", model: "gpt-6-sol", lateModel: null },
] as const)(
- "projects Cursor tasks: $status, late model $lateModel",
+ "projects Cursor tasks and unfinished tools: $status, late model $lateModel",
({ status, model, lateModel }) =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
@@ -115,6 +115,34 @@ describe("CursorAdapterV2", () => {
},
}).pipe(Effect.orDie);
}
+ const readUpdates: ReadonlyArray<InteractionUpdate> = [
+ {
+ type: "tool-call-started",
+ modelCallId: "native-model-call",
+ callId: "read-secret",
+ toolCall: { type: "read", args: { path: "secret.txt" } },
+ },
+ ...(["tool-call-started", "tool-call-completed"] as const).map((type) => ({
+ type,
+ modelCallId: "native-model-call",
+ callId: "read-open",
+ toolCall: {
+ type: "read" as const,
+ args: { path: "open.txt" },
+ ...(type === "tool-call-completed"
+ ? {
+ result: {
+ status: "success" as const,
+ value: { fileSize: 3, content: "ok\n", totalLines: 1 },
+ },
+ }
+ : {}),
+ },
+ })),
+ ];
+ for (const update of readUpdates) {
+ yield* input.onDelta!(update).pipe(Effect.orDie);
+ }
return {
agentId: "native-cursor-lifecycle",
runId: "native-cursor-run",
@@ -205,6 +233,40 @@ describe("CursorAdapterV2", () => {
: "failed",
);
assert.isNotNull(rows.at(-1)?.subagent.completedAt);
+ const unfinished =
+ status === "finished" ? "interrupted" : status === "error" ? "failed" : "cancelled";
+ const finalReads = new Map<string, { status: string; output: unknown; done: boolean }>();
+ for (const event of events) {
+ if (
+ event.type === "turn_item.updated" &&
+ event.turnItem.type === "dynamic_tool" &&
+ event.turnItem.toolName === "Read"
+ ) {
+ finalReads.set(String(event.turnItem.title), {
+ status: event.turnItem.status,
+ output: event.turnItem.output,
+ done: event.turnItem.completedAt !== null,
+ });
+ }
+ }
+ const finalNodes = new Map<string, string>();
+ for (const event of events) {
+ if (event.type === "node.updated" && event.node.kind === "tool_call") {
+ finalNodes.set(String(event.node.nativeItemRef?.nativeId), event.node.status);
+ }
+ }
+ assert.deepEqual(Object.fromEntries(finalReads), {
+ "Read secret.txt": { status: unfinished, output: undefined, done: true },
+ "Read open.txt": {
+ status: "completed",
+ output: { fileSize: 3, content: "ok\n", totalLines: 1 },
+ done: true,
+ },
+ });
+ assert.deepEqual(Object.fromEntries(finalNodes), {
+ "read-secret": unfinished,
+ "read-open": "completed",
+ });
}).pipe(
Effect.scoped,
Effect.provide(
diff --git a/packages/provider-cursor/src/server/adapter.ts b/packages/provider-cursor/src/server/adapter.ts
index 03f346d9a6d..ab6afddb4b8 100644
--- a/packages/provider-cursor/src/server/adapter.ts
+++ b/packages/provider-cursor/src/server/adapter.ts
@@ -2113,7 +2113,8 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
yield* emitToolArtifacts({
active: tool,
completed: true,
- ...(input.status === "completed" ? {} : { unfinishedStatus: input.status }),
+ // No completion event means the tool outcome is unknown.
+ unfinishedStatus: input.status === "completed" ? "interrupted" : input.status,
});
}
input.context.tools.clear();