emrg: pasting one image into the GUI composer attaches it twice #2447
Description
What happens
Pasting one image into the GUI composer produces two [📷 image] attachments, and the message the model receives carries the image twice.
The GUI's own log shows one paste handler run and two attachments inside it:
[composer:image] attach 2 file(s): image/png, image/png
Both attachments resolve to the same saved file (the main process names saved images by a content hash) — so the bytes are identical and only the attach layer doubled them. In the log archive, 7 pastes, 7 of them attach 2 file(s); none read 1 file(s).
Why
emrg/gui/renderer/src/lib/composer.ts — collectImageFiles reads a paste/drop event through two properties, files and items[i].getAsFile(), and de-duplicates by object identity (out.includes(f)).
Reading both was introduced on the premise that a Chromium paste delivers the image only on items, so reading files alone would return nothing. A probe run inside the app shows that premise is wrong: a paste delivers files.length === 1, and files[0] and items[0].getAsFile() are two different objects with the same content — and getAsFile() returns a fresh object on every call. Identity de-duplication cannot see that they are one file, so one pasted image enters the list twice. (The same probe shows the earlier "paste does nothing" defect had a different cause — a digest method Electron does not implement, since fixed.)
What the fix must satisfy
- One pasted image attaches once.
- A drag that delivers several files still attaches all of them — including two distinct files that happen to share a name, size and type. Nothing may de-duplicate by content.
- The shape where
filesis empty anditemsis the only way in keeps working. - A unit test that reproduces the measured shape — two distinct
Fileobjects, same name/size/type, one per property — and goes red when the collection rule is reverted. - The comment in the source states what was measured, not the premise that turned out to be false.
Where it was observed
GUI composer on macOS, pasting a copied image; log ~/.emrg/logs/emrg-gui.log.
Activity
argszero commentedon Oct 21, 2026
Handled by #2448