chat: keep how far each session is shown, and take the stream up from there #68
Loading…
Reference in a new issue
No description provided.
Delete branch "shown-cursor"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The chat side keeps how far it has shown each session, in the registry's
shown(schema 2, #64), and takes the stream up from there.Info.Shownin every state. A new session is shown from its first event, which a subscription "from now" could miss (its role prompt, "From gc"); one shown before a restart is not shown again.[chat] catch_up(a duration, default one hour) are left out, and the room says so in one notice that links the session's transcript, also when only old events are left.Durationmoves fromconfigtochat, withconfig.Durationas its alias, so that[chat]can have one.Not done here: a restart in the middle of a turn does not restore what the renderer remembers (the plan notice's id, the reply-to links of tool results); those notices come again without them.
Read at
c218d17. The suite is green here under-race,internal/chatten times withGOMAXPROCS=1. The shape is right: one cursor, moved only where nothing waits unsent, the stream read again from it. Three things stop it from merging, each a case where the room gets the same thing twice or without end.1. A refusal is treated as an outage, and then never ends. Any error of
SendorReactends the reading and the stream is read again from the cursor after five seconds. That is right for a homeserver out of reach. It is wrong for a homeserver that answered and refused, because the same event is refused again at every reading, and everything between the cursor and that event is sent again each time.One way there with nothing unusual: the owner writes while the agent is in the middle of a paragraph. The prompt waits, the renderer puts ⏳ on the owner's message, and the cursor is behind it because text is pending. Now one send fails for any reason. The stream is read again in the same process, the room's record of the owner's message is still there (
promptMessage), and the renderer puts ⏳ on it a second time. Tuwunel 2.0.0 answers that with(tried here: the same reaction twice by one user). That is an error of
React, so the reading ends, and five seconds later it does the same, with the paragraphs since the cursor sent once more each time. A message the homeserver will not take for itself (too large, forbidden) does the same.So: tell "out of reach" (no answer, a 5xx, a 429) from "refused" (the homeserver answered with an error of its own). Read again only for the first. A refusal is logged, as before this change, and the event counts as shown; a duplicate reaction is the reaction being there already.
2. A tool notice and a permission request can be behind the cursor.
settledis false while a plan edit waits, and the plan's edits are throttled (1.2 s), while Claude Code's usual order is a plan update and then the tool call at once. Tried on the renderer: a plan, a second plan 100 ms later, a tool call and a permission request for it; after the permission message and its reaction are sent,settled()is false. A restart, or a re-reading after a failed send, in that window shows the tool notice and the permission request a second time, the first request left with nothing behind it. The coordinator has this as the one thing that may not happen.Make every event that sends what may not come twice a settled point: finish the plan's edit before a tool notice, a tool result and a permission request are sent, as the answer and the thoughts are already flushed before them. Then only text is ever behind the cursor.
3. The cursors of a city that ran 0.6.0 are stale, and the first start on this version replays up to an hour. 0.6.0 has the column and does not move it: in the city today
gueststands at 1096 of 1166 events andhostat 631, both where the migration put them at 09:16:26Z, and everything since was shown live. This code follows a session fromInfo.Shown, so at the roll each room is shown again whatever is younger thancatch_up, permission requests and their answers among it, and told that the rest was left out.The version that begins to keep the cursor has to begin it at the last event. That is a migration of the registry (schema 3:
shownto each session's last event, as the migration to 2 set it), with roomcity-b8; say in the pull request which of you does it, and it lands with this or before it.Two things to say in the pull request and the README, not to change:
!stopwithdraws it. That was so before this change; the description's "an answer to a request the room never saw" covers the answer and not this.It conflicts with main since #70: rebase when you take these up.
c218d17ef51211172b051211172b0591506374b791506374b7342991916d