Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(images): keep #669 general limits and isolate Codex budgets
Alfredo Lopez8064e26bef6b
diff --git a/codex-llm-proxy/src/server.ts b/codex-llm-proxy/src/server.tsindex 6b53183a8..7a5487ed1 100644--- a/codex-llm-proxy/src/server.ts+++ b/codex-llm-proxy/src/server.ts@@ -21,6 +21,7 @@ import {type OriginPolicyOptions,defaultAddressLookup,} from './originPolicy.js'+import { SCHEMA_VERSION_V2 } from '@clerum/llm-provider-attempt-contract'import { RequestLimitError, streamGate, visualStreamGate } from './requestLimits.js'type GatedRequest = Request & { codexStreamRelease?: () => void }@@ -132,9 +133,13 @@ export function createProxyApps(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()+ release = await visualStreamGate.acquire(parseAbort.signal)} catch (err) {+ req.off('aborted', abortParse)if (err instanceof RequestLimitError) {reject(res, 503, err.code)return@@ -142,6 +147,7 @@ export function createProxyApps(next()return}+ req.off('aborted', abortParse)req.codexStreamRelease = releasevisualJson(req, res, err => {if (err) {@@ -229,9 +235,19 @@ export function createProxyApps(// to req 'close' aborts the ChatGPT hop on every call (3–12ms canceled).// Abort only when the client drops the response before we finish writing.abortWhenClientDisconnects(req, res, abort)+ const visualRequest =+ (parsed.data.request as { schemaVersion?: unknown }).schemaVersion === SCHEMA_VERSION_V2try {- release = gated.codexStreamRelease- gated.codexStreamRelease = undefined+ // 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.+ if (visualRequest) {+ release = gated.codexStreamRelease+ gated.codexStreamRelease = undefined+ } else {+ releaseAdmission()+ }if (!release) {release = await streamGate.acquire(abort.signal)}diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex b88ea1a7d..e7543da5c 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.584",+ "version": "0.1.585","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.584",+ "version": "0.1.585","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",diff --git a/control-api/package.json b/control-api/package.jsonindex 7904ea41c..5cace845d 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.584",+ "version": "0.1.585","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.tsindex c0fc4a71b..4843ea9e6 100644--- a/control-api/src/services/llmProviderAttemptAuthorizer.ts+++ b/control-api/src/services/llmProviderAttemptAuthorizer.ts@@ -636,7 +636,10 @@ export async function authorizeLlmProviderAttempt(const parsed = parseCodexCompletionRequest(body.request)if (!parsed.ok) {- throw new LlmProviderAttemptAuthorizeError('invalid_request', parsed.message)+ throw new LlmProviderAttemptAuthorizeError(+ parsed.code === 'limit' ? 'payload_too_large' : 'invalid_request',+ parsed.message+ )}const request = parsed.valueif (request.provider !== PROVIDER) {diff --git a/control-api/test/services.llmProviderAttemptAuthorizer.test.ts b/control-api/test/services.llmProviderAttemptAuthorizer.test.tsindex c738832ce..c8f71a310 100644--- a/control-api/test/services.llmProviderAttemptAuthorizer.test.ts+++ b/control-api/test/services.llmProviderAttemptAuthorizer.test.ts@@ -607,6 +607,23 @@ describe('authorizeLlmProviderAttempt', () => {expect(current.insertAttempt).not.toHaveBeenCalled()})+ it('maps a contract parse limit failure to payload_too_large', async () => {+ await expect(+ authorizeLlmProviderAttempt(+ claims(),+ body({+ request: {+ ...REQUEST,+ schemaVersion: 'codex-completion-request.v2',+ messages: Array.from({ length: 129 }, () => ({ role: 'user' as const, content: 'x' })),+ },+ }),+ current+ )+ ).rejects.toMatchObject({ code: 'payload_too_large' })+ 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(diff --git a/desktop-app/ui/src/components/agents/AnnotationCanvas.tsx b/desktop-app/ui/src/components/agents/AnnotationCanvas.tsxindex 1a5174d5a..1c0ba77d1 100644--- a/desktop-app/ui/src/components/agents/AnnotationCanvas.tsx+++ b/desktop-app/ui/src/components/agents/AnnotationCanvas.tsx@@ -11,6 +11,24 @@ type AnnotationCanvasProps = {onClose: () => void}+/**+ * Apply the annotated replacement. A throwing `onSave` must revoke the blob+ * URL created for that rejected preview so it never leaks.+ */+export function commitAnnotatedPreview(+ onSave: (updated: ComposerImageAttachment) => void,+ updated: ComposerImageAttachment,+ createdPreviewUrl: string,+ serializedDataUrl: string+): void {+ try {+ onSave(updated)+ } catch (error) {+ if (createdPreviewUrl !== serializedDataUrl) URL.revokeObjectURL(createdPreviewUrl)+ throw error+ }+}+function resolveDefaultAnnotationColor() {if (typeof window === 'undefined') return COLOR_INPUT_FALLBACKconst tokenColor = window@@ -155,19 +173,18 @@ export function AnnotationCanvas({ attachment, onSave, onClose }: AnnotationCanvtypeof URL !== 'undefined' && typeof URL.createObjectURL === 'function'? URL.createObjectURL(blob): dataUrl- try {- onSave({+ commitAnnotatedPreview(+ onSave,+ {...attachment,mimeType: nextMimeType,dataBase64: dataUrl.slice(base64Index + 'base64,'.length),sizeBytes: blob.size,previewDataUrl: nextPreviewUrl,- })- } catch (error) {- // The rejected replacement never becomes the attachment's preview.- if (nextPreviewUrl !== dataUrl) URL.revokeObjectURL(nextPreviewUrl)- throw error- }+ },+ nextPreviewUrl,+ dataUrl+ )setPreviewIsAnnotating(false)} catch (error) {setAnnotationError(error instanceof Error ? error.message : String(error))diff --git a/desktop-app/ui/src/components/agents/ComposerPanel.tsx b/desktop-app/ui/src/components/agents/ComposerPanel.tsxindex a8219f632..56a8d6df5 100644--- a/desktop-app/ui/src/components/agents/ComposerPanel.tsx+++ b/desktop-app/ui/src/components/agents/ComposerPanel.tsx@@ -21,8 +21,7 @@ import {import {COMPOSER_ACCEPT_IMAGE_MIME_TYPES,COMPOSER_MAX_IMAGE_ATTACHMENTS,- COMPOSER_MAX_IMAGE_BYTES,- COMPOSER_MAX_IMAGE_DIMENSION,+ composerImageBudget,} from '@constants/attachments'import { useContextsDataController } from '@hooks/domain/useContextsDataController'import { useMcpServersDataController } from '@hooks/domain/useMcpServersDataController'@@ -77,23 +76,29 @@ function bytesFromBase64(data: string): Uint8Array | null {function composerImageDimensionRejection(name: string,mimeType: ComposerImageAttachment['mimeType'],- dataBase64: string+ dataBase64: string,+ maxDimension: number | null): string | null {+ if (maxDimension == null) return nullconst bytes = bytesFromBase64(dataBase64)const dimensions = bytes ? readImageHeaderDimensions(mimeType, bytes) : nullif (!dimensions) return null- if (- dimensions.width > COMPOSER_MAX_IMAGE_DIMENSION ||- dimensions.height > COMPOSER_MAX_IMAGE_DIMENSION- ) {- return `${name || 'Image'} is too large. Max resolution is ${COMPOSER_MAX_IMAGE_DIMENSION} px.`+ if (dimensions.width > maxDimension || dimensions.height > maxDimension) {+ return `${name || 'Image'} is too large. Max resolution is ${maxDimension} px.`}return null}-/** Per-image ceiling only. Aggregate bytes are enforced on the chat hop. */-function composerImageExceedsPerImageBudget(sizeBytes: number): boolean {- return sizeBytes > COMPOSER_MAX_IMAGE_BYTES+function composerImageExceedsPerImageBudget(sizeBytes: number, maxImageBytes: number): boolean {+ return sizeBytes > maxImageBytes+}++function composerPerImageLimitMessage(+ name: string,+ maxImageBytes: number,+ sizeUnit: 'MB' | 'MiB'+): string {+ return `${name || 'Image'} is too large. Max size is ${formatComposerMebibytes(maxImageBytes)} ${sizeUnit}.`}function getComposerReferenceIcon(attachment: ComposerReferenceAttachment) {@@ -171,6 +176,10 @@ export function ComposerPanel({ inline = false, agentSelector }: ComposerPanelPr// user can still switch to a capable model with the images kept.const hostModelSelection = useHostModels(selectedAgent ?? '', activeChatId ?? '')const imageAttachmentBlockMessage = hostModelSelection.imageBlockMessage+ // Size ceilings follow the host provider: Codex keeps #650 (16 MiB / 2048 /+ // hop-owned aggregate). Every other image-capable host keeps #669 (3 MiB ++ // 8 MB combined). Capability still comes from the host projection, not this.+ const imageBudget = composerImageBudget(hostModelSelection.data?.provider)const selectedAgentContext = selectedAgent? String(agentContextByName[selectedAgent] || '').trim(): ''@@ -515,13 +524,17 @@ export function ComposerPanel({ inline = false, agentSelector }: ComposerPanelPr} not added.`)}+ // Non-Codex images travel inline in one 10 MB body (#669). Codex leaves+ // the aggregate to the hop (#650).+ let totalBase64Bytes = composerImageAttachments.reduce(+ (total, attachment) => total + attachment.dataBase64.length,+ 0+ )for (const [index, { file, mimeType }] of selected.entries()) {- if (composerImageExceedsPerImageBudget(file.size)) {+ if (composerImageExceedsPerImageBudget(file.size, imageBudget.maxImageBytes)) {validationErrors.push(- `${file.name || 'Image'} is too large. Max size is ${formatComposerMebibytes(- COMPOSER_MAX_IMAGE_BYTES- )} MiB.`+ composerPerImageLimitMessage(file.name, imageBudget.maxImageBytes, imageBudget.sizeUnit))continue}@@ -544,13 +557,27 @@ export function ComposerPanel({ inline = false, agentSelector }: ComposerPanelPrconst dimensionError = composerImageDimensionRejection(file.name || 'Image',mimeType,- dataBase64+ dataBase64,+ imageBudget.maxDimension)if (dimensionError) {validationErrors.push(dimensionError)revokePreviewUrl(previewUrl)continue}+ if (+ imageBudget.maxTotalBase64Bytes != null &&+ totalBase64Bytes + dataBase64.length > imageBudget.maxTotalBase64Bytes+ ) {+ validationErrors.push(+ `${file.name || 'Image'} does not fit in this message: the images in one message are limited to ${formatComposerMebibytes(+ imageBudget.maxTotalBase64Bytes+ )} ${imageBudget.sizeUnit} in total. Send the attached images first or remove one.`+ )+ revokePreviewUrl(previewUrl)+ continue+ }+ totalBase64Bytes += dataBase64.lengthaccepted.push({id: crypto.randomUUID(),name: buildAttachmentName(file, source, mimeType, index),@@ -575,6 +602,7 @@ export function ComposerPanel({ inline = false, agentSelector }: ComposerPanelPr[buildAttachmentName,composerImageAttachments,+ imageBudget,inferComposerImageMimeType,onAddComposerImageAttachments,readFileAsDataUrl,@@ -601,24 +629,28 @@ export function ComposerPanel({ inline = false, agentSelector }: ComposerPanelPrconst dimensionError = composerImageDimensionRejection(updated.name || 'Image',updated.mimeType,- updated.dataBase64+ updated.dataBase64,+ imageBudget.maxDimension)- if (!composerImageExceedsPerImageBudget(updated.sizeBytes) && !dimensionError) {+ if (+ !composerImageExceedsPerImageBudget(updated.sizeBytes, imageBudget.maxImageBytes) &&+ !dimensionError+ ) {onUpdateComposerImageAttachment(updated)return}- if (composerImageExceedsPerImageBudget(updated.sizeBytes)) {+ if (composerImageExceedsPerImageBudget(updated.sizeBytes, imageBudget.maxImageBytes)) {throw new Error(`${updated.name || 'Image'} was kept unchanged. Max size is ${formatComposerMebibytes(- COMPOSER_MAX_IMAGE_BYTES- )} MiB per image.`+ imageBudget.maxImageBytes+ )} ${imageBudget.sizeUnit} per image.`)}throw new Error(- `${updated.name || 'Image'} was kept unchanged. Max resolution is ${COMPOSER_MAX_IMAGE_DIMENSION} px.`+ `${updated.name || 'Image'} was kept unchanged. Max resolution is ${imageBudget.maxDimension} px.`)},- [onUpdateComposerImageAttachment]+ [imageBudget, onUpdateComposerImageAttachment])const handleComposerPaste = useCallback(diff --git a/desktop-app/ui/src/components/agents/__tests__/AnnotationCanvas.test.tsx b/desktop-app/ui/src/components/agents/__tests__/AnnotationCanvas.test.tsxnew file mode 100644index 000000000..f197e2006--- /dev/null+++ b/desktop-app/ui/src/components/agents/__tests__/AnnotationCanvas.test.tsx@@ -0,0 +1,51 @@+// @vitest-environment jsdom+import { afterEach, describe, expect, it, vi } from 'vitest'+import type { ComposerImageAttachment } from '../../../uiTypes'+import { commitAnnotatedPreview } from '../AnnotationCanvas'++const attachment = (previewDataUrl: string): ComposerImageAttachment => ({+ id: 'att-1',+ name: 'note.png',+ mimeType: 'image/png',+ dataBase64: 'AAAA',+ sizeBytes: 4,+ previewDataUrl,+})++describe('commitAnnotatedPreview', () => {+ afterEach(() => {+ vi.restoreAllMocks()+ })++ it('revokes the created blob URL when onSave throws', () => {+ const revoke = vi.spyOn(URL, 'revokeObjectURL').mockImplementation(() => undefined)+ const created = 'blob:http://localhost/annotated'+ const serialized = 'data:image/png;base64,AAAA'++ expect(() =>+ commitAnnotatedPreview(+ () => {+ throw new Error('kept unchanged')+ },+ attachment(created),+ created,+ serialized+ )+ ).toThrow('kept unchanged')++ expect(revoke).toHaveBeenCalledTimes(1)+ expect(revoke).toHaveBeenCalledWith(created)+ })++ it('does not revoke when onSave accepts the replacement', () => {+ const revoke = vi.spyOn(URL, 'revokeObjectURL').mockImplementation(() => undefined)+ const created = 'blob:http://localhost/annotated'+ const next = attachment(created)+ const onSave = vi.fn()++ commitAnnotatedPreview(onSave, next, created, 'data:image/png;base64,AAAA')++ expect(onSave).toHaveBeenCalledWith(next)+ expect(revoke).not.toHaveBeenCalled()+ })+})diff --git a/desktop-app/ui/src/components/agents/__tests__/ComposerPanel.test.tsx b/desktop-app/ui/src/components/agents/__tests__/ComposerPanel.test.tsxindex 8e4bad9b3..fd167c219 100644--- a/desktop-app/ui/src/components/agents/__tests__/ComposerPanel.test.tsx+++ b/desktop-app/ui/src/components/agents/__tests__/ComposerPanel.test.tsx@@ -5,9 +5,11 @@ import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/reimport { readFileSync } from 'node:fs'import { resolve } from 'node:path'import {+ CODEX_COMPOSER_MAX_IMAGE_BYTES,+ CODEX_COMPOSER_MAX_IMAGE_DIMENSION,COMPOSER_MAX_IMAGE_ATTACHMENTS,COMPOSER_MAX_IMAGE_BYTES,- COMPOSER_MAX_IMAGE_DIMENSION,+ COMPOSER_MAX_TOTAL_IMAGE_BASE64_BYTES,} from '@constants/attachments'import type { HostModelsResult } from '@hooks/useChatStore'import {@@ -151,6 +153,14 @@ afterEach(() => {canAttachImages: false,imageBlockMessage: null,imageInput: { state: 'unknown', reason: 'model_unknown' },+ data: {+ provider: 'claude',+ hostDefault: 'claude-haiku-4-5',+ sessionModel: null,+ degraded: false,+ models: [{ name: 'claude-haiku-4-5', displayName: 'Haiku 4.5' }],+ },+ effectiveModel: 'claude-haiku-4-5',})for (const spy of Object.values(actionsMock)) spy.mockReset()delete (window as Partial<typeof window>).clerum@@ -530,30 +540,7 @@ describe('ComposerPanel with an image-capable model', () => {})await waitFor(() => expect(screen.getByRole('alert')).toBeTruthy())- expect(screen.getByRole('alert').textContent).toBe('huge.png is too large. Max size is 16 MiB.')- expect(actionsMock.handleAddComposerImageAttachments).not.toHaveBeenCalled()- })-- it('accepts a 12MiB image above the usual 10MiB target', async () => {- const { container } = render(<ComposerPanel inline />)- fireEvent.change(pickerInput(container), {- target: { files: [imageFileWithReportedSize('large.png', 'image/png', 12 * 1024 * 1024)] },- })- await waitFor(() => expect(actionsMock.handleAddComposerImageAttachments).toHaveBeenCalled())- expect(expectSinglePreparedImage().sizeBytes).toBe(12 * 1024 * 1024)- expect(screen.queryByRole('alert')).toBeNull()- })-- it('refuses a 2049 px image before send and names the pixel bound', async () => {- const { container } = render(<ComposerPanel inline />)- fireEvent.change(pickerInput(container), {- target: { files: [pngIhdrFile('over-res.png', COMPOSER_MAX_IMAGE_DIMENSION + 1, 128)] },- })- await waitFor(() =>- expect(screen.getByRole('alert').textContent).toContain(- `over-res.png is too large. Max resolution is ${COMPOSER_MAX_IMAGE_DIMENSION} px.`- )- )+ expect(screen.getByRole('alert').textContent).toBe('huge.png is too large. Max size is 3 MB.')expect(actionsMock.handleAddComposerImageAttachments).not.toHaveBeenCalled()})@@ -578,24 +565,52 @@ describe('ComposerPanel with an image-capable model', () => {)})- it('attaches 10MiB + 7MiB in the composer; the hop owns the aggregate', async () => {+ it('refuses an image that would push the message past the combined image budget', async () => {const { container } = render(<ComposerPanel inline />)- fireEvent.change(pickerInput(container), {- target: {- files: [- imageFileWithReportedSize('fits.png', 'image/png', 10 * 1024 * 1024),- imageFileWithReportedSize('over-total.png', 'image/png', 7 * 1024 * 1024),- ],- },+ const rawBytes = Math.floor(COMPOSER_MAX_IMAGE_BYTES * 0.8)+ const base64Bytes = Math.ceil(rawBytes / 3) * 4+ expect(base64Bytes * 2).toBeLessThanOrEqual(COMPOSER_MAX_TOTAL_IMAGE_BASE64_BYTES)+ expect(base64Bytes * 3).toBeGreaterThan(COMPOSER_MAX_TOTAL_IMAGE_BASE64_BYTES)+ const files = ['first.png', 'second.png', 'third.png'].map((name, index) => {+ const bytes = new Uint8Array(rawBytes)+ bytes.set(PNG_BYTES)+ bytes[PNG_BYTES.length] = index+ return imageFile(name, 'image/png', bytes)})++ fireEvent.change(pickerInput(container), { target: { files } })+await waitFor(() =>expect(actionsMock.handleAddComposerImageAttachments).toHaveBeenCalledTimes(1))- expect(addedBatches()[0]?.map(attachment => attachment.name)).toEqual([- 'fits.png',- 'over-total.png',- ])- expect(screen.queryByRole('alert')).toBeNull()+ const [batch] = addedBatches()+ expect(batch?.map(attachment => attachment.name)).toEqual(['first.png', 'second.png'])+ expect(screen.getByRole('alert').textContent).toBe(+ 'third.png does not fit in this message: the images in one message are limited to 8 MB in total. Send the attached images first or remove one.'+ )+ })++ it('counts images already in the composer toward the combined budget', async () => {+ composerState.composerImageAttachments = [+ {+ id: 'already-attached',+ name: 'already.png',+ mimeType: 'image/png',+ dataBase64: 'A'.repeat(COMPOSER_MAX_TOTAL_IMAGE_BASE64_BYTES - 8),+ sizeBytes: 1,+ previewDataUrl: 'data:image/png;base64,AAAA',+ },+ ]+ const { container } = render(<ComposerPanel inline />)++ fireEvent.change(pickerInput(container), {+ target: { files: [imageFile('small.png', 'image/png')] },+ })++ await waitFor(() =>+ expect(screen.getByRole('alert').textContent).toMatch(/^small\.png does not fit/)+ )+ expect(actionsMock.handleAddComposerImageAttachments).not.toHaveBeenCalled()})it('does not let a dropped non-image take one of the free image slots', async () => {@@ -632,6 +647,76 @@ describe('ComposerPanel with an image-capable model', () => {})})+describe('ComposerPanel Codex image budgets', () => {+ beforeEach(() => {+ composerModelState.data = {+ provider: 'codex-subscription',+ hostDefault: 'gpt-5.6-luna',+ sessionModel: 'gpt-5.6-luna',+ degraded: false,+ models: [{ name: 'gpt-5.6-luna', displayName: 'Luna' }],+ }+ composerModelState.effectiveModel = 'gpt-5.6-luna'+ })++ it('explains a Codex oversize image at 16 MiB', async () => {+ const { container } = render(<ComposerPanel inline />)+ fireEvent.change(pickerInput(container), {+ target: {+ files: [+ imageFileWithReportedSize('huge.png', 'image/png', CODEX_COMPOSER_MAX_IMAGE_BYTES + 1),+ ],+ },+ })+ await waitFor(() => expect(screen.getByRole('alert')).toBeTruthy())+ expect(screen.getByRole('alert').textContent).toBe('huge.png is too large. Max size is 16 MiB.')+ expect(actionsMock.handleAddComposerImageAttachments).not.toHaveBeenCalled()+ })++ it('accepts a 12MiB image above the usual 10MiB target', async () => {+ const { container } = render(<ComposerPanel inline />)+ fireEvent.change(pickerInput(container), {+ target: { files: [imageFileWithReportedSize('large.png', 'image/png', 12 * 1024 * 1024)] },+ })+ await waitFor(() => expect(actionsMock.handleAddComposerImageAttachments).toHaveBeenCalled())+ expect(expectSinglePreparedImage().sizeBytes).toBe(12 * 1024 * 1024)+ expect(screen.queryByRole('alert')).toBeNull()+ })++ it('refuses a 2049 px image before send and names the pixel bound', async () => {+ const { container } = render(<ComposerPanel inline />)+ fireEvent.change(pickerInput(container), {+ target: { files: [pngIhdrFile('over-res.png', CODEX_COMPOSER_MAX_IMAGE_DIMENSION + 1, 128)] },+ })+ await waitFor(() =>+ expect(screen.getByRole('alert').textContent).toContain(+ `over-res.png is too large. Max resolution is ${CODEX_COMPOSER_MAX_IMAGE_DIMENSION} px.`+ )+ )+ expect(actionsMock.handleAddComposerImageAttachments).not.toHaveBeenCalled()+ })++ it('attaches 10MiB + 7MiB in the composer; the hop owns the aggregate', async () => {+ const { container } = render(<ComposerPanel inline />)+ fireEvent.change(pickerInput(container), {+ target: {+ files: [+ imageFileWithReportedSize('fits.png', 'image/png', 10 * 1024 * 1024),+ imageFileWithReportedSize('over-total.png', 'image/png', 7 * 1024 * 1024),+ ],+ },+ })+ await waitFor(() =>+ expect(actionsMock.handleAddComposerImageAttachments).toHaveBeenCalledTimes(1)+ )+ expect(addedBatches()[0]?.map(attachment => attachment.name)).toEqual([+ 'fits.png',+ 'over-total.png',+ ])+ expect(screen.queryByRole('alert')).toBeNull()+ })+})+describe('ComposerPanel with a pending image after a model switch', () => {const pendingImage: ComposerImageAttachment = {id: 'pending-image-1',diff --git a/desktop-app/ui/src/constants/attachments.ts b/desktop-app/ui/src/constants/attachments.tsindex f7c266f9e..077a23776 100644--- a/desktop-app/ui/src/constants/attachments.ts+++ b/desktop-app/ui/src/constants/attachments.ts@@ -1,11 +1,53 @@// Must match INCOMING_IMAGE_MAX_COUNT in mcp-host/src/agent/incomingImageAttachments.ts.export const COMPOSER_MAX_IMAGE_ATTACHMENTS = 20+/**- * Composer per-image ceiling. The 16 MiB aggregate lives on the rpc-proxy /- * mcp-host hop and the shared contract, not in this picker. A poorly- * compressed 2048 PNG may exceed 10 MiB and must still attach here.+ * General (#654 / PR #669) per-image ceiling for every image-capable model+ * that is not Codex. Images travel inline in the ordinary 10 MB JSON body.*/-export const COMPOSER_MAX_IMAGE_BYTES = 16 * 1024 * 1024-/** Official Codex client long-side bound. The hop 400s frames above this. */-export const COMPOSER_MAX_IMAGE_DIMENSION = 2048+export const COMPOSER_MAX_IMAGE_BYTES = 3 * 1024 * 1024+/**+ * Combined base64 size of the images in one non-Codex message. rpc-proxy and+ * mcp-host parse ordinary JSON with a 10 MB body limit; 2 MB is left for the+ * text and the request envelope.+ */+export const COMPOSER_MAX_TOTAL_IMAGE_BASE64_BYTES = 8 * 1024 * 1024++/**+ * Codex-only (#650) per-image ceiling. The 16 MiB aggregate lives on the+ * Codex chat hop and the shared contract, not in this picker.+ */+export const CODEX_COMPOSER_MAX_IMAGE_BYTES = 16 * 1024 * 1024+/** Official Codex client long-side bound. The Codex hop 400s frames above this. */+export const CODEX_COMPOSER_MAX_IMAGE_DIMENSION = 2048+export const COMPOSER_ACCEPT_IMAGE_MIME_TYPES = ['image/jpeg', 'image/png'] as const++export const CODEX_SUBSCRIPTION_PROVIDER = 'codex-subscription'++export type ComposerImageBudget = {+ maxImageBytes: number+ /** `null` → no composer aggregate; the Codex hop owns that ceiling. */+ maxTotalBase64Bytes: number | null+ /** `null` → no composer pixel bound (general models). */+ maxDimension: number | null+ sizeUnit: 'MB' | 'MiB'+}++/** Product limits for the picker. Codex keeps #650; everyone else keeps #669. */+export function composerImageBudget(provider: string | null | undefined): ComposerImageBudget {+ if (provider === CODEX_SUBSCRIPTION_PROVIDER) {+ return {+ maxImageBytes: CODEX_COMPOSER_MAX_IMAGE_BYTES,+ maxTotalBase64Bytes: null,+ maxDimension: CODEX_COMPOSER_MAX_IMAGE_DIMENSION,+ sizeUnit: 'MiB',+ }+ }+ return {+ maxImageBytes: COMPOSER_MAX_IMAGE_BYTES,+ maxTotalBase64Bytes: COMPOSER_MAX_TOTAL_IMAGE_BASE64_BYTES,+ maxDimension: null,+ sizeUnit: 'MB',+ }+}diff --git a/desktop-app/ui/src/lib/__tests__/imageHeaderDimensions.test.ts b/desktop-app/ui/src/lib/__tests__/imageHeaderDimensions.test.tsindex dcced88e4..5d0144c34 100644--- a/desktop-app/ui/src/lib/__tests__/imageHeaderDimensions.test.ts+++ b/desktop-app/ui/src/lib/__tests__/imageHeaderDimensions.test.ts@@ -1,32 +1,55 @@import { describe, expect, it } from 'vitest'+import { createRequire } from 'node:module'import { readImageHeaderDimensions } from '../imageHeaderDimensions'-function pngIhdrStub(width: number, height: number): Uint8Array {- const bytes = new Uint8Array(8 + 8 + 13)- bytes.set([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a], 0)- const view = new DataView(bytes.buffer)- view.setUint32(8, 13)- bytes.set([0x49, 0x48, 0x44, 0x52], 12)- view.setUint32(16, width)- view.setUint32(20, height)- return bytes+const { declaredHeaderPng, jpegOfSize, padJpegToSize } = createRequire(__filename)(+ '../../../../../packages/llm-provider-attempt-contract/testImageFixtures.cjs'+) as {+ declaredHeaderPng: (width: number, height: number) => Buffer+ jpegOfSize: (targetBytes: number, width?: number, height?: number) => Buffer+ padJpegToSize: (jpeg: Buffer, targetBytes: number) => Buffer}describe('readImageHeaderDimensions', () => {- it('reads PNG IHDR width and height', () => {- expect(readImageHeaderDimensions('image/png', pngIhdrStub(2048, 256))).toEqual({+ it('reads PNG IHDR width and height from the shared fixture', () => {+ const bytes = declaredHeaderPng(2048, 256)+ expect(readImageHeaderDimensions('image/png', bytes)).toEqual({width: 2048,height: 256,})})- it('reads a 2049 px PNG so the composer can refuse it', () => {- expect(readImageHeaderDimensions('image/png', pngIhdrStub(2049, 128))).toEqual({+ it('reads a 2049 px PNG so the Codex composer can refuse it', () => {+ const bytes = declaredHeaderPng(2049, 128)+ expect(readImageHeaderDimensions('image/png', bytes)).toEqual({width: 2049,height: 128,})})+ it('reads a baseline JPEG SOF0 size', () => {+ const bytes = jpegOfSize(64, 640, 480)+ expect(readImageHeaderDimensions('image/jpeg', bytes)).toEqual({+ width: 640,+ height: 480,+ })+ })++ it('skips a COM segment and still reads JPEG dimensions', () => {+ const baseline = jpegOfSize(64, 320, 200)+ const padded = padJpegToSize(baseline, baseline.length + 16)+ expect(readImageHeaderDimensions('image/jpeg', padded)).toEqual({+ width: 320,+ height: 200,+ })+ })++ it('returns null for a truncated JPEG that never reaches SOF', () => {+ expect(readImageHeaderDimensions('image/jpeg', new Uint8Array([0xff, 0xd8, 0xff, 0xc0]))).toBe(+ null+ )+ })+it('ignores bytes that are not a PNG or JPEG header', () => {expect(readImageHeaderDimensions('image/png', new Uint8Array([0x41]))).toBeNull()expect(readImageHeaderDimensions('image/jpeg', new Uint8Array([0x41]))).toBeNull()diff --git a/external-rest-api/src/releaseManifest.ts b/external-rest-api/src/releaseManifest.tsindex 2589c33a6..bd0563545 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.85',+ rpcProxyVersion: '0.1.86',desktopVersion: '0.8.1',minimumDesktopVersion: '0.1.252',}diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex 4862d18f2..d0c10f84c 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.356",+ "version": "0.1.357","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.356",+ "version": "0.1.357","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex 83805f035..d78711ce7 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.356",+ "version": "0.1.357","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.tsindex 005594084..094588db7 100644--- a/mcp-host/src/__tests__/bodylimits.test.ts+++ b/mcp-host/src/__tests__/bodylimits.test.ts@@ -19,7 +19,7 @@ import type { AddressInfo } from 'net'import { createRequire } from 'node:module'import type { IncomingMessage } from '../server/types'-const { declaredHeaderPngOfSize, jpegOfSize } = createRequire(import.meta.url)(+const { declaredHeaderPngOfSize, jpegOfSize } = createRequire(__filename)('../../../packages/llm-provider-attempt-contract/testImageFixtures.cjs') as {declaredHeaderPngOfSize: (targetBytes: number) => Bufferdiff --git a/mcp-host/src/__tests__/server.attachments.test.ts b/mcp-host/src/__tests__/server.attachments.test.tsindex d604b07a4..b5259c783 100644--- a/mcp-host/src/__tests__/server.attachments.test.ts+++ b/mcp-host/src/__tests__/server.attachments.test.ts@@ -4,7 +4,7 @@ import { createRequire } from 'node:module'import type { Attachment } from '../core/types'import type { RPCServer } from '../server'-const { declaredHeaderPngOfSize } = createRequire(import.meta.url)(+const { declaredHeaderPngOfSize } = createRequire(__filename)('../../../packages/llm-provider-attempt-contract/testImageFixtures.cjs') as {declaredHeaderPngOfSize: (targetBytes: number) => Bufferdiff --git a/mcp-host/src/agent/__tests__/taskExecutor.test.ts b/mcp-host/src/agent/__tests__/taskExecutor.test.tsindex 065b61825..1e8e16f7c 100644--- a/mcp-host/src/agent/__tests__/taskExecutor.test.ts+++ b/mcp-host/src/agent/__tests__/taskExecutor.test.ts@@ -1023,7 +1023,9 @@ describe('TaskExecutor', () => {type: 'image',mimeType: 'image/jpeg',data: 'ZmFrZS1pbWFnZS1iYXNlNjQ=',- source: { kind: 'attachment', attachmentId: 'att-1', messageId: 'msg-1' },+ ...(providerType === 'codex-subscription'+ ? { source: { kind: 'attachment', attachmentId: 'att-1', messageId: 'msg-1' } }+ : {}),} satisfies MessageContentPart)})@@ -1048,6 +1050,28 @@ describe('TaskExecutor', () => {type: 'image',mimeType: 'image/png',data: 'cG5n',+ } satisfies MessageContentPart)+ })++ it('binds image source when a Codex fallback is configured on an OpenAI primary', async () => {+ vi.mocked(runToolUseLoop).mockResolvedValueOnce({ type: 'response', content: 'ok' } as any)+ const policy: LlmPolicy = {+ fallbacks: [{ provider: 'codex-subscription', model: 'fallback-model' }],+ triggerOn: ['provider_unavailable'],+ cooldownSeconds: 30,+ }+ const deps = createDeps({+ failover: { policy, engine: new FailoverEngine(policy), buildProvider: () => null },+ })+ const task = createTask('Analyze this image')+ task.sourceMessage!.attachments = [createImageAttachment()]+ await new TaskExecutor(task, deps).run()+ const parts = getLastUserMessageFromLoopCall().contentParts ?? []+ expect(vi.mocked(runToolUseLoop).mock.calls[0][0].imageSourceIdentity).toBe(true)+ expect(parts[1]).toEqual({+ type: 'image',+ mimeType: 'image/jpeg',+ data: 'ZmFrZS1pbWFnZS1iYXNlNjQ=',source: { kind: 'attachment', attachmentId: 'att-1', messageId: 'msg-1' },} satisfies MessageContentPart)})@@ -1104,9 +1128,6 @@ describe('TaskExecutor', () => {type: 'image',mimeType: 'image/jpeg',data: 'ZmFrZS1pbWFnZS1iYXNlNjQ=',- // A real identity, not a placeholder: internal sources have no delivery- // id, so the task that queued the message identifies it.- source: { kind: 'attachment', attachmentId: 'att-1', messageId: task.id },} satisfies MessageContentPart)})diff --git a/mcp-host/src/agent/incomingImageAttachments.ts b/mcp-host/src/agent/incomingImageAttachments.tsindex 000a6d41c..25788d878 100644--- a/mcp-host/src/agent/incomingImageAttachments.ts+++ b/mcp-host/src/agent/incomingImageAttachments.ts@@ -10,9 +10,10 @@ import type { TaskError } from '../queue/types'* Images accepted in one incoming message. Kept separate from* `CLERUM_ATTACHMENT_MAX_COUNT`, which caps the attachments a response returns.* Must match COMPOSER_MAX_IMAGE_ATTACHMENTS in desktop-app/ui/src/constants/attachments.ts.- * The hop envelope is 24 MiB (rpc-proxy `chatJsonBody` + this host's chat- * parser) with a 16 MiB credited image budget. This count is the fail-loud- * admission cap, separate from the hop credit.+ * Per-image bytes stay on the channel `attachmentMaxBytes` (issue #654 / PR+ * #669) — this module must not clamp general inbound traffic to the Codex+ * `VISUAL_LIMITS`. The Codex chat hop is a separate 24 MiB parser with a+ * 16 MiB credited image budget. This count is the fail-loud admission cap.*/export const INCOMING_IMAGE_MAX_COUNT = 20diff --git a/mcp-host/src/agent/taskExecutor.ts b/mcp-host/src/agent/taskExecutor.tsindex 2c28452af..35027d96d 100644--- a/mcp-host/src/agent/taskExecutor.ts+++ b/mcp-host/src/agent/taskExecutor.ts@@ -1475,15 +1475,7 @@ export class TaskExecutor {toolProgressInterval: appConfig.nativeTool.toolProgressInterval,})loopConfig.abortSignal = this.abortController.signal- loopConfig.imageSourceIdentity =- this.deps.llmProvider.requiresImageSourceIdentity === true ||- [- this.deps.llmProvider.getProviderType(),- ...(this.deps.failover?.policy.fallbacks.map(entry => entry.provider) ?? []),- ].some(- provider =>- isLlmProvider(provider) && descriptorFor(provider).requiresImageSourceIdentity === true- )+ loopConfig.imageSourceIdentity = this.providerChainRequiresImageSourceIdentity()loopConfig.onAttachments = attachments =>mergeCollectedAttachments(this.completedAttachments, attachments)// Guardrails (spec §6) — build the tool-lane guardrail from the Host block.@@ -2139,6 +2131,24 @@ export class TaskExecutor {return attachments}+ /**+ * Codex V2 hashes each image source. Bind identity only when this chain+ * (primary or a configured fallback) requires it so a non-Codex wire stays+ * on the #654 shape.+ */+ private providerChainRequiresImageSourceIdentity(): boolean {+ return (+ this.deps.llmProvider.requiresImageSourceIdentity === true ||+ [+ this.deps.llmProvider.getProviderType(),+ ...(this.deps.failover?.policy.fallbacks.map(entry => entry.provider) ?? []),+ ].some(+ provider =>+ isLlmProvider(provider) && descriptorFor(provider).requiresImageSourceIdentity === true+ )+ )+ }+private buildSourceMessageContentParts(messageContent: string): MessageContentPart[] {const providerType = this.deps.llmProvider.getProviderType()// getProviderType() always returns a registered LlmProvider, so in practice@@ -2158,6 +2168,7 @@ export class TaskExecutor {// Neither value is a placeholder, and neither is rewritten here: a value// the shared contract does not accept fails its projection check instead.const messageId = this.task.sourceMessage?.messageId?.trim() || this.task.id+ const bindSource = this.providerChainRequiresImageSourceIdentity()const imageParts = sourceAttachments.filter(att =>@@ -2168,7 +2179,9 @@ export class TaskExecutor {type: 'image',mimeType: att.mimeType as 'image/jpeg' | 'image/png',data: att.dataBase64,- source: { kind: 'attachment', attachmentId: att.id, messageId },+ ...(bindSource+ ? { source: { kind: 'attachment' as const, attachmentId: att.id, messageId } }+ : {}),}))if (!imageParts.length) {diff --git a/mcp-host/src/core/adapters/__tests__/llmImageCompatibility.test.ts b/mcp-host/src/core/adapters/__tests__/llmImageCompatibility.test.tsindex 9896c4e3f..8cd494706 100644--- a/mcp-host/src/core/adapters/__tests__/llmImageCompatibility.test.ts+++ b/mcp-host/src/core/adapters/__tests__/llmImageCompatibility.test.ts@@ -24,6 +24,7 @@ import {} from '../../../llm/codexSubscription'import { FailoverEngine } from '../../../llm/failover/engine'import type { LlmPolicy } from '../../../llm/failover/types'+import type { ImageInputResolver } from '../../../llm/imageInput'import { CodexAuthorizeError } from '../../../llm/providerAttemptAuthorizer'import { LlmErrorCode } from '../../errors'import { stripHistoricalMedia } from '../../extensions/prePrune'@@ -42,6 +43,36 @@ import {import { maybeWrapFailover } from '../failoverLlmPort'import { LlmPortAdapter } from '../llmPortAdapter'+const ALLOW_IMAGES: ImageInputResolver = () => ({+ capability: {+ state: 'supported',+ evidence: {+ source: 'curated',+ reference: 'https://example.test/image-input',+ checkedAt: '2026-01-01T00:00:00Z',+ },+ },+})++/** #654 withholds tool images without affirmative evidence; these suites opt in. */+function adapterFor(+ provider: SingleTurnProvider,+ model: string,+ providerName: string+): LlmPortAdapter {+ return new LlmPortAdapter(+ provider,+ model,+ providerName,+ undefined,+ undefined,+ undefined,+ undefined,+ undefined,+ ALLOW_IMAGES+ )+}+const SYSTEM_PARTS: SystemPromptParts = {stable: 'stable tier',context: 'context tier',@@ -132,11 +163,15 @@ type ProviderCall = { parts?: SystemPromptParts; messages: ChatMessage[] }* cache-aware methods so the adapter routes to them; `imageSourceIdentity`* models a transport that binds every image source (Codex V2).*/-function recordingProvider(options: { cache: boolean; imageSourceIdentity?: boolean }) {+function recordingProvider(options: {+ cache: boolean+ imageSourceIdentity?: boolean+ providerType?: string+}) {const complete: ProviderCall[] = []const completeWithTools: ProviderCall[] = []const base = {- getProviderType: () => 'openai' as const,+ getProviderType: () => (options.providerType ?? 'openai') as 'openai',classifyError: () => ({code: LlmErrorCode.ApiCallFailed,retryable: true,@@ -201,16 +236,25 @@ const DISPATCH_VARIANTS: DispatchVariant[] = [{ label: 'completeWithTools via the concat fallback', tools: true, cache: false },]+function dispatchPair(variant: DispatchVariant): { providerType: string; model: string } {+ // #654: only dispatch on a path the transport matrix actually keeps.+ if (variant.cache) return { providerType: 'claude', model: 'claude-sonnet-4-5' }+ if (variant.tools) return { providerType: 'openai', model: 'gpt-4o' }+ return { providerType: 'vertex', model: 'gemini-2.5-pro' }+}+async function runVariant(variant: DispatchVariant,imageSourceIdentity: boolean,messages: ChatMessage[]): Promise<ProviderCall> {+ const pair = dispatchPair(variant)const { provider, complete, completeWithTools } = recordingProvider({cache: variant.cache,imageSourceIdentity,+ providerType: pair.providerType,})- const adapter = new LlmPortAdapter(provider, 'gpt-4o', 'openai')+ const adapter = adapterFor(provider, pair.model, pair.providerType)if (variant.tools) {await adapter.completeWithTools({ messages, tools: TOOLS, systemPromptParts: SYSTEM_PARTS })@@ -319,8 +363,8 @@ describe('image source identity compatibility (#650)', () => {])expect(visual[0].contentParts?.[1]).not.toHaveProperty('sourceIdentityOnly')- const { provider, complete } = recordingProvider({ cache: true })- await new LlmPortAdapter(provider, 'gpt-4o', 'openai').complete({+ const { provider, complete } = recordingProvider({ cache: true, providerType: 'claude' })+ await adapterFor(provider, 'claude-sonnet-4-5', 'claude').complete({messages,systemPromptParts: SYSTEM_PARTS,})@@ -340,13 +384,14 @@ describe('image source identity compatibility (#650)', () => {filtered.contentParts?.filter(part => part.type === 'text').map(part => part.text)).toEqual([filtered.content])- const binding = recordingProvider({ cache: true, imageSourceIdentity: true })- await new LlmPortAdapter(binding.provider, 'codex-subscription', 'codex-subscription').complete(- {- messages,- systemPromptParts: SYSTEM_PARTS,- }- )+ const binding = recordingProvider({+ cache: false,+ imageSourceIdentity: true,+ providerType: 'codex-subscription',+ })+ await adapterFor(binding.provider, 'codex-subscription', 'codex-subscription').complete({+ messages,+ })expect(imagePartsOf(binding.complete[0].messages).map(image => image.source)).toEqual([{ kind: 'tool', attachmentId: 'att-a', toolCallId: 'tc_one' },{ kind: 'tool', attachmentId: 'att-b', toolCallId: 'tc_two' },@@ -358,18 +403,20 @@ describe('image source identity compatibility (#650)', () => {const snapshot = structuredClone(messages)const request: CompletionRequest = { messages, systemPromptParts: SYSTEM_PARTS }- const legacy = recordingProvider({ cache: true })- await new LlmPortAdapter(legacy.provider, 'gpt-4o', 'openai').complete(request)+ const legacy = recordingProvider({ cache: true, providerType: 'claude' })+ await adapterFor(legacy.provider, 'claude-sonnet-4-5', 'claude').complete(request)// The filtering produced a provider-specific view, not a mutation.expect(legacy.complete[0].messages).not.toBe(messages)expect(messages).toEqual(snapshot)expect(imagePartsOf(legacy.complete[0].messages)).toHaveLength(1)- const binding = recordingProvider({ cache: true, imageSourceIdentity: true })- await new LlmPortAdapter(binding.provider, 'codex-subscription', 'codex-subscription').complete(- request- )+ const binding = recordingProvider({+ cache: false,+ imageSourceIdentity: true,+ providerType: 'codex-subscription',+ })+ await adapterFor(binding.provider, 'codex-subscription', 'codex-subscription').complete(request)expect(imagePartsOf(binding.complete[0].messages)).toEqual(imagePartsOf(snapshot))})@@ -377,11 +424,11 @@ describe('image source identity compatibility (#650)', () => {const { messages } = repeatedFrameMessages()const legacy = recordingProvider({ cache: false })- await new LlmPortAdapter(legacy.provider, 'gpt-4o', 'openai').complete({ messages })+ await adapterFor(legacy.provider, 'gemini-2.5-pro', 'vertex').complete({ messages })expect(imagePartsOf(legacy.complete[0].messages)).toHaveLength(1)const legacyTools = recordingProvider({ cache: false })- await new LlmPortAdapter(legacyTools.provider, 'gpt-4o', 'openai').completeWithTools({+ await adapterFor(legacyTools.provider, 'gpt-4o', 'openai').completeWithTools({messages,tools: TOOLS,})@@ -406,8 +453,8 @@ describe('image source identity compatibility (#650)', () => {})expect(JSON.stringify(messages)).not.toContain('sourceIdentityOnly')- const { provider, complete } = recordingProvider({ cache: true })- await new LlmPortAdapter(provider, 'gpt-4o', 'openai').complete({ messages })+ const { provider, complete } = recordingProvider({ cache: false, providerType: 'vertex' })+ await adapterFor(provider, 'gemini-2.5-pro', 'vertex').complete({ messages })// Nothing to translate, so the adapter hands the canonical view straight on.expect(complete[0].messages).toEqual(messages)@@ -493,8 +540,8 @@ describe('mixed-chain pruning recovery (#650)', () => {expect(imagePartsOf(stripped)[0].sourceIdentityOnly).toBe(true)const snapshot = structuredClone(stripped)- const { provider, complete } = recordingProvider({ cache: true })- await new LlmPortAdapter(provider, 'gpt-4o', 'openai').complete({+ const { provider, complete } = recordingProvider({ cache: true, providerType: 'claude' })+ await adapterFor(provider, 'claude-sonnet-4-5', 'claude').complete({messages: stripped,systemPromptParts: SYSTEM_PARTS,})@@ -544,8 +591,8 @@ describe('mixed-chain pruning recovery (#650)', () => {expect(imagePartsOf(stripped).map(image => image.sourceIdentityOnly)).toEqual([true, true])const snapshot = structuredClone(stripped)- const { provider, complete } = recordingProvider({ cache: true })- await new LlmPortAdapter(provider, 'gpt-4o', 'openai').complete({+ const { provider, complete } = recordingProvider({ cache: true, providerType: 'claude' })+ await adapterFor(provider, 'claude-sonnet-4-5', 'claude').complete({messages: stripped,systemPromptParts: SYSTEM_PARTS,})@@ -597,7 +644,7 @@ describe('Codex V2 transport wiring (#650)', () => {expect(imagePartsOf(messages)[1].sourceIdentityOnly).toBe(true)expect(JSON.stringify(messages)).toContain('sourceIdentityOnly')- await new LlmPortAdapter(provider, 'gpt-5.3-codex', 'codex-subscription').completeWithTools({+ await adapterFor(provider, 'gpt-5.3-codex', 'codex-subscription').completeWithTools({messages,tools: TOOLS,})@@ -645,11 +692,11 @@ describe('Codex V2 transport wiring (#650)', () => {const { messages } = repeatedFrameMessages()const snapshot = structuredClone(messages)const wrapped = maybeWrapFailover({- primaryPort: new LlmPortAdapter(primary, 'gpt-5.3-codex', 'codex-subscription'),+ primaryPort: adapterFor(primary, 'gpt-5.3-codex', 'codex-subscription'),primaryPair: { provider: 'codex-subscription', model: 'gpt-5.3-codex' },engine,policy,- buildFallbackPort: () => new LlmPortAdapter(fallback.provider, 'gpt-5.4', 'openai'),+ buildFallbackPort: () => adapterFor(fallback.provider, 'gpt-5.4', 'openai'),})await wrapped.completeWithTools({ messages, tools: TOOLS })diff --git a/mcp-host/src/core/adapters/__tests__/llmPortAdapter.imageInput.test.ts b/mcp-host/src/core/adapters/__tests__/llmPortAdapter.imageInput.test.tsindex 827b28cfb..75db13aad 100644--- a/mcp-host/src/core/adapters/__tests__/llmPortAdapter.imageInput.test.ts+++ b/mcp-host/src/core/adapters/__tests__/llmPortAdapter.imageInput.test.ts@@ -321,7 +321,7 @@ describe('#654 LlmPortAdapter image guard', () => {expect(provider.completeSingleTurnWithTools).toHaveBeenCalledTimes(1)})- it('refuses Codex transport until #650 lands, even with curated evidence', async () => {+ it('dispatches Codex V2 chat when catalog evidence is curated', async () => {const provider = fakeProvider('codex-subscription')const adapter = new LlmPortAdapter(provider,@@ -335,12 +335,11 @@ describe('#654 LlmPortAdapter image guard', () => {allow({ state: 'supported', evidence: CURATED_EVIDENCE }))- await expectDenied(- () => adapter.completeWithTools({ messages: [imageMessage()], tools: [] }),- LlmErrorCode.ImageInputUnsupported,- 'cannot carry images'- )- expect(provider.completeSingleTurnWithTools).not.toHaveBeenCalled()+ await adapter.completeWithTools({ messages: [imageMessage()], tools: [] })++ expect(provider.completeSingleTurnWithTools).toHaveBeenCalledTimes(1)+ const [messages] = provider.completeSingleTurnWithTools.mock.calls[0]+ expect(messages[0].contentParts?.[0].type).toBe('image')})it('refuses a malformed base64 image part with LLM_INVALID_ATTACHMENT before consulting the resolver', async () => {@@ -648,7 +647,9 @@ describe('#669 LlmPortAdapter malformed tool screenshots', () => {expect(provider.completeSingleTurnWithTools).toHaveBeenCalledTimes(1)const [dispatched] = provider.completeSingleTurnWithTools.mock.calls[0] as [ChatMessage[]]- expect(imageParts(dispatched)).toEqual([{ type: 'image', mimeType: 'image/png', data: 'QUJD' }])+ expect(imageParts(dispatched)).toEqual([+ expect.objectContaining({ type: 'image', mimeType: 'image/png', data: 'QUJD' }),+ ])const carrier = dispatched[dispatched.length - 1]expect(carrier.imageOrigin).toBe('tool_result')expect(carrier.content).toContain(`[2 ${NOTICE_SUFFIX}`)diff --git a/mcp-host/src/llm/__tests__/imageInput.test.ts b/mcp-host/src/llm/__tests__/imageInput.test.tsindex e914e9b33..186617e37 100644--- a/mcp-host/src/llm/__tests__/imageInput.test.ts+++ b/mcp-host/src/llm/__tests__/imageInput.test.ts@@ -61,8 +61,8 @@ const EXPECTED_MATRIX: Record<string, Record<ImageTransportOperation, boolean>>completeWithToolsAndCache: false,},'codex-subscription': {- complete: false,- completeWithTools: false,+ complete: true,+ completeWithTools: true,completeAndCache: false,completeWithToolsAndCache: false,},@@ -143,13 +143,20 @@ describe('#654 transport matrix', () => {const authorized = chatTransportSupportsImageInput(provider)if (!authorized) continueconst hasDescriptorBaseURL = Boolean(descriptorFor(provider).baseURL)- const isExplicitArm = ['openai', 'azure', 'claude', 'vertex', 'bedrock'].includes(provider)+ const isExplicitArm = [+ 'openai',+ 'azure',+ 'claude',+ 'vertex',+ 'bedrock',+ 'codex-subscription',+ ].includes(provider)// `provider` is interpolated into the assertion message by the expect// failure, so a future divergent provider that inherits coverage fails// here with its own id.expect(hasDescriptorBaseURL || isExplicitArm).toBe(true)}- expect(chatTransportSupportsImageInput('codex-subscription')).toBe(false)+ expect(chatTransportSupportsImageInput('codex-subscription')).toBe(true)})it('projects the CHAT operation as tool-bearing, never as the tool-less plain path', () => {@@ -158,8 +165,8 @@ describe('#654 transport matrix', () => {expect(chatTransportSupportsImageInput('claude')).toBe(true)expect(chatTransportSupportsImageInput('vertex')).toBe(true)expect(chatTransportSupportsImageInput('bedrock')).toBe(true)- // #650 not landed: Codex cannot carry images anywhere yet.- expect(chatTransportSupportsImageInput('codex-subscription')).toBe(false)+ // #650: Codex V2 carries images on the chat tool-bearing path.+ expect(chatTransportSupportsImageInput('codex-subscription')).toBe(true)})it('rejects assistant/system images and honors per-family role support', () => {@@ -168,7 +175,8 @@ describe('#654 transport matrix', () => {expect(roleReason('claude', 'tool')).toBe('supported')expect(roleReason('claude', 'assistant')).toBe('transport_unsupported')expect(roleReason('vertex', 'assistant')).toBe('transport_unsupported')- expect(roleReason('codex-subscription', 'user')).toBe('transport_unsupported')+ expect(roleReason('codex-subscription', 'user')).toBe('supported')+ expect(roleReason('codex-subscription', 'tool')).toBe('transport_unsupported')})})diff --git a/mcp-host/src/llm/__tests__/imageInputTransport.test.ts b/mcp-host/src/llm/__tests__/imageInputTransport.test.tsindex c8da052ad..1fd8df1bd 100644--- a/mcp-host/src/llm/__tests__/imageInputTransport.test.ts+++ b/mcp-host/src/llm/__tests__/imageInputTransport.test.ts@@ -119,8 +119,15 @@ function buildHarness(family: Family): Harness {usage: { input_tokens: 1, output_tokens: 1, total_tokens: 2 },finish_reason: FinishReason.Stop,}- const withTools = vi.fn(async () => ({ ...textOk, tool_calls: [] }))- const single = vi.fn(async () => textOk)+ let lastMessages: ChatMessage[] | undefined+ const withTools = vi.fn(async (messages: ChatMessage[]) => {+ lastMessages = messages+ return { ...textOk, tool_calls: [] }+ })+ const single = vi.fn(async (messages: ChatMessage[]) => {+ lastMessages = messages+ return textOk+ })const provider = {completeSingleTurn: single,completeSingleTurnWithTools: withTools,@@ -134,7 +141,7 @@ function buildHarness(family: Family): Harness {return {provider,sdkCalls: () => single.mock.calls.length + withTools.mock.calls.length,- wire: () => undefined,+ wire: () => lastMessages,}}}@@ -174,7 +181,12 @@ function wireHasImage(family: Family, wire: unknown): boolean {))case 'codex':- return false+ return Boolean(+ Array.isArray(wire) &&+ wire.some((message: ChatMessage) =>+ message.contentParts?.some(part => part.type === 'image')+ )+ )}}@@ -255,7 +267,7 @@ const REACHABLE: Record<Family, ImageTransportOperation[]> = {/** Expected outcome, restated from plan §4.1 (not imported from the module). */function expectedSupported(family: Family, operation: ImageTransportOperation): boolean {- if (family === 'codex') return false+ if (family === 'codex') return operation === 'complete' || operation === 'completeWithTools'if (operation === 'complete') return family === 'vertex' || family === 'bedrock'if (operation === 'completeWithTools') return truereturn family === 'claude'@@ -318,14 +330,12 @@ describe('#654 transport cross-suite (real serializers)', () => {})it('names the pair that would have been called in the refusal', async () => {- const harness = buildHarness('codex')- const adapter = adapterFor(harness, 'codex')- await expect(- adapter.completeWithTools({ messages: [imageMessage()], tools: [] })- ).rejects.toMatchObject({+ const harness = buildHarness('openai-compatible')+ const adapter = adapterFor(harness, 'openai-compatible')+ await expect(adapter.complete({ messages: [imageMessage()] })).rejects.toMatchObject({code: LlmErrorCode.ImageInputUnsupported,retryable: false,- provider: 'codex-subscription',+ provider: 'openai',})})diff --git a/mcp-host/src/llm/imageInput.ts b/mcp-host/src/llm/imageInput.tsindex a648c04d9..1120cc1ce 100644--- a/mcp-host/src/llm/imageInput.ts+++ b/mcp-host/src/llm/imageInput.ts@@ -18,7 +18,7 @@* claude no yes yes user, tool* vertex yes yes n/a user* bedrock yes yes n/a user- * codex-subscription no no n/a none+ * codex-subscription yes yes n/a user** `complete` is the tool-less, cache-less path (`completeSingleTurn`): OpenAI,* OpenAI-compatible and Azure rebuild `role/content` and drop `contentParts`,@@ -139,9 +139,11 @@ const TRANSPORT_SUPPORT: Readonly<completeAndCache: false,completeWithToolsAndCache: false,},+ // #650: Codex V2 carries ordered image parts on the tool-less and+ // tool-bearing paths. Cache variants are not implemented on this transport.codex: {- complete: false,- completeWithTools: false,+ complete: true,+ completeWithTools: true,completeAndCache: false,completeWithToolsAndCache: false,},@@ -158,7 +160,7 @@ const IMAGE_ROLES_BY_FAMILY: Readonly<Record<ImageWireFamily, readonly MessageRoclaude: ['user', 'tool'],vertex: ['user'],bedrock: ['user'],- codex: [],+ codex: ['user'],unregistered: [],}diff --git a/mcp-host/tsconfig.json b/mcp-host/tsconfig.jsonindex 5fdb3c668..8b50c65ff 100644--- a/mcp-host/tsconfig.json+++ b/mcp-host/tsconfig.json@@ -16,5 +16,5 @@"sourceMap": true},"include": ["src/**/*"],- "exclude": ["node_modules", "dist", "**/*.test.ts", "**/__tests__/**"]+ "exclude": ["node_modules", "dist"]}diff --git a/rpc-proxy/package-lock.json b/rpc-proxy/package-lock.jsonindex 34e2a4b9e..a207cc768 100644--- a/rpc-proxy/package-lock.json+++ b/rpc-proxy/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-rpc-proxy",- "version": "0.1.85",+ "version": "0.1.86","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-rpc-proxy",- "version": "0.1.85",+ "version": "0.1.86","dependencies": {"cors": "^2.8.5","express": "^4.21.2",diff --git a/rpc-proxy/package.json b/rpc-proxy/package.jsonindex 2422d36cd..bf920cee4 100644--- a/rpc-proxy/package.json+++ b/rpc-proxy/package.json@@ -1,6 +1,6 @@{"name": "clerum-rpc-proxy",- "version": "0.1.85",+ "version": "0.1.86","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.tsindex c4574ceb4..924c3cac0 100644--- a/rpc-proxy/src/__tests__/bodylimits.test.ts+++ b/rpc-proxy/src/__tests__/bodylimits.test.ts@@ -346,32 +346,15 @@ 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 body over its limit,- // because parsing has to consume the stream http-proxy needs to forward.- // The route answers its cookie check first, so the observable proof is a- // non-413 outcome while the request body is still unread.- const abortController = new AbortController()- const chunk = new Uint8Array(64 * 1024).fill(0x41)- let sent = 0- const body = new ReadableStream<Uint8Array>({- pull(controller) {- if (sent >= 8 * MIB) return // hold the request open; never finish it- sent += chunk.length- controller.enqueue(chunk)- },+ // 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).+ 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),})- try {- const response = await fetch(`${baseUrl}/api/v1/sandbox-ui/ns/recipe/view/index.html`, {- method: 'POST',- headers: { 'content-type': 'text/plain' },- body,- duplex: 'half',- signal: abortController.signal,- } as RequestInit & { duplex: 'half' })- expect(response.status).not.toBe(413)- expect(response.status).toBe(401)- } finally {- abortController.abort()- }+ expect(response.status).not.toBe(413)+ expect(response.status).toBe(401)})})