Repository navigation
fix(mobile): keep what the reader was reading when older messages load on the phone page - #29170
brennanb2025 wants to merge 13 commits into
Conversation
A folded row's id is its first message's, so an older page that brings the start of a tool run (or an older sibling of a roster) replaced the displayed row: the list remounted it and the page's history split lost its first row. Rows now carry a presentation key that stays while any of their messages draw, handed on from the last committed render by the raw message ids each row draws, and a vanished key resolves to the row that took its messages.
…ollowing one to the follow owner The place-hold fired on the first drawn row's id, which a kept row key no longer changes, and held the lowest row on screen even while the reader followed the end, so at the 2,000 cap it wrote against the follow owner. It now fires when the source window's first message changes (an older page, a cap trim), only for a reader who is not following, and puts back the first tagged row on screen, else the nearest row the update kept, through the row keys. iOS bounce still gets no write.
…ls join it With the run's row kept, older calls joining its front pushed the lines the reader was on behind Show more. The reveal now counts the lines added above its first line apart from what Show more asked for, so those lines stay shown, each diff keeps its share, and Show less only undoes Show more. Lines and the run are tagged, so the page's hold puts the line being read back where it was. The flow test opens a chat inside a silent run, loads the rest from an old host's cursorless reply, then lands a reply and a send.
…already drew Pairing the run again for its first line on every render broke the bounded pairing a 2,049-call run relies on (one pairing per reveal). The flow test's icon mock names every icon the run reads.
Row-key hand-on walked the current rows oldest first, so when a trim left a run's first result alone above it, that orphan took the run's key and the open run remounted closed. Walk newest row first so the run keeps it.
…o the results it shows A cap trim that split the top run gave the run's key to whichever split-off result row a position-ordered scan met first: the result above it for calls made one at a time, the one below it for parallel calls. The run then remounted closed and the reader's line went. Each row is now identified by its own sources (a run by its assistant and call messages, a roster by its group, a lone result row by its results) and keeps the key of the one previous row it continues; results are content only. A key no row kept resolves to the row that took in what it drew. If identity ever came from two rows, neither inherits.
…t is still the same part The hold took a line only from the first row on screen and otherwise trusted that row's container. A result row absorbed by its run, a roster the fold moved to an older sibling, or a trimmed line then moved the reader. It now lists the tool lines on screen across every row (a run header only when no line shows, a row top only when neither), and puts back the first one still drawn: a run header only in the row that kept its key, a row top only while the same message places that row. One write, skipped under half a pixel.
… the hold's last cases into it An open run whose header is above the screen holds nothing: with only its Show more on screen, the rows after it keep their height when older calls join. Removing the header-on-screen check moves them 840 px. The collapsed case now checks the same rows. The iOS bounce and native cases move into the flow test over its page model, so the hold's separate fake scroller goes.
…t when the transcript grows RN Web reports content size a task after layout, so with no browser scroll anchoring a following reader saw one frame far above the end after Load earlier. One ResizeObserver over the page scroller and its content, bound to the list's mount, calls the same pin, which reads the live end and writes only when short of it.
…and layout to the live end The page's follow tests fold into one flow so the view test stays within its line limit; the place-hold reads the follow owner through one prop bag so the view does too.
The native list never needs the resize observer, so it shouldn't reach for the page-only node at attach.
|
Review loop status: converged on What this PR fixes: on the phone's chat page, loading older messages (tap Load earlier) used to collapse a tool run you had opened and move the line you were reading; at the 2,000-message cap, trims of a run's oldest calls did the same. Now the line you were reading stays where it was and the run stays open. Rounds (independent reviewers, each on its exact head):
QA on
Known limits (listed in the description, none worse than before): a lone tool result opened at the top shows closed once its call joins; omp Not covered here: following at the cap with browser scroll anchoring on is a separate shipped bug, fixed in #29198 (stacked on this PR). |
Under the history header the list sized spacers from measured places, which count the header, against guessed places, which don't, so the scroll range came out a header too tall and a following reader saw blank at the 2,000 message cap.
Drawing every row at the 2,000-message cap froze the iOS page during a live turn (the screen stayed on the first step for ~92 s): each append re-measured ~2,000 list cells. The blank flash it fixed comes back until the one-list page replaces the history header. This reverts commit 9cfa3c2.
|
Superseded by #29271, which carries this change together with the rest of the phone chat scroll work in one PR against main. |
Not ready (2026-10-16): on the iPhone page, a reader following a live agent turn at the 2,000-message limit sees the chat area go blank for 0.1-0.3 s about once per agent step (the shipped app loses its place there instead). An attempt to fix it here by drawing every row (9cfa3c2) froze the iPhone page for about 90 seconds during a live turn at the limit, so it is reverted (d400254). The flash comes from the page drawing older history in a separate block above the list; the one-list page (#29271) removes that block, and the iPhone check of it is running. The review status below predates both commits.
ELI5
On the phone page, an agent's tool calls fold into one row ("12× Edit …"). When you tap Load earlier, the older messages that arrive often belong to the same run of tool calls you were looking at. Until now the page treated that as a brand-new row: an open run snapped shut, the page's history rearranged, and you lost your place. Now the row stays the same row while older calls join it, an open run stays open with the lines you were reading still on screen and in the same spot, and the earlier conversation appears above it.
What Changed
The problem, as a reader saw it (phone page, partly the native app):
After:
Mechanism:
mobile-native-chat-row-keys.ts(new, phone only): each drawn row gets a presentation key. A row is identified by the messages it is made of, found through the raw message ids its blocks came from: a run by its assistant message and the messages that issued its calls; a subagent roster by its group; a row of tool results alone by those results. The results a run shows are its content, not its identity. When an older page or a cap trim regroups the window, a row keeps the key of the one previous row whose identity it carries, so a run keeps its key whichever side of it a split-off result lands on (above it for calls made one at a time, below it for parallel calls), and a result row never takes a run's key, even after the run's last call is trimmed. A key no row kept resolves to the row now drawing what it drew (an orphan result absorbed by its run resolves to the run). If identity ever came from two rows at once, neither would inherit a key, rather than one being picked by position. Only the last committed render is remembered, per chat, so nothing is stored or persisted. Message ids used for turns, sends, copy and disclosure are untouched, and the shared fold (also used by desktop) is not changed.keyExtractor, the page-history split and the row tags use that key. The page-history split follows a vanished first row to the row that took its messages instead of resetting.ToolRuntracks lines added above its first line separately from what "Show more" asked for, and tags each line by its existing tool-line identity.MobileNativeChatScrollHoldnow fires when the source window's first message changes (an older page, a cap trim, a replacement), only when the reader is not following (read from the existing follow owner through a newisFollowingaccessor). Before the update it lists, in page order across every row on screen, the tool lines on screen (a row with none on screen offers its run header if the header itself is on screen, otherwise its own top), each with its own height. After the update the first of those still drawn goes back to its height, in one write: a line counts in the row now drawing its old row's messages (an orphan result's line counts as its call's once they pair); a run header only in the row that kept its key, so a vanished result row can't stand in for the run that absorbed it; a row's top only while the same message places that row (the row keys now also say which message places each key's row this render), so a group that keeps its key but moved doesn't drag the screen with it. If nothing on screen survived, the nearest row below, then above, stands in; if none did, nothing is written. No write when it moved less than half a pixel, and iOS bounce still gets no write.use-mobile-native-chat-tail-follow.ts), on the page only: oneResizeObserveron the list's scroller and its content, attached for as long as the list is mounted, pins a following reader to the end, read from the live scroll height, before the browser paints. Until now the page heard about growth only from the list's content-size report, which React Native Web delivers a task after layout, so with no browser scroll anchoring (iPhone Safari) one frame could paint thousands of pixels above the end after Load earlier. The content-size report and viewport layout now call the same pin, which writes only when the view is short of the live end and never while iOS bounces past either end, so a late report finds the view already at the end and can't pull it back. The remembered content height it used to pin to is removed; the native app is unchanged.Why
Why rows keep a key on the phone, and not a cut: the cut hid loaded content to avoid regrouping. It can't work for a run with no visible boundary (the empty taps), and any later boundary makes it hide what the reader is watching (the vanishing run). The common pattern is the opposite: a loaded row keeps its identity and older members join it.
Why on the phone and not a host-side page boundary: hosts send raw messages, and phones meet older hosts (including remote runtimes over SSH that ignore the page cursor and resend the whole tail). A host boundary would leave every older host on the old behavior, and a page made only of tool calls has no boundary to cut at. Keying by raw message ids works with every host as-is, including a cursorless reply where every message is a new object.
Why one hold that stands aside while following: two writers to the scroll position at the same commit is how earlier rounds broke follow at the cap. The hold reads the follow owner's own state rather than keeping a second flag, and the follow owner learns of page growth before paint, so a following reader needs no help from the hold.
Why turn off the page list's windowing rather than fix its guesses: the wrong space comes from the list mixing measured positions (which count the header) with guesses (which don't), and any large header triggers it. A fixed row height isn't possible because rows vary, and keeping the history out of the header is the one-list follow-up. Turning windowing off removes the guesses entirely, and it costs nothing a reader with loaded history wasn't already paying.
Supersedes the approach in #29065 (kept open for its history).
Differences from the common pattern, labelled:
!commandor python cell as one message that holds both the command and its output. Several such cells after a reply share the reply's row; when the cap trims the reply (or an older page brings it back), that one row becomes several rows (or several become one). A key can stay with one row, not several, and picking one by position is what this PR removes, so those rows remount closed, as they do today without this PR.Linked Issue
None. Follow-up to #28413 (phone page history) on top of #29043 (tap-only paging); restarts the approach of #29065 per the design ruling.
Visual Proof
All on the exact head
9953366737funless noted, phone page at 390×844. Left: B1 (#29043, the base this stacks on). Right: this PR.1. Reading inside an open tool run, then Load earlier (Windows Chromium). Before: the tap collapses the run into a one-line summary and the line being read is gone (the message below jumps 316 px). After: the run stays open, the line stays at the same height across three taps, and older calls join the run above it.
2. A scrolled-up reader on an open run while the 2,000-message cap trims the run's oldest calls (Windows Chromium,
559c9b8210d; this case's code is unchanged since). Before: the run collapses. After: the line stays put and the run stays open.3. Known limit, unchanged from B1: a lone tool result opened at the top joins its run when Load earlier brings the call, and shows closed; the place is kept (
559c9b8210d).4. Following live output while an older page lands (frame-sampled, no screenshot can show a single frame): with browser scroll anchoring off (iPhone Safari's case), the previous head painted one frame 3,657-7,703 px above the end; this head paints 0 such frames in 16/16 landings on Windows Chromium (anchoring on and off) and 4/4 on the iOS simulator (real WebKit), and the reader is still following afterwards.
5. Desktop app smoke (Windows, built from this head, isolated profile): a 300-message chat scrolled to the top with older history loading on the way; nothing blank.
Testing
mobile-native-chat-reading-place.test.tsx(new): the real phone fold, row keys, page-history split,ToolRunand hold over a page model that lays out the rendered rows and counts scroll writes. A chat opens on a tool result inside a 40-call silent run; the reader opens the run and a diff, and either parks on a line inside the run or stays at the top beside Load earlier (where the result row is the first row on screen). Two older pages arrive as an old host's cursorless replies (new objects), the first again starting on a result. Each time the line being read is back at its old height with at most one write; then the earlier turn is above the list, the run keeps its row and stays open with the same diff length, the result rows resolve to the run that absorbed them, and a reply and a send leave the run drawn. The rows after the run keep their height when it is collapsed (its header holds) and when it is open with only its Show more on screen (its off-screen header holds nothing). The view is left alone while iOS bounces the list past the top, and in the native app. A subagent roster first on screen keeps its key when an older sibling joins (it moves up) and when its first sibling is trimmed (it moves down), and the messages after or before it keep their heights. Plus the 2,000-cap case: a trim and an append of equal height make no write while following (with and without the live line) and hold a parked reader on the same message with one write; a trim of the very line the reader is on keeps the next line at its height; and for a run of calls made one at a time and a run of parallel calls (each call, then each output), the reader opens the run and parks on a line, then two single trims and one two-message trim (each with an append) leave the run under its original key, open, with the line at the same height, and the first split-off result under its own key; once the run's last call is trimmed, no output row takes the run's key.Each part was checked to be pinned by switching it off in a bundled copy: no key hand-on, no alias, no hold write, no line anchor, no reveal continuity, diff budget by shown lines, and hold ignoring follow each fail a case. The parallel-call cap case and the last-call endpoint fail with the previous key assignment. The reader-at-the-top, collapsed-header, roster and trimmed-line checks fail with the previous hold; a run header followed through the absorbing row, a row top without the placement check, lines from the first row only, writing every correction (no single write, no sub-pixel skip) and a write while following each fail a case.
MobileNativeChatView.test.ts: one page flow. A following reader taps Load earlier and the older rows land with a larger live height; with only the resize observer delivered (the late size report held back) the view is already at the new end; the late report then makes no write. The pin's own move short of a reply that grew meanwhile doesn't stop following; after the reader scrolls up, more growth makes no write and the jump control shows; back at the end it follows again, and a smaller viewport pins to the live end, never the list's estimate. It fails on the previous head and with the observer removed. It replaces the page's three separate follow tests, which are now steps of this flow.MobileNativeChatScrollHold.test.tsxis removed: its iOS bounce and native cases now run in the flow test above, over the same page model.use-mobile-native-chat-page-history.test.tsxtakes the new keys argument.Touched tests were run under plain Node locally and on Windows; lint, typecheck and the full suite run in CI. Real-device QA: Windows Chromium (all cases, anchoring on and off), the iOS simulator (real WebKit, the following-reader case), and a desktop app smoke; see Visual Proof.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Agent skill upstream boundary
Notes
MobileNativeChatView.tsxsits at its line cap, so three one-use locals there were inlined to make room for the wiring.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)