Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(codex): raise the contract to 256 tool calls and 1024 messages
Alfredo Lopezfba84cb34cf2
diff --git a/codex-llm-proxy/test/approvedToolsUpstream.test.ts b/codex-llm-proxy/test/approvedToolsUpstream.test.tsindex ac9970698..099f787f6 100644--- a/codex-llm-proxy/test/approvedToolsUpstream.test.ts+++ b/codex-llm-proxy/test/approvedToolsUpstream.test.ts@@ -375,6 +375,72 @@ describe('approved-tools isolated upstream boundary', () => {})})+// Drives one completion through the real proxy transport against the fixture.+function transport(+ simulator: ReturnType<typeof createApprovedToolsUpstream>,+ content: string,+ id: string,+ outcome: 'success' | 'error'+) {+ const probeRequest = {+ schemaVersion: 'codex-completion-request.v1' as const,+ requestId: `req-${id}`,+ idempotencyKey: `idem-${id}`,+ provider: 'codex-subscription' as const,+ model: 'gpt-5.3-codex',+ messages: [{ role: 'user' as const, content }],+ tools: bridges.map(name => ({+ name,+ description: `${name} bridge`,+ parameters: { type: 'object' },+ })),+ }+ const requestHash = hashCodexCompletionRequestV1(probeRequest)+ const emitted: Array<{ type: string }> = []+ const finalize = vi.fn(async () => ({+ providerAttemptId: `att-${id}`,+ outcome,+ duplicate: false,+ }))+ const pending = streamCodexCompletion({+ executionTicket: `ticket-${id}`,+ requestHash,+ request: probeRequest,+ ticket: {+ jti: `jti-${id}`,+ hostRef: 'approved-tools-host',+ model: probeRequest.model,+ requestHash,+ providerAttemptId: `att-${id}`,+ },+ redeem: vi.fn(+ async (): Promise<RedeemAttemptSuccess> => ({+ accessToken: `hdr.${Buffer.from(+ JSON.stringify({ 'https://api.openai.com/auth': { chatgpt_account_id: 'acct_probe' } })+ ).toString('base64url')}.sig`,+ transport: {+ protocolVersion: 'codex-subscription-transport.v1',+ completionsOrigin: CODEX_COMPLETIONS_ORIGIN,+ catalogOrigin: 'https://chatgpt.com/backend-api/codex/models?client_version=1.0.0',+ operation: 'completion_stream',+ servedModel: probeRequest.model,+ maxStreamDurationMs: 300_000,+ },+ expiryClass: 'short_lived',+ attemptReceipt: 'b'.repeat(64),+ })+ ),+ finalize,+ fetchFn: simulator.fetchFn,+ lookup: async () => [{ address: '104.18.32.47', family: 4 }],+ onFrame: frame => {+ emitted.push(frame)+ },+ })++ return { pending, emitted, finalize }+}+describe('approved-tools tool-call limit probe', () => {const probe = { role: 'user', content: 'Run the tool call limit probe now.' }@@ -385,15 +451,15 @@ describe('approved-tools tool-call limit probe', () => {.map(frame => JSON.parse(frame.slice('data: '.length)) as Entry)}- it('answers a probe turn with 65 distinct search calls in one completion', async () => {+ it('answers a probe turn with 257 distinct search calls in one completion', async () => {const simulator = createApprovedToolsUpstream()const { response, body } = await request(simulator, [probe])expect(response.status).toBe(200)const rows = events(body)const calls = rows.slice(0, -1).map(row => row.item as Entry)expect(rows[rows.length - 1]).toEqual({ type: 'response.completed' })- expect(calls).toHaveLength(65)- expect(new Set(calls.map(call => call.call_id)).size).toBe(65)+ expect(calls).toHaveLength(257)+ expect(new Set(calls.map(call => call.call_id)).size).toBe(257)for (const call of calls) {expect(call).toMatchObject({type: 'function_call',@@ -446,66 +512,16 @@ describe('approved-tools tool-call limit probe', () => {it('makes the real transport fail the probe with tool_call_limit_exceeded', async () => {const simulator = createApprovedToolsUpstream()- const probeRequest = {- schemaVersion: 'codex-completion-request.v1' as const,- requestId: 'req-limit-probe',- idempotencyKey: 'idem-limit-probe',- provider: 'codex-subscription' as const,- model: 'gpt-5.3-codex',- messages: [{ role: 'user' as const, content: probe.content }],- tools: bridges.map(name => ({- name,- description: `${name} bridge`,- parameters: { type: 'object' },- })),- }- const requestHash = hashCodexCompletionRequestV1(probeRequest)- const emitted: Array<{ type: string }> = []- const finalize = vi.fn(async () => ({- providerAttemptId: 'att-limit-probe',- outcome: 'error' as const,- duplicate: false,- }))- const pending = streamCodexCompletion({- executionTicket: 'ticket-limit-probe',- requestHash,- request: probeRequest,- ticket: {- jti: 'jti-limit-probe',- hostRef: 'approved-tools-host',- model: probeRequest.model,- requestHash,- providerAttemptId: 'att-limit-probe',- },- redeem: vi.fn(- async (): Promise<RedeemAttemptSuccess> => ({- accessToken: `hdr.${Buffer.from(- JSON.stringify({ 'https://api.openai.com/auth': { chatgpt_account_id: 'acct_probe' } })- ).toString('base64url')}.sig`,- transport: {- protocolVersion: 'codex-subscription-transport.v1',- completionsOrigin: CODEX_COMPLETIONS_ORIGIN,- catalogOrigin: 'https://chatgpt.com/backend-api/codex/models?client_version=1.0.0',- operation: 'completion_stream',- servedModel: probeRequest.model,- maxStreamDurationMs: 300_000,- },- expiryClass: 'short_lived',- attemptReceipt: 'b'.repeat(64),- })- ),- finalize,- fetchFn: simulator.fetchFn,- lookup: async () => [{ address: '104.18.32.47', family: 4 }],- onFrame: frame => {- emitted.push(frame)- },- })-+ const { pending, emitted, finalize } = transport(+ simulator,+ probe.content,+ 'limit-probe',+ 'error'+ )await expect(pending).rejects.toMatchObject({name: 'CodexTransportError',code: 'tool_call_limit_exceeded',- details: { limit: 64, observed: 65 },+ details: { limit: 256, observed: 257 },})// Liveness witness: the upstream served exactly one probe completion.expect(simulator.evidence().limitProbe).toEqual({@@ -531,3 +547,112 @@ describe('approved-tools tool-call limit probe', () => {})})})++describe('approved-tools tool-call limit boundary', () => {+ const boundary = { role: 'user', content: 'Run the tool call limit boundary now.' }++ function calls(body: string): Entry[] {+ return body+ .split('\n\n')+ .filter(Boolean)+ .map(frame => JSON.parse(frame.slice('data: '.length)) as Entry)+ .slice(0, -1)+ .map(row => row.item as Entry)+ }++ function answered(items: Entry[]): Entry[] {+ return items.flatMap(item => [+ item,+ {+ type: 'function_call_output',+ call_id: item.call_id,+ output: JSON.stringify({ found: 0, returned: 0, results: [] }),+ },+ ])+ }++ it('answers a boundary turn with 256 distinct search calls, then a final answer', async () => {+ const simulator = createApprovedToolsUpstream()+ const first = await request(simulator, [boundary])+ expect(first.response.status).toBe(200)+ const items = calls(first.body)+ expect(items).toHaveLength(256)+ expect(new Set(items.map(item => item.call_id)).size).toBe(256)+ expect(new Set(items.map(item => item.arguments)).size).toBe(256)+ for (const item of items) expect(item).toMatchObject({ name: 'clerum__tool_search' })++ const final = await request(simulator, [boundary, ...answered(items)])+ expect(final.response.status).toBe(200)+ expect(final.event).toEqual({+ type: 'response.output_text.delta',+ delta: 'Tool call limit boundary complete: 256 tool results received.',+ })+ expect(simulator.evidence()).toMatchObject({+ limitBoundary: {+ turns: 1,+ completions: 2,+ toolResults: 256,+ finalResponses: 1,+ unexpectedRetries: 0,+ },+ completions: 2,+ searchCalls: 0,+ rejected: 0,+ })+ expect(simulator.evidence().requests.map(row => row.stage)).toEqual([+ 'limit_boundary',+ 'limit_boundary_final',+ ])+ })++ it('rejects a missing result, a foreign call ID, a failed search and a repeated turn', async () => {+ const simulator = createApprovedToolsUpstream()+ const items = calls((await request(simulator, [boundary])).body)+ const full = answered(items)+ const missing = await request(simulator, [boundary, ...full.slice(0, -1)])+ const foreign = await request(simulator, [+ boundary,+ ...answered([{ ...items[0]!, call_id: 'foreign' }, ...items.slice(1)]),+ ])+ const failedSearch = await request(simulator, [+ boundary,+ ...full.slice(0, -1),+ { ...full.at(-1)!, output: JSON.stringify({ isError: true }) },+ ])+ const retry = await request(simulator, [boundary])+ expect([missing, foreign, failedSearch, retry].map(result => result.response.status)).toEqual([+ 422, 422, 422, 422,+ ])+ // Liveness witness: the rejected continuations did not consume the turn.+ const final = await request(simulator, [boundary, ...full])+ expect(final.response.status).toBe(200)+ const repeated = await request(simulator, [boundary, ...full])+ expect(repeated.response.status).toBe(422)+ expect(simulator.evidence()).toMatchObject({+ limitBoundary: {+ turns: 1,+ completions: 7,+ toolResults: 256,+ finalResponses: 1,+ unexpectedRetries: 2,+ },+ rejected: 5,+ })+ })++ it('makes the real transport deliver all 256 calls without tool_call_limit_exceeded', async () => {+ const simulator = createApprovedToolsUpstream()+ const { pending, emitted, finalize } = transport(+ simulator,+ boundary.content,+ 'limit-boundary',+ 'success'+ )+ await pending+ const delivered = emitted.filter(frame => frame.type === 'tool_call')+ expect(delivered).toHaveLength(256)+ expect(emitted.some(frame => frame.type === 'error')).toBe(false)+ expect(simulator.evidence().limitBoundary).toMatchObject({ turns: 1, completions: 1 })+ expect(finalize).toHaveBeenCalledTimes(1)+ })+})diff --git a/codex-llm-proxy/test/approvedToolsUpstream.ts b/codex-llm-proxy/test/approvedToolsUpstream.tsindex 350aa4933..35126940b 100644--- a/codex-llm-proxy/test/approvedToolsUpstream.ts+++ b/codex-llm-proxy/test/approvedToolsUpstream.ts@@ -9,9 +9,13 @@ const BRIDGES = ['clerum__tool_search', 'clerum__tool_describe', 'clerum__tool_c// The deterministic external model is scoped to this fixture's read journey.const FIXTURE_QUERY = 'verification receipt'// A user turn with this text gets one response carrying more tool calls than-// the Codex contract allows (maxToolCalls 64), so the proxy must reject it.+// the Codex contract allows (maxToolCalls 256), so the proxy must reject it.const LIMIT_PROBE = 'tool call limit probe'-const LIMIT_PROBE_CALLS = 65+const LIMIT_PROBE_CALLS = 257+// A user turn with this text gets exactly maxToolCalls distinct search calls;+// the continuation must carry every result back before the final answer.+const LIMIT_BOUNDARY = 'tool call limit boundary'+const LIMIT_BOUNDARY_CALLS = 256function record(value: unknown): Row {if (!value || typeof value !== 'object' || Array.isArray(value))@@ -82,6 +86,27 @@ function failed(result: Row): boolean {return result.isError === true || result.is_error === true || Boolean(result.error)}+// Every call sent for the boundary turn must come back once, with a real+// search result after it. Returns the number of correlated results.+function boundaryResults(rows: Row[], sent: Set<string>): number {+ const calls = rows.filter(row => row.type === 'function_call')+ const outputs = rows.filter(row => row.type === 'function_call_output')+ if (calls.length !== sent.size || outputs.length !== sent.size)+ throw new Error('incomplete_boundary_batch')+ if (new Set(calls.map(call => call.call_id)).size !== calls.length)+ throw new Error('duplicate_call_id')+ for (const call of calls) {+ if (call.name !== BRIDGES[0] || typeof call.call_id !== 'string' || !sent.has(call.call_id))+ throw new Error('uncorrelated_boundary_call')+ const matched = outputs.filter(output => output.call_id === call.call_id)+ if (matched.length !== 1 || rows.indexOf(matched[0]!) < rows.indexOf(call))+ throw new Error('uncorrelated_result')+ const result = textResult(matched[0]!.output, BRIDGES[0])+ if (failed(result) || !Array.isArray(result.results)) throw new Error('boundary_search_failed')+ }+ return calls.length+}+function described(exchange: Exchange): string {if (exchange.call.name !== BRIDGES[1] ||@@ -293,6 +318,15 @@ export function createApprovedToolsUpstream() {// Probe turns answered with an over-limit batch, every completion served// for them, and completions that repeated an already answered probe turn.limitProbe: { turns: 0, completions: 0, unexpectedRetries: 0 },+ // Boundary turns answered with exactly maxToolCalls calls, completions+ // served for them, correlated results received and final answers sent.+ limitBoundary: {+ turns: 0,+ completions: 0,+ toolResults: 0,+ finalResponses: 0,+ unexpectedRetries: 0,+ },// Only bounded measurements, never request or result contents.requests: [] as Array<{definitionCount: number@@ -307,6 +341,8 @@ export function createApprovedToolsUpstream() {// Digests of the history up to each answered probe user turn. A retry of the// same turn resends that history unchanged.const answeredProbeTurns = new Set<string>()+ // Call IDs sent for each boundary turn, and whether its final answer was sent.+ const boundaryTurns = new Map<string, { sent: Set<string>; finalized: boolean }>()const fetchFn: typeof fetch = async (input, init) => {try {@@ -334,6 +370,62 @@ export function createApprovedToolsUpstream() {const user = history[lastUser]if (!user || typeof user.content !== 'string' || !user.content.trim())throw new Error('missing_user_request')+ if (user.content.toLowerCase().includes(LIMIT_BOUNDARY)) {+ if (evidence.requests.length >= 512) throw new Error('evidence_capacity_exceeded')+ evidence.limitBoundary.completions+++ const turn = createHash('sha256')+ .update(JSON.stringify(history.slice(0, lastUser + 1)))+ .digest('hex')+ const known = boundaryTurns.get(turn)+ const rows = history.slice(lastUser + 1)+ const measured = (stage: string) => ({+ definitionCount: tools.length,+ explicitNonStrictCount: tools.filter(tool => tool.strict === false).length,+ definitionBytes: Buffer.byteLength(JSON.stringify(tools)),+ inputBytes: Buffer.byteLength(JSON.stringify(payload.input)),+ connectorDefinitionCount: 0,+ leakedSchema: false,+ stage,+ })+ if (rows.length === 0) {+ if (known) {+ evidence.limitBoundary.unexpectedRetries+++ throw new Error('unexpected_retry')+ }+ // Distinct arguments: identical consecutive calls trip the host's+ // doom-loop guard, which would test that guard instead of the limit.+ const calls = Array.from({ length: LIMIT_BOUNDARY_CALLS }, (_, index) => ({+ type: 'function_call',+ id: randomUUID(),+ call_id: randomUUID(),+ name: BRIDGES[0],+ arguments: JSON.stringify({ query: `limit boundary ${index}`, limit: 1 }),+ }))+ boundaryTurns.set(turn, {+ sent: new Set(calls.map(call => call.call_id)),+ finalized: false,+ })+ evidence.limitBoundary.turns+++ evidence.completions+++ evidence.requests.push(measured('limit_boundary'))+ return stream(...calls.map(item => ({ type: 'response.output_item.done', item })))+ }+ if (!known) throw new Error('unknown_boundary_turn')+ if (known.finalized) {+ evidence.limitBoundary.unexpectedRetries+++ throw new Error('unexpected_retry')+ }+ const received = boundaryResults(rows, known.sent)+ known.finalized = true+ evidence.limitBoundary.toolResults += received+ evidence.limitBoundary.finalResponses+++ evidence.completions+++ evidence.requests.push(measured('limit_boundary_final'))+ return stream({+ type: 'response.output_text.delta',+ delta: `Tool call limit boundary complete: ${received} tool results received.`,+ })+ }if (user.content.toLowerCase().includes(LIMIT_PROBE)) {if (evidence.requests.length >= 512) throw new Error('evidence_capacity_exceeded')evidence.limitProbe.completions++diff --git a/codex-llm-proxy/test/codexTransport.conformance.test.ts b/codex-llm-proxy/test/codexTransport.conformance.test.tsindex 945609cad..d8e8dc04a 100644--- a/codex-llm-proxy/test/codexTransport.conformance.test.ts+++ b/codex-llm-proxy/test/codexTransport.conformance.test.ts@@ -336,7 +336,7 @@ describe('streamCodexCompletion', () => {expect(emitted).toEqual([])})- it.each([64, 65])(+ it.each([256, 257])('validates the complete %s-call response before emitting executable calls',async count => {const emitted: Array<{ type: string }> = []@@ -373,15 +373,15 @@ describe('streamCodexCompletion', () => {emitted.push(frame)},})- if (count === 64) {+ if (count === 256) {expect((await pending).outcome).toBe('success')- expect(emitted.filter(frame => frame.type === 'tool_call')).toHaveLength(64)+ expect(emitted.filter(frame => frame.type === 'tool_call')).toHaveLength(256)} else {await expect(pending).rejects.toMatchObject({name: 'CodexTransportError',code: 'tool_call_limit_exceeded',- message: 'tool calls exceed 64',- details: { limit: 64, observed: 65 },+ message: 'tool calls exceed 256',+ details: { limit: 256, observed: 257 },})expect(emitted.filter(frame => frame.type === 'tool_call')).toHaveLength(0)expect(finalize).toHaveBeenCalledWith(diff --git a/codex-llm-proxy/test/runtimePath.hermetic.e2e.test.ts b/codex-llm-proxy/test/runtimePath.hermetic.e2e.test.tsindex 9426b4446..a06c287f3 100644--- a/codex-llm-proxy/test/runtimePath.hermetic.e2e.test.ts+++ b/codex-llm-proxy/test/runtimePath.hermetic.e2e.test.ts@@ -561,14 +561,14 @@ describe('hermetic per-response tool-call limit', () => {}}- it('rejects 65 calls before any text with 422 tool_call_limit_exceeded', async () => {+ it('rejects 257 calls before any text with 422 tool_call_limit_exceeded', async () => {const { res, redeems, finalizes, counters } = await runWithToolCallCount(- 65,- 'att-hermetic-limit-65',+ 257,+ 'att-hermetic-limit-257',{ omitText: true })- // Liveness witness: the upstream really served the 65-call stream.+ // Liveness witness: the upstream really served the 257-call stream.expect(counters.streams).toBe(1)// One assertion so a regression reports both the status and the code.expect({@@ -584,15 +584,15 @@ describe('hermetic per-response tool-call limit', () => {expect(redeems).toHaveLength(1)expect(finalizes).toHaveLength(1)expect(finalizes[0]?.receipt).toMatchObject({- providerAttemptId: 'att-hermetic-limit-65',+ providerAttemptId: 'att-hermetic-limit-257',outcome: 'error',})})- it('rejects 65 calls after streamed text with an SSE tool_call_limit_exceeded frame', async () => {+ it('rejects 257 calls after streamed text with an SSE tool_call_limit_exceeded frame', async () => {const { res, redeems, finalizes, counters } = await runWithToolCallCount(- 65,- 'att-hermetic-limit-65-text',+ 257,+ 'att-hermetic-limit-257-text',{ omitText: false })@@ -608,15 +608,15 @@ describe('hermetic per-response tool-call limit', () => {expect(redeems).toHaveLength(1)expect(finalizes).toHaveLength(1)expect(finalizes[0]?.receipt).toMatchObject({- providerAttemptId: 'att-hermetic-limit-65-text',+ providerAttemptId: 'att-hermetic-limit-257-text',outcome: 'error',})})- it('delivers exactly 64 calls in one response', async () => {+ it('delivers exactly 256 calls in one response', async () => {const { res, redeems, finalizes, counters } = await runWithToolCallCount(- 64,- 'att-hermetic-limit-64',+ 256,+ 'att-hermetic-limit-256',{ omitText: true })@@ -624,15 +624,15 @@ describe('hermetic per-response tool-call limit', () => {expect(res.status).toBe(200)const frames = sseFrames(res.text)const toolCalls = frames.filter(frame => frame.type === 'tool_call')- expect(toolCalls).toHaveLength(64)+ expect(toolCalls).toHaveLength(256)expect(toolCalls.map(frame => frame.id)).toEqual(- Array.from({ length: 64 }, (_, index) => `call-hermetic-${index}`)+ Array.from({ length: 256 }, (_, index) => `call-hermetic-${index}`))expect(frames.find(frame => frame.type === 'done')?.outcome).toBe('success')expect(redeems).toHaveLength(1)expect(finalizes).toHaveLength(1)expect(finalizes[0]?.receipt).toMatchObject({- providerAttemptId: 'att-hermetic-limit-64',+ providerAttemptId: 'att-hermetic-limit-256',outcome: 'success',})})diff --git a/codex-llm-proxy/test/server.security.test.ts b/codex-llm-proxy/test/server.security.test.tsindex 13387da37..359d44535 100644--- a/codex-llm-proxy/test/server.security.test.ts+++ b/codex-llm-proxy/test/server.security.test.ts@@ -599,8 +599,8 @@ describe('codex-llm-proxy attempt telemetry', () => {for (const key of FORBIDDEN_LOG_KEYS) expect(key in line).toBe(false)}- it('(a) answers 422 and logs one attempt line when 65 calls arrive before any text', async () => {- const { res, receipts, lines, metricsText } = await run('att-limit-http', 0, 65)+ it('(a) answers 422 and logs one attempt line when 257 calls arrive before any text', async () => {+ const { res, receipts, lines, metricsText } = await run('att-limit-http', 0, 257)expect(res.status).toBe(422)// The staged SSE headers are replaced by a JSON response.expect(res.headers['content-type']).toMatch(/^application\/json/)@@ -612,8 +612,8 @@ describe('codex-llm-proxy attempt telemetry', () => {providerAttemptId: 'att-limit-http',outcome: 'failed',code: 'tool_call_limit_exceeded',- reason: 'tool calls exceed 64',- details: { limit: 64, observed: 65 },+ reason: 'tool calls exceed 256',+ details: { limit: 256, observed: 257 },deliveredAs: 'http_status',httpStatus: 422,toolCalls: 0,@@ -624,7 +624,7 @@ describe('codex-llm-proxy attempt telemetry', () => {})it('(b) sends an SSE error frame when text was already streamed', async () => {- const { res, lines } = await run('att-limit-sse', 1, 65)+ const { res, lines } = await run('att-limit-sse', 1, 257)expect(res.status).toBe(200)expect(res.text).toContain('data: {"type":"text","text":"t0"}')expect(res.text).toContain('data: {"type":"error","code":"tool_call_limit_exceeded"}')diff --git a/docs/architecture/codex-subscription-transport-contract.md b/docs/architecture/codex-subscription-transport-contract.mdindex e0116db8a..4bc6e77be 100644--- a/docs/architecture/codex-subscription-transport-contract.md+++ b/docs/architecture/codex-subscription-transport-contract.md@@ -52,8 +52,8 @@ one physical execution per ticket. A retry or fallback must mint a new attempt.| Limit | Value || -------------------- | ------- || maxRequestBodyBytes | 1048576 |-| maxMessages | 256 |-| maxToolCalls | 64 |+| maxMessages | 1024 |+| maxToolCalls | 256 || maxOutputTokens | 16384 || maxStreamDurationMs | 300000 || maxDeadlineMs | 300000 |@@ -64,14 +64,14 @@ one physical execution per ticket. A retry or fallback must mint a new attempt.Tool definitions have no independent count ceiling in the Evenfire requestcontract. The entire serialized request, including all definitions, remainsbounded by `maxRequestBodyBytes` (1 MiB). Every definition still undergoes-name, schema, finite-value and unknown-field validation. `maxToolCalls` (64)+name, schema, finite-value and unknown-field validation. `maxToolCalls` (256)bounds calls in each assistant history message and each newly returnedresponse. The proxy buffers tool calls until successful completion andvalidates the bound before publishing any executable call; the Host validatesit again before returning the batch. A response over the bound fails with`tool_call_limit_exceeded`, which is not retried and does not fail over. It isnot a catalog size limit and does not widen execution concurrency.-`maxMessages` (256) bounds the request history. The Host rejects a longer+`maxMessages` (1024) bounds the request history. The Host rejects a longerhistory with `request_limit_exceeded` before authorization, so no ticket isminted for it.diff --git a/docs/architecture/grok-subscription-transport-contract.md b/docs/architecture/grok-subscription-transport-contract.mdindex 21ff02750..97fa74ca3 100644--- a/docs/architecture/grok-subscription-transport-contract.md+++ b/docs/architecture/grok-subscription-transport-contract.md@@ -121,7 +121,7 @@ an error.## LimitsOwned by `@clerum/grok-provider-attempt-contract`. Independent of Codex-`LIMITS` (`maxToolCalls` is 64 for both contracts; `maxMessages` is 128 for Grok, 256 for Codex).+`LIMITS` (`maxToolCalls` is 64 for Grok and 256 for Codex; `maxMessages` is 128 for Grok and 1024 for Codex).Proxy robustness (both proxies):diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex 6f6bda981..1f9ab2509 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.358",+ "version": "0.1.359","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.358",+ "version": "0.1.359","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex dc6d15d8a..dfc631db5 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.358",+ "version": "0.1.359","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/orchestration/__tests__/toolUseLoop.toolCallLimit.test.ts b/mcp-host/src/core/orchestration/__tests__/toolUseLoop.toolCallLimit.test.tsindex da5ad4013..a1a119f0e 100644--- a/mcp-host/src/core/orchestration/__tests__/toolUseLoop.toolCallLimit.test.ts+++ b/mcp-host/src/core/orchestration/__tests__/toolUseLoop.toolCallLimit.test.ts@@ -34,7 +34,7 @@ function reasoningFailingAfterToolResults(error: LlmError) {describe('runToolUseLoop tool-call limit', () => {it('ends the loop with LLM_TOOL_CALL_LIMIT_EXCEEDED and no workflow fallback', async () => {const limit = new LlmError(- 'tool calls exceed 64',+ 'tool calls exceed 256','codex-subscription',LlmErrorCode.ToolCallLimitExceeded,falsediff --git a/mcp-host/src/llm/__tests__/codexSubscription.test.ts b/mcp-host/src/llm/__tests__/codexSubscription.test.tsindex 99e3cce7e..c12a9b97f 100644--- a/mcp-host/src/llm/__tests__/codexSubscription.test.ts+++ b/mcp-host/src/llm/__tests__/codexSubscription.test.ts@@ -84,18 +84,18 @@ describe('CodexSubscriptionProvider', () => {})}- it('returns a successful proxy batch of exactly 64 tool calls', async () => {- const wired = successfulBatch(64)+ it('returns a successful proxy batch of exactly 256 tool calls', async () => {+ const wired = successfulBatch(256)const provider = new CodexSubscriptionProvider('gpt-5.3-codex', wired as never)const result = await provider.completeSingleTurnWithTools([{ role: 'user', content: 'hi' }],[{ name: 'echo', description: 'echo', parameters: {} }])- expect(result.tool_calls).toHaveLength(64)+ expect(result.tool_calls).toHaveLength(256)})- it('rejects a 65-call proxy batch with tool_call_limit_exceeded before returning any executable tools', async () => {- const wired = successfulBatch(65)+ it('rejects a 257-call proxy batch with tool_call_limit_exceeded before returning any executable tools', async () => {+ const wired = successfulBatch(257)const provider = new CodexSubscriptionProvider('gpt-5.3-codex', wired as never)await expect(provider.completeSingleTurnWithTools(@@ -105,14 +105,14 @@ describe('CodexSubscriptionProvider', () => {).rejects.toMatchObject({name: 'CodexProxyError',code: 'tool_call_limit_exceeded',- message: 'tool calls exceed 64',+ message: 'tool calls exceed 256',})// Liveness witness: the batch really came back from the proxy.expect(wired.stream).toHaveBeenCalledTimes(1)})- it('surfaces a 65-call stream through the port adapter as a non-retryable LlmError', async () => {- const wired = successfulBatch(65)+ it('surfaces a 257-call stream through the port adapter as a non-retryable LlmError', async () => {+ const wired = successfulBatch(257)const adapter = new LlmPortAdapter(new CodexSubscriptionProvider('gpt-5.3-codex', wired as never),'gpt-5.3-codex',@@ -134,7 +134,7 @@ describe('CodexSubscriptionProvider', () => {})})- it('rejects more than 256 messages before authorize or dispatch', async () => {+ it('rejects more than 1024 messages before authorize or dispatch', async () => {const wired = deps()const provider = new CodexSubscriptionProvider('gpt-5.3-codex', wired as never)const history = (count: number) =>@@ -143,17 +143,17 @@ describe('CodexSubscriptionProvider', () => {content: `message ${index}`,}))- const rejected = provider.completeSingleTurn(history(257))+ const rejected = provider.completeSingleTurn(history(1025))await expect(rejected).rejects.toBeInstanceOf(CodexAuthorizeError)await expect(rejected).rejects.toMatchObject({code: 'request_limit_exceeded',- message: 'messages exceed 256',+ message: 'messages exceed 1024',})expect(wired.authorize).not.toHaveBeenCalled()expect(wired.stream).not.toHaveBeenCalled()// Liveness witness: at the limit the same provider authorizes and streams.- await provider.completeSingleTurn(history(256))+ await provider.completeSingleTurn(history(1024))expect(wired.authorize).toHaveBeenCalledTimes(1)expect(wired.stream).toHaveBeenCalledTimes(1)})@@ -486,24 +486,24 @@ describe('CodexSubscriptionProvider', () => {const provider = new CodexSubscriptionProvider('gpt-5.3-codex', deps() as never)const toolLimit = provider.classifyError(- new CodexProxyError('tool_call_limit_exceeded', 'tool calls exceed 64')+ new CodexProxyError('tool_call_limit_exceeded', 'tool calls exceed 256'))expect(toolLimit).toEqual({code: LlmErrorCode.ToolCallLimitExceeded,retryable: false,- message: 'tool calls exceed 64',+ message: 'tool calls exceed 256',providerCode: 'tool_call_limit_exceeded',providerDispatched: true,})expect(classifyFailoverClass(toolLimit.code, toolLimit.retryable)).toBeNull()const history = provider.classifyError(- new CodexAuthorizeError('request_limit_exceeded', 'messages exceed 256')+ new CodexAuthorizeError('request_limit_exceeded', 'messages exceed 1024'))expect(history).toEqual({code: LlmErrorCode.ContextLengthExceeded,retryable: false,- message: 'messages exceed 256',+ message: 'messages exceed 1024',providerCode: 'request_limit_exceeded',providerDispatched: false,})diff --git a/packages/llm-provider-attempt-contract/index.cjs b/packages/llm-provider-attempt-contract/index.cjsindex 958fd2884..99ece4f0c 100644--- a/packages/llm-provider-attempt-contract/index.cjs+++ b/packages/llm-provider-attempt-contract/index.cjs@@ -14,10 +14,11 @@ const TICKET_TYP = 'codex-execution-ticket'const LIMITS = Object.freeze({maxRequestBodyBytes: 1048576,- maxMessages: 256,+ maxMessages: 1024,// Bound calls in each assistant message independently of advertised definitions.- // 64 matches the Grok contract; a turn of N calls adds N+1 messages, so N stays <= maxMessages/4.- maxToolCalls: 64,+ // A turn of N calls adds N+1 messages, so N stays <= maxMessages/4. At this+ // bound maxOutputTokens leaves 64 output tokens per call in one response.+ maxToolCalls: 256,maxOutputTokens: 16384,maxDeadlineMs: 300000,maxIdLength: 128,diff --git a/packages/llm-provider-attempt-contract/index.d.ts b/packages/llm-provider-attempt-contract/index.d.tsindex 34c3626fb..4e9958325 100644--- a/packages/llm-provider-attempt-contract/index.d.ts+++ b/packages/llm-provider-attempt-contract/index.d.ts@@ -15,8 +15,8 @@ export declare const TICKET_TYP: 'codex-execution-ticket'export declare const LIMITS: {readonly maxRequestBodyBytes: 1048576- readonly maxMessages: 256- readonly maxToolCalls: 64+ readonly maxMessages: 1024+ readonly maxToolCalls: 256readonly maxOutputTokens: 16384readonly maxDeadlineMs: 300000readonly maxIdLength: 128diff --git a/packages/llm-provider-attempt-contract/index.test.cjs b/packages/llm-provider-attempt-contract/index.test.cjsindex 69d256c25..0ee11559b 100644--- a/packages/llm-provider-attempt-contract/index.test.cjs+++ b/packages/llm-provider-attempt-contract/index.test.cjs@@ -275,9 +275,9 @@ for (const count of [1, 32, 33, 83, 150, 250]) {}test('tool definition count never widens the independent assistant call limit', () => {- assert.equal(contract.LIMITS.maxToolCalls, 64)+ assert.equal(contract.LIMITS.maxToolCalls, 256)assert.equal(Object.hasOwn(contract.LIMITS, 'maxTools'), false)- for (const count of [64, 65]) {+ for (const count of [256, 257]) {const parsed = contract.parseCodexCompletionRequestV1({...BASE,tools: catalog(250),@@ -285,20 +285,20 @@ test('tool definition count never widens the independent assistant call limit',id: `call-${index}`, name: `eventasks__read_${index}`, arguments: {},})) }],})- assert.equal(parsed.ok, count === 64)- if (!parsed.ok) assert.equal(parsed.message, 'messages[0].toolCalls exceed 64')+ assert.equal(parsed.ok, count === 256)+ if (!parsed.ok) assert.equal(parsed.message, 'messages[0].toolCalls exceed 256')}})test('message count is bounded at maxMessages', () => {- assert.equal(contract.LIMITS.maxMessages, 256)- for (const count of [256, 257]) {+ assert.equal(contract.LIMITS.maxMessages, 1024)+ for (const count of [1024, 1025]) {const parsed = contract.parseCodexCompletionRequestV1({...BASE,messages: Array.from({ length: count }, (_, index) => ({ role: 'user', content: `m${index}` })),})- assert.equal(parsed.ok, count === 256)- if (!parsed.ok) assert.equal(parsed.message, 'messages exceed 256')+ assert.equal(parsed.ok, count === 1024)+ if (!parsed.ok) assert.equal(parsed.message, 'messages exceed 1024')}})diff --git a/tests/e2e/fixtures/codex-subscription/sanitized-upstream-contract.json b/tests/e2e/fixtures/codex-subscription/sanitized-upstream-contract.jsonindex 380ef194f..2a0339ba4 100644--- a/tests/e2e/fixtures/codex-subscription/sanitized-upstream-contract.json+++ b/tests/e2e/fixtures/codex-subscription/sanitized-upstream-contract.json@@ -41,8 +41,8 @@"oauthScopes": ["openid", "profile", "email", "offline_access"],"limits": {"maxRequestBodyBytes": 1048576,- "maxMessages": 256,- "maxToolCalls": 64,+ "maxMessages": 1024,+ "maxToolCalls": 256,"maxOutputTokens": 16384,"maxStreamDurationMs": 300000,"maxDeadlineMs": 300000,diff --git a/tests/e2e/fixtures/package-lock.json b/tests/e2e/fixtures/package-lock.jsonindex 2e5a1708b..17b402c80 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.85",+ "version": "1.0.86","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "@clerum/e2e-test-fixtures",- "version": "1.0.85",+ "version": "1.0.86","dependencies": {"@kubernetes/client-node": "^1.0.0"},diff --git a/tests/e2e/fixtures/package.json b/tests/e2e/fixtures/package.jsonindex 6d6baa5ba..a38efcff1 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.85",+ "version": "1.0.86","description": "E2E test fixtures and utilities for Clerum testing","type": "module","main": "index.ts",diff --git a/tests/e2e/integration/codex-subscription-contract-freeze.test.ts b/tests/e2e/integration/codex-subscription-contract-freeze.test.tsindex d72396e5f..a73e8e208 100644--- a/tests/e2e/integration/codex-subscription-contract-freeze.test.ts+++ b/tests/e2e/integration/codex-subscription-contract-freeze.test.ts@@ -154,8 +154,8 @@ describe('codex-subscription contract freeze', () => {}expect(limits).not.toHaveProperty('maxTools')- expect(limits?.maxToolCalls).toBe(64)- expect(limits?.maxMessages).toBe(256)+ expect(limits?.maxToolCalls).toBe(256)+ expect(limits?.maxMessages).toBe(1024)expect(limits?.maxRequestBodyBytes).toBe(1048576)const errors = contract.errorTaxonomydiff --git a/tests/e2e/package-lock.json b/tests/e2e/package-lock.jsonindex 35fedd54d..ea0cfa63e 100644--- a/tests/e2e/package-lock.json+++ b/tests/e2e/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-e2e-tests",- "version": "0.1.84",+ "version": "0.1.85","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-e2e-tests",- "version": "0.1.84",+ "version": "0.1.85","devDependencies": {"@types/jsonwebtoken": "^9.0.10","@types/node": "^22.0.0",diff --git a/tests/e2e/package.json b/tests/e2e/package.jsonindex 5291367a7..81bd1e857 100644--- a/tests/e2e/package.json+++ b/tests/e2e/package.json@@ -1,6 +1,6 @@{"name": "clerum-e2e-tests",- "version": "0.1.84",+ "version": "0.1.85","private": true,"type": "module","scripts": {diff --git a/tests/e2e/playwright/desktop/codex-subscription-approved-tools.spec.ts b/tests/e2e/playwright/desktop/codex-subscription-approved-tools.spec.tsindex cba1b4990..2c866a2d1 100644--- a/tests/e2e/playwright/desktop/codex-subscription-approved-tools.spec.ts+++ b/tests/e2e/playwright/desktop/codex-subscription-approved-tools.spec.ts@@ -12,6 +12,7 @@import { type Page, expect, test } from '@playwright/test'import {type Scenario,+ type UpstreamEvidence,localUrl,readEvidence,readUpstreamEvidence,@@ -522,9 +523,10 @@ for (const scenario of cases) {}// Only the deterministic upstream can answer with more function calls than the-// contract allows, so this case is registered in deterministic mode only. It-// runs after the approved-tools journeys and reuses the first prepared agent,-// whose subscription model binding those journeys persisted.+// contract allows, or with exactly that many, so these cases are registered in+// deterministic mode only. They run after the approved-tools journeys and reuse+// the first prepared agent, whose subscription model binding those journeys+// persisted.if (mode === 'deterministic') {test('tool call limit: Desktop shows Too Many Tool Calls without retry or connector call', async () => {const scenario = cases[0]!@@ -582,4 +584,64 @@ if (mode === 'deterministic') {}}})++ test('tool call limit boundary: Desktop completes a turn of exactly 256 tool calls', async () => {+ const scenario = cases[0]!+ const before = await readEvidence(scenario)+ const upstreamBefore = await readUpstreamEvidence(scenario)+ const app = await launchDesktopApp()+ let journeyPassed = false+ try {+ const desktop = await app.firstWindow()+ await test.step('Sign in visibly to Desktop and start a chat with the prepared agent', async () => {+ await openAgentChat(desktop, scenario)+ })+ const responses = await newAgentResponses(desktop)+ await test.step('Send the boundary turn and wait for the final answer', async () => {+ await send(desktop, 'tool call limit boundary')+ await expect(responses).toHaveCount(1, { timeout: 240_000 })+ await expect(responses).toContainText(+ 'Tool call limit boundary complete: 256 tool results received.',+ { timeout: 240_000 }+ )+ await expect(desktop.getByTestId('send-button')).toHaveAttribute(+ 'aria-label',+ 'Send message'+ )+ })+ await test.step('The answer is not an error and names no tool-call limit', async () => {+ await expect(responses).not.toHaveClass(/(^|\s)chat-bubble--error(\s|$)/)+ await expect(responses.getByText(/Too Many Tool Calls/)).toHaveCount(0)+ })+ await test.step('All 256 results reached the model once, with no retry', async () => {+ const upstreamAfter = await readUpstreamEvidence(scenario)+ const delta = (field: keyof UpstreamEvidence['limitBoundary']) =>+ upstreamAfter.limitBoundary[field] - upstreamBefore.limitBoundary[field]+ expect(delta('turns')).toBe(1)+ expect(delta('completions')).toBe(2)+ expect(delta('toolResults')).toBe(256)+ expect(delta('finalResponses')).toBe(1)+ expect(upstreamAfter.limitBoundary.unexpectedRetries).toBe(0)+ expect(upstreamAfter.rejected).toBe(upstreamBefore.rejected)+ const requests = upstreamAfter.requests.slice(upstreamBefore.requests.length)+ expect(requests.map(request => request.stage)).toEqual([+ 'limit_boundary',+ 'limit_boundary_final',+ ])+ // The continuation carried 256 calls and 256 results, so its input is+ // far larger than the request that started the turn.+ expect(requests[1]!.inputBytes).toBeGreaterThan(requests[0]!.inputBytes)+ // Only discovery searches ran; the connector was never called.+ expect((await readEvidence(scenario)).calls).toEqual(before.calls)+ })+ journeyPassed = true+ } finally {+ try {+ await app.close()+ } catch {+ if (journeyPassed) throw new Error('Desktop cleanup failed')+ // Preserve the original assertion failure when cleanup also fails.+ }+ }+ })}diff --git a/tests/e2e/playwright/helpers/approved-tools-scenarios.ts b/tests/e2e/playwright/helpers/approved-tools-scenarios.tsindex 5f896bff9..d84905006 100644--- a/tests/e2e/playwright/helpers/approved-tools-scenarios.ts+++ b/tests/e2e/playwright/helpers/approved-tools-scenarios.ts@@ -27,6 +27,13 @@ export type UpstreamEvidence = {finalResponses: numberdeniedResponses: numberlimitProbe: { turns: number; completions: number; unexpectedRetries: number }+ limitBoundary: {+ turns: number+ completions: number+ toolResults: number+ finalResponses: number+ unexpectedRetries: number+ }requests: Array<{definitionCount: numberexplicitNonStrictCount: number@@ -140,6 +147,17 @@ export async function readUpstreamEvidence(scenario: Scenario): Promise<Upstreamif (!Number.isSafeInteger(value) || value < 0)throw new Error(`Missing upstream limit probe evidence ${field}`)}+ for (const field of [+ 'turns',+ 'completions',+ 'toolResults',+ 'finalResponses',+ 'unexpectedRetries',+ ] as const) {+ const value = evidence.limitBoundary?.[field]+ if (!Number.isSafeInteger(value) || value < 0)+ throw new Error(`Missing upstream limit boundary evidence ${field}`)+ }if (!Array.isArray(evidence.requests)) throw new Error('Missing upstream request evidence')return evidence}diff --git a/tests/e2e/playwright/package-lock.json b/tests/e2e/playwright/package-lock.jsonindex 5fcb0747b..abbb808cf 100644--- a/tests/e2e/playwright/package-lock.json+++ b/tests/e2e/playwright/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-playwright-tests",- "version": "0.1.52",+ "version": "0.1.53","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-playwright-tests",- "version": "0.1.52",+ "version": "0.1.53","devDependencies": {"@playwright/test": "^1.50.0","@types/node": "^22.0.0",diff --git a/tests/e2e/playwright/package.json b/tests/e2e/playwright/package.jsonindex 97b8b23f0..6a051ab91 100644--- a/tests/e2e/playwright/package.json+++ b/tests/e2e/playwright/package.json@@ -1,6 +1,6 @@{"name": "clerum-playwright-tests",- "version": "0.1.52",+ "version": "0.1.53","private": true,"description": "Playwright E2E tests for Control UI and Desktop App","scripts": {