Skip to content

fix(mobile): keep the chat where the reader scrolled to - #28413

Merged
brennanb2025 merged 5 commits into
stablyai:mainfrom
AmoabaKelvin:fix-mobile-chat-scroll
Oct 14, 2026
Merged

brennanb2025 merged 5 commits into
stablyai:mainfrom
AmoabaKelvin:fix-mobile-chat-scroll

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​390 $\color{#cf222e}{\Huge{\mathbf{−}}}$​55 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​335
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​225 $\color{#cf222e}{\Huge{\mathbf{−}}}$​30 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​195

ELI5

On the phone, reading back through a chat while the agent was still working was close to impossible. In builds that draw the chat as a web page, every new line of output pulled you back to the bottom. The message you had stopped on could also vanish, and scrolling up to older messages could throw you a long way back. Now the chat stays where you put it.

What Changed

Three things a reader ran into, and what happens now.

Pulled back to the bottom, in over-the-air builds. Before, you scrolled up while the agent worked and the next line of output dragged you back to the newest message. During a live turn you could not get more than a message or two away. Now the view stays where you scrolled to and the "Scroll to latest" arrow appears. Scrolling back down to the end starts following again. A finished chat with long replies did the same with no output arriving: scrolling up made the list draw rows it had not drawn yet, the chat's height changed, and the page took that for new content and went back to the bottom.

The message you are reading disappears, in every build. Before, the phone kept only the newest 40 messages while a turn ran. Each new one pushed the oldest out, so after a busy couple of minutes the message on screen was gone and something else was in its place. Now the phone keeps what it has shown, up to the 2,000 message ceiling it already had for scrolling back through history.

Thrown backwards when older messages load, in every build. Before, scrolling near the top loaded older messages above you, and the screen stayed at the top of the list, which was now 60 messages earlier. Still at the top, it loaded again. One swipe could move you 180 messages back. Now older messages load above you and the message you were on stays where it was.

How it works:

  • The chat follows the newest message until it learns the reader scrolled away. It learned that from the list's drag events. React Native Web, which draws the page in over-the-air builds, never sends those events, so on the page the chat never stopped following. The page now reads the scroll position instead. Its own stick-to-bottom scroll only ever moves toward the end, so a move up that stops short of the end can only be the reader. A move back down to the end resumes following.
  • On the page, the stick-to-bottom scroll now goes to the measured end of the list and not to the list's estimate of it. The estimate can land short, and landing short would look like the reader scrolling up.
  • Older history used to load on any scroll position near the top. That included the chat's own stick-to-bottom scroll in a chat barely taller than the screen, and it switched following off without the reader doing anything. It now loads only when the reader scrolls, and loading no longer touches following. Where the reader's scroll ends decides.
  • In native builds the list is told to hold the first visible message in place when rows change above it (maintainVisibleContentPosition). It anchors below the "Load earlier messages" row, because that row stays at the top of the list and would otherwise be the thing held in place.
  • The page cannot use that setting. React Native Web's list draws rows by position, so rows added at the front made it draw a different set of rows in place of the ones on screen. On the page, history that loads above the list's first row is now drawn in the list's header, and the list keeps its own rows. A small component notes where a row on screen sits just before the new rows go into the document, and puts that row back in the same place just after. It goes by a row and not by how much the chat grew, because live output can land below the reader in the same update.
  • Live messages are no longer trimmed to the size of the first read. Loading an older page now counts from how many messages the phone holds, so a host too old to page by cursor is asked for enough to cover them.

Why

Scrolling up to read while an agent works is the most common thing to do in a long chat, and on current builds it did not work. Android 0.0.55 and the two iOS release runs of Oct 12 were built with the over-the-air shell, and desktop 1.4.225 ships the page they draw.

Choices worth explaining:

  • The page reads intent from scroll direction and not from touch events. It already receives scroll positions. Touch handling would be new code inside the WebView and would still need a rule for when momentum ends.
  • The phone keeps up to 2,000 live messages and not 40. A long session left open now holds more and does more work per update. 2,000 is the ceiling scrolling back already allowed, so it is not a new limit. The cost on a real phone has not been measured. Trimming only while the reader is at the end would avoid that cost, but the list would have to tell the data layer where the reader is.
  • On the page, loaded history is drawn in the header and not handed to the list. That list keeps a range of positions, not a set of rows, and has no way to shift the range. Its disableVirtualization setting draws from the first row to the last one already drawn, not every row. Restoring the scroll position alone was tried first and landed on the wrong message, because the rows on screen had been replaced. The cost is that history loaded by scrolling back stays drawn until the chat is left.

Known limits:

  • On the page, history loaded by scrolling back stays drawn until you leave the chat, up to the 2,000 message ceiling. Measured on an Android emulator with real chat content, the page went from about 1,300 elements at 40 messages to about 13,000 at 2,000. Scrolling stayed at 54 to 60 frames a second. The slowest update when a new message arrived went from 14 ms at 40 messages to 93 ms at 1,000 and 120 ms at 2,000. A real phone is slower than that emulator and was not measured.
  • In native builds, lifting your finger within 80 points of the end still snaps to the end. Unchanged here.

Follow-up:

  • Reuse rows that did not change when a message arrives. Today every row that contains tool calls is rebuilt, and so redrawn, on each new message: 209 of 299 rows in a real chat of 1,000 messages. That is why updates get slower as more rows are drawn, and it costs native builds too. The data work itself is small, 0.47 ms at 2,000 messages against 0.02 ms at 40 on a laptop.

Linked Issue

Fixes #11638

Fixes #22272

Visual Proof

The chat as an over-the-air build draws it, on an Android emulator, with a made-up chat and a new message arriving every 0.6 seconds. In both clips the reader scrolls up about three seconds in.

Before, with the page built from main. The view is pulled back to the newest message within a second and stays glued there.

orca-scroll-before.mp4

After, with the page built from this branch. The view stays where it was scrolled to and the arrow appears. A tap on the arrow goes to the newest message and following resumes.

orca-scroll-after.mp4

Loading older history, and native builds, are not recorded here.

Testing

Run on an Android emulator. Not run on iOS in either kind of build, and not against a desktop built from this branch.

What was run:

  • Shipped page. Android 0.0.55 paired to desktop 1.4.225, in a chat with a turn in progress. Scrolled up and the view stayed for four seconds with no output, then was pulled to the bottom when the next rows arrived. Six flings upward left the view two messages from the end.

  • Fixed page. The page was built from this branch with pnpm run build:mobile-web and served to the same 0.0.55 app by a local stand-in for the desktop, which replays a recorded chat through the desktop's own transcript reader and watcher. Scrolled up and played 60 lines of live output: the screen was identical and the arrow was showing. Scrolled back to the end and played 60 more: the view followed.

  • Native build. A debug build of the phone app from this branch, against the same stand-in. With 0.0.55 falling back to native screens, one slow swipe at the top loaded three pages and left the view at the top of them, and about 65 live messages replaced the screen of a reader who had scrolled up. With the debug build, the same swipe left the same text on screen and the same live output changed nothing. This run predates the page-side changes. Tests cover that path since.

  • A finished chat on the page. A made-up chat of 20 very long replies, with nothing arriving. Before, twelve swipes up ended at the very bottom of the last reply. After, the same swipes ended a full reply higher with the arrow showing.

  • Older history on the page. A made-up chat of 300 messages on the same setup. Before, one reach of the top loaded four or five pages and left the view at the top of them. After, one page loaded per reach and the same text stayed on screen with the loaded messages directly above it. Done twice in a row.

To try the page on a phone, which was not done here:

  1. pnpm run build:mobile-web, then pnpm dev. The dev desktop listens on 6769, beside an installed Orca.
  2. Pair an over-the-air build of the phone app from Settings > Mobile in the dev desktop.
  3. Open a chat with a working agent and scroll up. The view should stay, with the arrow showing. Scroll to the end and it should follow again.

Tests cover, on the page: a move up stops following and a return to the end resumes it, the chat's own scroll landing short of a grown end is not taken for the reader, a resized viewport pins to the measured end, and history loads on the reader's upward scroll only, the list keeps its rows when history loads above it and gets every row back once its first row is gone, and the view moves by what landed above the reader, also when live output lands below in the same update. In native builds: a drag that loads history from a short chat resumes following where it ends, history does not load from a scroll the reader did not make, and the anchor sits below the header. In the data layer: live output past the first window drops nothing, a page requested before that output still lands ahead of it, and a growing-tail read asks for what the phone holds plus one page.

  • 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

  • Wire: nothing changes between phone and desktop. The phone asks an older host for a larger growing-tail read than before, using the same request.
  • Release: the page changes reach phones with a desktop release, because the desktop ships the page. The native changes reach phones with a phone app release.
  • Performance: the 2,000 message point above, and loaded history staying drawn on the page. On the page there is also one comparison per scroll event.
  • iOS: not run. WebKit may report scroll positions differently during the bounce at the end of the list, and it can ignore a scroll position set during a fling, which holding the place on the page relies on.
  • SSH and remote hosts, and folder workspaces: the change is on the phone only and behaves the same for all of them.

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)

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0ec82923-a409-470a-9942-e7476d3d91cf
📥 Commits

Reviewing files that changed from the base of the PR and between 09f8754 and aa0a63a.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 394da7c1-30f5-488d-961f-9fe8ada0d884
📥 Commits

Reviewing files that changed from the base of the PR and between e468385 and 09f8754.

📒 Files selected for processing: 2
  • mobile/src/session/MobileNativeChatScrollHold.test.tsx
  • mobile/src/session/MobileNativeChatScrollHold.tsx
🚧 Files skipped from review as they are similar to previous changes: 1
  • mobile/src/session/MobileNativeChatScrollHold.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

📝 Walkthrough

The session hook now retains messages across replay and live updates and expands older-page reads up to MAX_MESSAGES. The chat view uses reader scroll state to gate history loading near the top and configures visible-row anchoring based on whether a history header exists. The tail-follow hook retains native gesture handling and adds web-specific offset tracking, measured-height pinning, and reader-driven pause and resume behavior. The view also adds web history row placement and scroll holding when older rows are prepended.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🟡 Moderate · up to 09f87

Native chat may load another history page during an ongoing near-top gesture without further upward movement. Tighten the pagination guard before merging to avoid unintended additional history loads.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 12 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed [#11638] use-mobile-native-chat-tail-follow.ts keeps native gesture tracking and infers reader movement from page scroll offsets. It pauses tail-following away from the end, resumes at the end, and …
Out of Scope Changes check Passed The production changes and tests concern mobile chat following, history pagination and anchoring, or the retained transcript needed to keep older messages available. The platform-mock changes support …
Title check Passed The title clearly and concisely describes the primary change: preserving the chat position while the reader scrolls.
Description check Passed The description is complete and aligned with the template. It explains the user impact, implementation, rationale, linked issues, visual proof, testing, known limits, and checklist status.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

RN Web reports no drag events, so the page never stopped following a live turn.
Native lost its place when older history loaded.
A busy turn outran the 40-message window and dropped the row being read.
RN Web's list draws rows by index, so rows added at the front replaced the ones on screen.
@AmoabaKelvin
AmoabaKelvin force-pushed the fix-mobile-chat-scroll branch from 31b0808 to e468385 Compare October 13, 2026 22:03

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟠 Major · Prevent repeated history loads during one near-top gesture. · MobileNativeChatView.tsx:278

mobile/src/session/MobileNativeChatView.tsx:278
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Prevent repeated history loads during one near-top gesture.

readerIsScrolling() remains true from onScrollBeginDrag until the gesture ends. When loadingEarlier becomes false, another near-top onScroll can call loadEarlier() again. The callback only blocks concurrent requests. It does not require new upward movement or a changed row count. Add a per-page trigger guard so native anchoring or continued scroll events at the same position cannot load successive pages.


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f967f15f-f2c4-446f-ab6e-8ce144ed4c2a
📥 Commits

Reviewing files that changed from the base of the PR and between 31b0808bf68a107b9059a293581d5388dafc69a8 and e468385.

📒 Files selected for processing: 5
  • mobile/src/session/MobileNativeChatScrollHold.test.tsx
  • mobile/src/session/MobileNativeChatScrollHold.tsx
  • mobile/src/session/MobileNativeChatView.tsx
  • mobile/src/session/use-mobile-native-chat-page-history.test.tsx
  • mobile/src/session/use-mobile-native-chat-page-history.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

AmoabaKelvin and others added 2 commits October 13, 2026 22:50
Total height also grows when live output lands below the reader in the same update.
@brennanb2025
brennanb2025 merged commit 12ba3bc into stablyai:main Oct 14, 2026
21 checks passed
nwparker added a commit that referenced this pull request Oct 14, 2026
Resolve MobileNativeChatView against #28413 page history: route the
row renderer through history.renderListRow and keep strictMode.
registered2nd pushed a commit to registered2nd/orca that referenced this pull request Oct 14, 2026
* fix(mobile): keep the chat where the reader scrolled to

RN Web reports no drag events, so the page never stopped following a live turn.
Native lost its place when older history loaded.

* fix(mobile): keep chat history the phone already shows

A busy turn outran the 40-message window and dropped the row being read.

* fix(mobile): keep the page's place when history loads

RN Web's list draws rows by index, so rows added at the front replaced the ones on screen.

* fix(mobile): hold the page's place by a row on screen

Total height also grows when live output lands below the reader in the same update.

---------

Co-authored-by: Brennan Benson <[email protected]>

(cherry picked from commit 12ba3bc)
brennanb2025 pushed a commit that referenced this pull request Oct 15, 2026
* fix(mobile): keep the chat where the reader scrolled to

RN Web reports no drag events, so the page never stopped following a live turn.
Native lost its place when older history loaded.

* fix(mobile): keep chat history the phone already shows

A busy turn outran the 40-message window and dropped the row being read.

* fix(mobile): keep the page's place when history loads

RN Web's list draws rows by index, so rows added at the front replaced the ones on screen.

* fix(mobile): hold the page's place by a row on screen

Total height also grows when live output lands below the reader in the same update.

---------

Co-authored-by: Brennan Benson <[email protected]>

(cherry picked from commit 12ba3bc)
(cherry picked from commit 78cbb87)
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.

[Bug]: Mobile native chat — paging in older history jumps the viewport and re-triggers itself (no prepend anchor) [Bug]: scrolling chat on mobile

2 participants