Skip to content

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

TypeScript

fix(codex): allow exceptional 16 MiB images at 2048 px

Alfredo Lopez8c8bcd22ecb1
diff --git a/codex-llm-proxy/src/codexTransport.ts b/codex-llm-proxy/src/codexTransport.ts
index 75d578628..f79680048 100644
--- a/codex-llm-proxy/src/codexTransport.ts
+++ b/codex-llm-proxy/src/codexTransport.ts
@@ -306,7 +306,11 @@ function toUpstreamPayload(
content: message.contentParts.map(part =>
part.type === 'text'
? { type: 'input_text', text: part.text }
- : { type: 'input_image', image_url: `data:${part.mimeType};base64,${part.data}` }
+ : {
+ type: 'input_image',
+ image_url: `data:${part.mimeType};base64,${part.data}`,
+ detail: 'high',
+ }
),
})
} else {
diff --git a/codex-llm-proxy/src/requestLimits.ts b/codex-llm-proxy/src/requestLimits.ts
index 1d092b926..c342b7181 100644
--- a/codex-llm-proxy/src/requestLimits.ts
+++ b/codex-llm-proxy/src/requestLimits.ts
@@ -6,6 +6,16 @@ export const STREAM_LIMITS = {
maxStreamDurationMs: 300_000,
} 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.
+ */
+export const VISUAL_STREAM_LIMITS = {
+ maxConcurrentStreams: 2,
+ maxQueuedRequests: 8,
+} as const
+
export class RequestLimitError extends Error {
readonly code = 'provider_unavailable'
constructor(message: string) {
@@ -27,8 +37,8 @@ export class StreamGate {
private queued = 0
constructor(
- private readonly maxConcurrent = STREAM_LIMITS.maxConcurrentStreams,
- private readonly maxQueued = STREAM_LIMITS.maxQueuedRequests
+ private readonly maxConcurrent: number = STREAM_LIMITS.maxConcurrentStreams,
+ private readonly maxQueued: number = STREAM_LIMITS.maxQueuedRequests
) {}
async acquire(): Promise<() => void> {
@@ -58,3 +68,7 @@ export class StreamGate {
}
export const streamGate = new StreamGate()
+export const visualStreamGate = new StreamGate(
+ VISUAL_STREAM_LIMITS.maxConcurrentStreams,
+ VISUAL_STREAM_LIMITS.maxQueuedRequests
+)
diff --git a/codex-llm-proxy/src/server.ts b/codex-llm-proxy/src/server.ts
index e676e3b1c..7e7cd21cd 100644
--- a/codex-llm-proxy/src/server.ts
+++ b/codex-llm-proxy/src/server.ts
@@ -1,4 +1,4 @@
-import express, { type Express, type Request, type Response } from 'express'
+import express, { type Express, type NextFunction, type Request, type Response } from 'express'
import { rateLimit } from 'express-rate-limit'
import { type Server, createServer } from 'node:http'
import { Registry, collectDefaultMetrics } from 'prom-client'
@@ -21,7 +21,9 @@ import {
type OriginPolicyOptions,
defaultAddressLookup,
} from './originPolicy.js'
-import { RequestLimitError, streamGate } from './requestLimits.js'
+import { RequestLimitError, streamGate, visualStreamGate } from './requestLimits.js'
+
+type GatedRequest = Request & { codexStreamRelease?: () => void }
const COMPLETION_KEYS = new Set(['executionTicket', 'requestHash', 'request', 'deadlineMs'])
const ADMIN_KEYS = new Set(['accessToken'])
@@ -123,24 +125,58 @@ export function createProxyApps(
// completion endpoint with an already valid platform identity may use the larger
// budget. V1 is still bounded by its contract parser, and admin or
// unauthenticated requests keep the ordinary cap.
- const selectTransportBudget = (req: Request, res: Response, next: () => void): void => {
+ 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 (config.imageInputModels.length > 0 && verifyPlatformJwt(bearer(req), config)) {
- visualJson(req, res, next)
+ void (async () => {
+ let release: (() => void) | undefined
+ try {
+ release = await visualStreamGate.acquire()
+ } catch (err) {
+ if (err instanceof RequestLimitError) {
+ reject(res, 503, err.code)
+ return
+ }
+ next()
+ return
+ }
+ req.codexStreamRelease = release
+ visualJson(req, res, err => {
+ if (err) {
+ req.codexStreamRelease?.()
+ req.codexStreamRelease = undefined
+ next(err)
+ return
+ }
+ next()
+ })
+ })()
return
}
ordinaryJson(req, res, next)
}
runtimeApp.post(COMPLETION_PATH, runtimeRateLimit, selectTransportBudget, (req, res) => {
+ const gated = req as GatedRequest
+ const releaseAdmission = (): void => {
+ gated.codexStreamRelease?.()
+ gated.codexStreamRelease = undefined
+ }
if (!req.is('application/json')) {
+ releaseAdmission()
reject(res, 415, 'unsupported_media_type')
return
}
if (verifyAdminPermit(bearer(req), config)) {
+ releaseAdmission()
reject(res, 403, 'insufficient_scope')
return
}
const platform = verifyPlatformJwt(bearer(req), config)
if (!platform) {
+ releaseAdmission()
reject(res, 401, 'Unauthorized')
return
}
@@ -149,33 +185,40 @@ export function createProxyApps(
? config.maxVisualBodyBytes
: config.maxBodyBytes
if (Buffer.byteLength(JSON.stringify(req.body ?? {}), 'utf8') > bodyLimit) {
+ releaseAdmission()
reject(res, 413, 'payload_too_large')
return
}
const extra = Object.keys(req.body ?? {}).find(key => !COMPLETION_KEYS.has(key))
if (extra) {
+ releaseAdmission()
reject(res, 400, 'unknown_field')
return
}
const parsed = completionBodySchema.safeParse(req.body)
if (!parsed.success) {
+ releaseAdmission()
reject(res, 400, 'invalid_request')
return
}
if (parsed.data.deadlineMs !== undefined && parsed.data.deadlineMs > config.maxDeadlineMs) {
+ releaseAdmission()
reject(res, 400, 'invalid_request')
return
}
const ticket = verifyExecutionTicket(parsed.data.executionTicket, config)
if (!ticket) {
+ releaseAdmission()
reject(res, 403, 'ticket_invalid')
return
}
if (platform.hostRefs.includes('*') || !platform.hostRefs.includes(ticket.hostRef)) {
+ releaseAdmission()
reject(res, 403, 'host_binding_mismatch')
return
}
if (!config.executionEnabled) {
+ releaseAdmission()
reject(res, 404, 'disabled')
return
}
@@ -188,7 +231,11 @@ export function createProxyApps(
// Abort only when the client drops the response before we finish writing.
abortWhenClientDisconnects(req, res, abort)
try {
- release = await streamGate.acquire()
+ release = gated.codexStreamRelease
+ gated.codexStreamRelease = undefined
+ if (!release) {
+ release = await streamGate.acquire()
+ }
res.status(200)
res.setHeader('content-type', 'text/event-stream')
res.setHeader('cache-control', 'no-cache')
diff --git a/codex-llm-proxy/test/codexTransport.conformance.test.ts b/codex-llm-proxy/test/codexTransport.conformance.test.ts
index c2a202407..be637dd02 100644
--- a/codex-llm-proxy/test/codexTransport.conformance.test.ts
+++ b/codex-llm-proxy/test/codexTransport.conformance.test.ts
@@ -119,7 +119,11 @@ describe('streamCodexCompletion', () => {
(part: { type: string; text?: string; mimeType?: string; data?: string }) =>
part.type === 'text'
? { type: 'input_text', text: part.text }
- : { type: 'input_image', image_url: `data:${part.mimeType};base64,${part.data}` }
+ : {
+ type: 'input_image',
+ image_url: `data:${part.mimeType};base64,${part.data}`,
+ detail: 'high',
+ }
)
)
expect(JSON.stringify(body)).not.toContain('attachmentId')
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 5ece66ea9..74e83bcb0 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.557",
+ "version": "0.1.558",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.557",
+ "version": "0.1.558",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/image-policy": "file:../packages/image-policy",
diff --git a/control-api/package.json b/control-api/package.json
index ac1d43bed..82a1b4068 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.557",
+ "version": "0.1.558",
"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 c9bcdb223..46ff0fe7e 100644
--- a/control-api/src/services/llmProviderAttemptAuthorizer.ts
+++ b/control-api/src/services/llmProviderAttemptAuthorizer.ts
@@ -1,7 +1,10 @@
import {
+ LIMITS,
buildCodexProxyEnvelope,
computeCodexPolicyHash,
hashCodexCompletionRequest,
+ isBoundedId,
+ measureNonImageAuthorizeBytes,
parseCodexCompletionRequest,
requestBodyLimitBytes,
} from '@clerum/llm-provider-attempt-contract'
@@ -198,6 +201,12 @@ export async function authorizeLlmProviderAttempt(
if (Buffer.byteLength(serialized, 'utf8') > requestBodyLimitBytes(body.request)) {
throw new LlmProviderAttemptAuthorizeError('invalid_request', 'request body exceeds the limit')
}
+ if (measureNonImageAuthorizeBytes(body) > LIMITS.maxRequestBodyBytes) {
+ throw new LlmProviderAttemptAuthorizeError(
+ 'invalid_request',
+ 'authorize wrapper exceeds the non-image limit'
+ )
+ }
const unknown = firstUnknownKey(body)
if (unknown) {
throw new LlmProviderAttemptAuthorizeError('unknown_field', `unknown field '${unknown}'`)
@@ -225,7 +234,7 @@ export async function authorizeLlmProviderAttempt(
typeof body.providerAttemptIndex === 'number' ? body.providerAttemptIndex : 1
const policyRevision = typeof body.policyRevision === 'number' ? body.policyRevision : NaN
const policyHash = typeof body.policyHash === 'string' ? body.policyHash : ''
- if (!invocationId || !Number.isInteger(attemptGeneration) || attemptGeneration < 1) {
+ if (!isBoundedId(invocationId) || !Number.isInteger(attemptGeneration) || attemptGeneration < 1) {
throw new LlmProviderAttemptAuthorizeError(
'invalid_request',
'invocationId and attemptGeneration are required'
@@ -407,6 +416,9 @@ export async function authorizeLlmProviderAttempt(
}
const presentedTargetRef = typeof body.targetRef === 'string' ? body.targetRef.trim() : ''
+ if (presentedTargetRef !== '' && !isBoundedId(presentedTargetRef)) {
+ throw new LlmProviderAttemptAuthorizeError('invalid_request', 'targetRef is invalid')
+ }
let reservedSdkAttemptToPromote: {
id: string
invocationId: string
diff --git a/control-api/test/services.llmProviderAttemptAuthorizer.test.ts b/control-api/test/services.llmProviderAttemptAuthorizer.test.ts
index e2314d946..af9168ab1 100644
--- a/control-api/test/services.llmProviderAttemptAuthorizer.test.ts
+++ b/control-api/test/services.llmProviderAttemptAuthorizer.test.ts
@@ -322,6 +322,7 @@ describe('authorizeLlmProviderAttempt', () => {
).toContainEqual({
type: 'input_image',
image_url: `data:${image.mimeType};base64,${image.data}`,
+ detail: 'high',
})
if (origin === 'tool') {
expect((projectedBody!.input as Array<{ type?: string }>).map(item => item.type)).toEqual([
@@ -464,6 +465,7 @@ describe('authorizeLlmProviderAttempt', () => {
expect(projectedParts).toContainEqual({
type: 'input_image',
image_url: `data:${part.mimeType};base64,${part.data}`,
+ detail: 'high',
})
}
expect(result.content).toBe('image received')
@@ -582,6 +584,34 @@ describe('authorizeLlmProviderAttempt', () => {
).rejects.toMatchObject({ code: 'unknown_field' })
})
+ it('rejects a V2 authorize wrapper whose invocationId is not a bounded id', async () => {
+ await expect(
+ authorizeLlmProviderAttempt(
+ claims(),
+ body({
+ request: { ...REQUEST, schemaVersion: 'codex-completion-request.v2' },
+ invocationId: 'x'.repeat(200),
+ }),
+ current
+ )
+ ).rejects.toMatchObject({ code: 'invalid_request' })
+ expect(current.insertAttempt).not.toHaveBeenCalled()
+ })
+
+ it('keeps the authorize wrapper on the 1 MiB non-image budget when the nested request is V2', async () => {
+ await expect(
+ authorizeLlmProviderAttempt(
+ claims(),
+ body({
+ request: { ...REQUEST, schemaVersion: 'codex-completion-request.v2' },
+ targetRef: 't'.repeat(2 * MIB),
+ }),
+ current
+ )
+ ).rejects.toMatchObject({ code: 'invalid_request' })
+ expect(current.insertAttempt).not.toHaveBeenCalled()
+ })
+
it('rejects a non-UUID Plugin Workload SDK attempt id', async () => {
await expect(
authorizeLlmProviderAttempt(
diff --git a/desktop-app/scripts/start-isolated-app.mjs b/desktop-app/scripts/start-isolated-app.mjs
index fcf0bad3e..ccd477aeb 100644
--- a/desktop-app/scripts/start-isolated-app.mjs
+++ b/desktop-app/scripts/start-isolated-app.mjs
@@ -199,9 +199,47 @@ function createRunDirectory(contract, options) {
return runPaths
}
+/**
+ * Electron needs a process identity (PATH, HOME, locale). It must not inherit
+ * the operator's session tokens, cloud keys, or SSH agent.
+ */
+const CHILD_ENV_ALLOWLIST = [
+ 'PATH',
+ 'HOME',
+ 'USER',
+ 'LOGNAME',
+ 'SHELL',
+ 'TMPDIR',
+ 'TMP',
+ 'TEMP',
+ 'LANG',
+ 'LC_ALL',
+ 'LC_CTYPE',
+ 'LC_MESSAGES',
+ 'TZ',
+ 'TERM',
+ 'DISPLAY',
+ 'WAYLAND_DISPLAY',
+ 'XAUTHORITY',
+ 'XDG_RUNTIME_DIR',
+ 'XDG_SESSION_TYPE',
+ 'XDG_CURRENT_DESKTOP',
+ 'XDG_DATA_DIRS',
+ '__CF_USER_TEXT_ENCODING',
+]
+
+function allowedParentEnvironment() {
+ const env = {}
+ for (const key of CHILD_ENV_ALLOWLIST) {
+ const value = process.env[key]
+ if (typeof value === 'string' && value !== '') env[key] = value
+ }
+ return env
+}
+
function childEnvironment(contract, runPaths, options, appPath) {
return {
- ...process.env,
+ ...allowedParentEnvironment(),
[contract.DEV_ISOLATION_ENABLE_ENV]: '1',
[contract.DEV_ISOLATION_ENV.runDir]: runPaths.runDir,
[contract.DEV_ISOLATION_ENV.restUrl]: options.restUrl,
diff --git a/desktop-app/test/e2e-playwright/codex-image-input.spec.ts b/desktop-app/test/e2e-playwright/codex-image-input.spec.ts
index 23ba89ad8..f09198a02 100644
--- a/desktop-app/test/e2e-playwright/codex-image-input.spec.ts
+++ b/desktop-app/test/e2e-playwright/codex-image-input.spec.ts
@@ -202,7 +202,23 @@ test('5 MiB JPEG follows the same capability lane as a small image', async ({ ap
})
})
-test('10 MiB PNG + 5 MiB JPEG follow the 15 MiB combined budget', async ({ appPage }) => {
+test('12 MiB PNG follows the exceptional hard ceiling above 10 MiB', async ({ appPage }) => {
+ test.setTimeout(360_000)
+ const image = paddedChallengeImage('png', 12 * MIB)
+ const filename = `visual-${randomUUID()}.png`
+ await startOwnedChat(appPage)
+ await uploadThroughChooser(appPage, [
+ { name: filename, mimeType: 'image/png', buffer: image.bytes },
+ ])
+ await assertPreview(appPage, filename)
+ await sendVisualTurn(appPage, {
+ prompt: visualPrompt(1),
+ filenames: [filename],
+ codes: [image.code],
+ })
+})
+
+test('10 MiB PNG + 5 MiB JPEG stay under the 16 MiB combined hard ceiling', async ({ appPage }) => {
test.setTimeout(360_000)
const ten = paddedChallengeImage('png', 10 * MIB)
const five = paddedChallengeImage('jpeg', 5 * MIB)
@@ -242,25 +258,25 @@ test('three 5 MiB images follow the combined budget', async ({ appPage }) => {
})
})
-test('refuses a single image over the 10 MiB limit before send', async ({ appPage }) => {
- const image = paddedChallengeImage('png', 11 * MIB)
+test('refuses a single image over the 16 MiB limit before send', async ({ appPage }) => {
+ const image = paddedChallengeImage('png', 17 * MIB)
const filename = `over-${randomUUID()}.png`
await startOwnedChat(appPage)
await uploadThroughChooser(appPage, [
{ name: filename, mimeType: 'image/png', buffer: image.bytes },
])
await expect(appPage.getByRole('alert')).toContainText(
- `${filename} is too large. Max size is 10 MiB.`
+ `${filename} is too large. Max size is 16 MiB.`
)
await expect(appPage.getByRole('button', { name: filename, exact: true })).toHaveCount(0)
await expect(appPage.getByTestId('agent-response')).toHaveCount(0)
})
-test('refuses the file that would pass the 15 MiB total and keeps the one that fits', async ({
+test('refuses the file that would pass the 16 MiB total and keeps the one that fits', async ({
appPage,
}) => {
const fits = paddedChallengeImage('png', 10 * MIB)
- const over = paddedChallengeImage('jpeg', 6 * MIB)
+ const over = paddedChallengeImage('jpeg', 7 * MIB)
const fitsName = `fits-${randomUUID()}.png`
const overName = `over-total-${randomUUID()}.jpeg`
await startOwnedChat(appPage)
@@ -269,7 +285,7 @@ test('refuses the file that would pass the 15 MiB total and keeps the one that f
{ name: overName, mimeType: 'image/jpeg', buffer: over.bytes },
])
await expect(appPage.getByRole('alert')).toContainText(
- `${overName} was not added. Attachments can total at most 15 MiB per message.`
+ `${overName} was not added. Attachments can total at most 16 MiB per message.`
)
await expect(appPage.getByRole('button', { name: fitsName, exact: true })).toBeVisible()
await expect(appPage.getByRole('button', { name: overName, exact: true })).toHaveCount(0)
diff --git a/desktop-app/ui/src/components/agents/__tests__/ComposerPanel.test.tsx b/desktop-app/ui/src/components/agents/__tests__/ComposerPanel.test.tsx
index 301a2bffa..d7bf2f0b8 100644
--- a/desktop-app/ui/src/components/agents/__tests__/ComposerPanel.test.tsx
+++ b/desktop-app/ui/src/components/agents/__tests__/ComposerPanel.test.tsx
@@ -316,12 +316,20 @@ describe('ComposerPanel image budget', () => {
expect(screen.queryByRole('alert')).toBeNull()
})
- it('refuses an image over the 10MiB limit and names the limit in MiB', async () => {
+ it('accepts a 12MiB image above the usual 10MiB target', async () => {
const { container } = render(<ComposerPanel inline={false} />)
- pickFiles(container, [imageFile('over.png', 11 * MIB)])
+ pickFiles(container, [imageFile('large.png', 12 * MIB)])
+ await waitFor(() => expect(attachedImages()).toHaveLength(1))
+ expect(attachedImages()[0]?.sizeBytes).toBe(12 * MIB)
+ expect(screen.queryByRole('alert')).toBeNull()
+ })
+
+ it('refuses an image over the 16MiB limit and names the limit in MiB', async () => {
+ const { container } = render(<ComposerPanel inline={false} />)
+ pickFiles(container, [imageFile('over.png', 17 * MIB)])
await waitFor(() =>
expect(screen.getByRole('alert').textContent).toContain(
- 'over.png is too large. Max size is 10 MiB.'
+ 'over.png is too large. Max size is 16 MiB.'
)
)
expect(composerActions.handleAddComposerImageAttachments).not.toHaveBeenCalled()
@@ -329,10 +337,10 @@ describe('ComposerPanel image budget', () => {
it('refuses the over-total file in a selection and keeps the one that fits', async () => {
const { container } = render(<ComposerPanel inline={false} />)
- pickFiles(container, [imageFile('fits.png', 10 * MIB), imageFile('over-total.png', 6 * MIB)])
+ pickFiles(container, [imageFile('fits.png', 10 * MIB), imageFile('over-total.png', 7 * MIB)])
await waitFor(() =>
expect(screen.getByRole('alert').textContent).toContain(
- 'over-total.png was not added. Attachments can total at most 15 MiB per message.'
+ 'over-total.png was not added. Attachments can total at most 16 MiB per message.'
)
)
expect(attachedImages().map(attachment => attachment.name)).toEqual(['fits.png'])
@@ -341,10 +349,10 @@ describe('ComposerPanel image budget', () => {
it('refuses an added image that would pass the total with 10MiB already attached', async () => {
composerState.composerImageAttachments = [existingAttachment('kept.png', 10 * MIB)]
const { container } = render(<ComposerPanel inline={false} />)
- pickFiles(container, [imageFile('over-total.png', 6 * MIB)])
+ pickFiles(container, [imageFile('over-total.png', 7 * MIB)])
await waitFor(() =>
expect(screen.getByRole('alert').textContent).toContain(
- 'can total at most 15 MiB per message'
+ 'can total at most 16 MiB per message'
)
)
expect(composerActions.handleAddComposerImageAttachments).not.toHaveBeenCalled()
@@ -402,24 +410,24 @@ describe('ComposerPanel annotation budget', () => {
})
})
- it('refuses an annotation over the 10MiB per-image limit and keeps the original', () => {
+ it('refuses an annotation over the 16MiB per-image limit and keeps the original', () => {
const original = existingAttachment('photo.png', 4 * MIB)
composerState.composerImageAttachments = [original]
const { container } = render(<ComposerPanel inline={false} />)
openAnnotation(container, 'photo.png')
- annotationStub.next = { ...original, sizeBytes: 11 * MIB }
+ annotationStub.next = { ...original, sizeBytes: 17 * MIB }
applyAnnotation()
expect(composerActions.handleUpdateComposerImageAttachment).not.toHaveBeenCalled()
// The message the annotation dialog renders above its overlay; the original
// attachment is never replaced.
expect(annotationStub.threw).toContain(
- 'photo.png was kept unchanged. Max size is 10 MiB per image.'
+ 'photo.png was kept unchanged. Max size is 16 MiB per image.'
)
})
- it('refuses an annotation that would push the message past the 15MiB total', () => {
+ it('refuses an annotation that would push the message past the 16MiB total', () => {
const original = existingAttachment('photo.png', 4 * MIB)
composerState.composerImageAttachments = [original, existingAttachment('other.png', 10 * MIB)]
const { container } = render(<ComposerPanel inline={false} />)
@@ -432,24 +440,24 @@ describe('ComposerPanel annotation budget', () => {
expect(composerActions.handleUpdateComposerImageAttachment).not.toHaveBeenCalled()
expect(annotationStub.threw).toContain(
- 'photo.png was kept unchanged. Attachments can total at most 15 MiB per message.'
+ 'photo.png was kept unchanged. Attachments can total at most 16 MiB per message.'
)
})
- it('applies an annotation that exactly reaches the 15MiB total', () => {
+ it('applies an annotation that exactly reaches the 16MiB total', () => {
const original = existingAttachment('photo.png', 4 * MIB)
composerState.composerImageAttachments = [original, existingAttachment('other.png', 10 * MIB)]
const { container } = render(<ComposerPanel inline={false} />)
openAnnotation(container, 'photo.png')
- annotationStub.next = { ...original, sizeBytes: 5 * MIB }
+ annotationStub.next = { ...original, sizeBytes: 6 * MIB }
applyAnnotation()
expect(annotationStub.threw).toBeNull()
expect(composerActions.handleUpdateComposerImageAttachment).toHaveBeenCalledTimes(1)
expect(composerActions.handleUpdateComposerImageAttachment.mock.calls[0]?.[0]).toMatchObject({
id: original.id,
- sizeBytes: 5 * MIB,
+ sizeBytes: 6 * MIB,
})
})
})
diff --git a/desktop-app/ui/src/constants/attachments.ts b/desktop-app/ui/src/constants/attachments.ts
index e8da613dd..57f2630e6 100644
--- a/desktop-app/ui/src/constants/attachments.ts
+++ b/desktop-app/ui/src/constants/attachments.ts
@@ -1,12 +1,11 @@
export const COMPOSER_MAX_IMAGE_ATTACHMENTS = 3
/**
- * Composer image budget. These mirror the server-side chat body budget shared by
- * rpc-proxy and mcp-host (10MiB per image, 3 images / 15MiB of image bytes in a
- * 24MiB JSON body), so an image the composer accepts is also one the runtime
- * will carry. Change them together with that budget.
+ * Composer hard image budget. Mirrors rpc-proxy / mcp-host hop credit: 16MiB
+ * per image and 16MiB total in a 24MiB JSON body so a poorly compressed 2048
+ * PNG may exceed 10MiB. The usual product target is 5 / 9 / 14 MiB.
*/
-export const COMPOSER_MAX_IMAGE_BYTES = 10 * 1024 * 1024
-export const COMPOSER_MAX_TOTAL_IMAGE_BYTES = 15 * 1024 * 1024
+export const COMPOSER_MAX_IMAGE_BYTES = 16 * 1024 * 1024
+export const COMPOSER_MAX_TOTAL_IMAGE_BYTES = 16 * 1024 * 1024
export const COMPOSER_ACCEPT_IMAGE_MIME_TYPES = ['image/jpeg', 'image/png'] as const
export const ZAI_IMAGE_ATTACHMENT_UNSUPPORTED_MESSAGE =
'Image attachments are not supported for agents running on Z AI yet. Switch this agent to a provider with image input support before attaching images.'
diff --git a/docs/architecture/codex-subscription-transport-contract.md b/docs/architecture/codex-subscription-transport-contract.md
index 5dd0e1720..fdd1d04e5 100644
--- a/docs/architecture/codex-subscription-transport-contract.md
+++ b/docs/architecture/codex-subscription-transport-contract.md
@@ -33,11 +33,15 @@ retain one remaining image per MIME/bytes pair and its explanatory text. They do
not restore pixels removed by pruning. The user-facing attachment collection
keeps its existing deduplication behavior.
-Local visual budgets are three images, 10 MiB decoded per image, 15 MiB decoded
-across a request, 8192 pixels per dimension and 64,000,000 pixels per image.
-The aggregate is independent: one 10 MiB image plus one 5 MiB image fits, as do
-three 5 MiB images; three 10 MiB images do not. Original bytes are preserved.
-These are conservative Evenfire limits, not claims about upstream capabilities.
+Local visual budgets have two layers. The usual product target is three images,
+5 MiB decoded per image, 9 MiB decoded across a request, and a 14 MiB envelope
+at 2048 pixels (the official Codex client size, with `detail: high`). The hard
+ceiling is 16 MiB per image and 16 MiB aggregate so a poorly compressed 2048
+PNG may exceed 10 MiB; the HTTP envelope stays 24 MiB so that encoded body
+still fits. Dimensions above 2048 px are rejected here because the frozen
+ChatGPT endpoint 400s them; that is a model/pixel limit, not a byte limit.
+Which models accept images is owned by issue #654 / PR #669 (models.dev).
+These byte numbers are conservative Evenfire limits, not upstream facts.
The shared pure validator checks canonical base64, MIME/container framing and
header dimensions; it does not decode pixels or prove image decodability.
The fixtures contain independently decoded 2x2 PNG/JPEG images.
@@ -54,7 +58,8 @@ The Host uses the same envelope builder. V2 has no outer deadline: its deadline
is `request.deadlineMs`, part of the authorized hash. A proxy configured below
the shared visual envelope budget refuses visual activation at startup.
-Desktop enforces the 10 MiB individual and 15 MiB combined attachment budgets.
+Desktop enforces the 16 MiB individual and 16 MiB combined hard attachment
+budgets (usual target remains 5 / 9 MiB).
RPC and Host permit a 24 MiB JSON body only on their message POST routes; their
6 MiB budget for other content and routes remains unchanged. The proxy's larger
parser requires a valid platform identity on the visual completion route.
diff --git a/docs/testing/codex-subscription-validation.md b/docs/testing/codex-subscription-validation.md
index 0d1800391..c51a744d4 100644
--- a/docs/testing/codex-subscription-validation.md
+++ b/docs/testing/codex-subscription-validation.md
@@ -10,9 +10,10 @@ ordered text/image content and local image/envelope budgets. Its
`fixtures/canonical-request-hashes.v2.json` freezes the new projection separately.
The image parser validates container structure and dimensions, not decoded pixels.
-Capacity checks cover 10 MiB per image, 15 MiB across up to three images, and a
-24 MiB V2 envelope. Exercise 10 MiB, 10+5 MiB and 3x5 MiB acceptance, plus
-individual/aggregate overflow. V1 and V2 non-image fields keep a 1 MiB ceiling;
+Capacity checks cover the usual 5 / 9 / 14 MiB target and the hard 16 MiB
+per-image / 16 MiB aggregate / 24 MiB envelope ceiling, plus the 2048 px
+model bound. Exercise 5 MiB, 12 MiB (exceptional, above 10 MiB), 10+5 MiB
+and 3x5 MiB acceptance, plus overflow above 16 MiB. V1 and V2 non-image fields keep a 1 MiB ceiling;
unrelated RPC/Host routes keep 6 MiB. The larger proxy parser must not admit an
anonymous, wrong-scope or admin request, or enlarge V1's effective body limit.
Changing these budgets does not change OAuth, grants, ticket binding, origins,
@@ -54,9 +55,9 @@ than silently skipping them.
### Opt-in Desktop image lane
`desktop-app/test/e2e-playwright/codex-image-input.spec.ts` covers direct PNG/JPEG
-uploads through the visible composer, including a 5 MiB JPEG, a 10+5 MiB pair,
-three 5 MiB images, and composer refusals over 10 MiB, over 15 MiB total, a
-fourth image, and a non-PNG/JPEG type. It creates a fresh 64-bit hexadecimal
+uploads through the visible composer, including a 5 MiB JPEG, a 12 MiB PNG
+(exceptional), a 10+5 MiB pair, three 5 MiB images, and composer refusals over
+16 MiB, over 16 MiB total, a fourth image, and a non-PNG/JPEG type. It creates a fresh 64-bit hexadecimal
challenge rendered only into image pixels. Large cases pad that same image so
the answer stays in pixels while the decoded size matches the hop budget. The
filename and prompt do not carry the answer. An enabled run requires that
diff --git a/external-rest-api/src/releaseManifest.ts b/external-rest-api/src/releaseManifest.ts
index 97b09aeb8..8e5935da1 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.8.1',
externalRestApiVersion: '0.1.82',
- rpcProxyVersion: '0.1.81',
+ rpcProxyVersion: '0.1.82',
desktopVersion: '0.8.1',
minimumDesktopVersion: '0.1.252',
}
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index fd8e4ee80..b7193f876 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.343",
+ "version": "0.1.344",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.343",
+ "version": "0.1.344",
"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 3ba267817..afdd8fa38 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.343",
+ "version": "0.1.344",
"description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude",
"main": "dist/main.js",
"engines": {
diff --git a/mcp-host/src/__tests__/bodylimits.test.ts b/mcp-host/src/__tests__/bodylimits.test.ts
index 03ca40472..cf1f16cb1 100644
--- a/mcp-host/src/__tests__/bodylimits.test.ts
+++ b/mcp-host/src/__tests__/bodylimits.test.ts
@@ -137,7 +137,16 @@ async function postMessage(payload: unknown): Promise<Response> {
}
describe('mcp-host runtime message body budget', () => {
- it('delivers a single 10MiB image (the per-image limit) byte-identical', async () => {
+ it('delivers a 12MiB image (exceptional, above 10MiB) byte-identical', async () => {
+ captured = []
+ const attachment = imageAttachment('a1', 12 * MIB)
+ const response = await postMessage(messagePayload([attachment]))
+ expect(response.status).toBe(200)
+ expect(captured).toHaveLength(1)
+ expect(captured[0].attachments).toEqual([attachment])
+ })
+
+ it('delivers a single 10MiB image (the former per-image limit) byte-identical', async () => {
captured = []
const attachment = imageAttachment('a1', 10 * MIB)
const response = await postMessage(messagePayload([attachment]))
@@ -194,9 +203,22 @@ describe('mcp-host runtime message body budget', () => {
)
})
- it('rejects a single image over the 10MiB per-image limit', async () => {
+ it('rejects a fourth qualifying image instead of charging it as text', async () => {
+ captured = []
+ const attachments = [
+ imageAttachment('a1', 64 * 1024),
+ imageAttachment('a2', 64 * 1024),
+ imageAttachment('a3', 64 * 1024),
+ imageAttachment('a4', 64 * 1024),
+ ]
+ const response = await postMessage(messagePayload(attachments))
+ expect(response.status).toBe(413)
+ expect(captured).toHaveLength(0)
+ })
+
+ it('rejects a single image over the 16MiB per-image limit', async () => {
captured = []
- const response = await postMessage(messagePayload([imageAttachment('a1', 11 * MIB)]))
+ const response = await postMessage(messagePayload([imageAttachment('a1', 17 * MIB)]))
expect(response.status).toBe(413)
expect(captured).toHaveLength(0)
})
@@ -210,12 +232,19 @@ describe('mcp-host runtime message body budget', () => {
expect(captured).toHaveLength(0)
})
- it('rejects two 8MiB images on the 15MiB total alone, under the 24MiB ceiling', async () => {
+ it('delivers two 8MiB images that sit on the 16MiB total', async () => {
+ captured = []
+ const attachments = [imageAttachment('a1', 8 * MIB), imageAttachment('a2', 8 * MIB)]
+ const response = await postMessage(messagePayload(attachments))
+ expect(response.status).toBe(200)
+ expect(captured).toHaveLength(1)
+ expect(captured[0].attachments).toEqual(attachments)
+ })
+
+ it('rejects 9MiB + 8MiB on the 16MiB total alone, under the 24MiB ceiling', async () => {
captured = []
- // Each image is under the 10MiB per-image limit and the body fits the 24MiB
- // ceiling, so the only rule that can reject this pair is the 15MiB total.
const response = await postMessage(
- messagePayload([imageAttachment('a1', 8 * MIB), imageAttachment('a2', 8 * MIB)])
+ messagePayload([imageAttachment('a1', 9 * MIB), imageAttachment('a2', 8 * MIB)])
)
expect(response.status).toBe(413)
expect(captured).toHaveLength(0)
diff --git a/mcp-host/src/server.ts b/mcp-host/src/server.ts
index 1c6788290..f09f9c14e 100644
--- a/mcp-host/src/server.ts
+++ b/mcp-host/src/server.ts
@@ -135,20 +135,18 @@ export type {
* any @clerum package, so the two services cannot share one source without a
* new package. Both copies must change together.
*
- * - MAX_CHAT_BODY_BYTES bounds the raw JSON body of `POST /v1/runtime/messages`.
- * 10MiB encodes to ~13.3MiB of base64, so a 10MiB image plus a 5MiB image
- * (the largest combination the 15MiB total allows) needs ~21MiB plus the
- * envelope. Every other route keeps the 6MiB default.
- * - MAX_NON_IMAGE_BODY_BYTES bounds that same body MINUS the base64 of images
- * counting against the documented attachment budget (10MiB per image, at
- * most 3 images / 15MiB total). Without the subtraction the attachment
- * budget would silently become a general 24MiB text budget.
+ * - MAX_CHAT_BODY_BYTES stays 24MiB so one exceptional 16MiB 2048 PNG
+ * (~21.3MiB base64) plus the 1MiB non-image share still fits. Every other
+ * route keeps the 6MiB default.
+ * - MAX_NON_IMAGE_BODY_BYTES bounds that same body MINUS credited image
+ * base64 (16MiB per image, at most 3 images / 16MiB total). Usual product
+ * target remains 5 / 9 / 14 MiB at 2048 px.
*/
const MAX_CHAT_BODY_BYTES = 24 * 1024 * 1024
const MAX_NON_IMAGE_BODY_BYTES = 6 * 1024 * 1024
const MAX_CHAT_IMAGES = 3
-const MAX_IMAGE_DECODED_BYTES = 10 * 1024 * 1024
-const MAX_IMAGE_DECODED_BYTES_TOTAL = 15 * 1024 * 1024
+const MAX_IMAGE_DECODED_BYTES = 16 * 1024 * 1024
+const MAX_IMAGE_DECODED_BYTES_TOTAL = 16 * 1024 * 1024
const BASE64_RE = /^[A-Za-z0-9+/]+={0,2}$/
const PNG_SIGNATURE = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])
const JPEG_SIGNATURE = Buffer.from([0xff, 0xd8, 0xff])
@@ -192,21 +190,26 @@ function decodedBase64Bytes(dataBase64: string): number | null {
* Byte length of the base64 that counts against the documented image budget.
* Only attachments with the exact wire shape the composer produces qualify:
* `kind: 'image'`, `encoding: 'base64'`, a PNG/JPEG MIME type, canonical
- * base64 whose leading bytes are that image's signature, and at most 10MiB
- * decoded each within a 3-image / 15MiB total budget. Anything else is charged
+ * base64 whose leading bytes are that image's signature, and at most 16MiB
+ * decoded each within a 3-image / 16MiB total budget. A fourth qualifying
+ * image is fail-loud rather than charged as text. Anything else is charged
* to the non-image budget, so a claim cannot be smuggled through by mislabelling
* a payload.
*/
-function budgetedImageBase64Length(body: unknown): number {
- if (!body || typeof body !== 'object' || Array.isArray(body)) return 0
+function inspectChatImageBudget(body: unknown): {
+ creditedBase64: number
+ tooManyImages: boolean
+} {
+ if (!body || typeof body !== 'object' || Array.isArray(body)) {
+ return { creditedBase64: 0, tooManyImages: false }
+ }
const attachments = (body as { attachments?: unknown }).attachments
- if (!Array.isArray(attachments)) return 0
+ if (!Array.isArray(attachments)) return { creditedBase64: 0, tooManyImages: false }
let credited = 0
let decodedTotal = 0
let counted = 0
for (const attachment of attachments) {
- if (counted >= MAX_CHAT_IMAGES) break
if (!attachment || typeof attachment !== 'object') continue
const candidate = attachment as {
kind?: unknown
@@ -227,15 +230,20 @@ function budgetedImageBase64Length(body: unknown): number {
? signature.subarray(0, PNG_SIGNATURE.length).equals(PNG_SIGNATURE)
: signature.subarray(0, JPEG_SIGNATURE.length).equals(JPEG_SIGNATURE)
if (!matchesSignature) continue
+ if (counted >= MAX_CHAT_IMAGES) {
+ return { creditedBase64: credited, tooManyImages: true }
+ }
credited += dataBase64.length
decodedTotal += decoded
counted += 1
}
- return credited
+ return { creditedBase64: credited, tooManyImages: false }
}
function chatBodyExceedsNonImageBudget(rawBodyBytes: number, body: unknown): boolean {
- return rawBodyBytes - budgetedImageBase64Length(body) > MAX_NON_IMAGE_BODY_BYTES
+ const budget = inspectChatImageBudget(body)
+ if (budget.tooManyImages) return true
+ return rawBodyBytes - budget.creditedBase64 > MAX_NON_IMAGE_BODY_BYTES
}
export class RPCServer {
diff --git a/mcp-host/tsconfig.json b/mcp-host/tsconfig.json
index 8b50c65ff..5fdb3c668 100644
--- a/mcp-host/tsconfig.json
+++ b/mcp-host/tsconfig.json
@@ -16,5 +16,5 @@
"sourceMap": true
},
"include": ["src/**/*"],
- "exclude": ["node_modules", "dist"]
+ "exclude": ["node_modules", "dist", "**/*.test.ts", "**/__tests__/**"]
}
diff --git a/packages/llm-provider-attempt-contract/index.cjs b/packages/llm-provider-attempt-contract/index.cjs
index 5329e8983..9e73ae67e 100644
--- a/packages/llm-provider-attempt-contract/index.cjs
+++ b/packages/llm-provider-attempt-contract/index.cjs
@@ -23,9 +23,10 @@ const LIMITS = Object.freeze({
/**
* V2 request/envelope ceiling. It is deliberately larger than
* `maxRequestBodyBytes` because a V2 body carries base64 image payloads, and
- * it is deliberately larger than the largest legal V2 image set
- * (`maxImages` * `maxImageBytes` decoded ≈ 21 MiB encoded) so the same number
- * covers the non-image share and the envelope's ticket and digest. It is not a
+ * it is deliberately larger than one hard-ceiling image (16 MiB decoded ≈
+ * 21.3 MiB encoded) plus the 1 MiB non-image share. Typical 5 / 9 requests
+ * fit in 14 MiB (`VISUAL_LIMITS.typicalEnvelopeBytes`); this 24 MiB number is
+ * the HTTP/nginx hard envelope, not the usual product target. It is not a
* text/tool allowance: `measureNonImageRequestBytes` keeps that share on the
* V1 ceiling.
*/
@@ -189,21 +190,49 @@ function requestBodyLimitBytes(request) {
* request, its hash and its projection are never touched, so this cannot change
* what is authorized or signed.
*/
+function blankImagePayloadsInMessages(messages) {
+ if (!Array.isArray(messages)) return messages
+ return messages.map(message => {
+ const parts = isPlainObject(message) ? message.contentParts : undefined
+ if (!Array.isArray(parts)) return message
+ return {
+ ...message,
+ contentParts: parts.map(part =>
+ isPlainObject(part) && part.type === 'image' ? { ...part, data: '' } : part
+ ),
+ }
+ })
+}
+
function measureNonImageRequestBytes(input) {
- const messages = input.messages
- const shadowMessages = Array.isArray(messages)
- ? messages.map(message => {
- const parts = isPlainObject(message) ? message.contentParts : undefined
- if (!Array.isArray(parts)) return message
- return {
- ...message,
- contentParts: parts.map(part =>
- isPlainObject(part) && part.type === 'image' ? { ...part, data: '' } : part
- ),
- }
- })
- : messages
- return Buffer.byteLength(JSON.stringify({ ...input, messages: shadowMessages }), 'utf8')
+ return Buffer.byteLength(
+ JSON.stringify({ ...input, messages: blankImagePayloadsInMessages(input.messages) }),
+ 'utf8'
+ )
+}
+
+/**
+ * Authorize JSON is a different document from a Codex request or proxy
+ * envelope. `requestBodyLimitBytes(body.request)` still gates the whole
+ * wrapper (24 MiB only when the nested request declares V2). This helper
+ * blanks image payloads inside `body.request` so wrapper fields — ids,
+ * hashes, ticket links — stay on the 1 MiB non-image budget.
+ */
+function measureNonImageAuthorizeBytes(body) {
+ if (!isPlainObject(body)) {
+ return Buffer.byteLength(JSON.stringify(body ?? null), 'utf8')
+ }
+ const request = body.request
+ if (!isPlainObject(request)) {
+ return Buffer.byteLength(JSON.stringify(body), 'utf8')
+ }
+ return Buffer.byteLength(
+ JSON.stringify({
+ ...body,
+ request: { ...request, messages: blankImagePayloadsInMessages(request.messages) },
+ }),
+ 'utf8'
+ )
}
function isBoundedId(value) {
@@ -843,6 +872,8 @@ module.exports = {
LIMITS,
VISUAL_LIMITS,
requestBodyLimitBytes,
+ measureNonImageAuthorizeBytes,
+ isBoundedId,
stableStringify,
parseCodexCompletionRequestV1,
parseCodexCompletionRequestV2,
diff --git a/packages/llm-provider-attempt-contract/index.d.ts b/packages/llm-provider-attempt-contract/index.d.ts
index 17a912308..4bff40ce3 100644
--- a/packages/llm-provider-attempt-contract/index.d.ts
+++ b/packages/llm-provider-attempt-contract/index.d.ts
@@ -14,10 +14,10 @@
* purpose: it is not a looser schema.
*
* Two size ceilings, one policy: V1 keeps the 1 MiB body ceiling, and V2 raises
- * it to 24 MiB for image payloads only. Everything a caller writes that is not
- * image data — content, tool definitions, ids — stays on the 1 MiB budget in
- * both versions, and `requestBodyLimitBytes` is the number a pre-parse HTTP
- * body cap should use.
+ * it to 24 MiB so one exceptional 2048-px image larger than 10 MiB still fits
+ * after base64. Everything a caller writes that is not image data — content,
+ * tool definitions, ids — stays on the 1 MiB budget in both versions, and
+ * `requestBodyLimitBytes` is the number a pre-parse HTTP body cap should use.
*/
export declare const SCHEMA_VERSION: 'codex-completion-request.v1'
@@ -41,15 +41,19 @@ export declare const LIMITS: {
/**
* Conservative local safety/product budgets for V2 image parts. These are
* deliberately not upstream facts: the frozen ChatGPT endpoint is not
- * certified by these numbers. The aggregate budget remains below three
- * maximum-sized images, so callers must satisfy both independent byte caps.
+ * certified by these numbers. `typical*` is the usual 2048 JPEG/PNG target;
+ * `max*` is the hard ceiling so one poorly compressed 2048 PNG may exceed
+ * 10 MiB. Model vision capability is owned by issue #654 / PR #669.
*/
export declare const VISUAL_LIMITS: {
readonly maxImages: 3
- readonly maxImageBytes: 10485760
- readonly maxTotalImageBytes: 15728640
- readonly maxImageDimension: 8192
- readonly maxImagePixels: 64000000
+ readonly typicalImageBytes: 5242880
+ readonly typicalTotalImageBytes: 9437184
+ readonly typicalEnvelopeBytes: 14680064
+ readonly maxImageBytes: 16777216
+ readonly maxTotalImageBytes: 16777216
+ readonly maxImageDimension: 2048
+ readonly maxImagePixels: 4194304
}
export type ContractResult<T> =
@@ -236,6 +240,14 @@ export declare function stableStringify(value: unknown): string
* with every image payload blanked and keeps that share on the 1 MiB ceiling.
*/
export declare function requestBodyLimitBytes(request: unknown): number
+/**
+ * Byte length of an authorize document after every image payload inside
+ * `body.request` is blanked. Wrapper fields stay on the 1 MiB non-image
+ * budget even when the nested request declares V2.
+ */
+export declare function measureNonImageAuthorizeBytes(body: unknown): number
+/** Closed identifier used by request ids, ticket claims, and authorize ids. */
+export declare function isBoundedId(value: unknown): value is string
export declare function parseCodexCompletionRequestV1(
input: unknown
): ContractResult<CodexCompletionRequestV1>
diff --git a/packages/llm-provider-attempt-contract/index.test.cjs b/packages/llm-provider-attempt-contract/index.test.cjs
index e6c549bea..5ad6d7a0c 100644
--- a/packages/llm-provider-attempt-contract/index.test.cjs
+++ b/packages/llm-provider-attempt-contract/index.test.cjs
@@ -791,6 +791,12 @@ test('v2 limits: image count, encoder bound, per-image bytes, total bytes, dimen
assert.match(overCeiling.message, /image exceeds/)
assert.match(overCeiling.message, new RegExp(String(contract.VISUAL_LIMITS.maxImageBytes)))
+ // Exceptional >10 MiB is allowed; the hard per-image ceiling is 16 MiB.
+ const twelveMiB = contract.parseCodexCompletionRequest(
+ v2WithParts([imagePart(declaredHeaderPngOfSize(12 * MIB).toString('base64'))])
+ )
+ assert.equal(twelveMiB.ok, true, twelveMiB.message)
+
// A larger individual image does not increase the aggregate resource budget.
const tenMiB = declaredHeaderPngOfSize(10 * MIB).toString('base64')
const fiveMiB = declaredHeaderPngOfSize(5 * MIB).toString('base64')
@@ -802,10 +808,14 @@ test('v2 limits: image count, encoder bound, per-image bytes, total bytes, dimen
v2WithParts([imagePart(tenMiB), imagePart(jpegOfSize(5 * MIB).toString('base64'), 'image/jpeg')])
)
assert.equal(combinedWithJpeg.ok, true, combinedWithJpeg.message)
+ const atAggregate = contract.parseCodexCompletionRequest(
+ v2WithParts([imagePart(tenMiB), imagePart(declaredHeaderPngOfSize(6 * MIB).toString('base64'))])
+ )
+ assert.equal(atAggregate.ok, true, atAggregate.message)
const overAggregate = contract.parseCodexCompletionRequest(
v2WithParts([
imagePart(tenMiB),
- imagePart(declaredHeaderPngOfSize(5 * MIB + 1).toString('base64')),
+ imagePart(declaredHeaderPngOfSize(6 * MIB + 1).toString('base64')),
])
)
assert.equal(overAggregate.ok, false)
@@ -826,30 +836,20 @@ test('v2 limits: image count, encoder bound, per-image bytes, total bytes, dimen
assert.equal(overDimension.code, 'limit')
assert.match(overDimension.message, /dimension/)
- // A 48 MP phone capture (8064x6048) is the payload the raise exists for.
- const phonePixels = 8064 * 6048
- assert.ok(phonePixels < contract.VISUAL_LIMITS.maxImagePixels)
- const atPhoneShape = contract.parseCodexCompletionRequest(
+ // Phone-sized frames are a Codex pixel problem, not a byte problem.
+ const phoneShape = contract.parseCodexCompletionRequest(
v2WithParts([imagePart(declaredHeaderPng(8064, 6048).toString('base64'))])
)
- assert.equal(atPhoneShape.ok, true, atPhoneShape.message)
+ assert.equal(phoneShape.ok, false)
+ assert.equal(phoneShape.code, 'limit')
+ assert.match(phoneShape.message, /dimension/)
- // Exactly the pixel ceiling, then one row over it.
- const pixelsAtLimit = 8000
- assert.equal(pixelsAtLimit * pixelsAtLimit, contract.VISUAL_LIMITS.maxImagePixels)
- const atPixels = contract.parseCodexCompletionRequest(
- v2WithParts([imagePart(declaredHeaderPng(pixelsAtLimit, pixelsAtLimit).toString('base64'))])
- )
- assert.equal(atPixels.ok, true, atPixels.message)
- const overPixels = contract.parseCodexCompletionRequest(
- v2WithParts([imagePart(declaredHeaderPng(pixelsAtLimit, pixelsAtLimit + 1).toString('base64'))])
+ // 2048×2048 is both the dimension and the pixel ceiling.
+ assert.equal(
+ contract.VISUAL_LIMITS.maxImageDimension * contract.VISUAL_LIMITS.maxImageDimension,
+ contract.VISUAL_LIMITS.maxImagePixels
)
- assert.equal(overPixels.code, 'limit')
- assert.match(overPixels.message, /pixel count/)
-
- // Both dimensions inside the dimension ceiling, product over the pixel
- // ceiling: isolates the pixel rule from the dimension rule.
- const squareOverPixels = contract.parseCodexCompletionRequest(
+ const atPixels = contract.parseCodexCompletionRequest(
v2WithParts([
imagePart(
declaredHeaderPng(
@@ -859,8 +859,7 @@ test('v2 limits: image count, encoder bound, per-image bytes, total bytes, dimen
),
])
)
- assert.equal(squareOverPixels.code, 'limit')
- assert.match(squareOverPixels.message, /pixel count/)
+ assert.equal(atPixels.ok, true, atPixels.message)
const wrongMime = contract.parseCodexCompletionRequest(
v2WithParts([imagePart(png, 'image/jpeg')])
@@ -961,10 +960,13 @@ test('requestBodyLimitBytes: V2 declares 24 MiB; every other body keeps the 1 Mi
assert.equal(contract.LIMITS.maxRequestBodyBytes, 1048576)
assert.equal(contract.LIMITS.maxVisualRequestBodyBytes, 25165824)
assert.equal(contract.VISUAL_LIMITS.maxImages, 3)
- assert.equal(contract.VISUAL_LIMITS.maxImageBytes, 10485760)
- assert.equal(contract.VISUAL_LIMITS.maxTotalImageBytes, 15728640)
- assert.equal(contract.VISUAL_LIMITS.maxImageDimension, 8192)
- assert.equal(contract.VISUAL_LIMITS.maxImagePixels, 64000000)
+ assert.equal(contract.VISUAL_LIMITS.typicalImageBytes, 5 * MIB)
+ assert.equal(contract.VISUAL_LIMITS.typicalTotalImageBytes, 9 * MIB)
+ assert.equal(contract.VISUAL_LIMITS.typicalEnvelopeBytes, 14 * MIB)
+ assert.equal(contract.VISUAL_LIMITS.maxImageBytes, 16 * MIB)
+ assert.equal(contract.VISUAL_LIMITS.maxTotalImageBytes, 16 * MIB)
+ assert.equal(contract.VISUAL_LIMITS.maxImageDimension, 2048)
+ assert.equal(contract.VISUAL_LIMITS.maxImagePixels, 2048 * 2048)
for (const v2 of [VISUAL_FIXTURE.png, VISUAL_FIXTURE.jpeg, VISUAL_FIXTURE.pngImageOnly]) {
assert.equal(v2.schemaVersion, contract.SCHEMA_VERSION_V2)
@@ -1077,10 +1079,10 @@ test('v2 total budget: the raw body is capped at 24 MiB and the three budgets st
assert.equal(asV1.message, 'request exceeds maxRequestBodyBytes')
})
-test('large real PNG: CRCs and inflatable scanlines at 3 MiB and at the 10 MiB ceiling', () => {
+test('large real PNG: CRCs and inflatable scanlines at 3 MiB and at 10 MiB', () => {
const cases = [
['3 MiB', 3 * MIB, 512, 512, 21],
- ['10 MiB ceiling', contract.VISUAL_LIMITS.maxImageBytes, 1150, 1150, 31],
+ ['10 MiB', 10 * MIB, 1150, 1150, 31],
]
for (const [label, target, width, height, seed] of cases) {
const png = realPngOfSize(target, width, height, seed)
@@ -1306,3 +1308,42 @@ test('buildCodexProxyEnvelope: fails closed on hash mismatch, bad input and inva
assert.deepEqual(Object.keys(v1Envelope.value), ['executionTicket', 'requestHash', 'request'])
assert.equal('deadlineMs' in v1Envelope.value, false)
})
+
+test('isBoundedId rejects empty, oversized, and non-id characters', () => {
+ assert.equal(contract.isBoundedId('invocation-1'), true)
+ assert.equal(contract.isBoundedId('ns/name:slot'), true)
+ assert.equal(contract.isBoundedId(''), false)
+ assert.equal(contract.isBoundedId('x'.repeat(129)), false)
+ assert.equal(contract.isBoundedId('has space'), false)
+ assert.equal(contract.isBoundedId(1), false)
+})
+
+test('measureNonImageAuthorizeBytes keeps wrapper fields on the 1 MiB budget', () => {
+ const image = imagePart(IMAGE_DATA.png)
+ const request = {
+ ...BASE,
+ schemaVersion: contract.SCHEMA_VERSION_V2,
+ messages: [
+ {
+ role: 'user',
+ content: 'look',
+ contentParts: [{ type: 'text', text: 'look' }, image],
+ },
+ ],
+ }
+ const wrapper = {
+ request,
+ invocationId: 'invocation-1',
+ attemptGeneration: 1,
+ targetRef: 'codex-primary',
+ }
+ const whole = Buffer.byteLength(JSON.stringify(wrapper), 'utf8')
+ const nonImage = contract.measureNonImageAuthorizeBytes(wrapper)
+ assert.ok(whole > nonImage)
+ assert.ok(nonImage < contract.LIMITS.maxRequestBodyBytes)
+ assert.equal(contract.requestBodyLimitBytes(wrapper.request), 25165824)
+
+ const stuffed = { ...wrapper, invocationId: 'x'.repeat(2 * 1024 * 1024) }
+ assert.ok(contract.measureNonImageAuthorizeBytes(stuffed) > contract.LIMITS.maxRequestBodyBytes)
+ assert.equal(contract.requestBodyLimitBytes(stuffed.request), 25165824)
+})
diff --git a/packages/llm-provider-attempt-contract/visualPayload.cjs b/packages/llm-provider-attempt-contract/visualPayload.cjs
index b8d2be46e..1eaa353a9 100644
--- a/packages/llm-provider-attempt-contract/visualPayload.cjs
+++ b/packages/llm-provider-attempt-contract/visualPayload.cjs
@@ -12,24 +12,30 @@
*
* The budget below is a conservative local safety/product decision. It is not
* an upstream capability fact; the frozen ChatGPT endpoint is not certified by
- * these numbers.
+ * these numbers. Codex charges patches, not file bytes: the official client
+ * resizes to 2048 px and sends `detail: high`. A poorly compressed 2048 PNG
+ * can exceed 10 MiB and must still be authorized; an 8192 px / 48 MP image
+ * will 400 upstream even when it is only 2 MiB.
*
- * The raised ceiling supports larger original captures, including 8064x6048
- * frames, without requiring a lossy re-encode. `maxImageBytes` and
- * `maxImagePixels` independently bound the payload; the
- * container checks above are unchanged by the raise, and the pixel budget stays
- * a declared-header bound rather than a decode.
- *
- * The 15 MiB aggregate is independent from the 10 MiB per-image ceiling:
- * one large photo can fit without doubling the maximum request allocation.
+ * Two layers share this object:
+ * - typical* is the usual 2048 JPEG/PNG product target (5 / 9 / 14 MiB).
+ * It is documentation and UX guidance, not a reject.
+ * - max* is the hard ceiling: one exceptional 2048 image may be larger
+ * than 10 MiB. The V2 HTTP envelope stays 24 MiB so 16 MiB decoded
+ * (~21.3 MiB base64) plus the 1 MiB non-image share still fits.
+ * Model capability lists (which models accept images) belong to issue #654 /
+ * PR #669 (models.dev). This package only bounds Codex transport.
*/
const VISUAL_LIMITS = Object.freeze({
maxImages: 3,
- maxImageBytes: 10485760,
- maxTotalImageBytes: 15728640,
- maxImageDimension: 8192,
- maxImagePixels: 64000000,
+ typicalImageBytes: 5242880,
+ typicalTotalImageBytes: 9437184,
+ typicalEnvelopeBytes: 14680064,
+ maxImageBytes: 16777216,
+ maxTotalImageBytes: 16777216,
+ maxImageDimension: 2048,
+ maxImagePixels: 4194304,
})
// Exact encoded length of a canonical base64 string that decodes to
diff --git a/rpc-proxy/package-lock.json b/rpc-proxy/package-lock.json
index 2a2ed41bf..a8715fece 100644
--- a/rpc-proxy/package-lock.json
+++ b/rpc-proxy/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-rpc-proxy",
- "version": "0.1.81",
+ "version": "0.1.82",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-rpc-proxy",
- "version": "0.1.81",
+ "version": "0.1.82",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.21.2",
diff --git a/rpc-proxy/package.json b/rpc-proxy/package.json
index bc9a25db4..936dba29e 100644
--- a/rpc-proxy/package.json
+++ b/rpc-proxy/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-rpc-proxy",
- "version": "0.1.81",
+ "version": "0.1.82",
"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 20fce14ea..3ecf290cf 100644
--- a/rpc-proxy/src/__tests__/bodylimits.test.ts
+++ b/rpc-proxy/src/__tests__/bodylimits.test.ts
@@ -113,7 +113,17 @@ async function postMessage(payload: unknown): Promise<Response> {
}
describe('rpc-proxy chat message body budget', () => {
- it('carries a 10MiB image (the per-image limit) to the auth boundary', async () => {
+ it('carries a 12MiB image (exceptional, above 10MiB) to the auth boundary', async () => {
+ const body = JSON.stringify({
+ content: 'look',
+ attachments: [imageAttachment('a1', 12 * MIB)],
+ })
+ expect(Buffer.byteLength(body)).toBeGreaterThan(16 * MIB)
+ const response = await post(MESSAGE_PATH, body)
+ expect(response.status).toBe(401)
+ })
+
+ it('carries a 10MiB image (the former per-image limit) to the auth boundary', async () => {
const body = JSON.stringify({
content: 'look',
attachments: [imageAttachment('a1', 10 * MIB)],
@@ -168,12 +178,27 @@ describe('rpc-proxy chat message body budget', () => {
expect(response.status).toBe(401)
})
- it('rejects a single image over the 10MiB per-image limit', async () => {
+ it('rejects a fourth qualifying image instead of charging it as text', async () => {
+ const body = JSON.stringify({
+ content: 'look',
+ attachments: [
+ imageAttachment('a1', 64 * 1024),
+ imageAttachment('a2', 64 * 1024),
+ imageAttachment('a3', 64 * 1024),
+ imageAttachment('a4', 64 * 1024),
+ ],
+ })
+ expect(Buffer.byteLength(body)).toBeLessThan(6 * MIB)
+ const response = await post(MESSAGE_PATH, body)
+ expect(response.status).toBe(413)
+ })
+
+ it('rejects a single image over the 16MiB per-image limit', async () => {
// Fits the 24MiB body ceiling, so this rejection is the budget gate, not the
- // parser: an uncredited 11MiB image is charged to the 6MiB non-image budget.
+ // parser: an uncredited 17MiB image is charged to the 6MiB non-image budget.
const body = JSON.stringify({
content: 'look',
- attachments: [imageAttachment('a1', 11 * MIB)],
+ attachments: [imageAttachment('a1', 17 * MIB)],
})
expect(Buffer.byteLength(body)).toBeLessThan(24 * MIB)
const response = await post(MESSAGE_PATH, body)
@@ -189,16 +214,23 @@ describe('rpc-proxy chat message body budget', () => {
expect(response.status).toBe(413)
})
- it('rejects two 8MiB images on the 15MiB total alone, under the 24MiB ceiling', async () => {
- // Each image is under the 10MiB per-image limit and the body fits the 24MiB
- // ceiling, so the only rule that can reject this pair is the 15MiB total:
- // the over-total image is not credited and lands on the 6MiB non-image budget.
+ it('carries two 8MiB images that sit on the 16MiB total', async () => {
const body = JSON.stringify({
content: 'look',
attachments: [imageAttachment('a1', 8 * MIB), imageAttachment('a2', 8 * MIB)],
})
expect(Buffer.byteLength(body)).toBeLessThan(24 * MIB)
const response = await post(MESSAGE_PATH, body)
+ expect(response.status).toBe(401)
+ })
+
+ it('rejects 9MiB + 8MiB on the 16MiB total alone, under the 24MiB ceiling', async () => {
+ const body = JSON.stringify({
+ content: 'look',
+ attachments: [imageAttachment('a1', 9 * MIB), imageAttachment('a2', 8 * MIB)],
+ })
+ expect(Buffer.byteLength(body)).toBeLessThan(24 * MIB)
+ const response = await post(MESSAGE_PATH, body)
expect(response.status).toBe(413)
})
diff --git a/rpc-proxy/src/app.ts b/rpc-proxy/src/app.ts
index dc3e804f1..ac34a7856 100644
--- a/rpc-proxy/src/app.ts
+++ b/rpc-proxy/src/app.ts
@@ -14,25 +14,23 @@ import { isUpstreamTimeoutError } from './services/wakeAndHold.js'
/**
* Body budgets for chat payloads carrying base64 image attachments.
*
- * The interoperable budget is 10MiB per image, at most 3 images (15MiB of image
- * bytes). mcp-host holds its own copy of this policy: the two services share no
- * package (see routes/rpc.ts on SESSIONS_LIMIT_CAP), so each names its own and
- * the two edits must land together.
+ * Usual product target is 5MiB / 9MiB / 14MiB at 2048 px. Hard hop credit is
+ * 16MiB per image and 16MiB total so a poorly compressed 2048 PNG may exceed
+ * 10MiB. mcp-host holds its own copy: the two services share no package, so
+ * both edits must land together.
*
* Two ceilings are enforced here:
- * - MAX_CHAT_BODY_BYTES bounds the raw JSON body on the message route. 10MiB
- * encodes to ~13.3MiB of base64, so a 10MiB image plus a 5MiB image (the
- * largest combination the 15MiB total allows) needs ~21MiB plus the
- * envelope.
- * - MAX_NON_IMAGE_BODY_BYTES bounds the same body MINUS the base64 of images
- * counting against the documented budget. Without that subtraction the
- * attachment budget would silently become a general 24MiB text budget.
+ * - MAX_CHAT_BODY_BYTES stays 24MiB so 16MiB decoded (~21.3MiB base64) plus
+ * the 1MiB non-image share still fits.
+ * - 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.
*/
const MAX_CHAT_BODY_BYTES = 24 * 1024 * 1024
const MAX_NON_IMAGE_BODY_BYTES = 6 * 1024 * 1024
const MAX_CHAT_IMAGES = 3
-const MAX_IMAGE_DECODED_BYTES = 10 * 1024 * 1024
-const MAX_IMAGE_DECODED_BYTES_TOTAL = 15 * 1024 * 1024
+const MAX_IMAGE_DECODED_BYTES = 16 * 1024 * 1024
+const MAX_IMAGE_DECODED_BYTES_TOTAL = 16 * 1024 * 1024
const BASE64_RE = /^[A-Za-z0-9+/]+={0,2}$/
const PNG_SIGNATURE = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])
const JPEG_SIGNATURE = Buffer.from([0xff, 0xd8, 0xff])
@@ -76,21 +74,26 @@ function decodedBase64Bytes(dataBase64: string): number | null {
* Byte length of the base64 that counts against the documented image budget.
* Only attachments with the exact wire shape the composer produces qualify:
* `kind: 'image'`, `encoding: 'base64'`, a PNG/JPEG MIME type, canonical
- * base64 whose leading bytes are that image's signature, and at most 10MiB
- * decoded each within a 3-image / 15MiB total budget. Anything else is charged
+ * base64 whose leading bytes are that image's signature, and at most 16MiB
+ * decoded each within a 3-image / 16MiB total budget. A fourth qualifying
+ * image is fail-loud rather than charged as text. Anything else is charged
* to the non-image budget, so a claim cannot be smuggled through by mislabelling
* a payload.
*/
-function budgetedImageBase64Length(body: unknown): number {
- if (!body || typeof body !== 'object' || Array.isArray(body)) return 0
+function inspectChatImageBudget(body: unknown): {
+ creditedBase64: number
+ tooManyImages: boolean
+} {
+ if (!body || typeof body !== 'object' || Array.isArray(body)) {
+ return { creditedBase64: 0, tooManyImages: false }
+ }
const attachments = (body as { attachments?: unknown }).attachments
- if (!Array.isArray(attachments)) return 0
+ if (!Array.isArray(attachments)) return { creditedBase64: 0, tooManyImages: false }
let credited = 0
let decodedTotal = 0
let counted = 0
for (const attachment of attachments) {
- if (counted >= MAX_CHAT_IMAGES) break
if (!attachment || typeof attachment !== 'object') continue
const candidate = attachment as {
kind?: unknown
@@ -111,15 +114,20 @@ function budgetedImageBase64Length(body: unknown): number {
? signature.subarray(0, PNG_SIGNATURE.length).equals(PNG_SIGNATURE)
: signature.subarray(0, JPEG_SIGNATURE.length).equals(JPEG_SIGNATURE)
if (!matchesSignature) continue
+ if (counted >= MAX_CHAT_IMAGES) {
+ return { creditedBase64: credited, tooManyImages: true }
+ }
credited += dataBase64.length
decodedTotal += decoded
counted += 1
}
- return credited
+ return { creditedBase64: credited, tooManyImages: false }
}
function chatBodyExceedsNonImageBudget(rawBodyBytes: number, body: unknown): boolean {
- return rawBodyBytes - budgetedImageBase64Length(body) > MAX_NON_IMAGE_BODY_BYTES
+ const budget = inspectChatImageBudget(body)
+ if (budget.tooManyImages) return true
+ return rawBodyBytes - budget.creditedBase64 > MAX_NON_IMAGE_BODY_BYTES
}
/**
diff --git a/tests/e2e/fixtures/codex-subscription/sanitized-upstream-contract.json b/tests/e2e/fixtures/codex-subscription/sanitized-upstream-contract.json
index ac8e5782a..9bc46ad10 100644
--- a/tests/e2e/fixtures/codex-subscription/sanitized-upstream-contract.json
+++ b/tests/e2e/fixtures/codex-subscription/sanitized-upstream-contract.json
@@ -85,10 +85,13 @@
"validation": "container-framing-and-dimensions",
"limits": {
"maxImages": 3,
- "maxImageBytes": 10485760,
- "maxTotalImageBytes": 15728640,
- "maxImageDimension": 8192,
- "maxImagePixels": 64000000
+ "typicalImageBytes": 5242880,
+ "typicalTotalImageBytes": 9437184,
+ "typicalEnvelopeBytes": 14680064,
+ "maxImageBytes": 16777216,
+ "maxTotalImageBytes": 16777216,
+ "maxImageDimension": 2048,
+ "maxImagePixels": 4194304
}
}
}
diff --git a/tests/e2e/fixtures/package-lock.json b/tests/e2e/fixtures/package-lock.json
index 294dde8e7..ed3798c84 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.81",
+ "version": "1.0.82",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@clerum/e2e-test-fixtures",
- "version": "1.0.81",
+ "version": "1.0.82",
"dependencies": {
"@kubernetes/client-node": "^1.0.0"
},
diff --git a/tests/e2e/fixtures/package.json b/tests/e2e/fixtures/package.json
index 2e65862dc..4a7bd3ce9 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.81",
+ "version": "1.0.82",
"description": "E2E test fixtures and utilities for Clerum testing",
"type": "module",
"main": "index.ts",