Skip to content

fix(mobile): keep what the reader was reading when older messages load on the phone page - #29170

Closed
brennanb2025 wants to merge 13 commits into
brennanb2025/mobile-page-history-tap-loadfrom
brennanb2025/mobile-page-keep-reading-place
Closed

brennanb2025 wants to merge 13 commits into
brennanb2025/mobile-page-history-tap-loadfrom
brennanb2025/mobile-page-keep-reading-place

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​426 $\color{#cf222e}{\Huge{\mathbf{−}}}$​173 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​253
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​464 $\color{#cf222e}{\Huge{\mathbf{−}}}$​108 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​356

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):

  • A chat opens partway through a long run of tool calls. You open the run and read a few lines, then tap Load earlier.
  • Before: the run's row was replaced by a new one, because a folded row is named after its first message and the older page brought an earlier first message. The open run collapsed, rows above the list were re-indexed (the page's "history above the list" split reset), and the view jumped. Successive taps replaced the row again each time.
  • The earlier attempt (fix(mobile): phone page keeps the message you were reading when older messages load #29065) hid the start of a run until it could no longer change. In its review history that drew nothing for several taps in a row (empty taps), and it hid the very run the reader was watching as soon as a reply or a send arrived (the run vanished, leaving only "done" or the new message). Its first-message hold also wrote a scroll correction while the reader was following the newest output at the 2,000-message cap, which then stopped the page from following.

After:

  • A row keeps its place on the page while any of its messages are still drawn. Older calls joining a run join the existing row instead of replacing it, so an open run stays open and nothing below it remounts.
  • Inside an open run, lines that arrive above the first line you had are added above it. The lines you were reading stay shown and stay at the same height on screen; "Show more" and "Show less" still only change what you asked them to change, and an opened diff keeps the length it had.
  • If you are reading somewhere in the middle (not following the newest output), or at the top beside Load earlier, the page keeps what you were reading where it was when older messages land above you or the cap trims earlier ones: the first thing on your screen that is still drawn (a tool line, else a run's header when it is on screen, else a message) goes back to the height it had. If the line at the top of your screen was itself trimmed, the next line keeps its own place rather than the run's top. A subagent roster that keeps its name but is now drawn at an older sibling's place is not followed; the messages you saw after it stay put (one paging limit is listed under the differences below). If you are following the newest output, the page leaves scrolling to the follow logic: no correction is written, at the cap or anywhere else. The follow logic now sees the page grow before the browser paints, so tapping Load earlier while following no longer flashes a frame far above the end on iPhone Safari.
  • At the 2,000-message cap: when the cap trims the beginning of a run, the remaining run keeps its expanded state, including when tool calls were issued in parallel. On the phone page, a retained visible call line stays in place. A line whose own call was trimmed away can't stay on screen, and once every call of a run has been trimmed, the results left behind are drawn as rows of their own.
  • Nothing is hidden any more: every page draws what it brought, and a later reply or send never removes a run that was already on screen.

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.
  • The list's 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.
  • ToolRun tracks lines added above its first line separately from what "Show more" asked for, and tags each line by its existing tool-line identity.
  • MobileNativeChatScrollHold now 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 new isFollowing accessor). 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.
  • The follow owner (use-mobile-native-chat-tail-follow.ts), on the page only: one ResizeObserver on 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:

  • Intended: row identity is established on the phone from raw message ids rather than sent by the host, because hosts send raw messages and older hosts must keep working.
  • Intended: the hold anchors a line, run header or message rather than correcting by a height difference, because live output can land below the reader in the same update and a kept row can grow inside itself. It also checks that the part it anchors is still the same part of the conversation (a row that keeps its key can grow, be absorbed or be moved by the phone's grouping), which a list whose rows never regroup doesn't need.
  • Intended: the hold is captured when the page lands, not when it was requested, so a reader who scrolled or resumed following meanwhile is judged by what is actually on screen.
  • Intended: no correction while iOS is bouncing the list (kept from the parent PR).
  • Temporary: the page still draws loaded history in a separate block above the list; the one-list follow-up (Keep phone chat history in one window while preserving reading position #29271) replaces it. Until then, a reader following a live turn at the 2,000-message limit on iPhone sees a brief blank once per agent step, and if a subagent roster row was the list's first row and an older sibling loads, the roster moves up and the rows between re-index.
  • Behavior change, intended (native app): an open run that gains older calls keeps its cell and stays open, but its lines shift down by the height of the inserted lines, because the native list keeps a cell's top, not a position inside it. Before this change the run collapsed and remounted, so this is strictly better: the run and its lines stay. A native line-level hold would remove the shift; it is not part of this PR. Collapsed runs hold.
  • Behavior change, intended: an expanded run that gains older calls shows them above the reader's lines, and its "Show more" count grows accordingly. Before this change the run collapsed; now the lines being read stay where they were and the older calls take their place above them, as older history does everywhere else in the chat.
  • Known limit: if the window starts on a tool result shown as its own row and you open it, then tap Load earlier and the older page brings that result's call, the result joins its run and shows with the run's closed state, so the line you opened is no longer shown open. The page keeps your place at the run. Same as before this PR; keeping it open needs open state owned per line rather than per row, which no follow-up has been planned for.
  • Known limit (omp shell cells): omp saves a !command or 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.
  • Known limit: On a desktop host older than 1.4.201 (no tool-call ids) that also answers Load earlier with its whole recent window instead of only the older messages, an expanded run that gains older calls switches to its oldest lines, so the lines being read move behind Show more. The run stays open and the message below it keeps its place.
  • Pre-existing, out of scope: a structured-lane turn can collapse when an older page brings its user message (its turn key changes); and on a chat switch a parked reader can get one hold write against the shared streaming row (chat-switch follow reset owns it).

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 9953366737f unless 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.

Before (B1) After (this PR)

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.

Before (B1) After (this PR)

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).

Before (B1) After (this PR)

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, ToolRun and 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.tsx is 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.tsx takes 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Phone only (page and native app); desktop and the shared fold are unchanged. No host, wire or saved-format change, so older phones with newer hosts and newer phones with older hosts both keep working.
  • Cost: on an ordinary streamed frame the key pass is one lookup per row. At the 2,000-message cap every append trims the oldest message, so the identity pass and the hold run on every frame there; the QA run records frame cost at the cap.
  • MobileNativeChatView.tsx sits at its line cap, so three one-use locals there were inlined to make room for the wiring.
  • Author: Brennan (X: @BrennanKB5).

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

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.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review loop status: converged on 9953366737f.

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):

  • Round 1: two identity findings at the cap (a split run handing its key to a result) — fixed by making a row's key belong to the messages it is made of, never to results.
  • Round 2: the same class for parallel calls — fixed by the same rule (a design ruling adopted it as the general mechanism).
  • Round 3: the place-keeper anchored on the wrong part of the screen in three layouts — fixed by holding the first part of what you were reading that is still the same part.
  • Round 4: pass; three small test/body items fixed.
  • Real-browser QA then found that a reader following live output saw one painted frame far above the end when older messages landed (only without browser scroll anchoring, i.e. iPhone Safari). Fixed in 9953366737f by letting the follow logic learn about new content before the browser paints. Round 5: pass, no findings.

QA on 9953366737f (screenshots in the description):

  • Windows Chromium, anchoring on and off: reading place and open run kept across three Load earlier taps (B1 collapses the run); parked reader at the cap held; following reader 0 painted frames off the end in 16/16 landings.
  • iOS simulator (real WebKit): following reader 0 painted frames off the end in 4/4 landings, still following afterwards.
  • Desktop app smoke on Windows: pass.

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 !command cells remount after a trim, as today; hosts older than 1.4.201 that resend their whole window can reveal a run's oldest lines.

Not covered here: following at the cap with browser scroll anchoring on is a separate shipped bug, fixed in #29198 (stacked on this PR).

Merge order: #29137, then #29043, then this PR.

@brennanb2025
brennanb2025 marked this pull request as ready for review October 16, 2026 01:01
@brennanb2025
brennanb2025 marked this pull request as draft October 16, 2026 07:56
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.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Superseded by #29271, which carries this change together with the rest of the phone chat scroll work in one PR against main.

@brennanb2025
brennanb2025 deleted the brennanb2025/mobile-page-keep-reading-place branch October 19, 2026 20:54
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