Skip to content

Commit 656f3f4

Browse files
only21milclaude
andauthored
fix(cursor): fail turns that end in a transport error after commentary (pingdotgg#23273)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 6d9ec7b commit 656f3f4

2 files changed

Lines changed: 34 additions & 8 deletions

File tree

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

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,23 @@ describe("CursorAdapterV2", () => {
256256
"Cursor Agent SDK run.wait failed: Too many requests (resource_exhausted, HTTP 429)",
257257
},
258258
},
259-
])("fails the turn with $reason", ({ wait, failure }) =>
259+
{
260+
reason: "a transport dump sent after earlier commentary",
261+
updates: [
262+
{ type: "text-delta", text: "Checking the build first." },
263+
{ type: "step-completed", stepId: 1, stepDurationMs: 1 },
264+
{ type: "text-delta", text: "Error: RetriableError: WritableIterable is closed" },
265+
] satisfies ReadonlyArray<InteractionUpdate>,
266+
wait: Effect.succeed({
267+
id: "native-cursor-run",
268+
requestId: "native-request",
269+
status: "finished" as const,
270+
model: { id: "claude-fable-5" },
271+
durationMs: 1,
272+
}),
273+
failure: { class: "transport_error", message: "Provider turn failed." },
274+
},
275+
])("fails the turn with $reason", ({ updates = [], wait, failure }) =>
260276
Effect.gen(function* () {
261277
const fileSystem = yield* FileSystem.FileSystem;
262278
const workspace = yield* fileSystem.makeTempDirectoryScoped({ prefix: "cursor-v2-failure-" });
@@ -280,12 +296,17 @@ describe("CursorAdapterV2", () => {
280296
agentId: "native-cursor-failure",
281297
listMessages: Effect.succeed([]),
282298
close: Effect.void,
283-
send: () =>
284-
Effect.succeed({
285-
agentId: "native-cursor-failure",
286-
runId: "native-cursor-run",
287-
wait,
288-
cancel: Effect.void,
299+
send: (input) =>
300+
Effect.gen(function* () {
301+
for (const update of updates) {
302+
yield* input.onDelta!(update).pipe(Effect.orDie);
303+
}
304+
return {
305+
agentId: "native-cursor-failure",
306+
runId: "native-cursor-run",
307+
wait,
308+
cancel: Effect.void,
309+
};
289310
}),
290311
}),
291312
}),

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ interface ActiveCursorTurn {
867867
readonly tools: Map<string, ActiveCursorToolCall>;
868868
readonly subagents: Map<string, ActiveCursorSubagent>;
869869
readonly assistant: ActiveCursorTextStream;
870-
readonly assistantReply: CursorTransportFailure;
870+
assistantReply: CursorTransportFailure;
871871
readonly reasoning: ActiveCursorTextStream;
872872
interrupted: boolean;
873873
finalized: boolean;
@@ -1916,6 +1916,11 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
19161916
}
19171917
switch (update.type) {
19181918
case "text-delta":
1919+
// Classify each assistant message on its own, so earlier
1920+
// commentary does not hide a later standalone transport dump.
1921+
if (context.assistant.current === null) {
1922+
context.assistantReply = new CursorTransportFailure();
1923+
}
19191924
context.assistantReply.push(update.text);
19201925
yield* completeReasoning(context);
19211926
yield* appendTextSegment({

0 commit comments

Comments
 (0)