You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(native-chat): reopen a phone chat from its cached rows and only fetch what changed - #37561
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)
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: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
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 checks: 4 passed
Check name
Status
Explanation
Title check
The title clearly summarizes the main change: reopening native chats from cached rows and fetching only changed content.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description check
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.
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.subscribesent 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:
resumeAfter, which is the id, file offset and timestamp of its newest row.resumed: true. The phone merges it with the existing reconnect replay check.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
resumeAfterparam 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.
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
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.
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:changedpassed everything up to its unit test step, except two test-file cast findings that I then fixed and re-checked withcheck: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-cursorAgent skill upstream boundary
Notes
agentSession.subscribeand aren't changed.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)