Skip to content

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

TypeScript

test(llm-proxy): require dev's unknown outcome and a retryable expired-ticket code

Alfredo Lopezb9cd2b69f046
diff --git a/codex-llm-proxy/test/codexTransport.conformance.test.ts b/codex-llm-proxy/test/codexTransport.conformance.test.ts
index ff4b448af..eb5df9bfc 100644
--- a/codex-llm-proxy/test/codexTransport.conformance.test.ts
+++ b/codex-llm-proxy/test/codexTransport.conformance.test.ts
@@ -1860,6 +1860,25 @@ describe('streamCodexCompletion', () => {
await expectRefused([textBefore, openCall, completed])
})
+ // R17-1: a stream that ends with no terminal event never delivers its calls,
+ // so a call left open there is not parsed and the attempt stays `unknown`,
+ // as on dev. Refusing its arguments would report a dropped connection as a
+ // malformed model response.
+ it.each([
+ ['empty', [openCall]],
+ ['truncated', [openCall, truncatedDelta]],
+ ])(
+ 'T-R17-1 reports a stream that ends with no terminal event and a call open with %s arguments as unknown',
+ async (_label, callEvents) => {
+ const { settled, frames, fetchFn, finalize } = await runUpstream([textBefore, ...callEvents])
+ expect(fetchFn).toHaveBeenCalledTimes(1)
+ expect(frames).toEqual([{ type: 'text', text: 'before' }])
+ expect(settled).toMatchObject({ rejected: false, result: { outcome: 'unknown' } })
+ expect(finalize).toHaveBeenCalledTimes(1)
+ expect(finalize.mock.calls[0]?.[0]?.receipt.outcome).toBe('unknown')
+ }
+ )
+
// A canceled or failed stream also ends with its open call truncated. That
// truncation is a consequence of the stream's own outcome, so the outcome
// wins over the arguments refusal.
diff --git a/codex-llm-proxy/test/server.security.test.ts b/codex-llm-proxy/test/server.security.test.ts
index 497bb08c2..068a0eb56 100644
--- a/codex-llm-proxy/test/server.security.test.ts
+++ b/codex-llm-proxy/test/server.security.test.ts
@@ -380,6 +380,59 @@ describe('codex-llm-proxy security surface', () => {
expect(verifyAdminPermit(permitNoExp, cfg)).toBeNull()
})
+ // R17-2: body admission can hold a body for up to maxQueueWaitMs before the
+ // ticket is read, the same span as the ticket TTL, so an honest request can
+ // reach this gate with an expired ticket. That answer must be the retryable
+ // ticket_expired; every other ticket failure stays ticket_invalid.
+ it('T-R17-2 answers ticket_expired for an authentic expired ticket and ticket_invalid otherwise', async () => {
+ const { runtimeApp } = createProxyApps(config({ executionEnabled: false }))
+ const { privateKey: foreignKey } = generateKeyPairSync('rsa', {
+ modulusLength: 2048,
+ publicKeyEncoding: { type: 'spki', format: 'pem' },
+ privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
+ })
+ const expiredClaims = {
+ jti: '11111111-1111-4111-8111-111111111111',
+ typ: 'codex-execution-ticket',
+ hostRef: 'research-host',
+ model: 'gpt-5.1',
+ requestHash: 'a'.repeat(64),
+ providerAttemptId: 'att-1',
+ exp: Math.floor(Date.now() / 1000) - 5,
+ }
+ const expiredTicket = (
+ claims: Record<string, unknown>,
+ key: string = privateKey,
+ audience = 'codex-llm-proxy'
+ ) => jwt.sign(claims, key, { algorithm: 'RS256', issuer: 'control-api', audience })
+ const send = (executionTicket: string) =>
+ request(runtimeApp)
+ .post('/internal/runtime/v1/codex/completions')
+ .set('Authorization', `Bearer ${platformToken()}`)
+ .send({ executionTicket, requestHash: 'a'.repeat(64), request: {} })
+
+ const expired = await send(expiredTicket(expiredClaims))
+ expect(expired.status).toBe(403)
+ expect(expired.body).toEqual({ error: 'ticket_expired' })
+
+ // jsonwebtoken checks exp before audience and claims, so each of these is
+ // expired too; none is an authentic Codex ticket.
+ for (const forged of [
+ expiredTicket(expiredClaims, foreignKey),
+ expiredTicket(expiredClaims, privateKey, 'grok-llm-proxy'),
+ expiredTicket({ ...expiredClaims, typ: 'grok-execution-ticket' }),
+ ]) {
+ const refused = await send(forged)
+ expect(refused.status).toBe(403)
+ expect(refused.body).toEqual({ error: 'ticket_invalid' })
+ }
+
+ // Witness: a live ticket passes the ticket gate and stops at the next one.
+ const live = await send(ticket())
+ expect(live.status).toBe(404)
+ expect(live.body).toEqual({ error: 'disabled' })
+ })
+
it('rejects an admin permit whose operation does not match the route', async () => {
const { adminApp } = createProxyApps(config())
const wrong = sign(
diff --git a/grok-llm-proxy/test/grokTransport.conformance.test.ts b/grok-llm-proxy/test/grokTransport.conformance.test.ts
index b9172f73b..d1364bb96 100644
--- a/grok-llm-proxy/test/grokTransport.conformance.test.ts
+++ b/grok-llm-proxy/test/grokTransport.conformance.test.ts
@@ -1864,6 +1864,25 @@ describe('streamGrokCompletion', () => {
await expectRefused([textBefore, openCall, completed])
})
+ // R17-1: a stream that ends with no terminal event never delivers its calls,
+ // so a call left open there is not parsed and the attempt stays `unknown`,
+ // as on dev. Refusing its arguments would report a dropped connection as a
+ // malformed model response.
+ it.each([
+ ['empty', [openCall]],
+ ['truncated', [openCall, truncatedDelta]],
+ ])(
+ 'T-R17-1-grok reports a stream that ends with no terminal event and a call open with %s arguments as unknown',
+ async (_label, callEvents) => {
+ const { settled, frames, fetchFn, finalize } = await runUpstream([textBefore, ...callEvents])
+ expect(fetchFn).toHaveBeenCalledTimes(1)
+ expect(frames).toEqual([{ type: 'text', text: 'before' }])
+ expect(settled).toMatchObject({ rejected: false, result: { outcome: 'unknown' } })
+ expect(finalize).toHaveBeenCalledTimes(1)
+ expect(finalize.mock.calls[0]?.[0]?.receipt.outcome).toBe('unknown')
+ }
+ )
+
// A canceled or failed stream also ends with its open call truncated. That
// truncation is a consequence of the stream's own outcome, so the outcome
// wins over the arguments refusal.
diff --git a/grok-llm-proxy/test/server.security.test.ts b/grok-llm-proxy/test/server.security.test.ts
index fa82da6c9..daae3ea66 100644
--- a/grok-llm-proxy/test/server.security.test.ts
+++ b/grok-llm-proxy/test/server.security.test.ts
@@ -281,6 +281,59 @@ describe('grok-llm-proxy security surface', () => {
expect(verifyAdminPermit(permitNoExp, cfg)).toBeNull()
})
+ // R17-2: body admission can hold a body for up to maxQueueWaitMs before the
+ // ticket is read, the same span as the ticket TTL, so an honest request can
+ // reach this gate with an expired ticket. That answer must be the retryable
+ // ticket_expired; every other ticket failure stays ticket_invalid.
+ it('T-R17-2-grok answers ticket_expired for an authentic expired ticket and ticket_invalid otherwise', async () => {
+ const { runtimeApp } = createProxyApps(config({ executionEnabled: false }))
+ const { privateKey: foreignKey } = generateKeyPairSync('rsa', {
+ modulusLength: 2048,
+ publicKeyEncoding: { type: 'spki', format: 'pem' },
+ privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
+ })
+ const expiredClaims = {
+ jti: '11111111-1111-4111-8111-111111111111',
+ typ: 'grok-execution-ticket',
+ hostRef: 'research-host',
+ model: 'gpt-5.1',
+ requestHash: 'a'.repeat(64),
+ providerAttemptId: 'att-1',
+ exp: Math.floor(Date.now() / 1000) - 5,
+ }
+ const expiredTicket = (
+ claims: Record<string, unknown>,
+ key: string = privateKey,
+ audience = 'grok-llm-proxy'
+ ) => jwt.sign(claims, key, { algorithm: 'RS256', issuer: 'control-api', audience })
+ const send = (executionTicket: string) =>
+ request(runtimeApp)
+ .post('/internal/runtime/v1/grok/completions')
+ .set('Authorization', `Bearer ${platformToken()}`)
+ .send({ executionTicket, requestHash: 'a'.repeat(64), request: {} })
+
+ const expired = await send(expiredTicket(expiredClaims))
+ expect(expired.status).toBe(403)
+ expect(expired.body).toEqual({ error: 'ticket_expired' })
+
+ // jsonwebtoken checks exp before audience and claims, so each of these is
+ // expired too; none is an authentic Grok ticket.
+ for (const forged of [
+ expiredTicket(expiredClaims, foreignKey),
+ expiredTicket(expiredClaims, privateKey, 'codex-llm-proxy'),
+ expiredTicket({ ...expiredClaims, typ: 'codex-execution-ticket' }),
+ ]) {
+ const refused = await send(forged)
+ expect(refused.status).toBe(403)
+ expect(refused.body).toEqual({ error: 'ticket_invalid' })
+ }
+
+ // Witness: a live ticket passes the ticket gate and stops at the next one.
+ const live = await send(ticket())
+ expect(live.status).toBe(404)
+ expect(live.body).toEqual({ error: 'disabled' })
+ })
+
it('rejects an admin permit whose operation does not match the route', async () => {
const { adminApp } = createProxyApps(config())
const wrong = sign(