Repository navigation
Description
A sent prompt appears once, even when the server echo text or filename differs from the optimistic row.
Session Chat currently retires an optimistic send by comparing the visible text and attachment filename. That fails whenever the echo is the same turn in a different shape: a skill whose token was not on the wire text (#795), a slash command whose expanded template does not collapse, or a file the server renamed. The duplicate row then stays in the timeline.
Both protocols accept a client message id (msg_…) and use it as the id of the user message they create:
- v2
POST /api/session/:sessionID/prompttakesid. - v1
POST /session/:id/prompt_asyncandPOST /session/:id/commandtakemessageID.
Send that id, use it as the optimistic row id, and treat a server user message with the same id as the echo of that row. The id match replaces only the text-and-filename comparison. The existing rules on when an echo retires the row stay: a waiting steer echo does not retire a shown optimistic row, and an echo already present in the baseline does not count. Display rewriting stays presentation only.
Client id format. Build the id the way both servers do: msg_, then 12 lowercase hex characters encoding epochMillis * 4096 + counter (the counter restarts at each new millisecond), then 14 random characters from 0-9A-Za-z. Servers only check the msg_ prefix. History order does not depend on the id (v1 sorts by server time, v2 by sequence), so the device clock only needs to be roughly right.
409. v2 answers 409 only when the id belongs to another session or to a non-user record. That is a failed send, not an echo: handle it like any other send failure (the optimistic row goes away, the draft comes back, the error shows). Every new send gets a new id. Never reuse an id on v1: it does not deduplicate, so a repeated messageID writes the message again and starts another run.
Retrying a send with the same id is out of scope.
v2 POST /api/session/:sessionID/command takes no client id, and its echo is the expanded template, which the app cannot collapse because the v2 command catalog has no template. Retire that row on the first new user message after the send: a user row whose id was not loaded when the send began. Text-and-filename matching goes away.
Related: #795
Remaining:
- Send a client
msg_id on v2 prompt, v1prompt_async, and v1command, and use it as the optimistic row id on iOS and Android - Match the echo by that id regardless of display text or filename, keeping the steer and baseline retirement rules
- Retire a v2
POST …/commandrow on the first new user message after the send; remove text-and-filename matching - Generate ids in the server format
- Treat a v2 409 as a failed send
Activity
#796 Retire optimistic sends by client message id (#802)