Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/provider-cursor/src/server/CursorSdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ describe("CursorSdk unhandled rejection guard", () => {
}),
);

it.effect("keeps the server running when the SDK aborts a stalled request", () =>
Effect.gen(function* () {
const stall = new DOMException("This operation was aborted", "AbortError");
stall.stack = "AbortError: This operation was aborted\n at Is.onStall (689.js:1:111536)";
assert.deepStrictEqual(yield* rejectThroughGuard(stall), []);
}),
);

it.effect("still exits on an abort that did not come from the stall detector", () =>
Effect.gen(function* () {
const abort = new DOMException("This operation was aborted", "AbortError");
abort.stack = "AbortError: This operation was aborted\n at somewhereElse (app.js:1:1)";
assert.deepStrictEqual(yield* rejectThroughGuard(abort), [[1]]);
}),
);

it.effect("still exits on other rejections", () =>
Effect.gen(function* () {
assert.deepStrictEqual(yield* rejectThroughGuard(new Error("WritableIterable is closed")), [
Expand Down
18 changes: 18 additions & 0 deletions packages/provider-cursor/src/server/CursorSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ function isCursorClosedStreamWrite(reason: unknown): boolean {
return reason instanceof Error && reason.name === "WriteIterableClosedError";
}

/**
* When the SDK's stall detector fires it aborts the request, then rejects a promise
* nothing awaits. The abort is the SDK's own recovery, so it must not stop the server.
* Only an abort raised from `onStall` counts; any other AbortError is still unexpected.
*/
function isCursorStallAbort(reason: unknown): boolean {
return (
reason instanceof Error &&
reason.name === "AbortError" &&
typeof reason.stack === "string" &&
/\bonStall\b/.test(reason.stack)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
);
}

function onUnhandledRejection(reason: unknown): void {
if (isCursorShellSpawnFailure(reason)) {
console.error("Cursor shell spawn failed. The server will keep running.", reason);
Expand All @@ -52,6 +66,10 @@ function onUnhandledRejection(reason: unknown): void {
console.error("Cursor SDK wrote to a closed exec stream. The server will keep running.");
return;
}
if (isCursorStallAbort(reason)) {
console.error("Cursor SDK aborted a stalled request. The server will keep running.");
return;
}
if (process.listenerCount("unhandledRejection") > 1) {
return;
}
Expand Down
Loading