Skip to content

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

TypeScript

fix(llm-proxy): map unmapped upstream 4xx to non-retryable upstream_rejected

Alfredo Lopez501262adeb01
diff --git a/codex-llm-proxy/src/codexTransport.ts b/codex-llm-proxy/src/codexTransport.ts
index 09d286914..8505ccc57 100644
--- a/codex-llm-proxy/src/codexTransport.ts
+++ b/codex-llm-proxy/src/codexTransport.ts
@@ -404,6 +404,14 @@ async function dispatchUpstreamStream(
retryAfter === undefined ? undefined : { retryAfterSeconds: retryAfter }
)
}
+ // G1-3 (#720): any other 4xx is what the same request would get again, so
+ // it is not retried or failed over from. A 408 is transient.
+ if (response.status >= 400 && response.status < 500 && response.status !== 408) {
+ throw new CodexTransportError(
+ 'upstream_rejected',
+ `upstream rejected the Codex request with status ${response.status}`
+ )
+ }
throw new CodexTransportError('provider_unavailable', 'upstream completion failed')
}
return consumeSse(response.body, input.onFrame, signal, names, deadline)
diff --git a/codex-llm-proxy/src/server.ts b/codex-llm-proxy/src/server.ts
index 246bf9846..3829af588 100644
--- a/codex-llm-proxy/src/server.ts
+++ b/codex-llm-proxy/src/server.ts
@@ -792,6 +792,8 @@ const ATTEMPT_ERROR_STATUS: Record<string, number> = {
// An upstream 429 (G1-1, #720); its Retry-After travels as a header.
rate_limited: 429,
tool_call_limit_exceeded: 422,
+ // An upstream 4xx the same request would get again (G1-3, #720).
+ upstream_rejected: 502,
invalid_tool_arguments: 422,
// The attempt ran for its whole stream budget. Retrying the same request
// would spend the same budget again, so it is a gateway timeout, not 503.
diff --git a/grok-llm-proxy/src/grokTransport.ts b/grok-llm-proxy/src/grokTransport.ts
index 102bbbfaa..e63afed35 100644
--- a/grok-llm-proxy/src/grokTransport.ts
+++ b/grok-llm-proxy/src/grokTransport.ts
@@ -435,12 +435,6 @@ async function dispatchUpstreamStream(
'xAI requires a newer Grok client version for subscription inference; contact support to upgrade Evenfire’s Grok client'
)
}
- if (response.status === 402 || response.status === 403) {
- throw new GrokTransportError(
- 'provider_unavailable',
- 'upstream entitlement denied the Grok request'
- )
- }
if (response.status === 429) {
const retryAfter = retryAfterSeconds(response)
throw new GrokTransportError(
@@ -449,6 +443,15 @@ async function dispatchUpstreamStream(
retryAfter === undefined ? undefined : { retryAfterSeconds: retryAfter }
)
}
+ // G1-3 (#720): any other 4xx, including a 402/403 entitlement refusal, is
+ // what the same request would get again, so it is not retried or failed
+ // over from. A 408 is transient.
+ if (response.status >= 400 && response.status < 500 && response.status !== 408) {
+ throw new GrokTransportError(
+ 'upstream_rejected',
+ `upstream rejected the Grok request with status ${response.status}`
+ )
+ }
throw new GrokTransportError('provider_unavailable', 'upstream completion failed')
}
return consumeSse(response.body, input.onFrame, signal, names, deadline)
diff --git a/grok-llm-proxy/src/server.ts b/grok-llm-proxy/src/server.ts
index 5413eb91d..9c881d28e 100644
--- a/grok-llm-proxy/src/server.ts
+++ b/grok-llm-proxy/src/server.ts
@@ -665,6 +665,8 @@ const ATTEMPT_ERROR_STATUS: Record<string, number> = {
// An upstream 429 (G1-1, #720); its Retry-After travels as a header.
rate_limited: 429,
tool_call_limit_exceeded: 422,
+ // An upstream 4xx the same request would get again (G1-3, #720).
+ upstream_rejected: 502,
tool_call_arguments_exceeded: 422,
invalid_tool_arguments: 422,
client_upgrade_required: 426,
diff --git a/tests/e2e/fixtures/codex-subscription/sanitized-upstream-contract.json b/tests/e2e/fixtures/codex-subscription/sanitized-upstream-contract.json
index 61c1a9872..d30f1f1d5 100644
--- a/tests/e2e/fixtures/codex-subscription/sanitized-upstream-contract.json
+++ b/tests/e2e/fixtures/codex-subscription/sanitized-upstream-contract.json
@@ -62,6 +62,7 @@
"connection_unavailable",
"provider_unavailable",
"rate_limited",
+ "upstream_rejected",
"origin_denied",
"ticket_invalid",
"ticket_replayed",
diff --git a/tests/e2e/fixtures/grok-subscription/sanitized-upstream-contract.json b/tests/e2e/fixtures/grok-subscription/sanitized-upstream-contract.json
index a4af0ec41..29dfdb144 100644
--- a/tests/e2e/fixtures/grok-subscription/sanitized-upstream-contract.json
+++ b/tests/e2e/fixtures/grok-subscription/sanitized-upstream-contract.json
@@ -76,6 +76,7 @@
"connection_unavailable",
"provider_unavailable",
"rate_limited",
+ "upstream_rejected",
"origin_denied",
"ticket_invalid",
"ticket_replayed",
diff --git a/tests/e2e/fixtures/package-lock.json b/tests/e2e/fixtures/package-lock.json
index dcb87e86f..173cd6dc8 100644
--- a/tests/e2e/fixtures/package-lock.json
+++ b/tests/e2e/fixtures/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "@clerum/e2e-test-fixtures",
- "version": "1.0.98",
+ "version": "1.0.99",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@clerum/e2e-test-fixtures",
- "version": "1.0.98",
+ "version": "1.0.99",
"dependencies": {
"@kubernetes/client-node": "^1.0.0"
},
diff --git a/tests/e2e/fixtures/package.json b/tests/e2e/fixtures/package.json
index cd7c21746..532ff75e9 100644
--- a/tests/e2e/fixtures/package.json
+++ b/tests/e2e/fixtures/package.json
@@ -1,6 +1,6 @@
{
"name": "@clerum/e2e-test-fixtures",
- "version": "1.0.98",
+ "version": "1.0.99",
"description": "E2E test fixtures and utilities for Clerum testing",
"type": "module",
"main": "index.ts",