@devries-cameron20 / t3code Mirror · read-only / commits / f54dfc0991
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, 19:30 UTC

fix(cursor): a closed-stream write in the Cursor SDK no longer stops the server (#22897)

Co-authored-by: MarMarLabs <marmar9615@icloud.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Theo Browne committed Oct 21, 2026 at 14:07 UTC f54dfc09915d5fd7ee6476cdf446cd978abc197c
2 files changed +60
packages/provider-cursor/src/server/CursorSdk.test.ts new
+47
@@ -0,0 +1,47 @@
1 +import { assert, describe, it } from "@effect/vitest";
2 +import * as Effect from "effect/Effect";
3 +import * as Layer from "effect/Layer";
4 +import { vi } from "vite-plus/test";
5 +
6 +import * as CursorSdk from "./CursorSdk.ts";
7 +
8 +vi.mock("./sdk.ts", () => ({ Agent: {}, createAgentPlatform: {}, SqliteLocalAgentStore: {} }));
9 +
10 +// Shaped like the SDK's minified class: the constructor is not named after the error.
11 +class o extends Error {
12 + override name = "WriteIterableClosedError";
13 +}
14 +
15 +// Calls the guard directly, with Vitest's own listener detached so the guard does not defer to it.
16 +const rejectThroughGuard = (reason: unknown) =>
17 + Effect.gen(function* () {
18 + const others = process.listeners("unhandledRejection");
19 + yield* Layer.build(CursorSdk.layer);
20 + const guard = process.listeners("unhandledRejection").find((l) => !others.includes(l));
21 + assert.isDefined(guard);
22 + using exit = vi.spyOn(process, "exit").mockImplementation(() => undefined as never);
23 + using _log = vi.spyOn(console, "error").mockImplementation(() => {});
24 + for (const listener of others) process.off("unhandledRejection", listener);
25 + try {
26 + guard(reason, Promise.resolve());
27 + } finally {
28 + for (const listener of others) process.on("unhandledRejection", listener);
29 + }
30 + return exit.mock.calls;
31 + }).pipe(Effect.scoped);
32 +
33 +describe("CursorSdk unhandled rejection guard", () => {
34 + it.effect("keeps the server running when the SDK writes to a closed stream", () =>
35 + Effect.gen(function* () {
36 + assert.deepStrictEqual(yield* rejectThroughGuard(new o("WritableIterable is closed")), []);
37 + }),
38 + );
39 +
40 + it.effect("still exits on other rejections", () =>
41 + Effect.gen(function* () {
42 + assert.deepStrictEqual(yield* rejectThroughGuard(new Error("WritableIterable is closed")), [
43 + [1],
44 + ]);
45 + }),
46 + );
47 +});
packages/provider-cursor/src/server/CursorSdk.ts
+13
@@ -34,11 +34,24 @@ function isCursorShellSpawnFailure(reason: unknown): boolean {
34 );
35 }
36
37 +/**
38 + * After a local exec fails, the SDK writes a final frame to the exec's stream from
39 + * a promise nothing awaits. If that stream has already closed, the write rejects.
40 + * The SDK's class is minified, so only its `name` identifies it.
41 + */
42 +function isCursorClosedStreamWrite(reason: unknown): boolean {
43 + return reason instanceof Error && reason.name === "WriteIterableClosedError";
44 +}
45 +
46 function onUnhandledRejection(reason: unknown): void {
47 if (isCursorShellSpawnFailure(reason)) {
48 console.error("Cursor shell spawn failed. The server will keep running.", reason);
49 return;
50 }
51 + if (isCursorClosedStreamWrite(reason)) {
52 + console.error("Cursor SDK wrote to a closed exec stream. The server will keep running.");
53 + return;
54 + }
55 if (process.listenerCount("unhandledRejection") > 1) {
56 return;
57 }