Skip to content

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

TypeScript

fix(desktop-ui): refuse an image the budget cannot measure, with a notice

Alfredo Lopezbadf202bc7c4
diff --git a/desktop-app/test/e2e-playwright/qa-recorder-image-capabilities.spec.ts b/desktop-app/test/e2e-playwright/qa-recorder-image-capabilities.spec.ts
index 3cadbc41e..81fa9a42e 100644
--- a/desktop-app/test/e2e-playwright/qa-recorder-image-capabilities.spec.ts
+++ b/desktop-app/test/e2e-playwright/qa-recorder-image-capabilities.spec.ts
@@ -368,10 +368,11 @@ async function expectImageSendBlocked(
await expect(notice).toContainText(messagePattern)
// Enter must not reach the controller either: nothing is delivered, the draft
- // survives, and the chip is still pending.
+ // survives, and the chip is still pending. `press` focuses the composer itself,
+ // so focus proves nothing here; the witness that the composer's Enter handler
+ // took the key is the unchanged draft below, since a key the handler did not
+ // consume would have inserted a newline.
await composer(page).press('Enter')
- // Witness that the key landed where a send would start.
- await expect(composer(page)).toBeFocused()
await expect(page.locator('[data-chat-message-id]')).toHaveCount(0)
await expect(sendButton(page)).toBeDisabled()
// Liveness witness, after the negatives: the blocked state the refusal had to
diff --git a/desktop-app/ui/src/components/agents/ComposerPanel.tsx b/desktop-app/ui/src/components/agents/ComposerPanel.tsx
index d11c55ad8..ec6d6ebed 100644
--- a/desktop-app/ui/src/components/agents/ComposerPanel.tsx
+++ b/desktop-app/ui/src/components/agents/ComposerPanel.tsx
@@ -580,11 +580,23 @@ export function ComposerPanel({ inline = false, agentSelector }: ComposerPanelPr
// Non-Codex images keep the #669 base64 ceiling; Codex images are held
// to the decoded image quota rpc-proxy and mcp-host enforce (#650).
const totalMeasure = imageBudget.maxTotal.measure
- let totalImageBytes = composerImageAttachments.reduce(
- (total, attachment) =>
- total + composerImageBudgetBytes(attachment.dataBase64, totalMeasure),
- 0
- )
+ // This callback runs under `void`, so a throw here would be an unhandled
+ // rejection the user never sees. An attached image that cannot be
+ // measured (a chip restored with malformed base64) refuses the whole
+ // gesture with a visible notice: the remaining quota is unknown.
+ let totalImageBytes = 0
+ for (const attachment of composerImageAttachments) {
+ try {
+ totalImageBytes += composerImageBudgetBytes(attachment.dataBase64, totalMeasure)
+ } catch (error) {
+ setComposerAttachmentError(
+ `${attachment.name || 'Image'} could not be measured against the image limit (${
+ error instanceof Error ? error.message : String(error)
+ }). Remove it and attach it again.`
+ )
+ return
+ }
+ }
for (const [index, { file, mimeType }] of selected.entries()) {
if (composerImageExceedsPerImageBudget(file.size, imageBudget.maxImageBytes)) {
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 e990b968e..4b78a4ea8 100644
--- a/desktop-app/ui/src/components/agents/__tests__/ComposerPanel.test.tsx
+++ b/desktop-app/ui/src/components/agents/__tests__/ComposerPanel.test.tsx
@@ -985,6 +985,28 @@ describe('ComposerPanel Codex image budgets', () => {
expect(expectSinglePreparedImage().name).toBe('next.png')
})
+ it('refuses a new image with a visible error when an attached image holds malformed base64', async () => {
+ // A chip restored from a failed send keeps the stored base64 as it is; one
+ // whose length is not a multiple of four cannot be measured in decoded bytes.
+ const restored = attachedImage('restored', 'restored.png', 8)
+ composerState.composerImageAttachments = [
+ { ...restored, dataBase64: restored.dataBase64.slice(0, -1) },
+ ]
+ const { container } = render(<ComposerPanel inline />)
+
+ fireEvent.change(pickerInput(container), {
+ target: { files: [pngOfSize('next.png', 64, 1)] },
+ })
+
+ // Liveness witness: the refusal reached the user and names the chip at fault.
+ await waitFor(() =>
+ expect(screen.queryByRole('alert')?.textContent).toBe(
+ 'restored.png could not be measured against the image limit (Image data is not canonical base64.). Remove it and attach it again.'
+ )
+ )
+ expect(actionsMock.handleAddComposerImageAttachments).not.toHaveBeenCalled()
+ })
+
it('refuses an annotation save that would push the decoded images past 16 MiB', () => {
const already = attachedImage('already', 'already.png', 8 * MIB)
const editing = attachedImage('editing', 'edit.png', 8 * MIB - 3)
diff --git a/desktop-app/ui/src/constants/__tests__/attachments.test.ts b/desktop-app/ui/src/constants/__tests__/attachments.test.ts
new file mode 100644
index 000000000..286a53e38
--- /dev/null
+++ b/desktop-app/ui/src/constants/__tests__/attachments.test.ts
@@ -0,0 +1,23 @@
+import { describe, expect, it } from 'vitest'
+import { composerImageBudgetBytes } from '../attachments'
+
+describe('composerImageBudgetBytes', () => {
+ it('counts the decoded bytes of canonical base64 the way rpc-proxy and mcp-host do', () => {
+ // The PNG signature: 12 characters with one `=` decode to 8 bytes.
+ const signature = 'iVBORw0KGgo='
+ expect(composerImageBudgetBytes(signature, 'decoded')).toBe(8)
+ expect(composerImageBudgetBytes(signature, 'decoded')).toBe(atob(signature).length)
+ expect(composerImageBudgetBytes('AA==', 'decoded')).toBe(1)
+ expect(composerImageBudgetBytes('AAAA', 'decoded')).toBe(3)
+ })
+
+ it('refuses base64 whose length is not a multiple of four instead of measuring it', () => {
+ // Witness: the canonical value of the same bytes is measured.
+ expect(composerImageBudgetBytes('iVBORw0KGgo=', 'decoded')).toBe(8)
+ for (const malformed of ['iVBORw0KGgo', 'iVBORw0KGgo==', 'A', 'AAAAA']) {
+ expect(() => composerImageBudgetBytes(malformed, 'decoded'), malformed).toThrow(
+ 'Image data is not canonical base64.'
+ )
+ }
+ })
+})
diff --git a/scripts/e2e/image-capabilities-fixture.mjs b/scripts/e2e/image-capabilities-fixture.mjs
index 7103ba830..91594cc2f 100644
--- a/scripts/e2e/image-capabilities-fixture.mjs
+++ b/scripts/e2e/image-capabilities-fixture.mjs
@@ -94,7 +94,13 @@ export function playwrightVerdict(report, { lane, configFile }) {
}
}
collect(report.suites)
- if (titles.length !== stats.expected || titles.some(title => !title.startsWith(grep)))
+ // The counters alone cannot vouch for the run: a truncated or empty suite tree
+ // with the same counters must not pass as the lane's journeys.
+ if (titles.length !== stats.expected)
+ throw new Error(
+ `Playwright report lists ${titles.length} specs for ${stats.expected} expected tests`
+ )
+ if (titles.some(title => !title.startsWith(grep)))
throw new Error(`Playwright report has specs outside the ${lane} lane`)
return 'PASS'
}
diff --git a/scripts/e2e/image-capabilities-fixture.test.mjs b/scripts/e2e/image-capabilities-fixture.test.mjs
index d58565884..13ae290e9 100644
--- a/scripts/e2e/image-capabilities-fixture.test.mjs
+++ b/scripts/e2e/image-capabilities-fixture.test.mjs
@@ -193,6 +193,28 @@ test('the Playwright verdict is PASS only for a complete, clean report from the
}
})
+test('the Playwright verdict fails a report whose suites list fewer specs than it counted', () => {
+ const options = { lane: 'image', configFile: laneConfigFile('image') }
+ const titles = ['a', 'b', 'c'].map(name => `image-capabilities fixture: ${name}`)
+ // Witness: the complete report of three expected specs is PASS.
+ assert.equal(playwrightVerdict(playwrightReport({ titles }), options), 'PASS')
+ for (const [label, suites] of [
+ ['empty suites', []],
+ [
+ 'truncated suites',
+ [{ title: 'qa-recorder.spec.ts', specs: [{ title: titles[0], ok: true }], suites: [] }],
+ ],
+ ]) {
+ const report = { ...playwrightReport({ titles }), suites }
+ assert.equal(report.stats.expected, 3, label)
+ assert.throws(
+ () => playwrightVerdict(report, options),
+ /Playwright report lists \d specs for 3 expected tests/,
+ label
+ )
+ }
+})
+
test('requires both exact source revisions and the live derived-base identity', () => {
assert.deepEqual(proveImages(manifest(), ids, head, profile), { head, profile, images: ids })
for (const mutate of [