Skip to content

fix(mobile): open each chat at its newest message when switching chats - #29099

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/mobile-chat-switch-opens-latest
Oct 16, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/mobile-chat-switch-opens-latest

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​30 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​24
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​35 $\color{#cf222e}{\Huge{\mathbf{−}}}$​13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​22

ELI5

On the phone, if you scroll up in one chat and then switch to another chat, the new chat opens somewhere in the middle instead of at its latest message, and new replies don't scroll into view. After this change, every chat you switch to opens at its newest message and keeps following new replies, like it does when you first open it.

What Changed

The problem. The phone's chat view stays on screen (mounted) when you move between chat tabs; only the chat it shows changes. The "am I following the newest message?" flag and the scroll bookkeeping lived on that view, not on the chat. So in chat A, scrolling up turned following off, and switching to chat B kept it off: B opened at A's scroll position (native app) or at its oldest loaded message with the jump-to-latest arrow showing (the over-the-air phone page). Since #28413 (shipped in 1.4.226) the phone page has this too; the native app already had it.

User-facing change. Switching to a chat always ends at its newest message, following. On the over-the-air phone page it gets there after the same short climb every page open already has on main: for about a tenth to a fifth of a second the new chat draws a little short and steps down through its last few screens while the list renders its rows in batches. Opening a chat for the first time does exactly this today; a follow-up PR makes the first drawn frame of any chat on the page its newest message. Things that belong to the view rather than to one chat stay as you left them: the Tools expand/collapse toggle and your pinch-zoom text size. This includes switching back: returning to a chat you had scrolled up in opens it at its newest message too, not at your old place (as when you first open a chat; your place isn't remembered per chat, before or after this change).

Mechanism.

  • use-mobile-native-chat-tail-follow.ts: the hook now takes the chat's identity (scopeKey, the host + worktree + tab key the composer and turn disclosure already use). When it changes, a layout effect runs before paint, so the follow state never paints at the old chat's position: it clears the page's last-offset bookkeeping and does the same "jump to latest" a send does, which turns following back on, hides the arrow and pins to the end. Content that measures in afterwards keeps it pinned, because following is on. On the page, that pin scrolls to the scroller's live height, not the last height the list reported: right after a switch the reported height is still the previous chat's, so a taller chat would have painted one frame mid-history before snapping to the end.
  • use-mobile-native-chat-page-history.tsx (page only): the remembered "row the list starts at" is now stored together with the chat it belongs to. Row ids such as the streaming bubble's repeat across chats, so an id alone could let chat A's history split leak into chat B.

Why

Linked Issue

Follow-up to #28413 (shipped in 1.4.226).

Visual Proof

The phone chat page in Orca's Electron build on Windows, this PR (left) vs main (right), with the agent still working in chat B.

Scroll up in chat A, then switch to chat B: B opens at its newest message and keeps following, vs main opening it short of the end with the arrow showing and new output not followed.
Switch to B: newest vs main short of the end

Switch back to chat A: A opens at its newest message, following, vs main opening it at the top of a short loaded window, short of the end. Neither build returns to where the reader left A; this PR goes to the newest message by design.
Switch back to A: newest vs main short

Also checked on the iOS simulator (page and native app): both open at the newest message and follow, vs main opening at the top of the loaded history. Both surfaces still show one to four in-between frames on a switch (the pre-existing climb described above).

Testing

  • One test in MobileNativeChatView.test.ts: scroll up in chat A and expand Tools, switch to chat B; B pins to its end, has no jump-to-latest arrow, keeps following new content, and Tools stays expanded.

  • One page test in the same file: after a switch, the pin goes to the new chat's live height, not the previous chat's reported height (it replaces the page resize test, which hit the same pin).

  • No local checks on this machine (shared machine policy); CI runs lint, typecheck and tests.

  • I manually tested these changes locally

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

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

Mobile only, no wire or host change, so mixed phone/host versions are unaffected. Same on SSH and local hosts: the chat identity includes the host.

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)

The chat view stays mounted across chat tabs, so a reader's scroll in one chat
carried into the next: it opened mid-transcript and not following. Reset follow
intent and the page's history head when the chat changes, before paint, and keep
view-wide state (Tools toggle, text size).
The page pin scrolled to the last reported content height, which after a
chat switch is still the previous chat's, so a taller chat could paint
one frame mid-history before its own height arrived. Pin to the scroller's
live height instead.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: ready for a merge decision

The problem. On the phone, the chat view stays on screen when you move between chat tabs, and the "am I following the newest message?" state lived on that view instead of on the chat. If you scrolled up in chat A and then switched to chat B, B opened short of its newest message, with the jump-to-latest arrow showing, and new replies didn't scroll into view. The over-the-air phone page has had this since #28413 (shipped in 1.4.226), and the native app had it before that.

What changes for you. Every chat you switch to, including one you come back to, opens at its newest message and keeps following new replies. Things that belong to the view (the Tools toggle, pinch-zoom text size) stay as you left them. Your old place in a chat isn't remembered per chat, before or after this change.

Fixed during review

  • On the page, the switch now pins to the scroller's live height instead of the previous chat's stored height, so a taller chat no longer paints a frame mid-history before snapping to the end.
  • The description now covers switching back to a chat.

Deferred or disclosed

  • Temporary: on the page, a newly opened chat still draws short and steps down through its last screen or so for about a tenth of a second while the list renders its rows in batches. Every first open of a long chat already does this on main; a follow-up makes the first drawn frame the newest message. A first attempt (drawing every loaded row at once) measured too slow on 2,000-message chats, so the follow-up's design is still being decided. The native app shows one to four in-between frames on a switch too.
  • Minor: right after a switch, the page resets its scroll bookkeeping to 0 rather than the live position, so a reader's very first upward frame can be missed (rare). A page-history scoping case is covered only by a harness.

What was verified

  • Two review rounds plus a readiness pass (0 P0-P2 open).
  • Electron build of the phone page on Windows (Chromium), this head vs main, Grok-reviewed: switching A to B, B to A, and a short chat to a tall one all land at the newest message and follow; main sits about 750 px short. Switching between terminal and chat views and reconnecting inside a chat behave the same as main. Screenshots are in the description.
  • iOS simulator, page and native app: both open at the newest message and follow; main opens at the top of the loaded history.
  • CI green on 03b02b3, including "PR checks passed".

Not verified

  • Text size carrying across a switch: the test rig's pinch input doesn't register.
  • A WebKit-without-scroll-anchoring desktop run is still queued.

@brennanb2025
brennanb2025 marked this pull request as ready for review October 15, 2026 15:55
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The chat view now passes its surface identity to the page-history and tail-follow hooks. Page history only reuses a remembered head row for the matching chat. On web, tail following reads the live scroll height and resets tracking when the chat changes. Tests cover scrolling and Tools-toggle behavior when switching chats.

Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to 03b02

The chat-switch behavior appears mergeable, but a targeted test would better protect against showing the wrong history rows when chats share row IDs.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: opening each mobile chat at its newest message when switching chats.
Description check Passed The description is detailed and relevant. It includes the user impact, implementation, rationale, linked issue reference, visual proof, testing updates, known limitations, and checklist status. The li…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • 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.

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

🧹 Nitpick comments: 1
mobile/src/session/use-mobile-native-chat-page-history.test.tsx: 1

23-23: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a scope-change case with overlapping row IDs.

The harness always passes the same 'chat' scope and never changes it after recording a head. The related view test changes sendSurfaceId, but it switches from a1 to b1; the previous head is absent, so an unscoped implementation also passes. Add a case where the new chat contains the previous chat's remembered head at a nonzero index.

Suggested fix
-  function Harness({ items }: { items: Item[] }): null {
-    history = useMobileNativeChatPageHistory(items, renderRow, 'chat')
+  function Harness({ items, scopeKey }: { items: Item[]; scopeKey: string }): null {
+    history = useMobileNativeChatPageHistory(items, renderRow, scopeKey)
     return null
   }
 
-  async function show(items: Item[]): Promise<void> {
+  async function show(items: Item[], scopeKey = 'chat'): Promise<void> {
     await act(async () => {
       if (renderer) {
-        renderer.update(createElement(Harness, { items }))
+        renderer.update(createElement(Harness, { items, scopeKey }))
       } else {
-        renderer = create(createElement(Harness, { items }))
+        renderer = create(createElement(Harness, { items, scopeKey }))
       }
     })
   }
 
+  it("does not reuse a page head from another chat", async () => {
+    await show(rows('a', 'b'), 'chat-a')
+    await show(rows('x', 'a', 'b'), 'chat-a')
+
+    await show(rows('p', 'a', 'b'), 'chat-b')
+
+    expect(history?.listRows).toEqual(rows('p', 'a', 'b'))
+    expect(headerRows()).toEqual([])
+  })

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bfbe45e1-ea35-484d-881e-adcd1930ac11
📥 Commits

Reviewing files that changed from the base of the PR and between e9199bd and 03b02b3.

📒 Files selected for processing: 5
  • mobile/src/session/MobileNativeChatView.test.ts
  • 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
  • mobile/src/session/use-mobile-native-chat-tail-follow.ts

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

@brennanb2025
brennanb2025 merged commit e9c7736 into main Oct 16, 2026
39 checks passed
@brennanb2025
brennanb2025 deleted the brennanb2025/mobile-chat-switch-opens-latest branch October 16, 2026 01:54
brennanb2025 added a commit that referenced this pull request Oct 16, 2026
#29099 took mobile/src/session/MobileNativeChatView.test.ts to 806 counted
lines, over the 800-line test cap, so the phone app's lint fails on main.
Move the four Stop and Stopping cases verbatim into
MobileNativeChatView.turn-status.test.ts, which has the same setup, and put
the listIds doc comment back above the function it describes.
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