Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test: upstream_rejected as 422 with the upstream status (RED, #720)
Alfredo Lopez47c13913119b
diff --git a/codex-llm-proxy/test/codexTransport.conformance.test.ts b/codex-llm-proxy/test/codexTransport.conformance.test.tsindex 53d4fa8a3..b1c76857e 100644--- a/codex-llm-proxy/test/codexTransport.conformance.test.ts+++ b/codex-llm-proxy/test/codexTransport.conformance.test.ts@@ -1649,7 +1649,7 @@ describe('streamCodexCompletion', () => {const err = await streamWith(() => new Response('rejected', { status })).pending.catch((caught: unknown) => caught)- expect(err).toMatchObject({ code: 'upstream_rejected' })+ expect(err).toMatchObject({ code: 'upstream_rejected', details: { upstreamStatus: status } })expect((err as Error).message).toContain(String(status))})diff --git a/codex-llm-proxy/test/server.security.test.ts b/codex-llm-proxy/test/server.security.test.tsindex 448d4acc2..169c6f853 100644--- a/codex-llm-proxy/test/server.security.test.ts+++ b/codex-llm-proxy/test/server.security.test.ts@@ -1228,8 +1228,9 @@ describe('codex-llm-proxy attempt telemetry', () => {})// G1-3 (#720): an upstream refusal the same request would get again is a- // non-retryable 502 upstream_rejected, not a retryable 503.- it('(g1-3a) answers 502 upstream_rejected for an unmapped upstream 4xx', async () => {+ // non-retryable 422 upstream_rejected, not a retryable 503. 502 stays the+ // gateway's "nothing answered" signal (review R1-H2).+ it('(g1-3a) answers 422 upstream_rejected with the upstream status', async () => {const { res, receipts, lines, metricsText } = await run('att-rejected-http',0,@@ -1238,23 +1239,43 @@ describe('codex-llm-proxy attempt telemetry', () => {undefined,{ fetchFn: (async () => new Response('not found', { status: 404 })) as typeof fetch })- expect(res.status).toBe(502)+ expect(res.status).toBe(422)expect(res.headers['content-type']).toMatch(/^application\/json/)- expect(res.body).toEqual({ error: 'upstream_rejected' })+ expect(res.body).toEqual({ error: 'upstream_rejected', upstreamStatus: 404 })expect(receipts).toEqual([expect.objectContaining({ outcome: 'error' })])expect(lines).toHaveLength(1)expect(lines[0]).toMatchObject({providerAttemptId: 'att-rejected-http',outcome: 'failed',code: 'upstream_rejected',+ details: { upstreamStatus: 404 },deliveredAs: 'http_status',- httpStatus: 502,+ httpStatus: 422,})expectNoForbiddenKeys(lines[0]!)expect(failureCount(metricsText, 'upstream_rejected')).toBe(1)expect(failureCount(metricsText, 'other')).toBe(0)})+ it('(g1-3c) carries the upstream status on the SSE error frame after a keepalive', async () => {+ const { res, lines } = await run('att-rejected-sse', 0, 0, undefined, undefined, {+ fetchFn: slowFailingUpstream(60, 402),+ configOverrides: { heartbeatIntervalMs: 20 },+ })+ expect(res.status).toBe(200)+ // Witness: a keepalive went out first, so only the frame can carry it.+ expect(keepaliveCount(res.text)).toBeGreaterThanOrEqual(1)+ expect(+ res.text.endsWith('data: {"type":"error","code":"upstream_rejected","upstreamStatus":402}\n\n')+ ).toBe(true)+ expect(lines).toHaveLength(1)+ expect(lines[0]).toMatchObject({+ code: 'upstream_rejected',+ details: { upstreamStatus: 402 },+ deliveredAs: 'sse_error',+ })+ })+// G1-4 (#720): a redeem whose connection nothing accepted (control-api or// its gateway restarting) is reported as the control plane being down.it('(g1-4a) answers 503 control_plane_unavailable when redeem cannot connect', async () => {diff --git a/grok-llm-proxy/test/grokTransport.conformance.test.ts b/grok-llm-proxy/test/grokTransport.conformance.test.tsindex 2a803a2b6..8869cf53c 100644--- a/grok-llm-proxy/test/grokTransport.conformance.test.ts+++ b/grok-llm-proxy/test/grokTransport.conformance.test.ts@@ -1653,7 +1653,7 @@ describe('streamGrokCompletion', () => {const err = await streamWith(() => new Response('rejected', { status })).pending.catch((caught: unknown) => caught)- expect(err).toMatchObject({ code: 'upstream_rejected' })+ expect(err).toMatchObject({ code: 'upstream_rejected', details: { upstreamStatus: status } })expect((err as Error).message).toContain(String(status))})diff --git a/grok-llm-proxy/test/server.security.test.ts b/grok-llm-proxy/test/server.security.test.tsindex d2dc1634e..197b4e7ac 100644--- a/grok-llm-proxy/test/server.security.test.ts+++ b/grok-llm-proxy/test/server.security.test.ts@@ -1070,29 +1070,51 @@ describe('grok-llm-proxy attempt telemetry', () => {})// G1-3 (#720): an upstream refusal the same request would get again is a- // non-retryable 502 upstream_rejected, not a retryable 503.- it('(g1-3a) answers 502 upstream_rejected for an unmapped upstream 4xx', async () => {+ // non-retryable 422 upstream_rejected, not a retryable 503. 502 stays the+ // gateway's "nothing answered" signal (review R1-H2).+ it('(g1-3a) answers 422 upstream_rejected with the upstream status', async () => {const { res, receipts, lines, metricsText } = await run({providerAttemptId: 'att-rejected-http',fetchFn: (async () => new Response('not found', { status: 404 })) as typeof fetch,})- expect(res.status).toBe(502)+ expect(res.status).toBe(422)expect(res.headers['content-type']).toMatch(/^application\/json/)- expect(res.body).toEqual({ error: 'upstream_rejected' })+ expect(res.body).toEqual({ error: 'upstream_rejected', upstreamStatus: 404 })expect(receipts).toEqual([expect.objectContaining({ outcome: 'error' })])expect(lines).toHaveLength(1)expect(lines[0]).toMatchObject({providerAttemptId: 'att-rejected-http',outcome: 'failed',code: 'upstream_rejected',+ details: { upstreamStatus: 404 },deliveredAs: 'http_status',- httpStatus: 502,+ httpStatus: 422,})expectNoForbiddenKeys(lines[0]!)expect(failureCount(metricsText, 'upstream_rejected')).toBe(1)expect(failureCount(metricsText, 'other')).toBe(0)})+ it('(g1-3c) carries the upstream status on the SSE error frame after a keepalive', async () => {+ const { res, lines } = await run({+ providerAttemptId: 'att-rejected-sse',+ fetchFn: slowFailingUpstream(60, 402),+ configOverrides: { heartbeatIntervalMs: 20 },+ })+ expect(res.status).toBe(200)+ // Witness: a keepalive went out first, so only the frame can carry it.+ expect(keepaliveCount(res.text)).toBeGreaterThanOrEqual(1)+ expect(+ res.text.endsWith('data: {"type":"error","code":"upstream_rejected","upstreamStatus":402}\n\n')+ ).toBe(true)+ expect(lines).toHaveLength(1)+ expect(lines[0]).toMatchObject({+ code: 'upstream_rejected',+ details: { upstreamStatus: 402 },+ deliveredAs: 'sse_error',+ })+ })+// G1-4 (#720): a redeem whose connection nothing accepted (control-api or// its gateway restarting) is reported as the control plane being down.it('(g1-4a) answers 503 control_plane_unavailable when redeem cannot connect', async () => {diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex 47fc2a5b8..d182ccfca 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.453",+ "version": "0.1.454","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.453",+ "version": "0.1.454","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex 272844c3e..52d071419 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.453",+ "version": "0.1.454","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__/codexLlmProxyClient.test.ts b/mcp-host/src/llm/__tests__/codexLlmProxyClient.test.tsindex ce99e8878..80c3e2b76 100644--- a/mcp-host/src/llm/__tests__/codexLlmProxyClient.test.ts+++ b/mcp-host/src/llm/__tests__/codexLlmProxyClient.test.ts@@ -841,17 +841,56 @@ describe('CodexSubscriptionProvider G1 classification', () => {}it('G1-8a keeps an upstream 4xx terminal with no failover', async () => {- const err = await proxyReply(Response.json({ error: 'upstream_rejected' }, { status: 502 }))+ const err = await proxyReply(+ Response.json({ error: 'upstream_rejected', upstreamStatus: 404 }, { status: 422 })+ )const classified = provider.classifyError(err)expect(classified).toMatchObject({code: LlmErrorCode.ApiCallFailed,retryable: false,providerCode: 'upstream_rejected',providerDispatched: true,+ // Review R1-H2: a 402 and a 404 no longer read the same downstream.+ httpStatus: 404,})expect(classifyFailoverClass(classified.code, classified.retryable)).toBeNull()})+ it('G1-8c reads the upstream status from an SSE error frame', async () => {+ const err = await proxyReply(+ new Response(sse([{ type: 'error', code: 'upstream_rejected', upstreamStatus: 402 }]), {+ status: 200,+ headers: { 'content-type': 'text/event-stream' },+ })+ )+ expect(err).toMatchObject({ code: 'upstream_rejected', upstreamStatus: 402 })+ expect(provider.classifyError(err)).toMatchObject({+ code: LlmErrorCode.ApiCallFailed,+ httpStatus: 402,+ })+ })++ it.each([200, 404.5, '404', 600])(+ 'G1-8d ignores an upstreamStatus of %j that is not an integer 4xx',+ async upstreamStatus => {+ const err = await proxyReply(+ Response.json({ error: 'upstream_rejected', upstreamStatus }, { status: 422 })+ )+ // Witness: the code still arrived; only the status was refused.+ expect(err).toMatchObject({ code: 'upstream_rejected' })+ expect((err as { upstreamStatus?: number }).upstreamStatus).toBeUndefined()+ expect(provider.classifyError(err).httpStatus).toBeUndefined()+ }+ )++ it('G1-8e reads upstreamStatus only for upstream_rejected', async () => {+ const err = await proxyReply(+ Response.json({ error: 'provider_unavailable', upstreamStatus: 404 }, { status: 503 })+ )+ expect(err).toMatchObject({ code: 'provider_unavailable' })+ expect((err as { upstreamStatus?: number }).upstreamStatus).toBeUndefined()+ })+it('G1-8b labels a gateway control_plane_unavailable reply as a control-plane outage', async () => {const err = await proxyReply(Response.json({ error: 'control_plane_unavailable' }, { status: 503 })diff --git a/mcp-host/src/llm/__tests__/grokLlmProxyClient.test.ts b/mcp-host/src/llm/__tests__/grokLlmProxyClient.test.tsindex d58c7b193..0b45ced14 100644--- a/mcp-host/src/llm/__tests__/grokLlmProxyClient.test.ts+++ b/mcp-host/src/llm/__tests__/grokLlmProxyClient.test.ts@@ -741,17 +741,56 @@ describe('GrokSubscriptionProvider G1 classification', () => {}it('G1-8a keeps an upstream 4xx terminal with no failover', async () => {- const err = await proxyReply(Response.json({ error: 'upstream_rejected' }, { status: 502 }))+ const err = await proxyReply(+ Response.json({ error: 'upstream_rejected', upstreamStatus: 403 }, { status: 422 })+ )const classified = provider.classifyError(err)expect(classified).toMatchObject({code: LlmErrorCode.ApiCallFailed,retryable: false,providerCode: 'upstream_rejected',providerDispatched: true,+ // Review R1-H2: an entitlement 403 and a 404 no longer read the same.+ httpStatus: 403,})expect(classifyFailoverClass(classified.code, classified.retryable)).toBeNull()})+ it('G1-8c reads the upstream status from an SSE error frame', async () => {+ const err = await proxyReply(+ new Response(sse([{ type: 'error', code: 'upstream_rejected', upstreamStatus: 402 }]), {+ status: 200,+ headers: { 'content-type': 'text/event-stream' },+ })+ )+ expect(err).toMatchObject({ code: 'upstream_rejected', upstreamStatus: 402 })+ expect(provider.classifyError(err)).toMatchObject({+ code: LlmErrorCode.ApiCallFailed,+ httpStatus: 402,+ })+ })++ it.each([200, 404.5, '404', 600])(+ 'G1-8d ignores an upstreamStatus of %j that is not an integer 4xx',+ async upstreamStatus => {+ const err = await proxyReply(+ Response.json({ error: 'upstream_rejected', upstreamStatus }, { status: 422 })+ )+ // Witness: the code still arrived; only the status was refused.+ expect(err).toMatchObject({ code: 'upstream_rejected' })+ expect((err as { upstreamStatus?: number }).upstreamStatus).toBeUndefined()+ expect(provider.classifyError(err).httpStatus).toBeUndefined()+ }+ )++ it('G1-8e reads upstreamStatus only for upstream_rejected', async () => {+ const err = await proxyReply(+ Response.json({ error: 'provider_unavailable', upstreamStatus: 404 }, { status: 503 })+ )+ expect(err).toMatchObject({ code: 'provider_unavailable' })+ expect((err as { upstreamStatus?: number }).upstreamStatus).toBeUndefined()+ })+it('G1-8b labels a gateway control_plane_unavailable reply as a control-plane outage', async () => {const err = await proxyReply(Response.json({ error: 'control_plane_unavailable' }, { status: 503 })