diff --git a/Working-notes.md b/Working-notes.md index 1d63347..193e060 100644 --- a/Working-notes.md +++ b/Working-notes.md @@ -44,6 +44,18 @@ Read this before changing anything. Each rule has its reason, because a rule wit (`Transfer.waiting`). Anything new that sends or fetches in a loop, or from a coroutine that outlives the screen (`viewModelScope`), asks the gate before each request. A `viewModelScope` does not stop when the phone locks; that is why the gate exists. + **A reply nobody asked for from the screen is followed only while the gate is open** + (`ChatViewModel.follow(own = false)`, `InstanceGate.whileOpen`): when the gate closes its + stream is let go, and on the return one read catches up and follows what is being written + then. Only a reply the person started from this screen (`own = true`: send, edit, + regenerate, continue, execute) keeps its stream behind the lock -- the request under way -- + and even that one's follow-ups wait at the gate: a broken stream opened again + (`StreamClient.follow(turn)`), the read after `done` with a `next`, the read after a close + without `done`. Anything new that chains a request onto a stream's end waits with + `gate.passLater()`, which sleeps until the gate is told of a change; `pass()` looks at the + lock every second and is for waits a person is watching. The events route itself is opened, + and opened again, only at the gate (`LembasApp.eventFrames`), and collected only from + `repeatOnLifecycle` or a resume effect, never from a scope that outlives the screen. 6. **The token is sealed** with an AES key in the Android Keystore (`auth/Instances.kt`) and the app's data is excluded from backups: a copy would be ciphertext nobody can open. 7. **No colour outside the theme.** `ui/theme/Tokens.kt` is generated from the server's @@ -173,6 +185,12 @@ design change, before a phone. or when the list went back towards its start (`wentBack`: a wheel, a key, a screen reader). The app's own scroll to the end, left short of it by something that arrived meanwhile, must never read as "scrolled away" -- that is the web's clamp bug in Compose's clothes. + **Every scroll the app makes goes through `ownScroll(own) { … }`**, which counts it: a scroll + under way that the app did not start is the person's (`personScrolls`, `scrollWasPersons`), + whatever moves the list -- a wheel, a key, a screen reader have no `DragInteraction`. Rows + that arrive while the person scrolls do not move the list (`movesToEnd(…, personScrolling)`); + a bare `list.scrollToItem` outside `ownScroll` would be taken for the person's and could end + the following. - **A reply's row does not change height when the reply ends**: the pulse of a reply being written stands in the finished foot's place (`FootTop`, `FootHeight` in `Transcript.kt`, an icon button's 48 dp). Change one and change the other. A picture's place has its shape from @@ -249,22 +267,54 @@ design change, before a phone. Each return to the front reads the chat once before listening: a reply that started and ended meanwhile is said by nobody. Both wait at `InstanceGate`. An instance without the frame costs that one read and nothing else. + **Reads of the transcript for news go through `Reads`** (`rereadAndFollow`): whoever learns + something takes `reads.mark()` at that moment, before any wait, and a read that began after + the mark and answered stands for it. A burst of frames, or the return read and a let-go + reply's catch-up, is one request. The return read runs beside the listening, not before it, + so a reply that starts during it is heard; what is heard is checked against what the read + found (`asksFor`, asked again inside the lock) before anything is read again. + **The frame with `live: false` is also a reply's end** (an instance that says the ends sends + the same frame again when a reply ends). For the open chat `asksFor` already makes it cost + nothing when the reply was followed to its `done` or is drawn as finished. - **`reply` is a moment, not a state** (`EventsHub.MOMENTS`): the hub tells a late watcher the last `schedules` and `reports`, never the last `reply`. A new kind of frame on `/events` is one or the other; decide it there. -- **The drawer's list reads its newest page again shortly after a `reply` frame** (`listSoon`, - `ChatsState.withNewest`), which is how a chat moves up and gets its dot while the drawer is - open. Nothing says when a reply ends: the running dot is as old as the last read. +- **The drawer's list is merged by id** (`ChatsState.withNewest`): the newest page's rows first, + then every row held that the page does not name, in its order. Never by position: a chat that + comes up from a later page is not a prefix of the old list, and cutting at "the last row the + page names" dropped every chat in between. A held chat that changed after the page's last one + did and is not in the page is gone on the server (the list is ordered by `updated_at`). +- **The list is read by itself only while the drawer is open** (`ChatsViewModel.shown`, + `readsFor`), through `Soon`: a trailing pause with a longest wait, and a read under way is + never cancelled by the next frame. A start in a chat already shown as running reads nothing + (every reconnection of `/events` says all live replies again). A frame with `live: false` + clears the row's running mark and marks it unread, with no read (`ended`) -- not unread for + the chat on screen (`ChatsViewModel.open`). +- **Whether an instance says the ends is learned, not assumed** (`ReplyEnds`: a `live: false` + for a reply it had said with `live: true`). Until then, and for instances that never do, + `watchRunning` reads the list again at a bounded rate (`runningPause`: 5 s doubling to a + minute) while a row shows running and the drawer is open and in front; once proven, never. + An end frame missed while `/events` was down leaves a mark until the drawer opens again. - **There is still no stream frame for a media job.** `watchMedia` polls while the screen is in - front; a job's `told` turning true makes the chat read itself again (`woke`), through the same - `rereadAndFollow` as the `reply` frame, so the two cannot follow one reply twice. + front, each request at the gate; a job's `told` turning true makes the chat read itself again + (`woke`), through the same `rereadAndFollow` as the `reply` frame, so the two cannot follow + one reply twice. How often a finished job was asked whether it told the chat is kept on the + model (`toldWaits`), not in the loop, or every return to the screen would start it over. - **A transcript read again goes through `ChatState.withNewest`**, never `copy(messages = read.messages)`: the newest page replaces only itself, and the older pages a person loaded stay above it. Replacing them takes the row being read from under the reader. Only a compaction, which rewrites the transcript, reads it whole (`refresh(whole = true)`). + The kept pages need no reconciling as the server is: it only ever removes a transcript's tail + (a rewind, an edit) or a queued prompt, and a page that still joins the rows above it proves + they are older than anything removed; the answer carries no count or marker to compare. A + server that learns to delete or rewrite a row in the middle must say so in `GET /chats/{id}`. + **A transcript left open is held to a size** (`ChatState.capped`: past 600 rows the newest + 400 stay and "older" is offered), only under a person at its end (`ChatActions.reading`). - **A turn nobody typed is `Message.byMachine`** (`machine`, or `origin` `harness`): a `MachineNote`, never the person's bubble. An empty finished reply after one, in an agent chat, - is the server's one line (`replyUnrecorded`); a reply still being written is never that. + is the server's one line (`replyUnrecorded`); a reply still being written is never that -- + by the screen's own knowledge of which reply is live, not only by the row's `complete`, which + reads as true when a server leaves it out -- and neither is one that holds a plan. - **The model lists are narrowed where they are read** (`ApiClient.modelList`, `agentModelList`: `capability` `chat` only). A picker fed from anywhere else narrows with `forChat()` itself. - **`gen-strings.py --check` reads keys as `[a-z_]+`**: a key with a digit (`media_model3d`) is