Skip to content

fix(mobile): phone page keeps the message you were reading when older messages load - #29065

Closed
brennanb2025 wants to merge 11 commits into
brennanb2025/mobile-page-history-tap-loadfrom
brennanb2025/mobile-page-hold-reading-message
Closed

brennanb2025 wants to merge 11 commits into
brennanb2025/mobile-page-history-tap-loadfrom
brennanb2025/mobile-page-hold-reading-message

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​198 $\color{#cf222e}{\Huge{\mathbf{−}}}$​48 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​150
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​202 $\color{#cf222e}{\Huge{\mathbf{−}}}$​119 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​83

ELI5

On the phone's chat page (the over-the-air version of the phone app that runs as a web page), when older messages load above you, Orca moves the list so you stay where you were. It did that by holding the lowest thing on screen, which is often the agent's live status line at the bottom. If the agent's reply grew in the same moment, that line moved further than the messages did, and you ended up past the message you were reading. Now Orca holds the first message you can see, so you stay on it.

Holding a message only works if that message is still there after the load. When the oldest loaded messages were the middle of a run of tool calls, loading the older page merged them into the agent's message above, so they disappeared and you jumped a page. Now the page doesn't show that leftover piece of a run until the older page brings the rest of it. If that piece is a long run of tool calls with no words, longer than one page of history, a single tap on Load earlier keeps loading until something new appears, instead of leaving you tapping pages that show nothing.

The same hold covers the 2,000-message limit: when the oldest message is dropped and it was the one you were reading, or only the live status line is on screen, Orca holds the nearest message that's still there instead of letting the view move.

Stacked on #29043 (older history loads only from the Load earlier button). Review that one first.

What Changed

The problem. On the phone page the web list doesn't keep the reader's place when rows are added above them, so Orca corrects the scroll position itself, once, in the update where the first row changes (a page of older history landing). On main the correction anchors the lowest element on screen: the list's own rows are scanned from the bottom, and the footer (the live status line and any messages waiting behind the running turn) counts too.

  • When the footer is the lowest thing on screen and the agent's output lands in the same update as the page, the footer moves by the page plus the new output. The correction moves the reader by both, so they end up past their message by the height of the new output.
  • When the footer is the anchor and the turn ends in that update (the status line goes away), the anchored element is gone, nothing is corrected, and the reader is thrown a full page away from their message.
  • At the 2,000-message limit, a new message drops the oldest one. When that was the message on screen, or only the live status line was on screen, there was nothing left to hold and the view moved by the dropped row's height.
  • Rows change identity when an older page lands. The phone groups a run of tool calls into the agent message before it. History is paged by message count, so a page often starts in the middle of such a run, and the page draws that piece as rows of its own. When the older page arrives with the agent message the run belongs to, those rows are merged into it and their ids are gone. Two things key on those ids: the scroll correction (its anchor is gone, so the reader jumps a page) and the page's history split (since fix(mobile): keep the chat where the reader scrolled to #28413 it keys on the list's first row; when that row disappears it puts every row back in the list, the list's row indexes shift, and the web list can briefly drop the rows the reader is on).

Before (on main), on the phone page: tap Load earlier while the agent is replying, or just as it finishes, and the view can land below the message you were reading, or a whole page away from it.

After: the message at the top of your screen stays exactly where it was when the page lands, whatever happens to the live status line or the Load earlier button in the same update, and wherever the page boundary fell in the agent's tool calls. While older history is still available, the page starts at the first message the grouping can't merge backwards: typically the agent's next message with words, or your next prompt. The leftover tool calls before it (one or two rows, an orphan result and the rest of a run without its message, though those rows can carry dozens of calls) show up when you tap Load earlier, inside the message they belong to. If one page of older history doesn't reach the start of that run (a run of calls with no words longer than a page), the same tap keeps loading, with its spinner up, until a new row appears above, or the history, the 2,000-message limit, a failed page, switching chats or leaving the chat ends it. One tap reads at most 8 pages within about 15 seconds (#29137's limits for every Load earlier tap); a run longer than that stops quietly with what it loaded, and the next tap reads on. A failed page (refused, an error, or no answer) ends the tap and shows the retry line under Load earlier ("Couldn't load earlier messages. Tap to try again.", from #29137, which this stack sits on); the next tap clears it and reads on. A page overtaken by a fresh window from the host ends the tap quietly, with no line. Once the whole history is loaded, nothing is held back.

At the 2,000-message limit, if the message you were reading is the one dropped, the next message on screen stays where it was; if only the live status line is on screen, the last message above it does.

Mechanism.

  • MobileNativeChatMessage.tsx: every message row carries testID="chat-row:<message id>", which React Native Web draws as data-testid on the page. (On native it is an accessibility identifier and nothing reads it.)
  • MobileNativeChatScrollHold.tsx: before the update, it finds the message rows by that attribute (querySelectorAll('[data-testid^="chat-row:"]')), so the Load earlier button and the live status line are never candidates without the hold knowing how the list's header and footer are built. It finds the first message on screen with a binary search over the rows' bottoms (rows are in normal flow, so their bottoms are ordered; up to 2,000 rows), and records the id and position of it and of the messages after it on screen (or, when no message is on screen, of the nearest one). After the update it puts back the first of those that's still there, found by id, so one rule covers the reader's own message, a message the 2,000-message trim dropped, and the live-status-line-only case, and it still works when the update redraws that row in a different place. Timing, trigger and the iOS bounce guard are unchanged from fix(mobile): phone page loads older messages only from the Load earlier button, so the chat no longer freezes at the top #29043.
  • native-chat-tool-fold.ts: firstToolFoldBoundary names the first drawn message the tool grouping places the same whatever comes before it (it can't join an earlier run, and it starts or ends one itself). It reads the grouping's own rule: the "ends the run" condition is moved into endsToolRun, used by both, so they can't drift. The grouping's output is unchanged.
  • mobile-native-chat-render-data.ts / MobileNativeChatOverlay.tsx: on the page, while an older page can still load, the list is grouped from that message on. Every row the page draws then keeps its id when older rows arrive, so both the scroll correction and the history split find their row.
  • use-mobile-native-chat-session.ts: a page is counted in raw messages, but the reader sees grouped rows. Reading on is already built into fix(mobile): Load earlier messages always ends, and says when it can't, in every phone chat #29137's one older-page loader, which both chat types use: it reads the next page in the same tap whenever a page answers "drew nothing", with one spinner, one retry line and one limit for the whole tap (8 pages, about 15 seconds), and it ends the tap on the existing stops (no more history, the 2,000-message limit, a failed or refused page, a chat switch, a fresh window from the host, unmount). This PR supplies only that answer for the transcript chat: loadEarlier takes an optional reader of the list's first drawn row (the page passes it; native doesn't), and a page that lands without changing that row answers "drew nothing". Structured chats ignore the argument; they already answer it from their own pages. No effect watches the list. Nothing changes in the paging request or the wire.

Lands and reverts on its own. Reverting this commit brings back main's lowest-element anchor; nothing else depends on it. The next PR in the stack (how the page follows new output) builds on it.

Why

The first visible message is what the reader is reading, and it's the anchor the common pattern uses (lists that hold place keep the first visible item where it was). Holding by a height difference instead (move by however much the content grew) would count the new output below the reader too, the same bug in another form.

The page boundary is made stable rather than teaching each reader of row ids to survive a vanished row. The common pattern never splits a group of tool calls across history pages (pages end on whole turns, or grouped rows keep one id across pages), so the rows a client draws never change identity when older rows arrive. Orca's pages are cut by the host by count and bytes, so the phone starts its list where the grouping can't reach back instead; changing the host's page bounds would touch the paging request and older hosts. Fixing each reader instead (hold the next surviving row, re-split history on the next surviving row) leaves every future id-keyed reader to rediscover the same case, and still fails when the merged rows fill the screen.

Rows are identified by an attribute rather than by their position in the list's markup, so the hold doesn't need to be told whether the list currently has a header, a Load earlier button or a footer. That avoids classifying the old layout with the new props, which was a review finding on #28807.

Differences from the common pattern.

  • Intended: Orca holds the place itself on the page, with one scroll write when the first row changes; the web list can't do it.
  • Intended: messages waiting behind the running turn (drawn in the footer under the live status line) are messages too, so they can be the anchor when no other message is on screen. The live status line never is.
  • Intended: when only the live status line is on screen, Orca holds the last message above it, not the line (main held the line, which moves as output arrives).
  • Intended: the page boundary is aligned on the phone, not by the host's paging, so no request, host or older peer changes. A page shows a row or two fewer at its top until Load earlier.
  • Intended: because the phone, not the host, decides where a page starts, one Load earlier tap can take several page requests (at most 8, within the tap's ~15 s limit): the common pattern cuts pages on whole turns on the host, so every page has something to draw. This is safe to keep: older hosts work unchanged (each request is the same request as before), and the extra round trips happen only for a run of tool calls with no words that is longer than a page.
  • Intended: native builds keep drawing the leftover piece of a run at the top: their list holds its own place and has no history split keyed on row ids.
  • Temporary (follow-up): when an entire page is one run of tool calls with no message that starts or ends one (about 20 calls in a row with no words), there is no stable start, so the page draws everything as before and Load earlier can still jump. The scroll correction now falls to the next message on screen that survives, but the history split can still put every row back in the list. Removing that needs pages aligned to whole turns where they're cut, on the host.
  • Temporary (follow-up): subagents one turn spawned are drawn as one row at the first one's place. If the page boundary falls between them, that row moves up to the older page when it lands; the scroll correction then holds the next message on screen instead.
  • Temporary (follow-up): structured chats page by the host's own history (200 entries a page) and already read on, up to 8 pages, until a page has a message of the main agent; they don't yet read on until a row is drawn. A run of tool calls with no words longer than 200 entries can still leave a tap that draws nothing there.
  • Intended: if a single trim at the 2,000-message limit drops every message on screen, nothing is held, as before (it needs a burst of output larger than the screen while you're reading the very oldest messages).

Linked Issue

None. Follow-up to #28413; part of the split of draft #28807.

Visual Proof

Pending: iPhone over-the-air page QA (tap Load earlier while the agent is replying, and as the turn ends) will be attached by the review loop.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • MobileNativeChatScrollHold.test.tsx: holds the first message on screen (with a message scrolled past above it, and the untagged Load earlier control, a turn status row and the live line around it; the fake list answers only the selector the hold uses) and not output landing below it; finds it again although the update redrew it; at the 2,000-message limit holds the next kept message when the one on screen is dropped, and the last message above when only the live line is on screen; no write when every recorded message is gone, while bounced, on the same first row, or on native.

  • use-mobile-native-chat-page-history.test.tsx: one end-to-end case through the real session, grouping and history split: the window starts in the middle of a run of calls with no words that is longer than a page. One tap reads a page that draws nothing, keeps its spinner up and reads the next; that page fails, so the tap ends with the retry line; the next tap clears the line, its page lands, and the run's start appears. Every row the list drew keeps its id and index (what the scroll correction and the history split rely on), and the older rows go above it. It fails if the "drew nothing" answer is removed (checked).

  • CI runs lint, typecheck and tests. No local runs (shared-machine limits).

AI Disclosure

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 page only (over-the-air build on iOS and Android web views); native builds, desktop, SSH and remote hosts are unaffected. The shared tool grouping only gains a reader of its rule; desktop's output is unchanged. No wire or settings changes.

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)

…eading

When rows change above the reader on the phone page (a page of older history
landing), the place-hold put the lowest thing on screen back where it was.
That could be the live status line, which moves when output lands in the same
update, so the reader was pushed past their message. The hold now anchors the
first message on screen, found by the data-testid every message row carries
(set as testID), so the Load earlier control and the live status line are
never the anchor, and the row is found again by its id after the update.
… regroup it

A page that starts inside a run of tool calls drew rows the older page's assistant
row later took over, so their ids vanished on Load earlier: the place-hold lost the
message it held and the page history reset its split. Until the older page loads,
the page starts at the first message the tool fold draws the same whatever comes
before it.
… a row

A page counts raw messages, but the page draws folded rows and hides a run's start until older
history loads, so a tap over a tool run with no words longer than a page drew nothing. The tap now
reads on within its own request chain, spinner up, until the first drawn row changes or history,
the 2,000 limit, a failed page, a chat switch or unmount ends it.
… the update kept

The hold put back only the first message on screen, so when the update dropped that message (the
2,000 cap trims the oldest) or no message was on screen (only the live status line), the view moved
by the dropped rows' height. It now records the messages on screen, or the nearest one when none
is, and puts back the first one the update kept.
…d-on change

# Conflicts:
#	mobile/src/session/MobileNativeChatOverlay.tsx
#	mobile/src/session/use-mobile-native-chat-session.ts
…ge change

# Conflicts:
#	mobile/src/session/MobileNativeChatOverlay.tsx
#	mobile/src/session/use-mobile-native-chat-session.ts
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Closing: replaced by #29170, which keeps the reader's place when older messages load on the phone chat page. Branch kept.

@brennanb2025
brennanb2025 deleted the brennanb2025/mobile-page-hold-reading-message 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