The best way to control Claude Code, Codex and more from any computer or phone
fix(cursor): a write-after-end in the Cursor SDK no longer stops the server (#27703)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 2, 2026 at 18:00 UTC
727a502816601be7fe47b7d33dfd5b8df98145c9
2 files changed
+42
-5
packages/provider-cursor/src/server/CursorSdk.test.ts
+26
@@ -35,6 +35,21 @@ describe("CursorSdk unhandled rejection guard", () => {
35
}),
36
);
37
38
+ it.effect("keeps the server running when the SDK writes after its request stream ended", () =>
39
+ Effect.gen(function* () {
40
+ // Shaped like `ConnectError.from(e, Code.Aborted)` from the SDK's connect-node body pump.
41
+ const cause = Object.assign(new Error("write after end"), {
42
+ code: "ERR_STREAM_WRITE_AFTER_END",
43
+ });
44
+ const reason = Object.assign(new Error("[aborted] write after end", { cause }), {
45
+ name: "ConnectError",
46
+ code: 10,
47
+ rawMessage: "write after end",
48
+ });
49
+ assert.deepStrictEqual(yield* rejectThroughGuard(reason), []);
50
+ }),
51
+ );
52
+
53
it.effect("still exits on other rejections", () =>
54
Effect.gen(function* () {
55
assert.deepStrictEqual(yield* rejectThroughGuard(new Error("WritableIterable is closed")), [
@@ -42,4 +57,15 @@ describe("CursorSdk unhandled rejection guard", () => {
57
]);
58
}),
59
);
60
+
61
+ it.effect("still exits on aborted requests other than a write after end", () =>
62
+ Effect.gen(function* () {
63
+ const cause = Object.assign(new Error("socket hang up"), { code: "ECONNRESET" });
64
+ const reason = Object.assign(new Error("[aborted] socket hang up", { cause }), {
65
+ name: "ConnectError",
66
+ code: 10,
67
+ });
68
+ assert.deepStrictEqual(yield* rejectThroughGuard(reason), [[1]]);
69
+ }),
70
+ );
71
});
packages/provider-cursor/src/server/CursorSdk.ts
+16
-5
@@ -32,12 +32,23 @@ function isCursorShellSpawnFailure(reason: unknown): boolean {
32
}
33
34
/**
35
- * After a local exec fails, the SDK writes a final frame to the exec's stream from
36
- * a promise nothing awaits. If that stream has already closed, the write rejects.
37
- * The SDK's class is minified, so only its `name` identifies it.
35
+ * The SDK writes final frames from promises nothing awaits. A closed stream rejects them
36
+ * with WriteIterableClosedError; an ended request body rejects them with the Aborted
37
+ * ConnectError its connect-node pump wraps around ERR_STREAM_WRITE_AFTER_END. The classes
38
+ * are minified, so only `name` identifies them.
39
*/
40
function isCursorClosedStreamWrite(reason: unknown): boolean {
40
- return reason instanceof Error && reason.name === "WriteIterableClosedError";
41
+ if (!(reason instanceof Error)) {
42
+ return false;
43
+ }
44
+ if (reason.name === "WriteIterableClosedError") {
45
+ return true;
46
+ }
47
+ return (
48
+ reason.name === "ConnectError" &&
49
+ reason.cause instanceof Error &&
50
+ Reflect.get(reason.cause, "code") === "ERR_STREAM_WRITE_AFTER_END"
51
+ );
52
}
53
54
function onUnhandledRejection(reason: unknown): void {
@@ -46,7 +57,7 @@ function onUnhandledRejection(reason: unknown): void {
57
return;
58
}
59
if (isCursorClosedStreamWrite(reason)) {
49
- console.error("Cursor SDK wrote to a closed exec stream. The server will keep running.");
60
+ console.error("Cursor SDK wrote to a closed stream. The server will keep running.");
61
return;
62
}
63
if (process.listenerCount("unhandledRejection") > 1) {