TypeScript
fix(cursor): fail turns that end in a transport error after commentary (#23273)
Victor Vogel656f3f409456
diff --git a/packages/provider-cursor/src/server/adapter.test.ts b/packages/provider-cursor/src/server/adapter.test.tsindex a297af469cf..0686b0c831d 100644--- a/packages/provider-cursor/src/server/adapter.test.ts+++ b/packages/provider-cursor/src/server/adapter.test.ts@@ -256,7 +256,23 @@ describe("CursorAdapterV2", () => {"Cursor Agent SDK run.wait failed: Too many requests (resource_exhausted, HTTP 429)",},},- ])("fails the turn with $reason", ({ wait, failure }) =>+ {+ reason: "a transport dump sent after earlier commentary",+ updates: [+ { type: "text-delta", text: "Checking the build first." },+ { type: "step-completed", stepId: 1, stepDurationMs: 1 },+ { type: "text-delta", text: "Error: RetriableError: WritableIterable is closed" },+ ] satisfies ReadonlyArray<InteractionUpdate>,+ wait: Effect.succeed({+ id: "native-cursor-run",+ requestId: "native-request",+ status: "finished" as const,+ model: { id: "claude-fable-5" },+ durationMs: 1,+ }),+ failure: { class: "transport_error", message: "Provider turn failed." },+ },+ ])("fails the turn with $reason", ({ updates = [], wait, failure }) =>Effect.gen(function* () {const fileSystem = yield* FileSystem.FileSystem;const workspace = yield* fileSystem.makeTempDirectoryScoped({ prefix: "cursor-v2-failure-" });@@ -280,12 +296,17 @@ describe("CursorAdapterV2", () => {agentId: "native-cursor-failure",listMessages: Effect.succeed([]),close: Effect.void,- send: () =>- Effect.succeed({- agentId: "native-cursor-failure",- runId: "native-cursor-run",- wait,- cancel: Effect.void,+ send: (input) =>+ Effect.gen(function* () {+ for (const update of updates) {+ yield* input.onDelta!(update).pipe(Effect.orDie);+ }+ return {+ agentId: "native-cursor-failure",+ runId: "native-cursor-run",+ wait,+ cancel: Effect.void,+ };}),}),}),diff --git a/packages/provider-cursor/src/server/adapter.ts b/packages/provider-cursor/src/server/adapter.tsindex 9ff5ba75f46..825596c04e6 100644--- a/packages/provider-cursor/src/server/adapter.ts+++ b/packages/provider-cursor/src/server/adapter.ts@@ -867,7 +867,7 @@ interface ActiveCursorTurn {readonly tools: Map<string, ActiveCursorToolCall>;readonly subagents: Map<string, ActiveCursorSubagent>;readonly assistant: ActiveCursorTextStream;- readonly assistantReply: CursorTransportFailure;+ assistantReply: CursorTransportFailure;readonly reasoning: ActiveCursorTextStream;interrupted: boolean;finalized: boolean;@@ -1916,6 +1916,11 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (}switch (update.type) {case "text-delta":+ // Classify each assistant message on its own, so earlier+ // commentary does not hide a later standalone transport dump.+ if (context.assistant.current === null) {+ context.assistantReply = new CursorTransportFailure();+ }context.assistantReply.push(update.text);yield* completeReasoning(context);yield* appendTextSegment({