Skip to content

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

TypeScript

fix(mcp-host): classify upstream_rejected as LLM_UPSTREAM_REJECTED (#720)

Alfredo Lopezf6cb78d7d3c1
diff --git a/desktop-app/ui/src/constants/agents.ts b/desktop-app/ui/src/constants/agents.ts
index 41c348804..fde34cef4 100644
--- a/desktop-app/ui/src/constants/agents.ts
+++ b/desktop-app/ui/src/constants/agents.ts
@@ -15,6 +15,7 @@ export const AGENT_ERROR_CODE_LABELS: Record<string, string> = {
LLM_MODEL_NOT_AVAILABLE: 'Model Not Available',
LLM_CONTENT_FILTERED: 'Content Filtered',
LLM_API_CALL_FAILED: 'Connection Error',
+ LLM_UPSTREAM_REJECTED: 'Provider Rejected Request',
LLM_TOOL_CALL_LIMIT_EXCEEDED: 'Too Many Tool Calls',
LLM_STREAM_DURATION_EXCEEDED: 'Response Took Too Long',
LLM_CONTEXT_LENGTH_EXCEEDED: 'Conversation Too Long',
diff --git a/docs/architecture/codex-subscription-transport-contract.md b/docs/architecture/codex-subscription-transport-contract.md
index 69a267a40..fa225bac1 100644
--- a/docs/architecture/codex-subscription-transport-contract.md
+++ b/docs/architecture/codex-subscription-transport-contract.md
@@ -473,8 +473,10 @@ code the proxy constructs, and every code it refuses a request with
not 502, because the gateways answer 502 when nothing behind them answered.
The upstream status travels as `upstreamStatus` on both paths
(`{"error":"upstream_rejected","upstreamStatus":404}`, or the same field on
- the SSE error frame) and in the log line's `details`; the Host exposes it as
- the classified error's `httpStatus`. An upstream 408 is transient and stays
+ the SSE error frame) and in the log line's `details`. The Host classifies
+ the code as `LLM_UPSTREAM_REJECTED` ("Provider Rejected Request"), not
+ retryable and without failover, and exposes the upstream status as the
+ classified error's `httpStatus`. An upstream 408 is transient and stays
`provider_unavailable`.
- `control_plane_unavailable`: HTTP 503. No control-plane process answered
the redeem; see "Control-plane outage" below.
@@ -662,9 +664,12 @@ retryable and without failover, where the same outage used to be a retryable
HCC sets as `CONTEXT_MAPPER_HOST_IMAGE`, and wait until every Host pod runs
the new image; then roll out the proxies and the control-plane ConfigMap,
restarting `control-api-rpc-gateway` and `nginx-workflow-approval-gateway`,
-which mount `nginx.conf` through `subPath`. `rate_limited` and
-`upstream_rejected` need no order: an old Host already classifies them as a
-new one does, without `httpStatus`.
+which mount `nginx.conf` through `subPath`. `rate_limited` needs no order: an
+old Host already classifies it as a new one does. `upstream_rejected` needs
+none either: an old Host classifies it as `LLM_API_CALL_FAILED` ("Connection
+Error") without `httpStatus`, with the same behaviour (not retryable, no
+failover), and a Desktop from before #720 shows the generic "Error" label for
+`LLM_UPSTREAM_REJECTED`.
The Host classifies `control_plane_unavailable` as
`LLM_CONTROL_PLANE_UNAVAILABLE`, retryable, with the failover class
diff --git a/docs/architecture/grok-subscription-transport-contract.md b/docs/architecture/grok-subscription-transport-contract.md
index d3abe3e27..a1550de99 100644
--- a/docs/architecture/grok-subscription-transport-contract.md
+++ b/docs/architecture/grok-subscription-transport-contract.md
@@ -340,8 +340,10 @@ code the proxy constructs, and every code it refuses a request with
It is not 502, because the gateways answer 502 when nothing behind them
answered. The upstream status travels as `upstreamStatus` on both paths
(`{"error":"upstream_rejected","upstreamStatus":403}`, or the same field on
- the SSE error frame) and in the log line's `details`; the Host exposes it as
- the classified error's `httpStatus`. The upstream status mapping is: 400
+ the SSE error frame) and in the log line's `details`. The Host classifies
+ the code as `LLM_UPSTREAM_REJECTED` ("Provider Rejected Request"), not
+ retryable and without failover, and exposes the upstream status as the
+ classified error's `httpStatus`. The upstream status mapping is: 400
`invalid_request`, 401 `connection_unavailable`, 426
`client_upgrade_required`, 429 `rate_limited`, any other 4xx except 408
`upstream_rejected`, anything else (408 and 5xx included)
@@ -561,9 +563,12 @@ retryable and without failover, where the same outage used to be a retryable
HCC sets as `CONTEXT_MAPPER_HOST_IMAGE`, and wait until every Host pod runs
the new image; then roll out the proxies and the control-plane ConfigMap,
restarting `control-api-rpc-gateway` and `nginx-workflow-approval-gateway`,
-which mount `nginx.conf` through `subPath`. `rate_limited` and
-`upstream_rejected` need no order: an old Host already classifies them as a
-new one does, without `httpStatus`.
+which mount `nginx.conf` through `subPath`. `rate_limited` needs no order: an
+old Host already classifies it as a new one does. `upstream_rejected` needs
+none either: an old Host classifies it as `LLM_API_CALL_FAILED` ("Connection
+Error") without `httpStatus`, with the same behaviour (not retryable, no
+failover), and a Desktop from before #720 shows the generic "Error" label for
+`LLM_UPSTREAM_REJECTED`.
The Host classifies `control_plane_unavailable` as
`LLM_CONTROL_PLANE_UNAVAILABLE`, retryable, with the failover class
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index bb1332278..258da8a34 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.460",
+ "version": "0.1.461",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.460",
+ "version": "0.1.461",
"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 76f91a4e6..a470f72ce 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.460",
+ "version": "0.1.461",
"description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude",
"main": "dist/main.js",
"engines": {
diff --git a/mcp-host/src/core/errors.ts b/mcp-host/src/core/errors.ts
index 58d373867..137ce1198 100644
--- a/mcp-host/src/core/errors.ts
+++ b/mcp-host/src/core/errors.ts
@@ -43,6 +43,13 @@ export enum LlmErrorCode {
* {@link LlmErrorCode.ModelOverloaded}.
*/
ControlPlaneUnavailable = 'LLM_CONTROL_PLANE_UNAVAILABLE',
+ /**
+ * Issue #720 — a subscription proxy reported `upstream_rejected`: the
+ * provider answered a 4xx the proxy has no specific code for (Grok 402/403
+ * entitlement, 404, 409, 422). The same request gets the same answer, so it
+ * is not retryable and never fails over.
+ */
+ UpstreamRejected = 'LLM_UPSTREAM_REJECTED',
/** One model response asked for more tool calls than the provider contract allows. */
ToolCallLimitExceeded = 'LLM_TOOL_CALL_LIMIT_EXCEEDED',
/**
diff --git a/mcp-host/src/llm/__tests__/codexLlmProxyClient.test.ts b/mcp-host/src/llm/__tests__/codexLlmProxyClient.test.ts
index 63f098767..4310eb925 100644
--- a/mcp-host/src/llm/__tests__/codexLlmProxyClient.test.ts
+++ b/mcp-host/src/llm/__tests__/codexLlmProxyClient.test.ts
@@ -867,7 +867,7 @@ describe('CodexSubscriptionProvider G1 classification', () => {
)
expect(err).toMatchObject({ code: 'upstream_rejected', upstreamStatus: 402 })
expect(provider.classifyError(err)).toMatchObject({
- code: LlmErrorCode.ApiCallFailed,
+ code: 'LLM_UPSTREAM_REJECTED',
httpStatus: 402,
})
})
diff --git a/mcp-host/src/llm/__tests__/grokLlmProxyClient.test.ts b/mcp-host/src/llm/__tests__/grokLlmProxyClient.test.ts
index 366be8ff7..10d35cda7 100644
--- a/mcp-host/src/llm/__tests__/grokLlmProxyClient.test.ts
+++ b/mcp-host/src/llm/__tests__/grokLlmProxyClient.test.ts
@@ -767,7 +767,7 @@ describe('GrokSubscriptionProvider G1 classification', () => {
)
expect(err).toMatchObject({ code: 'upstream_rejected', upstreamStatus: 402 })
expect(provider.classifyError(err)).toMatchObject({
- code: LlmErrorCode.ApiCallFailed,
+ code: 'LLM_UPSTREAM_REJECTED',
httpStatus: 402,
})
})
diff --git a/mcp-host/src/llm/codexSubscription.ts b/mcp-host/src/llm/codexSubscription.ts
index 9fec8ff3d..d6bc50810 100644
--- a/mcp-host/src/llm/codexSubscription.ts
+++ b/mcp-host/src/llm/codexSubscription.ts
@@ -473,12 +473,12 @@ export class CodexSubscriptionProvider implements SingleTurnProvider {
}
}
// An upstream 4xx the proxy could not map (#720): the same request gets
- // the same answer, so it is terminal whatever the generic arm decides.
+ // the same answer, so it is terminal and has its own label.
// httpStatus is the upstream's own status, when the proxy sent it (R1-H2).
if (code === 'upstream_rejected') {
const upstreamStatus = err instanceof CodexProxyError ? err.upstreamStatus : undefined
return {
- code: LlmErrorCode.ApiCallFailed,
+ code: LlmErrorCode.UpstreamRejected,
retryable: false,
message: err instanceof Error ? err.message : String(err),
providerCode: code,
diff --git a/mcp-host/src/llm/failover/classify.ts b/mcp-host/src/llm/failover/classify.ts
index 9e9ea756b..236660d71 100644
--- a/mcp-host/src/llm/failover/classify.ts
+++ b/mcp-host/src/llm/failover/classify.ts
@@ -34,7 +34,8 @@ export const ALL_FAILOVER_CLASSES: readonly FailoverClass[] = [
* - `ApiCallFailed ∧ !retryable` → null (400 / validation / content-policy —
* never trigger; masking these would hide bugs)
* - everything else (InvalidResponse, ContextLengthExceeded, ContentFiltered,
- * ModelNotAvailable, ToolCallLimitExceeded, StreamDurationExceeded) → null
+ * ModelNotAvailable, ToolCallLimitExceeded, StreamDurationExceeded,
+ * UpstreamRejected) → null
*/
export function classifyFailoverClass(
code: LlmErrorCode,
diff --git a/mcp-host/src/llm/grokSubscription.ts b/mcp-host/src/llm/grokSubscription.ts
index 421c338b3..482203597 100644
--- a/mcp-host/src/llm/grokSubscription.ts
+++ b/mcp-host/src/llm/grokSubscription.ts
@@ -338,12 +338,12 @@ export class GrokSubscriptionProvider implements SingleTurnProvider {
}
}
// An upstream 4xx the proxy could not map (#720): the same request gets
- // the same answer, so it is terminal whatever the generic arm decides.
+ // the same answer, so it is terminal and has its own label.
// httpStatus is the upstream's own status, when the proxy sent it (R1-H2).
if (code === 'upstream_rejected') {
const upstreamStatus = err instanceof GrokProxyError ? err.upstreamStatus : undefined
return {
- code: LlmErrorCode.ApiCallFailed,
+ code: LlmErrorCode.UpstreamRejected,
retryable: false,
message: err instanceof Error ? err.message : String(err),
providerCode: code,