Skip to content

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

TypeScript

fix(codex): keep text completions off the visual stream gate

Alfredo Lopez05c0ca030041
diff --git a/codex-llm-proxy/src/requestLimits.ts b/codex-llm-proxy/src/requestLimits.ts
index 6295b4baa..2356e88f4 100644
--- a/codex-llm-proxy/src/requestLimits.ts
+++ b/codex-llm-proxy/src/requestLimits.ts
@@ -7,9 +7,11 @@ export const STREAM_LIMITS = {
} as const
/**
- * Visual JSON parse retains a 24 MiB body. The 256Mi pod cannot hold the
- * ordinary 8-stream gate across that size, so visual admission is a tighter
- * sibling. Do not raise proxy memory to widen this.
+ * Admission for a body whose Content-Length exceeds the ordinary cap.
+ * The 256Mi pod cannot hold the ordinary 8-stream gate across a 24 MiB image,
+ * so those requests are a tighter sibling and a V2 request keeps the slot
+ * until the stream ends. Small bodies, including every valid V1, must not
+ * enter this gate. Do not raise proxy memory to widen it.
*/
export const VISUAL_STREAM_LIMITS = {
maxConcurrentStreams: 2,
diff --git a/codex-llm-proxy/src/server.ts b/codex-llm-proxy/src/server.ts
index 5a323f05e..6a5141549 100644
--- a/codex-llm-proxy/src/server.ts
+++ b/codex-llm-proxy/src/server.ts
@@ -21,7 +21,12 @@ import {
type OriginPolicyOptions,
defaultAddressLookup,
} from './originPolicy.js'
-import { SCHEMA_VERSION_V2 } from '@clerum/llm-provider-attempt-contract'
+import {
+ LIMITS,
+ SCHEMA_VERSION_V2,
+ measureNonImageAuthorizeBytes,
+ requestBodyLimitBytes,
+} from '@clerum/llm-provider-attempt-contract'
import { RequestLimitError, streamGate, visualStreamGate } from './requestLimits.js'
type GatedRequest = Request & { codexStreamRelease?: () => void }
@@ -46,6 +51,17 @@ function bearer(req: Request): string {
return raw.replace(/^bearer\s+/i, '').trim()
}
+function contentLengthBytes(req: Request): number | null {
+ const header = req.headers['content-length']
+ if (typeof header !== 'string' || !/^[0-9]+$/.test(header)) return null
+ const value = Number(header)
+ return Number.isSafeInteger(value) ? value : null
+}
+
+function isRecord(value: unknown): value is Record<string, unknown> {
+ return value !== null && typeof value === 'object' && !Array.isArray(value)
+}
+
function reject(res: Response, status: number, code: string): void {
if (res.headersSent) return
logger.warn({ event: 'codex_proxy_denied', code }, 'request denied')
@@ -124,46 +140,58 @@ export function createProxyApps(
const visualJson = express.json({ limit: config.maxVisualBodyBytes })
// Selecting the transport budget needs the platform identity, so this runs as a
// route handler after the rate limiter: an unauthenticated caller cannot force
- // token verification or body parsing ahead of the limit. A valid platform
- // identity may use the visual envelope; V1 is still re-bounded after parse.
- // Admin or unauthenticated requests keep the ordinary cap.
+ // token verification or body parsing ahead of the limit. Admin or
+ // unauthenticated requests keep the ordinary cap.
+ //
+ // schemaVersion is not known until the body is parsed, so the visual gate
+ // must not be taken for every platform JWT. Only a declared Content-Length
+ // above the ordinary cap can be a visual envelope. Those bodies take the
+ // 2-wide gate (the image bytes stay resident for the ChatGPT stream). Every
+ // smaller body, including every valid V1, stays on the ordinary parser and
+ // later the 8-wide stream gate. A missing length cannot be upgraded: it is
+ // parsed at the ordinary cap, so a chunked caller cannot occupy a visual slot.
const selectTransportBudget = (req: GatedRequest, res: Response, next: NextFunction): void => {
- // Visual parse keeps a 24 MiB buffer. Admit that parse inside the visual
- // gate so two concurrent bodies stay inside the 256Mi pod. Identity is
- // read from the Authorization header; an anonymous caller cannot force
- // the larger parser.
- if (verifyPlatformJwt(bearer(req), config)) {
- void (async () => {
- let release: (() => void) | undefined
- const parseAbort = new AbortController()
- const abortParse = (): void => parseAbort.abort()
- req.once('aborted', abortParse)
- try {
- release = await visualStreamGate.acquire(parseAbort.signal)
- } catch (err) {
- req.off('aborted', abortParse)
- if (err instanceof RequestLimitError) {
- reject(res, 503, err.code)
- return
- }
- next()
- return
- }
- req.off('aborted', abortParse)
- req.codexStreamRelease = release
- visualJson(req, res, err => {
- if (err) {
- req.codexStreamRelease?.()
- req.codexStreamRelease = undefined
- next(err)
- return
- }
- next()
- })
- })()
+ if (!verifyPlatformJwt(bearer(req), config)) {
+ ordinaryJson(req, res, next)
+ return
+ }
+ const declared = contentLengthBytes(req)
+ if (declared !== null && declared > config.maxVisualBodyBytes) {
+ reject(res, 413, 'payload_too_large')
+ return
+ }
+ if (declared === null || declared <= config.maxBodyBytes) {
+ ordinaryJson(req, res, next)
return
}
- ordinaryJson(req, res, next)
+ void (async () => {
+ let release: (() => void) | undefined
+ const parseAbort = new AbortController()
+ const abortParse = (): void => parseAbort.abort()
+ req.once('aborted', abortParse)
+ try {
+ release = await visualStreamGate.acquire(parseAbort.signal)
+ } catch (err) {
+ req.off('aborted', abortParse)
+ if (err instanceof RequestLimitError) {
+ reject(res, 503, err.code)
+ return
+ }
+ next()
+ return
+ }
+ req.off('aborted', abortParse)
+ req.codexStreamRelease = release
+ visualJson(req, res, err => {
+ if (err) {
+ req.codexStreamRelease?.()
+ req.codexStreamRelease = undefined
+ next(err)
+ return
+ }
+ next()
+ })
+ })()
}
runtimeApp.post(COMPLETION_PATH, runtimeRateLimit, selectTransportBudget, (req, res) => {
const gated = req as GatedRequest
@@ -187,11 +215,16 @@ export function createProxyApps(
reject(res, 401, 'Unauthorized')
return
}
- const bodyLimit =
- req.body?.request?.schemaVersion === 'codex-completion-request.v2'
- ? config.maxVisualBodyBytes
- : config.maxBodyBytes
- if (Buffer.byteLength(JSON.stringify(req.body ?? {}), 'utf8') > bodyLimit) {
+ const request = isRecord(req.body) ? req.body.request : undefined
+ const visualDeclared = isRecord(request) && request.schemaVersion === SCHEMA_VERSION_V2
+ const configuredLimit = visualDeclared ? config.maxVisualBodyBytes : config.maxBodyBytes
+ const wholeBodyBytes = Buffer.byteLength(JSON.stringify(req.body ?? {}), 'utf8')
+ // Declaring V2 raises only the image budget. Text, tools and wrapper
+ // fields stay on the contract's 1 MiB non-image ceiling.
+ if (
+ wholeBodyBytes > Math.min(configuredLimit, requestBodyLimitBytes(request)) ||
+ measureNonImageAuthorizeBytes(req.body) > LIMITS.maxRequestBodyBytes
+ ) {
releaseAdmission()
reject(res, 413, 'payload_too_large')
return
@@ -240,10 +273,9 @@ export function createProxyApps(
const visualRequest =
(parsed.data.request as { schemaVersion?: unknown }).schemaVersion === SCHEMA_VERSION_V2
try {
- // Visual parse used the tight 2-wide gate so a 24 MiB body fits the
- // 256Mi pod. V1 must not keep that slot through the ChatGPT stream —
- // release it and take the ordinary 8-wide stream gate. V2 keeps the
- // visual release until the stream ends.
+ // A visual slot exists only when Content-Length exceeded the ordinary
+ // cap. V2 keeps it until the stream ends because the image bytes stay
+ // resident. Every other request releases it and takes the 8-wide gate.
if (visualRequest) {
release = gated.codexStreamRelease
gated.codexStreamRelease = undefined
diff --git a/codex-llm-proxy/test/server.security.test.ts b/codex-llm-proxy/test/server.security.test.ts
index 70f9ae5a9..b39509ca1 100644
--- a/codex-llm-proxy/test/server.security.test.ts
+++ b/codex-llm-proxy/test/server.security.test.ts
@@ -165,7 +165,15 @@ describe('codex-llm-proxy security surface', () => {
const payload = {
executionTicket: 'invalid-ticket',
requestHash: 'a'.repeat(64),
- request: { schemaVersion: 'codex-completion-request.v2', pad: 'x'.repeat(10 * 1024 * 1024) },
+ request: {
+ schemaVersion: 'codex-completion-request.v2',
+ messages: [
+ {
+ role: 'user',
+ contentParts: [{ type: 'image', data: 'A'.repeat(10 * 1024 * 1024) }],
+ },
+ ],
+ },
}
const admitted = await request(runtimeApp)
.post('/internal/runtime/v1/codex/completions')
@@ -198,6 +206,20 @@ describe('codex-llm-proxy security surface', () => {
expect(admin.status).toBe(413)
})
+ it('does not let a V2 declaration raise the non-image budget to 24 MiB', async () => {
+ const { runtimeApp } = createProxyApps(config({ maxBodyBytes: 1_048_576 }))
+ const res = await request(runtimeApp)
+ .post('/internal/runtime/v1/codex/completions')
+ .set('Authorization', `Bearer ${platformToken()}`)
+ .send({
+ executionTicket: 'invalid-ticket',
+ requestHash: 'a'.repeat(64),
+ request: { schemaVersion: 'codex-completion-request.v2', pad: 'x'.repeat(2 * 1024 * 1024) },
+ })
+ expect(res.status).toBe(413)
+ expect(res.body.error).toBe('payload_too_large')
+ })
+
it('rate limits the completion endpoint before body parsing and authorization', async () => {
const { runtimeApp } = createProxyApps(
config({ maxBodyBytes: 1024 })
diff --git a/codex-llm-proxy/test/streamGate.handoff.test.ts b/codex-llm-proxy/test/streamGate.handoff.test.ts
index 5428811ff..fd272703f 100644
--- a/codex-llm-proxy/test/streamGate.handoff.test.ts
+++ b/codex-llm-proxy/test/streamGate.handoff.test.ts
@@ -1,5 +1,6 @@
import { generateKeyPairSync } from 'node:crypto'
import { createServer } from 'node:http'
+import { connect as connectTcp } from 'node:net'
import jwt from 'jsonwebtoken'
import { afterEach, describe, expect, it } from 'vitest'
import {
@@ -21,7 +22,7 @@ const { privateKey, publicKey } = generateKeyPairSync('rsa', {
privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
})
-function config(): CodexLlmProxyConfig {
+function config(overrides: Partial<CodexLlmProxyConfig> = {}): CodexLlmProxyConfig {
return {
runtimePort: 8080,
adminPort: 8081,
@@ -36,6 +37,7 @@ function config(): CodexLlmProxyConfig {
controlApiBaseUrl: '',
controlApiServiceName: 'codex-llm-proxy',
controlApiServiceToken: '',
+ ...overrides,
}
}
@@ -78,7 +80,8 @@ function ticket(requestHash: string): string {
}
function completionRequest(
- schemaVersion: 'codex-completion-request.v1' | 'codex-completion-request.v2'
+ schemaVersion: 'codex-completion-request.v1' | 'codex-completion-request.v2',
+ content = 'hi'
) {
ticketSeq += 1
return {
@@ -87,7 +90,7 @@ function completionRequest(
idempotencyKey: `idem-gate-${ticketSeq}`,
provider: 'codex-subscription',
model: 'gpt-5.1',
- messages: [{ role: 'user', content: 'hi' }],
+ messages: [{ role: 'user', content }],
}
}
@@ -114,9 +117,10 @@ async function waitFor(predicate: () => boolean, label: string): Promise<void> {
}
function completionPayload(
- schemaVersion: 'codex-completion-request.v1' | 'codex-completion-request.v2'
+ schemaVersion: 'codex-completion-request.v1' | 'codex-completion-request.v2',
+ content = 'hi'
): { token: string; body: string } {
- const raw = completionRequest(schemaVersion)
+ const raw = completionRequest(schemaVersion, content)
const parsed = parseCodexCompletionRequest(raw)
if (!parsed.ok) throw new Error(parsed.message)
const requestHash = hashCodexCompletionRequest(parsed.value)
@@ -132,9 +136,10 @@ function completionPayload(
async function postCompletion(
port: number,
- schemaVersion: 'codex-completion-request.v1' | 'codex-completion-request.v2'
+ schemaVersion: 'codex-completion-request.v1' | 'codex-completion-request.v2',
+ content = 'hi'
): Promise<Response> {
- const { token, body } = completionPayload(schemaVersion)
+ const { token, body } = completionPayload(schemaVersion, content)
return fetch(`http://127.0.0.1:${port}/internal/runtime/v1/codex/completions`, {
method: 'POST',
headers: {
@@ -145,6 +150,51 @@ async function postCompletion(
})
}
+function postChunked(port: number, token: string): Promise<number> {
+ return new Promise((resolve, reject) => {
+ const socket = connectTcp(port, '127.0.0.1', () => {
+ const chunk = Buffer.from('{}')
+ socket.write(
+ `POST /internal/runtime/v1/codex/completions HTTP/1.1\r\n` +
+ `Host: 127.0.0.1:${port}\r\n` +
+ `Authorization: Bearer ${token}\r\n` +
+ `Content-Type: application/json\r\n` +
+ `Connection: close\r\n` +
+ `Transfer-Encoding: chunked\r\n` +
+ `\r\n` +
+ `${chunk.length.toString(16)}\r\n`
+ )
+ socket.write(chunk)
+ socket.write('\r\n0\r\n\r\n')
+ })
+ const chunks: Buffer[] = []
+ const finish = () => {
+ const raw = Buffer.concat(chunks).toString('utf8')
+ const match = /^HTTP\/1\.1 (\d+)/.exec(raw)
+ if (!match) {
+ reject(new Error(`no status in ${raw.slice(0, 180)}`))
+ return
+ }
+ resolve(Number(match[1]))
+ }
+ socket.setTimeout(2_000, () => {
+ socket.destroy()
+ finish()
+ })
+ socket.on('data', data => {
+ chunks.push(data)
+ if (Buffer.concat(chunks).toString('utf8').includes('\r\n\r\n')) {
+ socket.destroy()
+ finish()
+ }
+ })
+ socket.on('error', err => {
+ if ((err as NodeJS.ErrnoException).code !== 'ECONNRESET') reject(err)
+ })
+ socket.on('close', finish)
+ })
+}
+
describe('visual stream-gate handoff', () => {
const hangs: Array<{ release: () => void }> = []
const serversToClose: Array<{ close: () => Promise<void> }> = []
@@ -171,13 +221,21 @@ describe('visual stream-gate handoff', () => {
)
})
- it('releases the visual slot for V1 and keeps it for V2; a saturated visual gate is 503', async () => {
+ it('keeps small V1 text off the visual gate while large V2 streams hold it', async () => {
expect(VISUAL_STREAM_LIMITS.maxConcurrentStreams).toBe(2)
expect(STREAM_LIMITS.maxConcurrentStreams).toBe(8)
+ const small = completionPayload('codex-completion-request.v1')
+ const maxBodyBytes = Buffer.byteLength(small.body) + 512
+ const largeContent = 'x'.repeat(maxBodyBytes)
+ const large = completionPayload('codex-completion-request.v2', largeContent)
+ expect(Buffer.byteLength(large.body)).toBeGreaterThan(maxBodyBytes)
+
const hang = hangStream()
hangs.push(hang)
- const servers = createProxyApps(config(), { streamCompletion: hang.impl })
+ const servers = createProxyApps(config({ maxBodyBytes, maxVisualBodyBytes: 1024 * 1024 }), {
+ streamCompletion: hang.impl,
+ })
serversToClose.push(servers)
const listener = createServer(servers.runtimeApp).listen(0)
listeners.push(listener)
@@ -185,31 +243,68 @@ describe('visual stream-gate handoff', () => {
if (!address || typeof address === 'string') throw new Error('listener has no port')
const port = address.port
- const v1 = postCompletion(port, 'codex-completion-request.v1')
+ const firstVisual = postCompletion(port, 'codex-completion-request.v2', largeContent)
+ const secondVisual = postCompletion(port, 'codex-completion-request.v2', largeContent)
await waitFor(
- () => streamGate.snapshot().running === 1 && visualStreamGate.snapshot().running === 0,
- 'V1 did not release the visual gate before taking streamGate'
+ () => visualStreamGate.snapshot().running === 2 && streamGate.snapshot().running === 0,
+ 'large V2 did not hold the visual gate'
)
- const firstVisual = postCompletion(port, 'codex-completion-request.v2')
- const secondVisual = postCompletion(port, 'codex-completion-request.v2')
+ const v1 = postCompletion(port, 'codex-completion-request.v1')
await waitFor(
- () => visualStreamGate.snapshot().running === 2 && streamGate.snapshot().running === 1,
- 'V2 did not keep the visual gate through the stream'
+ () => streamGate.snapshot().running === 1 && visualStreamGate.snapshot().running === 2,
+ 'small V1 waited on the visual gate instead of the ordinary stream gate'
)
const queued = Array.from({ length: VISUAL_STREAM_LIMITS.maxQueuedRequests }, () =>
- postCompletion(port, 'codex-completion-request.v2')
+ postCompletion(port, 'codex-completion-request.v2', largeContent)
)
await waitFor(
() => visualStreamGate.snapshot().queued === VISUAL_STREAM_LIMITS.maxQueuedRequests,
'visual queue did not fill to 8'
)
- const overflow = await postCompletion(port, 'codex-completion-request.v2')
+ const overflow = await postCompletion(port, 'codex-completion-request.v2', largeContent)
expect(overflow.status).toBe(503)
expect(await overflow.json()).toEqual({ error: 'provider_unavailable' })
+ const textWhileSaturated = postCompletion(port, 'codex-completion-request.v1')
+ await waitFor(
+ () => streamGate.snapshot().running === 2 && visualStreamGate.snapshot().running === 2,
+ 'a small V1 was rejected or queued behind saturated image streams'
+ )
+
+ hang.release()
+ await Promise.all([v1, textWhileSaturated, firstVisual, secondVisual, ...queued])
+ })
+
+ it('does not queue a chunked platform body behind saturated image streams', async () => {
+ const small = completionPayload('codex-completion-request.v1')
+ const maxBodyBytes = Buffer.byteLength(small.body) + 512
+ const largeContent = 'x'.repeat(maxBodyBytes)
+ const hang = hangStream()
+ hangs.push(hang)
+ const servers = createProxyApps(config({ maxBodyBytes, maxVisualBodyBytes: 1024 * 1024 }), {
+ streamCompletion: hang.impl,
+ })
+ serversToClose.push(servers)
+ const listener = createServer(servers.runtimeApp).listen(0)
+ listeners.push(listener)
+ const address = listener.address()
+ if (!address || typeof address === 'string') throw new Error('listener has no port')
+ const port = address.port
+
+ const firstVisual = postCompletion(port, 'codex-completion-request.v2', largeContent)
+ const secondVisual = postCompletion(port, 'codex-completion-request.v2', largeContent)
+ await waitFor(
+ () => visualStreamGate.snapshot().running === 2 && visualStreamGate.snapshot().queued === 0,
+ 'large V2 did not fill the visual gate'
+ )
+
+ const status = await postChunked(port, platformToken())
+ expect(status).toBe(400)
+ expect(visualStreamGate.snapshot()).toEqual({ running: 2, queued: 0 })
+
hang.release()
- await Promise.all([v1, firstVisual, secondVisual, ...queued])
+ await Promise.all([firstVisual, secondVisual])
})
})
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 5d2665b68..c76225829 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.587",
+ "version": "0.1.588",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.587",
+ "version": "0.1.588",
"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.json
index 9ac84821c..d3cc0edd9 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.587",
+ "version": "0.1.588",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/src/services/llmProviderAttemptAuthorizer.ts b/control-api/src/services/llmProviderAttemptAuthorizer.ts
index 87b00bab7..3781cff6a 100644
--- a/control-api/src/services/llmProviderAttemptAuthorizer.ts
+++ b/control-api/src/services/llmProviderAttemptAuthorizer.ts
@@ -618,11 +618,14 @@ export async function authorizeLlmProviderAttempt(
assertBodyNestingWithinLimit(body)
const serialized = JSON.stringify(body)
if (Buffer.byteLength(serialized, 'utf8') > requestBodyLimitBytes(body.request)) {
- throw new LlmProviderAttemptAuthorizeError('invalid_request', 'request body exceeds the limit')
+ throw new LlmProviderAttemptAuthorizeError(
+ 'payload_too_large',
+ 'request body exceeds the limit'
+ )
}
if (measureNonImageAuthorizeBytes(body) > LIMITS.maxRequestBodyBytes) {
throw new LlmProviderAttemptAuthorizeError(
- 'invalid_request',
+ 'payload_too_large',
'authorize wrapper exceeds the non-image limit'
)
}
@@ -636,7 +639,7 @@ export async function authorizeLlmProviderAttempt(
const parsed = parseCodexCompletionRequest(body.request)
if (!parsed.ok) {
- // Only byte-size `limit` failures are 413. Range, count and depth stay 400.
+ // `kind: 'size'` is 413: byte ceilings and image geometry. Range, count and depth stay 400.
throw new LlmProviderAttemptAuthorizeError(
parsed.code === 'limit' && parsed.kind === 'size' ? 'payload_too_large' : 'invalid_request',
parsed.message
diff --git a/control-api/test/services.llmProviderAttemptAuthorizer.test.ts b/control-api/test/services.llmProviderAttemptAuthorizer.test.ts
index 6c6846414..49a5b9ccc 100644
--- a/control-api/test/services.llmProviderAttemptAuthorizer.test.ts
+++ b/control-api/test/services.llmProviderAttemptAuthorizer.test.ts
@@ -22,9 +22,10 @@ import {
} from '../src/services/llmProviderAttemptAuthorizer.js'
import type { McpHostAccessClaims } from '../src/utils/auth/mcpHostJwtToken.js'
-const { jpegOfSize, padPngToSize } = createRequire(import.meta.url)(
+const { declaredHeaderPng, jpegOfSize, padPngToSize } = createRequire(import.meta.url)(
'../../packages/llm-provider-attempt-contract/testImageFixtures.cjs'
) as {
+ declaredHeaderPng: (width: number, height: number) => Buffer
jpegOfSize: (targetBytes: number, width?: number, height?: number) => Buffer
padPngToSize: (png: Buffer | string, targetBytes: number) => Buffer
}
@@ -704,7 +705,43 @@ describe('authorizeLlmProviderAttempt', () => {
}),
current
)
- ).rejects.toMatchObject({ code: 'invalid_request' })
+ ).rejects.toMatchObject({ code: 'payload_too_large' })
+ expect(current.insertAttempt).not.toHaveBeenCalled()
+ })
+
+ it('maps an over-dimension image to payload_too_large', async () => {
+ const current = deps()
+ await expect(
+ authorizeLlmProviderAttempt(
+ claims(),
+ body({
+ request: {
+ ...REQUEST,
+ schemaVersion: 'codex-completion-request.v2',
+ messages: [
+ {
+ role: 'user' as const,
+ content: 'look',
+ contentParts: [
+ { type: 'text' as const, text: 'look' },
+ {
+ type: 'image' as const,
+ mimeType: 'image/png',
+ data: declaredHeaderPng(3000, 3000).toString('base64'),
+ source: {
+ kind: 'attachment' as const,
+ attachmentId: 'att_1',
+ messageId: 'msg-1',
+ },
+ },
+ ],
+ },
+ ],
+ },
+ }),
+ current
+ )
+ ).rejects.toMatchObject({ code: 'payload_too_large' })
expect(current.insertAttempt).not.toHaveBeenCalled()
})
diff --git a/external-rest-api/src/releaseManifest.ts b/external-rest-api/src/releaseManifest.ts
index 633dac2e0..98d96df23 100644
--- a/external-rest-api/src/releaseManifest.ts
+++ b/external-rest-api/src/releaseManifest.ts
@@ -9,7 +9,7 @@ export type ReleaseManifest = {
export const releaseManifest: ReleaseManifest = {
releaseId: 'v0.9.0',
externalRestApiVersion: '0.1.82',
- rpcProxyVersion: '0.1.86',
+ rpcProxyVersion: '0.1.87',
desktopVersion: '0.9.0',
minimumDesktopVersion: '0.1.252',
}
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index 1f9ab2509..bbd3cb218 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.359",
+ "version": "0.1.360",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.359",
+ "version": "0.1.360",
"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 dfc631db5..2a96d2c3b 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.359",
+ "version": "0.1.360",
"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__/imageInput.test.ts b/mcp-host/src/llm/__tests__/imageInput.test.ts
index f040f6fa1..b1d33aeb5 100644
--- a/mcp-host/src/llm/__tests__/imageInput.test.ts
+++ b/mcp-host/src/llm/__tests__/imageInput.test.ts
@@ -270,6 +270,53 @@ describe('#654 decideImageInput intersection', () => {
).toEqual({ state: 'supported', reason: 'supported' })
})
+ it('does not upgrade curated-unsupported or expired Codex evidence', () => {
+ const unsupported = {
+ state: 'unsupported' as const,
+ evidence: {
+ source: 'curated' as const,
+ reference: 'evidence:codex-text-only',
+ checkedAt: '2026-09-16T00:00:00Z',
+ },
+ }
+ expect(
+ decideImageInput({
+ providerType: 'codex-subscription',
+ method: 'completeWithTools',
+ roles: ['user'],
+ capability: unsupported,
+ })
+ ).toEqual({
+ state: 'unsupported',
+ reason: 'model_unsupported',
+ evidence: unsupported.evidence,
+ })
+
+ const expired = {
+ state: 'supported' as const,
+ evidence: {
+ source: 'curated' as const,
+ reference: 'evidence:codex',
+ checkedAt: '2026-09-01T00:00:00Z',
+ validUntil: '2026-10-01T00:00:00.000Z',
+ },
+ }
+ expect(
+ decideImageInput({
+ providerType: 'codex-subscription',
+ method: 'completeWithTools',
+ roles: ['user'],
+ capability: expired,
+ now: Date.parse('2026-10-02T00:00:00Z'),
+ })
+ ).toEqual({
+ state: 'unknown',
+ reason: 'evidence_expired',
+ validUntil: '2026-10-01T00:00:00.000Z',
+ evidence: expired.evidence,
+ })
+ })
+
it('treats absent or malformed evidence as unknown, never as support', () => {
for (const capability of [undefined, null, {}, { state: 'maybe' }, { state: 'supported' }]) {
expect(
diff --git a/packages/llm-provider-attempt-contract/index.test.cjs b/packages/llm-provider-attempt-contract/index.test.cjs
index 76fe610b4..4f3887dbb 100644
--- a/packages/llm-provider-attempt-contract/index.test.cjs
+++ b/packages/llm-provider-attempt-contract/index.test.cjs
@@ -836,6 +836,7 @@ test('v2 limits: image count, encoder bound, per-image bytes, total bytes, dimen
])
)
assert.equal(overDimension.code, 'limit')
+ assert.equal(overDimension.kind, 'size')
assert.match(overDimension.message, /dimension/)
// Phone-sized frames are a Codex pixel problem, not a byte problem.
@@ -844,6 +845,7 @@ test('v2 limits: image count, encoder bound, per-image bytes, total bytes, dimen
)
assert.equal(phoneShape.ok, false)
assert.equal(phoneShape.code, 'limit')
+ assert.equal(phoneShape.kind, 'size')
assert.match(phoneShape.message, /dimension/)
// 2048×2048 is both the dimension and the pixel ceiling.
diff --git a/packages/llm-provider-attempt-contract/visualPayload.cjs b/packages/llm-provider-attempt-contract/visualPayload.cjs
index 32bda41a3..1e906aac5 100644
--- a/packages/llm-provider-attempt-contract/visualPayload.cjs
+++ b/packages/llm-provider-attempt-contract/visualPayload.cjs
@@ -184,10 +184,10 @@ function assertWithinDimensionBudget(dimensions) {
dimensions.width > VISUAL_LIMITS.maxImageDimension ||
dimensions.height > VISUAL_LIMITS.maxImageDimension
) {
- return fail('limit', `image dimension exceeds ${VISUAL_LIMITS.maxImageDimension}`, 'range')
+ return fail('limit', `image dimension exceeds ${VISUAL_LIMITS.maxImageDimension}`, 'size')
}
if (dimensions.width * dimensions.height > VISUAL_LIMITS.maxImagePixels) {
- return fail('limit', `image pixel count exceeds ${VISUAL_LIMITS.maxImagePixels}`, 'range')
+ return fail('limit', `image pixel count exceeds ${VISUAL_LIMITS.maxImagePixels}`, 'size')
}
return null
}
diff --git a/rpc-proxy/package-lock.json b/rpc-proxy/package-lock.json
index a207cc768..72e061899 100644
--- a/rpc-proxy/package-lock.json
+++ b/rpc-proxy/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-rpc-proxy",
- "version": "0.1.86",
+ "version": "0.1.87",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-rpc-proxy",
- "version": "0.1.86",
+ "version": "0.1.87",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.21.2",
diff --git a/rpc-proxy/package.json b/rpc-proxy/package.json
index bf920cee4..9cf066f20 100644
--- a/rpc-proxy/package.json
+++ b/rpc-proxy/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-rpc-proxy",
- "version": "0.1.86",
+ "version": "0.1.87",
"description": "External-facing RPC proxy for tenant-scoped MCP access",
"main": "dist/main.js",
"engines": {
diff --git a/rpc-proxy/src/__tests__/bodylimits.test.ts b/rpc-proxy/src/__tests__/bodylimits.test.ts
index 924c3cac0..14f6d22c3 100644
--- a/rpc-proxy/src/__tests__/bodylimits.test.ts
+++ b/rpc-proxy/src/__tests__/bodylimits.test.ts
@@ -6,9 +6,10 @@
* payloads (a 10MiB image, a 5MiB JPEG, 10MiB + 5MiB, and three 5MiB images) to the auth
* boundary instead of being rejected as too large.
* - The larger ceiling is NOT a general text allowance: non-image bytes stay
- * capped at 6MiB, and every other route keeps its 6MiB parser.
- * - The sandbox-ui view proxy stays parser-free, so http-proxy can stream the
- * raw body upstream instead of the parser draining it.
+ * capped at 6MiB, and every other route keeps its 10mb parser.
+ * - The sandbox-ui view proxy stays parser-free. A finished application/json
+ * body larger than the 24MiB chat ceiling is still 401, so neither the
+ * 10mb parser nor the chat parser is mounted.
*
* Auth is deliberately NOT mocked. A 401 is the proof that the body crossed the
* parser and only the auth boundary stopped it.
@@ -84,9 +85,8 @@ beforeEach(() => {
})
afterAll(async () => {
- // The view-proxy case aborts a request mid-body, so drop any socket that is
- // still open: a listener left behind here would surface as a parse error in
- // whichever sibling test file ran next.
+ // Drop any socket still open so a listener left behind here cannot surface
+ // as a parse error in whichever sibling test file ran next.
server.closeAllConnections()
await new Promise<void>(resolve => server.close(() => resolve()))
})
@@ -346,15 +346,14 @@ describe('rpc-proxy chat message body budget', () => {
})
it('leaves the sandbox-ui view proxy parser-free so its stream is not drained', async () => {
- // A JSON parser on this path would answer 413 for any finished body over
- // its limit. The route answers its cookie check first, so a bounded body
- // larger than the 6 MiB ordinary cap must still be 401 (not 413).
+ // application/json larger than both the 10mb route parser and the 24MiB
+ // chat parser. A mounted parser answers 413. The route answers its cookie
+ // check first, so this body is 401.
const response = await fetch(`${baseUrl}/api/v1/sandbox-ui/ns/recipe/view/index.html`, {
method: 'POST',
- headers: { 'content-type': 'text/plain' },
- body: 'A'.repeat(7 * MIB),
+ headers: { 'content-type': 'application/json' },
+ body: JSON.stringify({ blob: 'A'.repeat(25 * MIB) }),
})
- expect(response.status).not.toBe(413)
expect(response.status).toBe(401)
})
})
diff --git a/rpc-proxy/src/middleware/chatJsonBody.ts b/rpc-proxy/src/middleware/chatJsonBody.ts
index dfb2b2e70..d4ff1ce91 100644
--- a/rpc-proxy/src/middleware/chatJsonBody.ts
+++ b/rpc-proxy/src/middleware/chatJsonBody.ts
@@ -9,8 +9,9 @@ import express, { type NextFunction, type Request, type Response } from 'express
* both edits must land together.
*
* Two ceilings are enforced here:
- * - MAX_CHAT_BODY_BYTES stays 24MiB so 16MiB decoded (~21.3MiB base64) plus
- * the 1MiB non-image share still fits.
+ * - MAX_CHAT_BODY_BYTES stays 24MiB so one 16MiB image (~21.3MiB base64)
+ * still fits. The 6MiB non-image share is a separate ceiling, not added
+ * on top of that image.
* - MAX_NON_IMAGE_BODY_BYTES bounds the same body MINUS credited image
* base64. Without that subtraction the attachment budget would become a
* general 24MiB text budget.