Repository navigation
perf(mobile): stop polling live worktree names - #8051
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe RPC client now generalizes streaming readiness handling and disposes runtime client-event subscriptions through the corresponding unsubscribe method, including subscriptions cancelled before readiness. The live worktree-name hook now coordinates event readiness, repository-scoped refreshes, fallback polling, stale response handling, reconnect refreshes, and cleanup. Worktree renames now invalidate cached data and notify remote clients, while read-state updates remain notification-free. New tests cover these behaviors. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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. Comment |
worktrees:updateMeta deliberately skips the renderer notifier (PR stablyai#209), but paired mobile clients no longer poll for titles, so a manual rename would never reach them. Emit the remote-only worktreesChanged client event (with resolved-cache invalidation), gated on displayName so per-click isUnread writes stay event-free. Co-authored-by: Orca <[email protected]>
Co-authored-by: Orca <[email protected]>
…ng parser getRepoIdFromWorktreeId matches the mobile client's event filter exactly and cannot throw after the meta write already persisted. Co-authored-by: Orca <[email protected]>
|
Reviewed and validated. Added three commits on top: manual desktop renames now push a remote-client-only |
* perf(mobile): replace worktree name polling with events * fix(worktrees): push rename invalidation to remote clients worktrees:updateMeta deliberately skips the renderer notifier (PR stablyai#209), but paired mobile clients no longer poll for titles, so a manual rename would never reach them. Emit the remote-only worktreesChanged client event (with resolved-cache invalidation), gated on displayName so per-click isUnread writes stay event-free. Co-authored-by: Orca <[email protected]> * test(worktrees): add missing runtimeStub type member for typecheck Co-authored-by: Orca <[email protected]> * fix(worktrees): derive rename event repoId with the shared non-throwing parser getRepoIdFromWorktreeId matches the mobile client's event filter exactly and cannot throw after the meta write already persisted. Co-authored-by: Orca <[email protected]> --------- Co-authored-by: Orca <[email protected]>
Summary
Description
Stop polling
worktree.showevery 3 seconds while a mobile session is focused. The mobile title hook now:runtime.clientEventsstream;worktreesChangedevent or a provider-neutralreposChangedevent;Evidence — this is a performance issue
The old request-volume test was run against the pre-fix hook with fake timers:
That RPC is not a cheap metadata lookup. The runtime call chain is:
The resolved-worktree cache TTL is 1 second, shorter than the 3-second mobile poll, so an otherwise-idle poll can miss the cache every time. With
Rconfigured repos, the 10 idle ticks above can therefore cause up to10 × Rlocal Git or SSH worktree-list scans every 30 seconds.The committed regression test now proves:
worktree.showRPCs while idleIt also proves that an unrelated repo event causes 0 requests, while the current repo event causes exactly 1 immediate refresh. The compatibility test proves an older runtime still makes 4 requests over the first 9 seconds (initial + three fallback ticks), matching the old cadence.
Reproduce the focused after measurement:
pnpm --dir mobile test src/session/use-live-worktree-name.test.ts --reporter=verboseELI5
The phone used to ask the desktop “did this workspace's name change?” every three seconds. Answering could make the desktop check every local and remote repo. Now the desktop rings a bell when workspace metadata changes, and the phone asks only then. If the desktop is too old to have the bell, the phone keeps using the old check.
Trade-offs / end-user regressions
Screenshots
No visual change.
Testing
pnpm --dir mobile lintpnpm --dir mobile exec tsc --noEmit -p tsconfig.jsonpnpm --dir mobile test— 187 files passed; 1,321 tests passed; 2 skippedpnpm --dir mobile format:checkpnpm check:max-lines-ratchetpnpm build— not run; no dependency, native, route, or packaging changesAI Review Report
Reviewed the request hot path, cache TTL, per-repo fanout, focus lifecycle, reconnect replay, stale async responses, older-runtime behavior, and server-listener cleanup.
The review found two risks and the implementation addresses both:
readyevent and a successful read; an RPC error leaves the original fallback running.readyresponse. The RPC client retains a cancelled tombstone until it receives the subscription ID, then sends the matchingruntime.clientEvents.unsubscribewithout delivering the late event.Cross-platform review: no shortcuts, labels, filesystem paths, shell behavior, or Electron platform branches changed. Worktree IDs use the shared cross-platform parser. The event is provider-neutral and the avoided scan covers both local and SSH providers, so macOS, Linux, Windows, SSH, and non-GitHub git providers retain the same behavior.
Security Audit
repoIdis used only for equality against the repo parsed by the shared worktree-ID utility.Notes
Mobile backwards-compatibility verdict: compatible. Persisted keys, route/deep-link shapes, required RPC payloads, and shared desktop behavior are unchanged. The new subscription is additive and feature-detected by its
readyresponse.