Skip to content

Commit a7192c6

Browse files
Huijirocursoragent
andcommitted
fix(cursor): keep summarize wait from stealing send answers
Do not treat startTurn result.result as a compaction summary when mid-run summary updates set context.compaction. Emit late summarize wait results, classify usage limits on compact, and cover the stream pump in the SDK runner test. Co-authored-by: Cursor <[email protected]>
1 parent 2edaf45 commit a7192c6

2 files changed

Lines changed: 60 additions & 13 deletions

File tree

‎packages/provider-cursor/src/server/CursorAgentSdk.test.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,34 @@ const cursorSdkMock = vi.hoisted(() => {
4949
agentId: "agent-cursor-agent-sdk-test",
5050
wait: runWait,
5151
cancel: runCancel,
52+
stream: async function* () {},
5253
};
5354
},
5455
);
56+
const summarize = vi.fn(async () => {
57+
runOperations.push("run.summarize");
58+
return {
59+
id: "run-cursor-agent-sdk-summarize",
60+
agentId: "agent-cursor-agent-sdk-test",
61+
wait: runWait,
62+
cancel: runCancel,
63+
stream: async function* () {
64+
yield { type: "summary", status: "running" };
65+
yield { type: "summary", status: "completed" };
66+
yield { type: "summary", status: "error" };
67+
},
68+
};
69+
});
5570
const create = vi.fn(async () => ({
5671
agentId: "agent-cursor-agent-sdk-test",
5772
send,
73+
summarize,
5874
close: agentClose,
5975
}));
6076
const resume = vi.fn(async () => ({
6177
agentId: "agent-cursor-agent-sdk-test",
6278
send,
79+
summarize,
6380
close: agentClose,
6481
}));
6582
const listRuns = vi.fn(async () => {
@@ -84,6 +101,7 @@ const cursorSdkMock = vi.hoisted(() => {
84101
runCancel,
85102
runWait,
86103
send,
104+
summarize,
87105
setAgentCloseFailure: (failure: unknown) => {
88106
agentCloseFailure = failure;
89107
},
@@ -172,4 +190,37 @@ describe("CursorAgentSdkRunner", () => {
172190
]);
173191
}).pipe(Effect.provide(layerTest)),
174192
);
193+
194+
it.effect("pumps summarize stream updates without deadlocking wait", () =>
195+
Effect.gen(function* () {
196+
cursorSdkMock.runOperations.length = 0;
197+
cursorSdkMock.summarize.mockClear();
198+
cursorSdkMock.setStaleRunActive(false);
199+
200+
const updates: Array<unknown> = [];
201+
const runner = yield* CursorAgentSdk.CursorAgentSdkRunner;
202+
const session = yield* runner.open({
203+
operation: "create",
204+
options: { model: { id: "default" }, mode: "agent", local: { cwd: process.cwd() } },
205+
threadId: ThreadId.make("thread-cursor-agent-sdk-summarize-test"),
206+
providerSessionId: ProviderSessionId.make(
207+
"provider-session-cursor-agent-sdk-summarize-test",
208+
),
209+
});
210+
const run = yield* session.summarize({
211+
onDelta: (update) =>
212+
Effect.sync(() => {
213+
updates.push(update);
214+
}),
215+
});
216+
yield* run.wait;
217+
218+
assert.deepStrictEqual(cursorSdkMock.runOperations, ["run.summarize"]);
219+
assert.deepStrictEqual(updates, [
220+
{ type: "summary-started" },
221+
{ type: "summary-completed" },
222+
{ type: "summary-completed", failed: true },
223+
]);
224+
}).pipe(Effect.provide(layerTest)),
225+
);
175226
});

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2574,17 +2574,7 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
25742574
yield* sdkRun.wait.pipe(
25752575
Effect.flatMap((result) =>
25762576
Effect.gen(function* () {
2577-
if (context !== null && context.compaction !== null) {
2578-
if (result.result !== undefined && result.result.length > 0) {
2579-
context.compaction.summary = result.result;
2580-
}
2581-
if (context.compaction.status === "running") {
2582-
context.compaction.status =
2583-
result.status === "finished" ? "completed" : "failed";
2584-
context.compaction.failed = result.status !== "finished";
2585-
yield* emitCompactionItem(context);
2586-
}
2587-
} else if (
2577+
if (
25882578
context !== null &&
25892579
context.assistant.nextSegment === 0 &&
25902580
// Text from a resume that made no progress is not the turn's answer.
@@ -2881,6 +2871,8 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
28812871
result.status === "finished" ? "completed" : "failed";
28822872
context.compaction!.failed = result.status !== "finished";
28832873
yield* emitCompactionItem(context);
2874+
} else if (result.result !== undefined && result.result.length > 0) {
2875+
yield* emitCompactionItem(context);
28842876
}
28852877
yield* finalizeTurn({
28862878
context,
@@ -2890,7 +2882,9 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
28902882
failure: makeProviderFailure({
28912883
cause: result.error,
28922884
message: result.error?.message,
2893-
class: "provider_error",
2885+
class: CursorAgentSdk.isCursorUsageLimitError(result.error)
2886+
? "usage_limit"
2887+
: "provider_error",
28942888
}),
28952889
}
28962890
: {}),
@@ -2916,7 +2910,9 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
29162910
message: CursorAgentSdk.isCursorAgentSdkRunnerError(cause)
29172911
? CursorAgentSdk.cursorSdkFailureMessage(cause)
29182912
: undefined,
2919-
class: "transport_error",
2913+
class: CursorAgentSdk.isCursorUsageLimitError(cause)
2914+
? "usage_limit"
2915+
: "transport_error",
29202916
}),
29212917
}),
29222918
});

0 commit comments

Comments
 (0)