Skip to content

Image attach phase 3: the send, what is remembered, and the vision flag - #151

Open
N041M wants to merge 1 commit into
claude/image-attach-2-shellfrom
claude/image-attach-3-wire
Open

N041M wants to merge 1 commit into
claude/image-attach-2-shellfrom
claude/image-attach-3-wire

Conversation

@N041M

@N041M N041M commented Aug 22, 2026

Copy link
Copy Markdown
Owner

Phase 3 of docs/image-attach-plan.md (§5). Stacked on #150.

conversation.pickAttachment runs as a worker job (it opens a modal and decodes for seconds — the model.startLocalSetup precedent), mints a core-side id (the shell's handle never leaves the core), reads ONCE at pick, and hands the webview base64 for display only — a send names ids, so nothing the webview holds can become what the model saw. conversation.discardAttachment (added; the plan lacked it) frees a slot for phase 4's ✕. One constant, 4, caps both the pending set (~8 MiB worst case) and what a send may name. Unknown/spent ids refuse the whole send before anything persists; ids are spent only at the point of no return. The empty-text guard is relaxed by exactly one case: empty text WITH pictures sends as "" plus pictures.

message_attachments stores the bytes (what is remembered is what was sent), deleted with a rewound message in the same transaction, excluded from snapshot capture on the messages line's terms. conversation.load rebuilds both directions — the wire rows for thumbnails AND Message.images for replay, the half that would have failed silently. Cloud model rows in model.availableRoles gain vision; local models deliberately carry no claim (absent = unknown).

Two substantive findings, both amended in the plan: the flat 1,600-token image estimate was CUT — §4.8 measures from the provider's own usage report, which already bills images, so the estimate would double-count and there is no honest seam; and the worker loop had reached pyright's complexity ceiling, so its fourteen channel branches lifted whole into ChannelsMixin._run_channel_job (same order, same handlers, still inside the loop's try).

19 tests in tests/test_image_attach_wire.py, 17 mutations killed via a scratchpad harness (never git checkout on uncommitted work). All of ./scripts/gates.sh green (python 2178 / frontend / rust 207), verified independently.

A message can now carry pictures end to end. conversation.pickAttachment opens
phase 2's picker, holds what comes back, and hands the webview a preview;
conversation.sendMessage names ids and phase 1's block path does the rest.
Nothing draws it yet - phase 4 is the composer and the thread.

A WORKER JOB, not an inline handler, and for the reason model.startLocalSetup
was moved on 2026-08-22: this opens a modal dialog somebody may leave sitting
there and then decodes for seconds, and the read loop is the only thread that
delivers permission.respond and conversation.stop. It queues like
routine.importPreview, whose picker has exactly this shape.

The core mints the attachment id and never passes the shell's file handle out.
A handle is the shell's way of naming a file it will let itself read; an id
names bytes this process is holding. The bytes are read ONCE, at pick, so a
file edited or deleted between the pick and the send changes nothing about the
message - what was previewed is what is sent. The base64 goes out FOR DISPLAY
and never comes back: a send names ids, so nothing the webview holds can become
what the model saw.

ONE CAP, 4, doing two jobs. It bounds what a send may name and how many picks
are held at once, because the pending set exists only to become a message and a
separate number could only be wrong in one direction or the other. It is a
memory bound as much as a UX one - what is held is decoded bytes at up to 2 MiB
each - and it is checked BEFORE the dialog opens, so nobody is sent to find a
file there was never room for. discardAttachment (the plan did not have it)
frees a slot for the phase-4 x; an id nobody is holding is a silent no-op,
because there is nothing to say about a thing already gone.

pickAttachment is the second reader of ALLOWED_IMAGE_MEDIA_TYPES and the one
place a violation can still be answered in a plain sentence, which is what
providers/base.py promised at the constant. The shell enforces the closed four
at encode time, so reaching that branch means the two sides disagree - exactly
why it is a sentence and not an assert.

The empty-text guard is relaxed by EXACTLY one case: empty or whitespace text
WITH pictures becomes "" plus those pictures, because a person sending just a
photo is ordinary. Empty text with nothing attached still refuses and a
non-string text still refuses, pictures or no pictures; what that guard exists
to stop is a turn with nothing in it leaving a blank row no rollback removes,
and a message carrying four pictures is not that turn. Whitespace is stored as
"" rather than as the spaces, because phase 1's adapters omit the text block
when there is nothing to say and " " would be something to say.

An unknown or already-spent id refuses the WHOLE send, before a conversation
row, a message row or a spent role pick exists - the empty-text guard's own
placement argument, and partial is not an option: a message that quietly went
without one of its pictures is the failure a person cannot see and the model
answers wrongly about. The ids are spent at the point of no return and not at
any refusal above it, or somebody's pictures would be consumed by a turn that
was then refused and they would have to find every one of them again.

message_attachments stores the BYTES, not a path. What is remembered has to be
what was actually sent; a path is a promise about a file Addison does not own.
It is bounded by construction - under 2 MiB each by the shell's own ceiling,
four per message - so the worst a message adds is ~8 MiB and only because
somebody chose four pictures by hand. A rewind deletes a message's pictures in
the same transaction as the message: with PRAGMA foreign_keys = ON that is not
tidiness, it is the difference between a rewind and an aborted COMMIT (the
widget_state precedent). The table is EXCLUDED from snapshot capture on the
`messages` line's terms - capturing one half without the other could only
produce a picture whose message is gone.

conversation.load rebuilds both directions, and the second is the one that
would have failed silently: the wire half redraws thumbnails, and Message.images
is what the model can still see. This history IS the model's memory of the chat,
so a reopened conversation that had dropped its pictures would go on being asked
about them. _persist_message therefore also derives rows from message.images
when no record is passed - the 4.8 continuation copies recent turns verbatim
into a new conversation, and without that fallback a chat that condensed itself
would keep the words and lose the pixels. Those copies have no filename, on
phase 1's reasoning: an invented one has a model answering about a receipt it
never saw.

model.availableRoles' cloud rows carry `vision`, the truncation_finish_reasons
pattern - a capability as structured data, never prose. models_catalog holds the
four answers as a COPY, because a capability is an instance method on a
per-model provider and a list path must not grow a round-trip per row; a test
asks the four adapters themselves so the copy cannot drift. Local models carry
nothing: Ollama's answer is per model (POST /api/show) and this path does not
fetch it. Absent means unknown, and the composer speaks only where it knows the
answer is no.

THE BUDGET ITEM IS CUT, and the plan is amended in this commit. It assumed a
turn-size estimator that walks messages; there is none. 4.8 measures a turn from
the provider's own usage report, which already counts the pictures the way that
provider bills them - a flat 1,600 on top would not improve the measurement, it
would double it, and context_budget.py would grow a seam it does not have.

The worker loop had reached what pyright will analyse: with the two new job
kinds it stopped with "code is too complex to analyze", and measurement showed
ONE more branch was already too many - so the next job kind anybody added would
have failed the type gate whatever it was. Fourteen of those branches were the
channel namespace's, and rpc/channels.py already owned all fourteen handlers, so
they moved there as _run_channel_job. Same order, same handlers, still called
from inside the loop's try, so every except arm still catches what it caught.

Nineteen tests, each mutated red before it was kept: the media-type refusal, the
fifth pick, the freed slot, the silent discard, the cleared pending set on a new
chat, the picker sentence passing through, the unknown id refusing before
anything is written, the relaxation in both directions (widen it and the blank
row comes back; remove it and a picture-only message cannot be sent), the spent
id, the rows landing beside the message, the picture-only first message not
titling the chat, the reopened chat carrying pictures to the thread AND to the
model, the rewind taking both, and the vision table against the live adapters.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant