@devries-cameron20 / t3code Mirror · read-only / commits / be1d066732
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, 18:15 UTC

fix(provider-cursor): finished Cursor turns no longer end in Provider error after the SDK's late resume (#24231)

Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

shivam committed Oct 25, 2026 at 02:23 UTC be1d0667320de371db76221d011a65ca7adb2bfe
2 files changed +110 -10
packages/provider-cursor/src/server/adapter.test.ts
+72 -9
@@ -272,7 +272,62 @@ describe("CursorAdapterV2", () => {
272 }),
273 failure: { class: "transport_error", message: "Provider turn failed." },
274 },
275 - ])("fails the turn with $reason", ({ updates = [], wait, failure }) =>
275 + {
276 + reason: "no failure when Cursor's resume after the turn ended made no progress",
277 + // Cursor's SDK resumed from an older checkpoint after the answer was
278 + // delivered, regenerated the closing, then gave up on the run.
279 + updates: [
280 + { type: "text-delta", text: "The answer." },
281 + { type: "turn-ended" },
282 + { type: "text-delta", text: "A regenerated closing." },
283 + { type: "turn-ended" },
284 + ] satisfies ReadonlyArray<InteractionUpdate>,
285 + wait: Effect.succeed({
286 + id: "native-cursor-run",
287 + requestId: "native-request",
288 + status: "error" as const,
289 + error: { message: "Agent turn stopped after repeated resume attempts made no progress" },
290 + model: { id: "claude-fable-5" },
291 + durationMs: 1,
292 + }),
293 + failure: null,
294 + },
295 + {
296 + reason: "the error a continuation after the turn ended stopped with",
297 + updates: [
298 + { type: "text-delta", text: "The answer." },
299 + { type: "turn-ended" },
300 + { type: "text-delta", text: "Following up on the stop hook." },
301 + ] satisfies ReadonlyArray<InteractionUpdate>,
302 + wait: Effect.succeed({
303 + id: "native-cursor-run",
304 + requestId: "native-request",
305 + status: "error" as const,
306 + error: { message: "Agent turn stopped after repeated resume attempts made no progress" },
307 + model: { id: "claude-fable-5" },
308 + durationMs: 1,
309 + }),
310 + failure: {
311 + class: "provider_error",
312 + message: "Agent turn stopped after repeated resume attempts made no progress",
313 + },
314 + },
315 + {
316 + reason: "no answer from a resume after the turn ended that made no progress",
317 + updates: [{ type: "turn-ended" }] satisfies ReadonlyArray<InteractionUpdate>,
318 + wait: Effect.succeed({
319 + id: "native-cursor-run",
320 + requestId: "native-request",
321 + status: "error" as const,
322 + error: { message: "Agent turn stopped after repeated resume attempts made no progress" },
323 + result: "A regenerated closing.",
324 + model: { id: "claude-fable-5" },
325 + durationMs: 1,
326 + }),
327 + failure: null,
328 + answers: [],
329 + },
330 + ])("ends the turn with $reason", ({ updates = [], wait, failure, answers }) =>
331 Effect.gen(function* () {
332 const fileSystem = yield* FileSystem.FileSystem;
333 const workspace = yield* fileSystem.makeTempDirectoryScoped({ prefix: "cursor-v2-failure-" });
@@ -365,15 +420,23 @@ describe("CursorAdapterV2", () => {
420 attachments: [],
421 },
422 });
368 - const terminal = yield* runtime.events.pipe(
369 - Stream.filter((event) => event.type === "turn.terminal"),
370 - Stream.runHead,
423 + const events = yield* runtime.events.pipe(
424 + Stream.takeUntil((event) => event.type === "turn.terminal"),
425 + Stream.runCollect,
426 );
372 - assert.isTrue(Option.isSome(terminal));
373 - if (Option.isSome(terminal)) {
374 - assert.equal(terminal.value.status, "failed");
375 - assert.equal(terminal.value.failure?.class, failure.class);
376 - assert.equal(terminal.value.failure?.message, failure.message);
427 + const terminal = events.find((event) => event.type === "turn.terminal");
428 + assert.equal(terminal?.status, failure === null ? "completed" : "failed");
429 + assert.equal(terminal?.failure?.class, failure?.class);
430 + assert.equal(terminal?.failure?.message, failure?.message);
431 + if (answers !== undefined) {
432 + assert.deepEqual(
433 + events.flatMap((event) =>
434 + event.type === "message.updated" && event.message.role === "assistant"
435 + ? [event.message.text]
436 + : [],
437 + ),
438 + answers,
439 + );
440 }
441 }).pipe(
442 Effect.scoped,
packages/provider-cursor/src/server/adapter.ts
+38 -1
@@ -824,6 +824,11 @@ interface CursorProjectionTarget {
824 // Fallback final output when Cursor's result carries none. The persisted row only
825 // ever shows a bounded tail, so keep a little more than that.
826 const MAX_CURSOR_STREAMED_OUTPUT_CHARS = 256 * 1024;
827 +// After a turn ends, a retryable stream error can make Cursor's SDK resume from
828 +// an older checkpoint inside the same run. When those resumes save nothing, it
829 +// ends the run with this error even though the answer was already delivered.
830 +const CURSOR_RESUME_NO_PROGRESS_MESSAGE =
831 + "Agent turn stopped after repeated resume attempts made no progress";
832
833 interface ActiveCursorToolCall {
834 readonly callId: string;
@@ -871,6 +876,8 @@ interface ActiveCursorTurn {
876 readonly reasoning: ActiveCursorTextStream;
877 interrupted: boolean;
878 finalized: boolean;
879 + /** The agent's latest turn ended and no new work has started since. */
880 + turnEnded: boolean;
881 }
882
883 interface CursorLiveAgent {
@@ -1914,6 +1921,18 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
1921 if (context.finalized) {
1922 return;
1923 }
1924 + if (update.type === "turn-ended") {
1925 + context.turnEnded = true;
1926 + } else if (
1927 + update.type === "step-started" ||
1928 + update.type === "user-message-appended" ||
1929 + update.type === "text-delta" ||
1930 + update.type === "thinking-delta" ||
1931 + update.type === "partial-tool-call" ||
1932 + update.type === "tool-call-started"
1933 + ) {
1934 + context.turnEnded = false;
1935 + }
1936 switch (update.type) {
1937 case "text-delta":
1938 // Classify each assistant message on its own, so earlier
@@ -2099,6 +2118,11 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
2118 yield* Deferred.succeed(input.context.completed, undefined);
2119 });
2120
2121 + const isResumeFailureAfterTurnEnded = (context: ActiveCursorTurn, result: RunResult) =>
2122 + context.turnEnded &&
2123 + result.status === "error" &&
2124 + result.error?.message === CURSOR_RESUME_NO_PROGRESS_MESSAGE;
2125 +
2126 const terminalStatus = (
2127 context: ActiveCursorTurn,
2128 result: RunResult,
@@ -2115,7 +2139,7 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
2139 case "cancelled":
2140 return "cancelled";
2141 case "error":
2118 - return "failed";
2142 + return isResumeFailureAfterTurnEnded(context, result) ? "completed" : "failed";
2143 }
2144 };
2145
@@ -2319,6 +2343,7 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
2343 },
2344 interrupted: false,
2345 finalized: false,
2346 + turnEnded: false,
2347 };
2348 yield* Ref.set(activeTurn, context);
2349 yield* emitProviderEvent({
@@ -2350,6 +2375,8 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
2375 if (
2376 context !== null &&
2377 context.assistant.nextSegment === 0 &&
2378 + // Text from a resume that made no progress is not the turn's answer.
2379 + !isResumeFailureAfterTurnEnded(context, result) &&
2380 result.result !== undefined &&
2381 result.result.length > 0
2382 ) {
@@ -2361,6 +2388,16 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
2388 text: result.result,
2389 });
2390 }
2391 + if (context !== null && isResumeFailureAfterTurnEnded(context, result)) {
2392 + yield* Effect.logWarning(
2393 + "orchestration-v2.cursor-resume-failed-after-turn-ended",
2394 + {
2395 + providerSessionId: input.providerSessionId,
2396 + providerThreadId: turnInput.providerThread.id,
2397 + providerTurnId,
2398 + },
2399 + );
2400 + }
2401 if (context !== null) {
2402 const transportFailure = context.assistantReply.failure;
2403 const status =