Skip to content

feat(native-chat): reopen a phone chat from its cached rows and only fetch what changed - #37561

Merged
AmoabaKelvin merged 1 commit into
mainfrom
native-chat-resume-cursor
Nov 3, 2026
Merged

AmoabaKelvin merged 1 commit into
mainfrom
native-chat-resume-cursor

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​313 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​313
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​130 $\color{#cf222e}{\Huge{\mathbf{−}}}$​22 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​108

ELI5

Going back to a chat you just had open on the phone used to blank the screen and download the last 40 messages again, even when nothing had changed. The phone now remembers those messages, shows them right away, and asks the computer only for what's new.

What Changed

Before: every reopen of a terminal-backed chat showed "Loading conversation…" until nativeChat.subscribe sent a full 40-row tail, about 65 KB in the session I measured.

After: the rows are on screen as soon as you open the chat, and the host sends only the row you already had plus anything newer.

How it works:

  • The mobile page keeps its last settled rows per chat in memory (8 chats, least recently used dropped first). The cache replaces the hook's one-transcript retention, so an unsettled read shows those rows the same way a rebind already did.
  • On reopen the page sends resumeAfter, which is the id, file offset and timestamp of its newest row.
  • The host does its usual tail read. If that exact row is in the window, it sends the window from that row onward, marked resumed: true. The phone merges it with the existing reconnect replay check.
  • In every other case the host sends today's full snapshot, and the phone replaces its rows. That covers a rewritten or truncated file, and a chat with more than 40 new rows since the last visit.

Why

Issue #37512 proposed a byte cursor on every frame. I used the last held row instead, because it says the same thing with far less: no cursor on live frames, no change to the watch engine, no mid-line offset rules, and no new capability. The optional resumeAfter param is the opt-in, and old hosts strip it.

The cost is that the held row is sent again on each reopen. That's deliberate: seeing it lets the replay check notice that later rows have gone from the file, including on a reconnect, which replays the original params.

Linked Issue

#37512. This covers reopening within the life of the page. After an app relaunch the phone still downloads the full tail, so the issue stays open. Surviving a relaunch needs a new native storage verb, a store release, and transcripts stored on the phone, which is a product call.

Visual Proof

Reopening a chat from another tab. Both runs hold the first frame for 1.5 s on the host, standing in for a slow link, because on my LAN it arrives too fast to see.

Before (main) After
reopen-main.mp4
reopen-branch.mp4

In the after video the composer says "Waiting for terminal…" and the tabs say Terminal because the scratch Claude processes had exited by that capture. The transcript behaviour is the part to compare.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Real pairing on macOS: an iOS simulator running the release OTA shell, paired to a headless serve from this branch, with real Claude terminals in chat view. I logged the JSON size of each subscribe frame on the host.

Reopen Rows sent Bytes
main, nothing changed 40 64,683
This branch, nothing changed 1 2,562 to 4,485 (the size of the newest row)
This branch, the chat grew while away 3 3,056
This branch, transcript truncated while away 40 (full) 64,683

After truncation the phone showed the file's new tail, with the removed rows gone. Leaving for the host list and coming back also resumed.

Focused tests: a new host test against real JSONL files, new hook tests, and the mobile RPC recording goldens, which pass with no re-record.

pnpm check:changed passed everything up to its unit test step, except two test-file cast findings that I then fixed and re-checked with check:code-quality:changed. I stopped the unit test step after about 20 minutes on a busy machine, because the shared params file fans out widely. CI is the full run.

Not run: Android, Linux, Windows or a real WSL or SSH host. They use the same host read and the same page code.

Risk

Level: Medium

The riskiest part is trusting cached rows. If the newest row keeps its id, offset and timestamp while earlier rows were rewritten to the same byte length, the phone keeps the old earlier rows until the page goes away or a full snapshot replaces them. I found no provider that does this, and a 64-byte boundary check would miss it too.

Older clients and hosts see no change: an old page never sends the param, and an old host drops it and sends a snapshot.

Worst-case memory is 8 chats paged all the way to 2,000 rows, held for the life of the page. At the roughly 1.6 KB per row measured here, that's about 26 MB.

If a reopen fails before any read succeeds, the rows stay visible but can't supply a prompt card, so the phone won't offer to answer a question that may already be answered.

A plain revert undoes all of it. Nothing is saved to disk.

AI Disclosure

Review

To try it: in a terminal-backed chat on the phone, open a second chat tab and go back. The rows should appear at once, with no "Loading conversation…". Then send a prompt from the desktop while you're on the other tab and go back: only the new rows should arrive.

Dev build worktree: /Users/kelvinamoaba/orca/workspaces/orca/native-chat-resume-cursor

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

  • Security: rows stay in page memory, keyed by host, workspace, agent, session and path. Nothing is written to the phone's storage.
  • Cross-platform and SSH: the host change sits in the RPC layer, after the same tail read every route uses.
  • OpenCode and ZCode are excluded on the host because their old rows can change. They get a full snapshot each time, but still paint cached rows first.
  • Performance: the host reads the same tail as before, so this saves wire bytes and paint time, not host file reads.
  • Structured chats use agentSession.subscribe and aren't changed.
  • A cached reopen during a live turn can replay the typing reveal on a reply written while away. It's cosmetic and I left it.

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)
  • I stated the risk: what could break, for whom, and how to back it out
  • 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 Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The RPC contract adds an optional resume point. The runtime subscription can return an initial snapshot starting at a matching message and mark it as resumed. The mobile session caches transcripts, restores cached rows and paging state when reopened, and sends a resume point when available. It keeps unconfirmed cached rows visible while the transcript read is pending or errors. Tests cover runtime matching and fallback behavior, plus mobile reopening and snapshot handling.

Merge Risk: Minimal · up to b9ab8

Cached chats resume with full-snapshot fallback for mutable providers. No current behavioral failure was established; additional fallback coverage is recommended.

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 with cyclomatic complexity of at least 2. Documenta… 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 summarizes the main change: reopening native chats from cached rows and fetching only changed content.
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.
Description check Passed The description follows the required template and clearly explains the user impact, implementation, motivation, linked issue, visual proof, testing, risk, compatibility, performance, rollback, and che…
Full details: Description check

Explanation

The description follows the required template and clearly explains the user impact, implementation, motivation, linked issue, visual proof, testing, risk, compatibility, performance, rollback, and checklist status. It documents that the full unit test suite was not completed locally and that CI is expected to cover it.

Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 8 functions across 9 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
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

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

Follow-up Comments

Nitpick Add matching-resume coverage for OpenCode and ZCode.

100-118: Trivial · Functional Correctness · Quick win

Add matching-resume coverage for OpenCode and ZCode.

The added tests cover resume behavior only for Claude. Existing OpenCode subscription tests do not pass resumeAfter. Add a focused test for opencode and zcode that supplies a matching resume point and asserts the normal full snapshot with no resumed field.

Open the source location


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4b4c813b-05ad-4add-91a2-07862b2393e9
Commits

Reviewing files that changed from the base of the PR and between b96d19d and b9ab894.

Files selected for processing: 9
  • mobile/src/session/native-chat/mobile-native-chat-stream-frame.ts
  • mobile/src/session/native-chat/mobile-native-chat-transcript-cache.ts
  • mobile/src/session/native-chat/use-mobile-native-chat-session-resume.test.ts
  • mobile/src/session/native-chat/use-mobile-native-chat-session.test.ts
  • mobile/src/session/native-chat/use-mobile-native-chat-session.ts
  • src/main/runtime/rpc/methods/native-chat-resume.test.ts
  • src/main/runtime/rpc/methods/native-chat.ts
  • src/shared/native-chat/native-chat-scope-cache.ts
  • src/shared/rpc-contract/native-chat-params.ts

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

@AmoabaKelvin
AmoabaKelvin merged commit 5edc05f into main Nov 3, 2026
50 checks passed
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