Repository navigation
fix(mobile): restore the last-open tab when returning to a worktree on mobile - #9801
Conversation
…ores the last open tab A phone's tab selection lived only in the host's in-memory ClientSessionTabSelectionStore. Any host restart wiped it, and the per-device projection then fell back to deterministic topology, so returning to a worktree on mobile always landed on the first tab instead of the tab last opened on the phone. Persist the per-device selections in the Store (keyed deviceId -> worktreeId), hydrate them when the runtime constructs, and guard projection so an early empty snapshot after restart cannot wipe a hydrated selection before tabs arrive. Selections are pruned with the worktree/repo and on device revoke, and malformed persisted payloads degrade to empty instead of throwing.
|
Warning Review limit reached
Next review available in: 1 minute Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughAdds persisted per-device mobile client tab selections keyed by worktree. Persisted payloads are normalized during loading, selections are pruned when worktrees are removed, and Store APIs expose reading and writing the state. Runtime initialization hydrates selections and persists activation or deletion changes. Empty snapshots no longer overwrite hydrated selections. Tests cover malformed payloads, reloads, pruning, deletion persistence, and device-specific restoration. 🚥 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: d77082f0-f474-455f-8f35-9932b9aa270c
📒 Files selected for processing (7)
src/main/persistence.test.tssrc/main/persistence.tssrc/main/runtime/client-session-tab-selection.test.tssrc/main/runtime/client-session-tab-selection.tssrc/main/runtime/multi-client-navigation-isolation.integration.test.tssrc/main/runtime/orca-runtime.tssrc/shared/types.ts
| store.removeProject('r1') | ||
|
|
||
| expect(store.getMobileClientTabSelections()['device-a']).toEqual({ | ||
| 'other-repo::/tmp/wt': { | ||
| activeTabId: 'tab-2', | ||
| activeGroupId: null, | ||
| activeTabIdByGroupId: {} | ||
| } | ||
| }) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Verify repository pruning survives a reload.
The assertion only checks in-memory state. Flush after removeProject, recreate the Store, and assert the removed worktree selection is still absent; otherwise a missing save after pruning is not covered.
| it('drops malformed persisted payloads instead of hydrating them', () => { | ||
| expect( | ||
| normalizePersistedMobileClientTabSelections({ | ||
| 'device-a': { | ||
| 'wt-1': { activeTabId: 'tab-1', activeGroupId: null, activeTabIdByGroupId: { g: 'tab' } }, | ||
| 'wt-bad': { activeTabId: 42, activeGroupId: null, activeTabIdByGroupId: { g: 7 } } | ||
| }, | ||
| 'device-bad': 'nope', | ||
| 'device-empty': {} | ||
| }) | ||
| ).toEqual({ | ||
| 'device-a': { | ||
| 'wt-1': { activeTabId: 'tab-1', activeGroupId: null, activeTabIdByGroupId: { g: 'tab' } } | ||
| } | ||
| }) | ||
| expect(normalizePersistedMobileClientTabSelections(null)).toEqual({}) | ||
| expect(normalizePersistedMobileClientTabSelections('garbage')).toEqual({}) | ||
| }) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Reject array-shaped persisted payloads.
This only covers primitive invalid device values. Arrays also pass the normalizer’s object checks, so an array containing a valid selection is accepted under a numeric worktree key. Add regression cases for root/device arrays and reject them with Array.isArray(...).
Manual QA and review follow-upValidated the production user flow with an isolated current-worktree Electron host and Orca Mobile on an iPhone 17 Pro simulator (iOS 26.5):
EvidenceDesktop host with three tabs: Mobile connected to the PR worktree: Terminal 3 selected before restart: Host fully stopped and mobile reconnecting: Terminal 3 restored after host restart: Review fixes pushed
Verification
The repository-wide lint still reports an unrelated existing switch-exhaustiveness error in src/renderer/src/components/skills/skill-freshness-group.tsx; all files changed by this PR pass the equivalent checks. |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 80287154-dfec-440e-b944-3897267edd2f
📒 Files selected for processing (4)
src/main/persistence.test.tssrc/main/persistence.tssrc/main/runtime/client-session-tab-selection.test.tssrc/main/runtime/client-session-tab-selection.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- src/main/persistence.test.ts
- src/main/runtime/client-session-tab-selection.ts
…le-worktree-reopen # Conflicts: # src/main/persistence.ts
…n mobile (stablyai#9801) * fix(mobile): persist per-device tab selection so worktree return restores the last open tab A phone's tab selection lived only in the host's in-memory ClientSessionTabSelectionStore. Any host restart wiped it, and the per-device projection then fell back to deterministic topology, so returning to a worktree on mobile always landed on the first tab instead of the tab last opened on the phone. Persist the per-device selections in the Store (keyed deviceId -> worktreeId), hydrate them when the runtime constructs, and guard projection so an early empty snapshot after restart cannot wipe a hydrated selection before tabs arrive. Selections are pruned with the worktree/repo and on device revoke, and malformed persisted payloads degrade to empty instead of throwing. * fix(mobile): harden persisted tab selection cleanup * fix(mobile): preserve tab selection across worktree rename





Problem
Returning to a worktree on mobile opened the first tab instead of the tab the phone last had open.
Root cause
The host tracks each paired device's tab selection in
ClientSessionTabSelectionStore— in memory only. Any host restart (desktop relaunch, serve restart) wiped it. The per-device projection then deliberately ignores host focus ("a new paired device starts from deterministic topology") and falls back totabs[0], so the phone always landed on the first tab — not even the desktop's active tab.Reproduced live in the iOS simulator against a dev desktop:
Fix (host-side)
StoreundermobileClientTabSelectionsByDeviceId(deviceId → worktreeId → selection); the runtime hydrates them at construction and writes back on every activate/forget.project()so an early empty snapshot right after restart can't wipe a hydrated selection before tabs hydrate.pruneWorktreeStateForRepo, existingforgetWorktree) and on device revoke (existingforgetClientNavigationState).Host-side (rather than phone-side AsyncStorage) keeps the host the single owner of per-device navigation state, fixes all paired devices at once, and needs no mobile release. Phones talking to older desktops behave as before.
Tests
client-session-tab-selection.test.ts: persist → rebuild (restart) round-trip, forget persistence + no-op-write guard, empty-snapshot guard, malformed-payload normalization.multi-client-navigation-isolation.integration.test.ts: activation persists through the store contract; a second runtime over the same store restores the device's tab while a fresh device still gets deterministic topology.persistence.test.ts: disk round-trip acrosscreateStore()reloads, corrupt-payload fallback, repo-removal pruning.QA (live, iOS sim + dev desktop)
With the fix: phone on Terminal 3 → desktop killed and relaunched → phone leaves + re-enters worktree → Terminal 3 restored (screenshotted at every step; selection visible in
orca-data.json). Before the fix the same flow landed on Terminal 1.pnpm typecheck,oxlint, max-lines ratchet, and the touched suites (401 tests) all pass.Notes / follow-ups
Store(store: null) keeps today's in-memory-only behavior.