Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(mcp-host): map 403 to the auth failover class across all arms (R1-M1)

Diego Zacariasc4a7c28e3b06
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index a62cdc464..8519e148d 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.238",
+ "version": "0.1.239",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.238",
+ "version": "0.1.239",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@anthropic-ai/sdk": "^0.32.0",
diff --git a/mcp-host/package.json b/mcp-host/package.json
index 2b209bb31..2dcb39dec 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.238",
+ "version": "0.1.239",
"description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude",
"main": "dist/main.js",
"engines": {
diff --git a/mcp-host/src/llm/__tests__/claude.classifyError.test.ts b/mcp-host/src/llm/__tests__/claude.classifyError.test.ts
index 9c4d0c105..962e47e47 100644
--- a/mcp-host/src/llm/__tests__/claude.classifyError.test.ts
+++ b/mcp-host/src/llm/__tests__/claude.classifyError.test.ts
@@ -66,10 +66,13 @@ describe('ClaudeProvider.classifyError', () => {
expect(c.message).toBe('billing issue')
})
- it('classifies error.type permission_error as InsufficientQuota (account access), not retryable', () => {
+ it('classifies error.type permission_error as AuthenticationFailed (403 identity/authz), not retryable (R1-M1)', () => {
+ // A 403 is identity/authorization (account access / IAM permission), not
+ // billing — it lands on the `auth` failover class uniformly with the other
+ // arms. billing_error above keeps InsufficientQuota (Anthropic's quota channel).
const err = anthropicApiError(403, 'permission_error', 'no permission')
const c = provider.classifyError(err)
- expect(c.code).toBe(LlmErrorCode.InsufficientQuota)
+ expect(c.code).toBe(LlmErrorCode.AuthenticationFailed)
expect(c.retryable).toBe(false)
expect(c.providerCode).toBe('permission_error')
expect(c.message).toBe('no permission')
diff --git a/mcp-host/src/llm/__tests__/errorClassification.test.ts b/mcp-host/src/llm/__tests__/errorClassification.test.ts
index 5117b183b..e9e7f98b6 100644
--- a/mcp-host/src/llm/__tests__/errorClassification.test.ts
+++ b/mcp-host/src/llm/__tests__/errorClassification.test.ts
@@ -19,13 +19,13 @@ describe('classifyByHttpStatus', () => {
})
})
- it('maps 403 to InsufficientQuota (account/billing access), NOT AuthenticationFailed', () => {
- // 403 is separated from 401: a bad credential is 401 (a rotatable key); 403
- // is account access / billing / permission and must not masquerade as a
- // credential failure (which would silently divert traffic via the `auth`
- // failover class).
+ it('maps 403 to AuthenticationFailed (identity/authorization), uniform with 401 (R1-M1)', () => {
+ // 403 is an identity/authorization failure (account access / IAM permission),
+ // not billing — genuine quota has its own channel. It shares the `auth`
+ // failover class with 401 across all four provider arms; the 401-vs-403
+ // detail survives in httpStatus, not in the failover class.
const c = classifyByHttpStatus({ status: 403, message: 'forbidden' })
- expect(c?.code).toBe(LlmErrorCode.InsufficientQuota)
+ expect(c?.code).toBe(LlmErrorCode.AuthenticationFailed)
expect(c?.retryable).toBe(false)
expect(c?.httpStatus).toBe(403)
})
diff --git a/mcp-host/src/llm/claude.ts b/mcp-host/src/llm/claude.ts
index 8162501b9..c53726137 100644
--- a/mcp-host/src/llm/claude.ts
+++ b/mcp-host/src/llm/claude.ts
@@ -85,10 +85,14 @@ export class ClaudeProvider implements SingleTurnProvider {
case 'overloaded_error':
return { code: LlmErrorCode.ModelOverloaded, retryable: true, message: rawMsg }
case 'billing_error':
- case 'permission_error':
- // Account access / billing, not a rotatable credential (kept off
- // AuthenticationFailed — see the 403 split in errorClassification).
+ // Genuine billing / credit exhaustion — Anthropic's dedicated quota
+ // channel (like body `insufficient_quota`). Stays on InsufficientQuota.
return { code: LlmErrorCode.InsufficientQuota, retryable: false, message: rawMsg }
+ case 'permission_error':
+ // A 403: account access / IAM permission — an identity/authorization
+ // failure, not billing. Classify as AuthenticationFailed so it lands
+ // on the `auth` failover class uniformly with the other arms (R1-M1).
+ return { code: LlmErrorCode.AuthenticationFailed, retryable: false, message: rawMsg }
default:
return null
}
diff --git a/mcp-host/src/llm/errorClassification.ts b/mcp-host/src/llm/errorClassification.ts
index 9f5a59ba9..1286a7c66 100644
--- a/mcp-host/src/llm/errorClassification.ts
+++ b/mcp-host/src/llm/errorClassification.ts
@@ -51,13 +51,15 @@ export function classifyByHttpStatus(err: unknown): ClassifiedError | null {
switch (e.status) {
case 401:
- // A rotatable bad credential — kept on `auth` failover class.
- return { code: LlmErrorCode.AuthenticationFailed, retryable: false, message: rawMsg, ...diag }
case 403:
- // 403 ≠ 401: not a bad key value but account access / billing / permission.
- // Split off AuthenticationFailed so a forbidden model/account does not
- // masquerade as a rotatable-credential failure (spec 02 §3.1).
- return { code: LlmErrorCode.InsufficientQuota, retryable: false, message: rawMsg, ...diag }
+ // 401 (bad key) and 403 (forbidden: account access / IAM permission) are
+ // both identity/authorization failures — the caller must fix credentials
+ // or grants before this provider serves. Genuine quota has its own channel
+ // (body `insufficient_quota`, Vertex RESOURCE_EXHAUSTED, Bedrock
+ // ServiceQuotaExceededException), so 403 stays on the `auth` failover class
+ // uniformly across all four provider arms (R1-M1). The 401-vs-403 detail
+ // survives in `httpStatus`/`providerCode` (diag), not in the class.
+ return { code: LlmErrorCode.AuthenticationFailed, retryable: false, message: rawMsg, ...diag }
case 402:
return { code: LlmErrorCode.InsufficientQuota, retryable: false, message: rawMsg, ...diag }
case 404: