Claude Code. Any Model. The most powerful AI coding agent now speaks every language.
fix(routing): stop a subscription chain on a raw 403 credential rejection
Jack Rudenko45d74c8a9e27
diff --git a/packages/cli/src/handlers/fallback-handler.ts b/packages/cli/src/handlers/fallback-handler.tsindex 5733f8a0..dad939be 100644--- a/packages/cli/src/handlers/fallback-handler.ts+++ b/packages/cli/src/handlers/fallback-handler.ts@@ -320,6 +320,17 @@ export function isRetryableError(if ((status === 401 || recovered === 401) && isCredentialRejection(401, errorBody)) {return false;}+ // A RAW 403 credential rejection stops it too (measured: `403+ // {"error":{"type":"invalid_api_key"}}` from a subscription hop advanced+ // onto the metered `meta@`). Raw only: the upstream body still carries the+ // provider's own `error.type`, so `isCredentialRejection` can tell Zen Go's+ // `403 RegionError` (a model opt-in, which advances) from a dead login. A+ // RECOVERED 403 cannot be told apart that way — claudish's remapped 400+ // body says `invalid_request_error` — so it keeps advancing; a 403 the+ // ComposedHandler placed already carries the terminal verdict header above.+ if (status === 403 && isCredentialRejection(403, errorBody)) {+ return false;+ }}// ── Recover the ORIGINAL status from a remapped terminal error (#148) ──────diff --git a/packages/cli/src/handlers/shared/auth-failure.ts b/packages/cli/src/handlers/shared/auth-failure.tsindex 4e10dcca..71124353 100644--- a/packages/cli/src/handlers/shared/auth-failure.ts+++ b/packages/cli/src/handlers/shared/auth-failure.ts@@ -112,8 +112,9 @@ export function isCredentialRejection(status: number, errorBody: string): boolea/*** The provider's own `error.type` in a raw upstream JSON error body. Read at* the sites that hold the upstream body (the generic remap, settleAuthRetry);- * claudish's remapped 400 does not carry it, and FallbackHandler's own- * subscription rule covers 401 only, so a 403 RegionError advances there too.+ * claudish's remapped 400 does not carry it. FallbackHandler's own+ * subscription rule therefore stops on a RAW 403 (whose body still carries the+ * type, so a 403 RegionError advances) and not on a recovered one.*/function providerErrorType(errorBody: string): string | undefined {try {