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
perf(mobile): hash only changed Home rows from relayed servers - #50778
When one workspace on a relayed server changes, the phone asks the desktop for that server's rows again. The desktop then re-fingerprinted every row, even though only one had changed. Now it remembers each row's fingerprint and only re-fingerprints the row that changed.
Files
Added
Deleted
Net
Test
1
$\color{#1a7f37}{\Huge{\mathbf{+}}}$163
0
$\color{#1a7f37}{\Huge{\mathbf{+}}}$163
Prod
2
$\color{#1a7f37}{\Huge{\mathbf{+}}}$69
$\color{#cf222e}{\Huge{\mathbf{−}}}$10
$\color{#1a7f37}{\Huge{\mathbf{+}}}$59
What Changed
WorktreeCatalogRowHashes (in worktree-catalog-snapshot.ts) keeps one catalog's last row hashes by worktreeId. On the next reply it reuses a row's hash when the row is equal by value (isDeepStrictEqual) to the copy it last hashed. Otherwise it hashes the row as before. It keeps only the latest reply's rows.
resolveWorktreeCatalogSnapshot takes this memo as an optional argument. Only mobileRelay.hosts.worktrees passes one, with one memo per relayed server. The desktop's own worktree.ps replies are unchanged.
The memo for a server is dropped when that server has no rows.
The reply format is the same: same snapshotId, unchanged and rowsFromBase semantics. Phones need no update.
Why
Home's homeRelayedServerRowsQuery re-reads a server on each relayHostRowsChanged notice, at most once per its 3 s floor. On the desktop each read refetches the server's rows. Each refetch arrives as new objects, so identify() ran contentSnapshotId(JSON.stringify(row)) on every row. On a 7,500-row server, one changed row cost 7,501 SHA-256 hashes (every row plus the envelope). A busy agent keeps notices coming, so the desktop hashed about 2,500 rows per second. This PR keeps #49472's projection and query savings unchanged.
Alternatives considered:
Applying a pushed delta, or refetching only the changed ids: neither the server's worktreeRowsChanged event nor relayHostRowsChanged carries row ids. Either option needs a protocol change.
Dropping the notice-driven refresh: Home has no other poll for relayed rows. Without it, agents on relayed servers would go stale.
Keeping row objects stable inside the server-row caches (stamping and both producers): this also works. But the sidebar producer's fetches, including the 30 s fallback, would then pay a per-row compare even when no phone reads. Comparing at hash time costs nothing when no phone reads.
N/A: there is no UI change. Only the desktop's internal row hashing for relayed-server replies changes.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
src/main/runtime/rpc/methods/pairing/mobile-relay-host-row-hashes.test.ts is a deterministic count test. It drives the real mobileRelay.hosts.worktrees handler, MobileRelayHostCatalog and OnDemandServerWorktreeRows against a fake 7,500-row server. Every fetch returns freshly parsed rows, a third of them carry the other-client stamp, and one row is marked active. The test counts contentSnapshotId calls:
Re-read after...
main
this PR
one row changed
7,501 hashes
2 (the row + the envelope)
nothing changed
7,501 hashes
1 (the envelope)
Both cases fail on main and pass here. The test also checks that the delta reply sends only the changed row, including a changed row that carries a stamp.
Locally I ran only targeted vitest (this file plus mobile-relay-hosts.test.ts), oxlint and oxfmt --check. CI covers typecheck.
Performance
These numbers assume one notice-driven re-read every 3 s, which is the floor, on a server with N = 7,500 worktrees:
Row hashes on the desktop: about 2,500 per second before, about 0.33 per second after (one changed row per read).
Handler time per re-read (the vitest harness above, 30 re-reads, includes the fake fetch round trip): about 19.7 ms on main, about 15.9 ms with this PR.
What still scales with N: the desktop still fetches and parses the server's full worktree.ps reply on each read. Removing that needs row ids in the server's events. Hashing is replaced by a by-value compare per row, which ran in about half the time of stringify + SHA-256 in a local microbenchmark (best of 5: about 4 ms against about 8 ms for 7,500 rows).
Memory: for each relayed server a phone reads, the desktop keeps references to the last reply's rows. Those are the rows the server-row cache already holds, at most one generation behind.
Risk
Level: Low
A wrongly reused hash could make a phone keep a stale row. A hash is reused only when the row is deep-equal by value to the row it was computed from, so a wrong reuse cannot happen. The one difference: if a row's keys arrive in a different order with the same values, the phone keeps its existing copy, which has the same content. The desktop's own worktree.ps path is untouched. The wire format is unchanged, so older phones are unaffected. A plain revert backs this out.
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
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
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)
A phone's mobileRelay.hosts.worktrees re-read after one relayed row changed
re-hashed every row of that server (JSON.stringify + SHA-256 each). Keep each
server's last row hashes by worktree id and reuse a hash when the row is equal
by value, so a one-row change hashes one row.
Refs #49472
No actionable comments were generated in the recent review.
Walkthrough
The snapshot resolver now accepts an optional row-hash memo. It reuses hashes for deeply equal worktree rows with the same string worktreeId. The mobile relay worktrees RPC keeps this state per host and clears it when worktrees are absent. Tests with 7,500 worktrees check changed-row deltas, unchanged rereads, and updates to a row with another-client stamp.
Merge Risk: Minimal · up to 8da23
Home refreshes from relayed servers should hash far fewer rows while the reply format stays the same. No merge-blocking risk was found. The only known concern is minor memory retention for servers that are removed.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title accurately names the main change: the desktop now hashes only the changed Home rows for relayed-server replies, which is the core purpose of the PR. It is short, specific, and matches the ra…
Description check
The description follows the template closely. It has an ELI5 section, a detailed What Changed section, a Why section with alternatives considered, a Linked Issue (Refs #49472, which is a reference rat…
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.
Full details: Title check
Explanation
The title accurately names the main change: the desktop now hashes only the changed Home rows for relayed-server replies, which is the core purpose of the PR. It is short, specific, and matches the raw summary (row-hash memo reusing prior hashes for deeply equal rows) and the objectives. The 'perf(mobile)' prefix follows a conventional-commit style and is acceptable.
Full details: Description check
Explanation
The description follows the template closely. It has an ELI5 section, a detailed What Changed section, a Why section with alternatives considered, a Linked Issue (Refs #49472, which is a reference rather than a 'Fixes' link), Visual Proof marked N/A with reason, Testing with a targeted test file and a results table, a Performance section with measured numbers, and a Risk section with level and revert plan. Gaps: the AI Disclosure section is empty, the Review section is empty, and the full pnpm lint/typecheck/test/build run is not reported (the checklist item is unchecked, and the Testing section says CI covers typecheck). The Linked Issue uses 'Refs' rather than 'Fixes', and the template says an actual issue should be linked for outside contributors. These are non-critical or contributor-status dependent, so the description is mostly complete.
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
16-16: Minor · Performance & Scalability · Low value
Release per-server row-hash memos when their servers are removed.
rowHashesByServer keeps one entry per host ID that was ever read with rows. The only delete runs when a later read returns no worktrees. A server removed from the phone stops receiving reads, so its entry stays for the process lifetime. Nothing else in the code deletes the entry, and the map is not exported.
Growth is bounded by the number of servers read in one process. Each retained entry scales with that server's row count. The impact is minor memory retention, not a crash or incorrect reply. Choose one of these fixes:
Bound the map size, for example with least-recently-used eviction.
Delete the entry when the server is removed or unpaired, using a removal signal the host catalog already emits.
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: 09833916-25eb-4162-9360-3843a29631b1
Commits
Reviewing files that changed from the base of the PR and between 082b6aa and 6e37f91.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 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
When one workspace on a relayed server changes, the phone asks the desktop for that server's rows again. The desktop then re-fingerprinted every row, even though only one had changed. Now it remembers each row's fingerprint and only re-fingerprints the row that changed.
What Changed
WorktreeCatalogRowHashes(inworktree-catalog-snapshot.ts) keeps one catalog's last row hashes byworktreeId. On the next reply it reuses a row's hash when the row is equal by value (isDeepStrictEqual) to the copy it last hashed. Otherwise it hashes the row as before. It keeps only the latest reply's rows.resolveWorktreeCatalogSnapshottakes this memo as an optional argument. OnlymobileRelay.hosts.worktreespasses one, with one memo per relayed server. The desktop's ownworktree.psreplies are unchanged.The reply format is the same: same
snapshotId,unchangedandrowsFromBasesemantics. Phones need no update.Why
Home's
homeRelayedServerRowsQueryre-reads a server on eachrelayHostRowsChangednotice, at most once per its 3 s floor. On the desktop each read refetches the server's rows. Each refetch arrives as new objects, soidentify()rancontentSnapshotId(JSON.stringify(row))on every row. On a 7,500-row server, one changed row cost 7,501 SHA-256 hashes (every row plus the envelope). A busy agent keeps notices coming, so the desktop hashed about 2,500 rows per second. This PR keeps #49472's projection and query savings unchanged.Alternatives considered:
worktreeRowsChangedevent norrelayHostRowsChangedcarries row ids. Either option needs a protocol change.Linked Issue
Refs #49472
Visual Proof
N/A: there is no UI change. Only the desktop's internal row hashing for relayed-server replies changes.
Testing
src/main/runtime/rpc/methods/pairing/mobile-relay-host-row-hashes.test.tsis a deterministic count test. It drives the realmobileRelay.hosts.worktreeshandler,MobileRelayHostCatalogandOnDemandServerWorktreeRowsagainst a fake 7,500-row server. Every fetch returns freshly parsed rows, a third of them carry the other-client stamp, and one row is marked active. The test countscontentSnapshotIdcalls:Both cases fail on main and pass here. The test also checks that the delta reply sends only the changed row, including a changed row that carries a stamp.
Locally I ran only targeted vitest (this file plus
mobile-relay-hosts.test.ts),oxlintandoxfmt --check. CI covers typecheck.Performance
These numbers assume one notice-driven re-read every 3 s, which is the floor, on a server with N = 7,500 worktrees:
worktree.psreply on each read. Removing that needs row ids in the server's events. Hashing is replaced by a by-value compare per row, which ran in about half the time of stringify + SHA-256 in a local microbenchmark (best of 5: about 4 ms against about 8 ms for 7,500 rows).Risk
Level: Low
A wrongly reused hash could make a phone keep a stale row. A hash is reused only when the row is deep-equal by value to the row it was computed from, so a wrong reuse cannot happen. The one difference: if a row's keys arrive in a different order with the same values, the phone keeps its existing copy, which has the same content. The desktop's own
worktree.pspath is untouched. The wire format is unchanged, so older phones are unaffected. A plain revert backs this out.AI Disclosure
Review
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)