Skip to content

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

TypeScript

test(mcp-host): ticket_expired is a retryable admission failure (#739)

Alfredo Lopezcf527f434b85
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index 912a54162..191a73589 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.431",
+ "version": "0.1.432",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.431",
+ "version": "0.1.432",
"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 9cd3124fb..df69fee31 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.431",
+ "version": "0.1.432",
"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.ts
index e7ff65fd3..fd6369828 100644
--- a/mcp-host/src/llm/__tests__/codexLlmProxyClient.test.ts
+++ b/mcp-host/src/llm/__tests__/codexLlmProxyClient.test.ts
@@ -316,6 +316,51 @@ describe('CodexLlmProxyClient', () => {
expect(classifyFailoverClass(classified.code, classified.retryable)).toBeNull()
})
+ // T-TE-1 (D4) — the proxy passes control-api's redeem refusal through as
+ // `403 { error: 'ticket_expired' }` when the ticket died while the request
+ // was queued. Nothing reached the provider, so a re-authorized retry is the
+ // remedy. `ticket_replayed` / `ticket_invalid` are defects and stay terminal.
+ it.each([
+ { error: 'ticket_expired', status: 403, retryable: true, failover: 'provider_unavailable' },
+ { error: 'ticket_replayed', status: 409, retryable: false, failover: null },
+ { error: 'ticket_invalid', status: 403, retryable: false, failover: null },
+ ] as const)(
+ 'T-TE-1a classifies the proxy $status $error as ApiCallFailed with retryable=$retryable',
+ async ({ error, status, retryable, failover }) => {
+ const fetchFn = vi.fn(async () => Response.json({ error }, { status }))
+ const client = new CodexLlmProxyClient({
+ runtimeUrl: resolveCodexProxyRuntimeUrl(
+ 'http://codex-llm-proxy.control-plane.svc.cluster.local:8080'
+ ),
+ readPlatformJwt: () => 'platform-jwt',
+ fetchFn: fetchFn as unknown as typeof fetch,
+ })
+ const err = await client
+ .stream({ executionTicket: 'ticket-123456', requestHash: 'a'.repeat(64), request: {} })
+ .then(
+ () => undefined,
+ (e: unknown) => e
+ )
+ expect(fetchFn).toHaveBeenCalledTimes(1)
+ expect(err).toBeInstanceOf(CodexProxyError)
+ expect(err).toMatchObject({
+ code: error,
+ message: `proxy stream failed with ${status} (${error})`,
+ dispatched: true,
+ })
+
+ const classified = new CodexSubscriptionProvider('gpt-5.3-codex', {} as never).classifyError(
+ err
+ )
+ expect(classified).toMatchObject({
+ code: LlmErrorCode.ApiCallFailed,
+ retryable,
+ providerCode: error,
+ })
+ expect(classifyFailoverClass(classified.code, classified.retryable)).toBe(failover)
+ }
+ )
+
// The proxy's total stream cap arrives as 504 before any frame, or as an SSE
// error frame after one. The attempt spent its whole budget, so the same
// request would spend it again elsewhere: no retry, no failover.
diff --git a/mcp-host/src/llm/__tests__/codexSubscription.test.ts b/mcp-host/src/llm/__tests__/codexSubscription.test.ts
index c7fb920c0..c006d263e 100644
--- a/mcp-host/src/llm/__tests__/codexSubscription.test.ts
+++ b/mcp-host/src/llm/__tests__/codexSubscription.test.ts
@@ -728,6 +728,44 @@ describe('CodexSubscriptionProvider', () => {
expect(classifyFailoverClass(classified.code, classified.retryable)).toBeNull()
})
+ // T-TE-1 (D4) — control-api answers 403 `ticket_expired` when the redeem
+ // arrives after the execution ticket's `exp`. The attempt never reached the
+ // provider, so it is a capacity race: re-authorizing yields a fresh ticket.
+ // `ticket_replayed` and `ticket_invalid` are defects and stay terminal.
+ it('T-TE-1c classifies ticket_expired as a retryable ApiCallFailed that fails over', () => {
+ const provider = new CodexSubscriptionProvider('gpt-5.3-codex', deps() as never)
+ const classified = provider.classifyError(
+ new CodexProxyError('ticket_expired', 'proxy stream failed with 403 (ticket_expired)')
+ )
+ expect(classified).toEqual({
+ code: LlmErrorCode.ApiCallFailed,
+ retryable: true,
+ message: 'execution ticket expired before redeem; re-authorize',
+ providerCode: 'ticket_expired',
+ providerDispatched: true,
+ })
+ expect(classifyFailoverClass(classified.code, classified.retryable)).toBe(
+ 'provider_unavailable'
+ )
+ })
+
+ it.each([
+ ['ticket_replayed', 409],
+ ['ticket_invalid', 403],
+ ] as const)('T-TE-1c keeps %s a non-retryable ApiCallFailed', (code, status) => {
+ const provider = new CodexSubscriptionProvider('gpt-5.3-codex', deps() as never)
+ const message = `proxy stream failed with ${status} (${code})`
+ const classified = provider.classifyError(new CodexProxyError(code, message))
+ expect(classified).toEqual({
+ code: LlmErrorCode.ApiCallFailed,
+ retryable: false,
+ message,
+ providerCode: code,
+ providerDispatched: true,
+ })
+ expect(classifyFailoverClass(classified.code, classified.retryable)).toBeNull()
+ })
+
it('keeps insufficient_scope distinguishable', () => {
const provider = new CodexSubscriptionProvider('gpt-5.3-codex', deps() as never)
const classified = provider.classifyError(
diff --git a/mcp-host/src/llm/__tests__/grokLlmProxyClient.test.ts b/mcp-host/src/llm/__tests__/grokLlmProxyClient.test.ts
index dd2ae83b9..a55719220 100644
--- a/mcp-host/src/llm/__tests__/grokLlmProxyClient.test.ts
+++ b/mcp-host/src/llm/__tests__/grokLlmProxyClient.test.ts
@@ -358,6 +358,42 @@ describe('GrokLlmProxyClient', () => {
expect(classifyFailoverClass(classified.code, classified.retryable)).toBeNull()
})
+ // T-TE-1 (D4) — the proxy passes control-api's redeem refusal through as
+ // `403 { error: 'ticket_expired' }` when the ticket died while the request
+ // was queued. Nothing reached the provider, so a re-authorized retry is the
+ // remedy. `ticket_replayed` / `ticket_invalid` are defects and stay terminal.
+ it.each([
+ { error: 'ticket_expired', status: 403, retryable: true, failover: 'provider_unavailable' },
+ { error: 'ticket_replayed', status: 409, retryable: false, failover: null },
+ { error: 'ticket_invalid', status: 403, retryable: false, failover: null },
+ ] as const)(
+ 'T-TE-1b classifies the proxy $status $error as ApiCallFailed with retryable=$retryable',
+ async ({ error, status, retryable, failover }) => {
+ const fetchFn = vi.fn(async () => Response.json({ error }, { status }))
+ const err = await client(fetchFn)
+ .stream(STREAM_INPUT)
+ .then(
+ () => undefined,
+ (e: unknown) => e
+ )
+ expect(fetchFn).toHaveBeenCalledTimes(1)
+ expect(err).toBeInstanceOf(GrokProxyError)
+ expect(err).toMatchObject({
+ code: error,
+ message: `proxy stream failed with ${status} (${error})`,
+ dispatched: true,
+ })
+
+ const classified = new GrokSubscriptionProvider('grok-4.6', {} as never).classifyError(err)
+ expect(classified).toMatchObject({
+ code: LlmErrorCode.ApiCallFailed,
+ retryable,
+ providerCode: error,
+ })
+ expect(classifyFailoverClass(classified.code, classified.retryable)).toBe(failover)
+ }
+ )
+
// The proxy's total stream cap arrives as 504 before any frame, or as an SSE
// error frame after one. The attempt spent its whole budget, so the same
// request would spend it again elsewhere: no retry, no failover.
diff --git a/mcp-host/src/llm/__tests__/grokSubscription.test.ts b/mcp-host/src/llm/__tests__/grokSubscription.test.ts
index fafa49f77..be46b47b1 100644
--- a/mcp-host/src/llm/__tests__/grokSubscription.test.ts
+++ b/mcp-host/src/llm/__tests__/grokSubscription.test.ts
@@ -139,6 +139,44 @@ describe('GrokSubscriptionProvider', () => {
expect(classifyFailoverClass(classified.code, classified.retryable)).toBeNull()
})
+ // T-TE-1 (D4) — control-api answers 403 `ticket_expired` when the redeem
+ // arrives after the execution ticket's `exp`. The attempt never reached the
+ // provider, so it is a capacity race: re-authorizing yields a fresh ticket.
+ // `ticket_replayed` and `ticket_invalid` are defects and stay terminal.
+ it('T-TE-1d classifies ticket_expired as a retryable ApiCallFailed that fails over', () => {
+ const provider = new GrokSubscriptionProvider('grok-4.6', deps() as never)
+ const classified = provider.classifyError(
+ new GrokProxyError('ticket_expired', 'proxy stream failed with 403 (ticket_expired)')
+ )
+ expect(classified).toEqual({
+ code: LlmErrorCode.ApiCallFailed,
+ retryable: true,
+ message: 'execution ticket expired before redeem; re-authorize',
+ providerCode: 'ticket_expired',
+ providerDispatched: true,
+ })
+ expect(classifyFailoverClass(classified.code, classified.retryable)).toBe(
+ 'provider_unavailable'
+ )
+ })
+
+ it.each([
+ ['ticket_replayed', 409],
+ ['ticket_invalid', 403],
+ ] as const)('T-TE-1d keeps %s a non-retryable ApiCallFailed', (code, status) => {
+ const provider = new GrokSubscriptionProvider('grok-4.6', deps() as never)
+ const message = `proxy stream failed with ${status} (${code})`
+ const classified = provider.classifyError(new GrokProxyError(code, message))
+ expect(classified).toEqual({
+ code: LlmErrorCode.ApiCallFailed,
+ retryable: false,
+ message,
+ providerCode: code,
+ providerDispatched: true,
+ })
+ expect(classifyFailoverClass(classified.code, classified.retryable)).toBeNull()
+ })
+
it('still completes a successful terminal outcome', async () => {
const provider = new GrokSubscriptionProvider('grok-4.6', deps() as never)
await expect(