Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test: require an 8 MiB request cap derived from the contracts (#731)
Alfredo Lopez2d12a1998ba1
diff --git a/grok-llm-proxy/test/contractFreeze.test.ts b/grok-llm-proxy/test/contractFreeze.test.tsindex 317b80e2e..cf525ba98 100644--- a/grok-llm-proxy/test/contractFreeze.test.ts+++ b/grok-llm-proxy/test/contractFreeze.test.ts@@ -52,6 +52,8 @@ describe('grok-subscription contract freeze', () => {expect(fixture.limits.maxToolCalls).toBe(256)expect(fixture.limits.maxMessages).toBe(LIMITS.maxMessages)expect(fixture.limits.maxMessages).toBe(1024)+ expect(fixture.limits.maxRequestBodyBytes).toBe(LIMITS.maxRequestBodyBytes)+ expect(fixture.limits.maxRequestBodyBytes).toBe(8388608)expect(fixture.limits.maxRetriesPerAttempt).toBe(1)// Every other bound the fixture shares with the contract, cross-checked the// same way. Without this, a raise in `LIMITS` that forgets the fixture isdiff --git a/grok-llm-proxy/test/grokTransport.conformance.test.ts b/grok-llm-proxy/test/grokTransport.conformance.test.tsindex 5b9213762..3e1d18a75 100644--- a/grok-llm-proxy/test/grokTransport.conformance.test.ts+++ b/grok-llm-proxy/test/grokTransport.conformance.test.ts@@ -1,5 +1,6 @@import { describe, expect, it, vi } from 'vitest'import {+ LIMITS,hashGrokCompletionRequestV1,parseGrokCompletionRequestV1,} from '@clerum/grok-provider-attempt-contract'@@ -119,6 +120,14 @@ function argumentFrames(deltas: string[]): string[] {}describe('streamGrokCompletion', () => {+ // R3-1 (#731): a response may carry tool-call arguments as large as the+ // request the Host is allowed to send back, and no larger. Held equal to the+ // contract so raising the request cap moves this bound with it.+ it('T-R3-1d bounds tool-call arguments at the contract request cap', () => {+ expect(MAX_TOOL_CALL_ARGUMENT_CHARS).toBe(LIMITS.maxRequestBodyBytes)+ expect(MAX_TOOL_CALL_ARGUMENT_CHARS).toBe(8 * 1024 * 1024)+ })+it('does not read further upstream bytes while the frame consumer is back-pressured', async () => {const encoder = new TextEncoder()const events = [diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex 0335f54a9..65ec0a513 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.394",+ "version": "0.1.395","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.394",+ "version": "0.1.395","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex 3c10bca26..60d10aafc 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.394",+ "version": "0.1.395","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__/codexSubscription.test.ts b/mcp-host/src/llm/__tests__/codexSubscription.test.tsindex 05789d738..d0e96528f 100644--- a/mcp-host/src/llm/__tests__/codexSubscription.test.ts+++ b/mcp-host/src/llm/__tests__/codexSubscription.test.ts@@ -1,4 +1,5 @@import { describe, expect, it, vi } from 'vitest'+import { LIMITS } from '@clerum/llm-provider-attempt-contract'import { minifiedMcpResult } from '../../__tests__/fixtures/minifiedMcpResult'import {buildToolDescribeResponse,@@ -175,7 +176,9 @@ describe('CodexSubscriptionProvider', () => {},{role: 'tool' as const,- content: minifiedMcpResult(3, 1_048_576),+ // Sized from the contract, so the payload stays over the cap whatever+ // its value; the escaped quotes of minified JSON push it past.+ content: minifiedMcpResult(3, LIMITS.maxRequestBodyBytes),tool_call_id: 'call_1',name: 'crm_search_contacts',},@@ -206,6 +209,30 @@ describe('CodexSubscriptionProvider', () => {expect(wired.stream).toHaveBeenCalledTimes(1)})+ it('T-R3-1c dispatches a 2 MiB conversation instead of refusing it (#731)', async () => {+ const wired = deps()+ const provider = new CodexSubscriptionProvider('gpt-5.3-codex', wired as never)+ const large = [+ { role: 'user' as const, content: 'summarize every contact' },+ {+ role: 'assistant' as const,+ content: '',+ tool_calls: [{ id: 'call_1', name: 'crm_search_contacts', arguments: { q: '*' } }],+ },+ {+ role: 'tool' as const,+ content: minifiedMcpResult(3, 2 * 1024 * 1024),+ tool_call_id: 'call_1',+ name: 'crm_search_contacts',+ },+ ]+ expect(Buffer.byteLength(JSON.stringify(large), 'utf8')).toBeGreaterThan(2 * 1024 * 1024)++ await provider.completeSingleTurn(large)+ expect(wired.authorize).toHaveBeenCalledTimes(1)+ expect(wired.stream).toHaveBeenCalledTimes(1)+ })+it('T-C2 reports a 257-call assistant message as request_limit_exceeded before authorize (#731)', async () => {const wired = deps()const provider = new CodexSubscriptionProvider('gpt-5.3-codex', wired as never)@@ -265,7 +292,7 @@ describe('CodexSubscriptionProvider', () => {{id: 'call_1',name: 'export_rows',- arguments: { ids: Array.from({ length: 1_048_577 }, () => 0) },+ arguments: { ids: new Array<number>(LIMITS.maxRequestBodyBytes + 1).fill(0) },},],},diff --git a/mcp-host/src/llm/__tests__/contextOverrunJourney.test.ts b/mcp-host/src/llm/__tests__/contextOverrunJourney.test.tsindex a8c6d5749..1b7ecdc62 100644--- a/mcp-host/src/llm/__tests__/contextOverrunJourney.test.ts+++ b/mcp-host/src/llm/__tests__/contextOverrunJourney.test.ts@@ -125,6 +125,15 @@ function unshrinkableHistory(finalResultBytes: number): ChatMessage[] {* `turns` rounds of user → assistant (one tool call, small arguments) → tool* result carrying `bytesPerResult` of minified JSON.*/+/**+ * J1's history is sized from the contract: enough equal turns to pass the byte+ * cap by 10%. The result size stays fixed and the turn count grows with the+ * cap, so the protected tail (the last three turns) stays small and pre-prune+ * alone still brings pressure under the threshold.+ */+const J1_RESULT_BYTES = 35_000+const J1_TURNS = Math.ceil((LIMITS.maxRequestBodyBytes * 1.1) / J1_RESULT_BYTES)+function mcpHeavyHistory(turns: number, bytesPerResult: number): ChatMessage[] {const msgs: ChatMessage[] = [{ role: 'system', content: 'You are a helpful assistant.' }]for (let turn = 1; turn <= turns; turn++) {@@ -160,7 +169,7 @@ describe('#731 context-overrun journey', () => {})it('J1 deployed config: pre-prune alone shrinks an MCP-heavy history and the contract accepts the request (#731)', async () => {- const msgs = mcpHeavyHistory(32, 35_000)+ const msgs = mcpHeavyHistory(J1_TURNS, J1_RESULT_BYTES)const inputBytes = Buffer.byteLength(JSON.stringify(msgs), 'utf8')expect(inputBytes).toBeGreaterThan(LIMITS.maxRequestBodyBytes)@@ -203,12 +212,14 @@ describe('#731 context-overrun journey', () => {})it('J1 kill switch (CLERUM_COMPACTION_PRE_PRUNE=false): the truncate tier compacts and the contract accepts the request (#731)', async () => {- const msgs = mcpHeavyHistory(32, 35_000)+ const msgs = mcpHeavyHistory(J1_TURNS, J1_RESULT_BYTES)// Precondition, asserted rather than assumed: the uncompacted history is- // already past the contract's 1 MiB ceiling, so a request built from it+ // already past the contract's byte ceiling, so a request built from it// cannot be accepted. Without this the rest of the test could pass on a// history that never needed compacting.- expect(Buffer.byteLength(JSON.stringify(msgs), 'utf8')).toBeGreaterThan(1_048_576)+ expect(Buffer.byteLength(JSON.stringify(msgs), 'utf8')).toBeGreaterThan(+ LIMITS.maxRequestBodyBytes+ )const manager = new PressureContextManager(100000, undefined, undefined, undefined, {prePruneEnabled: false,@@ -237,7 +248,9 @@ describe('#731 context-overrun journey', () => {// built is a request the contract accepts and would hash.expect(wired.authorize).toHaveBeenCalledTimes(1)const req = wired.authorize.mock.calls[0][0].request- expect(Buffer.byteLength(JSON.stringify(req), 'utf8')).toBeLessThanOrEqual(1_048_576)+ expect(Buffer.byteLength(JSON.stringify(req), 'utf8')).toBeLessThanOrEqual(+ LIMITS.maxRequestBodyBytes+ )expect(hashCanonicalCodexRequest(req).ok).toBe(true)})@@ -258,7 +271,11 @@ describe('#731 context-overrun journey', () => {const wired = deps()const provider = new CodexSubscriptionProvider('gpt-5.3-codex', wired as never)- const first = await manager.manage(unshrinkableHistory(1_150_000), conversation)+ // The final result alone passes the byte cap by 10%, whatever its value.+ const first = await manager.manage(+ unshrinkableHistory(Math.ceil(LIMITS.maxRequestBodyBytes * 1.1)),+ conversation+ )const second = await manager.manage(first, conversation)const third = await manager.manage(second, conversation)@@ -287,7 +304,9 @@ describe('#731 context-overrun journey', () => {expect(third).toBe(second)expect(() => validateToolLinkages(third)).not.toThrow()// Precondition for the refusal below, asserted rather than assumed.- expect(Buffer.byteLength(JSON.stringify(third), 'utf8')).toBeGreaterThan(1_048_576)+ expect(Buffer.byteLength(JSON.stringify(third), 'utf8')).toBeGreaterThan(+ LIMITS.maxRequestBodyBytes+ )// Business signal: the turn proceeds and the contract refuses it by name.const rejected = provider.completeSingleTurnWithTools(third, TOOLS)diff --git a/mcp-host/src/llm/__tests__/grokSubscription.test.ts b/mcp-host/src/llm/__tests__/grokSubscription.test.tsindex 5d9e5794d..2335131d9 100644--- a/mcp-host/src/llm/__tests__/grokSubscription.test.ts+++ b/mcp-host/src/llm/__tests__/grokSubscription.test.ts@@ -1,4 +1,5 @@import { describe, expect, it, vi } from 'vitest'+import { LIMITS } from '@clerum/grok-provider-attempt-contract'import { minifiedMcpResult } from '../../__tests__/fixtures/minifiedMcpResult'import { LlmErrorCode } from '../../core/errors'import { classifyFailoverClass } from '../failover/classify'@@ -351,6 +352,30 @@ describe('GrokSubscriptionProvider', () => {expect(classifyFailoverClass(classified.code, classified.retryable)).toBeNull()})+ it('T-R3-1c-grok dispatches a 2 MiB conversation instead of refusing it (#731)', async () => {+ const wired = deps()+ const provider = new GrokSubscriptionProvider('grok-4.6', wired as never)+ const large = [+ { role: 'user' as const, content: 'summarize every contact' },+ {+ role: 'assistant' as const,+ content: '',+ tool_calls: [{ id: 'call_1', name: 'crm_search_contacts', arguments: { q: '*' } }],+ },+ {+ role: 'tool' as const,+ content: minifiedMcpResult(3, 2 * 1024 * 1024),+ tool_call_id: 'call_1',+ name: 'crm_search_contacts',+ },+ ]+ expect(Buffer.byteLength(JSON.stringify(large), 'utf8')).toBeGreaterThan(2 * 1024 * 1024)++ await provider.completeSingleTurn(large)+ expect(wired.authorizer.authorize).toHaveBeenCalledTimes(1)+ expect(wired.proxy.stream).toHaveBeenCalledTimes(1)+ })+it('T-C-grok reports an over-sized request as request_limit_exceeded before authorize (#731)', async () => {const wired = deps()const provider = new GrokSubscriptionProvider('grok-4.6', wired as never)@@ -370,7 +395,9 @@ describe('GrokSubscriptionProvider', () => {},{role: 'tool' as const,- content: minifiedMcpResult(3, 1_048_576),+ // Sized from the contract, so the payload stays over the cap whatever+ // its value; the escaped quotes of minified JSON push it past.+ content: minifiedMcpResult(3, LIMITS.maxRequestBodyBytes),tool_call_id: 'call_1',name: 'crm_search_contacts',},@@ -464,7 +491,7 @@ describe('GrokSubscriptionProvider', () => {{id: 'call_1',name: 'export_rows',- arguments: { ids: Array.from({ length: 1_048_577 }, () => 0) },+ arguments: { ids: new Array<number>(LIMITS.maxRequestBodyBytes + 1).fill(0) },},],},@@ -572,7 +599,10 @@ describe('GrokSubscriptionProvider', () => {it('classifies oversized tool-call arguments as a size refusal, not an overload', () => {const provider = new GrokSubscriptionProvider('grok-4.6', deps() as never)const classified = provider.classifyError(- new GrokProxyError('tool_call_arguments_exceeded', 'tool call arguments exceed 1048576')+ new GrokProxyError(+ 'tool_call_arguments_exceeded',+ `tool call arguments exceed ${LIMITS.maxRequestBodyBytes}`+ ))expect(classified).toMatchObject({code: LlmErrorCode.ContextLengthExceeded,diff --git a/packages/grok-provider-attempt-contract/index.test.cjs b/packages/grok-provider-attempt-contract/index.test.cjsindex 8793096d3..422e06c0d 100644--- a/packages/grok-provider-attempt-contract/index.test.cjs+++ b/packages/grok-provider-attempt-contract/index.test.cjs@@ -314,6 +314,42 @@ test('opaque canonical names remain bounded by serialized UTF-8 request bytes',})})+// A conversation whose size is data, not tools: tool calls answered by+// minified JSON exports, the shape that filled the subscription paths.+function dataHeavyConversation(targetBytes) {+ const row = JSON.stringify({ id: 'c_0001', company: 'Northwind Labs', score: 42.5, tags: ['saas', 'partner'] })+ const chunk = `[${new Array(Math.ceil((256 * 1024) / (row.length + 1))).fill(row).join(',')}]`+ const request = {+ ...BASE,+ tools: [{ name: 'crm__export', description: 'Export CRM rows', parameters: { type: 'object' } }],+ messages: [{ role: 'user', content: 'Summarize the CRM export.' }],+ }+ for (let i = 0; Buffer.byteLength(JSON.stringify(request), 'utf8') < targetBytes; i++) {+ const id = `call-${i}`+ request.messages.push({+ role: 'assistant',+ content: '',+ toolCalls: [{ id, name: 'crm__export', arguments: { page: i } }],+ })+ request.messages.push({ role: 'tool', content: chunk, toolCallId: id, name: 'crm__export' })+ }+ return request+}++// R3-1 (#731): the non-image request cap is 8 MiB, as in the Codex contract.+// The two byte-bound tests above derive their payload from LIMITS, so they+// keep pinning the exact boundary at the new value.+test('T-R3-1a-grok maxRequestBodyBytes is 8 MiB', () => {+ assert.equal(contract.LIMITS.maxRequestBodyBytes, 8 * 1024 * 1024)+})++test('T-R3-1b-grok a 4 MiB conversation of tool results is accepted', () => {+ const request = dataHeavyConversation(4 * 1024 * 1024)+ assert.ok(Buffer.byteLength(JSON.stringify(request), 'utf8') >= 4 * 1024 * 1024)+ const parsed = contract.parseGrokCompletionRequestV1(request)+ assert.equal(parsed.ok, true, parsed.message)+})+test('T-E2 the element bound reports itself distinctly from the byte bound', () => {// Same defect as the Codex contract's: before #731 the element count inside// `checkStructure` and the real byte measurement refused with the identicaldiff --git a/packages/llm-provider-attempt-contract/index.test.cjs b/packages/llm-provider-attempt-contract/index.test.cjsindex f80796d8e..e14ee191a 100644--- a/packages/llm-provider-attempt-contract/index.test.cjs+++ b/packages/llm-provider-attempt-contract/index.test.cjs@@ -314,6 +314,39 @@ test('large catalogs remain bounded by serialized request bytes including UTF-8'})})+// A conversation whose size is data, not tools: tool calls answered by+// minified JSON exports, the shape that filled the subscription paths.+function dataHeavyConversation(targetBytes) {+ const row = JSON.stringify({ id: 'c_0001', company: 'Northwind Labs', score: 42.5, tags: ['saas', 'partner'] })+ const chunk = `[${new Array(Math.ceil((256 * 1024) / (row.length + 1))).fill(row).join(',')}]`+ const request = {+ ...BASE,+ tools: [{ name: 'crm__export', description: 'Export CRM rows', parameters: { type: 'object' } }],+ messages: [{ role: 'user', content: 'Summarize the CRM export.' }],+ }+ for (let i = 0; Buffer.byteLength(JSON.stringify(request), 'utf8') < targetBytes; i++) {+ const id = `call-${i}`+ request.messages.push({ role: 'assistant', content: '', toolCalls: [{ id, name: 'crm__export', arguments: { page: i } }] })+ request.messages.push({ role: 'tool', content: chunk, toolCallId: id, name: 'crm__export' })+ }+ return request+}++// R3-1 (#731): the non-image request cap is 8 MiB. Customer workloads reached+// the former 1 MiB with data, and 8 MiB carries a 1M-token window as escaped+// JSON. The two byte-bound tests above derive their payload from LIMITS, so+// they keep pinning the exact boundary at the new value.+test('T-R3-1a maxRequestBodyBytes is 8 MiB', () => {+ assert.equal(contract.LIMITS.maxRequestBodyBytes, 8 * 1024 * 1024)+})++test('T-R3-1b a 4 MiB conversation of tool results is accepted', () => {+ const request = dataHeavyConversation(4 * 1024 * 1024)+ assert.ok(Buffer.byteLength(JSON.stringify(request), 'utf8') >= 4 * 1024 * 1024)+ const parsed = contract.parseCodexCompletionRequestV1(request)+ assert.equal(parsed.ok, true, parsed.message)+})+test('T-E2 the element bound reports itself distinctly from the byte bound', () => {// Before #731 two different guards refused with the identical sentence: the// element count inside `checkStructure` and the real byte measurement thatdiff --git a/tests/e2e/integration/codex-subscription-contract-freeze.test.ts b/tests/e2e/integration/codex-subscription-contract-freeze.test.tsindex a73e8e208..7398fb860 100644--- a/tests/e2e/integration/codex-subscription-contract-freeze.test.ts+++ b/tests/e2e/integration/codex-subscription-contract-freeze.test.ts@@ -156,7 +156,7 @@ describe('codex-subscription contract freeze', () => {expect(limits).not.toHaveProperty('maxTools')expect(limits?.maxToolCalls).toBe(256)expect(limits?.maxMessages).toBe(1024)- expect(limits?.maxRequestBodyBytes).toBe(1048576)+ expect(limits?.maxRequestBodyBytes).toBe(8388608)const errors = contract.errorTaxonomyexpect(Array.isArray(errors) && (errors as unknown[]).length > 0).toBe(true)diff --git a/tests/e2e/package-lock.json b/tests/e2e/package-lock.jsonindex ea0cfa63e..6c6c23be7 100644--- a/tests/e2e/package-lock.json+++ b/tests/e2e/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-e2e-tests",- "version": "0.1.85",+ "version": "0.1.86","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-e2e-tests",- "version": "0.1.85",+ "version": "0.1.86","devDependencies": {"@types/jsonwebtoken": "^9.0.10","@types/node": "^22.0.0",diff --git a/tests/e2e/package.json b/tests/e2e/package.jsonindex 81bd1e857..7f9f2ae67 100644--- a/tests/e2e/package.json+++ b/tests/e2e/package.json@@ -1,6 +1,6 @@{"name": "clerum-e2e-tests",- "version": "0.1.85",+ "version": "0.1.86","private": true,"type": "module","scripts": {