Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(control-api): pin the Codex refusal between the two visual caps
Alfredo Lopezd1b6b8944e58
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex 5866a0ac6..b18e36f6c 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.638",+ "version": "0.1.639","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.638",+ "version": "0.1.639","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",diff --git a/control-api/package.json b/control-api/package.jsonindex 2783e9829..770c65c01 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.638",+ "version": "0.1.639","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/src/app.ts b/control-api/src/app.tsindex 41cc4d1fe..e3c21b83f 100644--- a/control-api/src/app.ts+++ b/control-api/src/app.ts@@ -66,7 +66,8 @@ const RPC_HOST_ACCESS_PATH = /^\/api\/v1\/rpc\/access\/users\/[^/]+\/mcp-hosts\/// byte or buffer the whole part in the control plane.const GFS_UPLOAD_PART_PATH =/^\/api\/v1\/(?:gfs\/proxy\/v1|external\/gfs)\/uploads\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/parts\/[0-9]+$/i-// Authorize parses its own 24 MiB JSON after the cheap limiter and JWT.+// Authorize parses its own JSON, up to the larger of the Codex and Grok visual+// envelopes (35 MiB), after the cheap limiter and JWT.// The global 150mb parser must not buffer an unauthenticated body.const LLM_AUTHORIZE_PATH = /^\/api\/v1\/mcp-host\/llm\/provider-attempts\/authorize\/?$/idiff --git a/control-api/test/routes.mcp-host.llmProviderAttempts.test.ts b/control-api/test/routes.mcp-host.llmProviderAttempts.test.tsindex 444d8b1d1..7afdda5ca 100644--- a/control-api/test/routes.mcp-host.llmProviderAttempts.test.ts+++ b/control-api/test/routes.mcp-host.llmProviderAttempts.test.ts@@ -46,7 +46,7 @@ const HOST = 'research-host'function buildApp() {const app = express()- // Route-only harness: JWT-before-24-MiB-parser. createApp() skip of the+ // Route-only harness: JWT-before-35-MiB-parser. createApp() skip of the// global 150mb parser is locked in llmProviderAttempts.createApp.test.ts.const api = express.Router()api.use(@@ -144,6 +144,72 @@ describe('POST /api/v1/mcp-host/llm/provider-attempts/authorize', () => {}}, 30_000)+ // The route parser admits the Grok 35 MiB envelope for both providers, so a+ // Codex body between the two visual caps now reaches the Codex authorizer,+ // and that authorizer is what must refuse it (#806 review, L1).+ it('refuses a Codex V2 body between the Codex and Grok visual caps in the Codex authorizer', async () => {+ const actual = await vi.importActual<+ typeof import('../src/services/llmProviderAttemptAuthorizer.js')+ >('../src/services/llmProviderAttemptAuthorizer.js')+ const rejections: unknown[] = []+ vi.mocked(authorizer.authorizeLlmProviderAttempt).mockImplementation((claims, body) =>+ actual.authorizeLlmProviderAttempt(claims, body, { enabled: true }).catch(err => {+ rejections.push(err)+ throw err+ })+ )+ expect(CODEX_LIMITS.maxVisualRequestBodyBytes).toBeLessThan(+ GROK_LIMITS.maxVisualRequestBodyBytes+ )+ /** A Codex V2 authorize body of exactly `bytes` bytes. */+ const codexBodyOf = (bytes: number) => {+ const frame = JSON.stringify({+ request: { schemaVersion: 'codex-completion-request.v2', provider: 'codex-subscription' },+ pad: '',+ })+ return `${frame.slice(0, -2)}${'x'.repeat(bytes - frame.length)}"}`+ }+ const app = buildApp()+ const listener = createServer(app).listen(0)+ try {+ const address = listener.address()+ if (!address || typeof address === 'string') throw new Error('listener has no port')+ const url = `http://127.0.0.1:${address.port}/api/v1/mcp-host/llm/provider-attempts/authorize`+ const headers = {+ Authorization: `Bearer ${token()}`,+ 'content-type': 'application/json',+ }+ const between = codexBodyOf(CODEX_LIMITS.maxVisualRequestBodyBytes + 1)+ expect(Buffer.byteLength(between)).toBe(CODEX_LIMITS.maxVisualRequestBodyBytes + 1)+ const refused = await fetch(url, { method: 'POST', headers, body: between })+ expect(refused.status).toBe(413)+ expect(await refused.json()).toEqual({ error: 'payload_too_large' })+ // The parser admitted the body: the 413 is the Codex authorizer's+ // whole-body check, not express.json's limit.+ expect(authorizer.authorizeLlmProviderAttempt).toHaveBeenCalledTimes(1)+ expect(rejections).toEqual([+ expect.objectContaining({+ code: 'payload_too_large',+ message: 'request body exceeds the limit',+ }),+ ])+ // Witness: at the Codex cap exactly the whole-body check passes, and the+ // next check, the non-image budget, is the one that refuses the padding.+ const atCap = codexBodyOf(CODEX_LIMITS.maxVisualRequestBodyBytes)+ const nextCheck = await fetch(url, { method: 'POST', headers, body: atCap })+ expect(nextCheck.status).toBe(413)+ expect(authorizer.authorizeLlmProviderAttempt).toHaveBeenCalledTimes(2)+ expect(rejections[1]).toMatchObject({+ code: 'payload_too_large',+ message: 'authorize wrapper exceeds the non-image limit',+ })+ } finally {+ await new Promise<void>((resolve, reject) =>+ listener.close(err => (err ? reject(err) : resolve()))+ )+ }+ }, 30_000)+it('maps authorizer taxonomy without collapsing it into 500', async () => {const app = buildApp()vi.mocked(authorizer.authorizeLlmProviderAttempt).mockRejectedValueOnce(diff --git a/deploy/base/control-plane/control-api.yaml b/deploy/base/control-plane/control-api.yamlindex 3b2ff4ba7..20c55162e 100644--- a/deploy/base/control-plane/control-api.yaml+++ b/deploy/base/control-plane/control-api.yaml@@ -132,9 +132,7 @@ spec:# must keep >=768Mi for the legacy path:# - deploy/overlays/minikube/patches/resource-limits.yaml (in this repo)# - keyper-labs/evenfire-infra gcp-dev/gcp-prod patches/resource-limits.yaml- # (private infra repo — both currently pin 512Mi; a companion PR must- # raise them to 768Mi before/with the next GKE deploy, or RC3 is inert- # in dev/prod exactly as it was in minikube before the audit caught it).+ # (private infra repo; both pin 768Mi as of 2026-09-24).memory: 768Mirequests:cpu: 50m