Skip to content

Commit 16cb875

Browse files
committed
fix(cursor): check failed_precondition before the overload keywords
Final-round auditor found the #2729 failed_precondition arm did not fire on the shape it exists to catch. It sat AFTER the overload keywords in both classifyCursorError and inferHttpStatusFromAdapterMessage, and a plan-gated rejection normally reads 'failed_precondition: model unavailable for this plan' — which matched 'unavailable' first: classifyCursorError -> 'Cursor server overloaded' inferHttpStatus... -> 503 So clients kept retrying a deterministic rejection that can never succeed, which is the exact misclassification the arm was added to stop. The original test only covered 'Cursor Connect error failed_precondition: Error', which has no competing keyword, so 25/25 passed over the defect. Moved the check ahead of the overload keywords in both functions. The explicit gRPC status is a structured backend signal; 'unavailable' and 'temporarily' next to it are inference over free text. Differential vs origin/dev: exactly one case changes (fp + unavailable, 503 -> 400). Real overloads, auth, rate limit, timeout and invalid-request are all unchanged, and authentication still outranks both. 211 pass / 0 fail across the ten affected suites; tsc exit 0.
1 parent 2483f40 commit 16cb875

3 files changed

Lines changed: 44 additions & 7 deletions

File tree

‎src/adapters/cursor/cursor-errors.ts‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,21 +241,28 @@ export function classifyCursorError(message: string, sizeContext?: CursorSizeCon
241241
lower.includes("access denied")
242242
) return "Cursor authentication failed";
243243

244-
if (
245-
lower.includes("unavailable") ||
246-
lower.includes("overloaded") ||
247-
lower.includes("temporarily") ||
248-
lower.includes("server is busy")
249-
) return "Cursor server overloaded";
250-
251244
// gRPC FAILED_PRECONDITION is deterministic and non-retryable (unlike UNAVAILABLE):
252245
// the backend rejected the call because the account/plan state does not allow it —
253246
// seen live when a plan-gated model (e.g. claude-fable-5) runs on a plan without it.
254247
// Leaving it as "Cursor upstream error" (502) made clients retry it as overload.
248+
//
249+
// This MUST precede the overload keywords. The explicit gRPC status code is a
250+
// structured signal from the backend; the keywords are inference over free text. A
251+
// plan-gated rejection routinely reads "failed_precondition: model unavailable for
252+
// this plan", which matched "unavailable" first and came back as a retryable
253+
// overload — the exact misclassification this branch was added to stop. Checking the
254+
// code first lets the deterministic signal win over the words around it.
255255
if (lower.includes("failed_precondition") || lower.includes("failed precondition")) {
256256
return "Cursor invalid request";
257257
}
258258

259+
if (
260+
lower.includes("unavailable") ||
261+
lower.includes("overloaded") ||
262+
lower.includes("temporarily") ||
263+
lower.includes("server is busy")
264+
) return "Cursor server overloaded";
265+
259266
if (
260267
lower.includes("invalid") ||
261268
lower.includes("not found") ||

‎src/lib/errors.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,12 @@ export function inferHttpStatusFromAdapterMessage(message: string): number {
335335
// subscription/permission wording.
336336
if (isAuthenticationMessage(lower)) return 401;
337337
if (isSubscriptionGateMessage(lower) || isPermissionMessage(lower)) return 403;
338+
// Same precedence rule as classifyCursorError: an explicit gRPC FAILED_PRECONDITION is a
339+
// structured, deterministic rejection, so it outranks the overload keywords that routinely
340+
// appear beside it ("failed_precondition: model unavailable for this plan"). Without this,
341+
// the message matched "unavailable" and returned a retryable 503, so clients kept retrying
342+
// a rejection that can never succeed.
343+
if (lower.includes("failed_precondition") || lower.includes("failed precondition")) return 400;
338344
if (
339345
lower.includes("unavailable") ||
340346
lower.includes("overloaded") ||

‎tests/cursor-errors.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,30 @@ describe("classifyCursorError", () => {
6969
expect(inferHttpStatusFromAdapterMessage("Cursor invalid request: Cursor Connect error failed_precondition: Error")).toBe(400);
7070
});
7171

72+
test("failed_precondition wins over overload keywords in the same message", () => {
73+
// The original arm sat AFTER the overload keywords, so the shape this branch exists
74+
// to catch slipped straight past it: a plan-gated rejection normally reads
75+
// "failed_precondition: model unavailable for this plan", which matched "unavailable"
76+
// first and came back "Cursor server overloaded" -> 503. Clients then retried a
77+
// deterministic rejection forever. The explicit gRPC status is a structured signal
78+
// from the backend; "unavailable" and "temporarily" here are just words near it.
79+
expect(classifyCursorError("failed_precondition: model unavailable for this plan"))
80+
.toBe("Cursor invalid request");
81+
expect(classifyCursorError("failed_precondition: model temporarily gated"))
82+
.toBe("Cursor invalid request");
83+
expect(inferHttpStatusFromAdapterMessage("Cursor invalid request: failed_precondition: model unavailable for this plan"))
84+
.toBe(400);
85+
86+
// A real overload with no gRPC precondition code must still be retryable.
87+
expect(classifyCursorError("service temporarily unavailable")).toBe("Cursor server overloaded");
88+
expect(classifyCursorError("backend overloaded, retry")).toBe("Cursor server overloaded");
89+
expect(classifyCursorError("server is busy")).toBe("Cursor server overloaded");
90+
91+
// Authentication is checked earlier and stays authoritative over both.
92+
expect(classifyCursorError("failed_precondition: unauthorized token"))
93+
.toBe("Cursor authentication failed");
94+
});
95+
7296
test("timeout / deadline", () => {
7397
expect(classifyCursorError("Cursor transport timed out before first response")).toBe("Cursor request timed out");
7498
expect(classifyCursorError("deadline exceeded")).toBe("Cursor request timed out");

0 commit comments

Comments
 (0)