Repository navigation
fix(mobile): open the Resume workspace through a mounted host stack - #12001
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between 76ac490c4eac32713b1c926d3ea0e3fdb5cdb0a6 and cd97b2b. 📒 Files selected for processing (9)
🚧 Files skipped from review as they are similar to previous changes (9)
📝 WalkthroughWalkthroughThe change adds shared host-stack navigation that mounts a host route before replacing its nested route. New hooks open host-stack targets for mobile sessions and tasks. Mobile session route construction now uses direct route parameters with an optional workspace name. The home screen resume flow uses the session hook. Tests cover route targets, host mounting, nested replacement, optional names, and hook-based resume navigation. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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
🧹 Nitpick comments (1)
mobile/src/session/mobile-session-route.test.ts (1)
12-30: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider covering the cancellation path.
navigationHarnessreturns avi.fn()unsubscribe fromaddListener, but no test asserts thatcancel()calls it or that a canceled controller skipsdispatch.disposeandretargetare the new state-machine behaviors innavigateToHostStackRoute, andcoordinateHostStackNavigationdepends onisActive(). Adding two assertions on the existing harness would lock that behavior in.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 3f1b0761-10eb-49f9-9851-4270ca3655de
📥 Commits
Reviewing files that changed from the base of the PR and between b04c695 and 1bd184a4e06932def1256c4658368df51659499d.
📒 Files selected for processing (8)
mobile/app/index.tsxmobile/src/navigation/host-stack-navigation.tsmobile/src/navigation/use-open-host-stack-route.tsmobile/src/session/mobile-session-route.test.tsmobile/src/session/mobile-session-route.tsmobile/src/session/use-open-mobile-session.tsmobile/src/tasks/mobile-task-navigation.tsmobile/src/tasks/use-open-mobile-tasks.ts
Greptile SummaryThis PR fixes a blank screen when tapping Resume on the Home screen by applying the same mount-then-replace navigation strategy already used for Tasks and the host editor. The root cause was a cold
Confidence Score: 5/5Safe to merge — the change is confined to mobile navigation state handling, fixes a real blank-screen regression, and is fully covered by new and existing tests. The extraction is a straightforward refactor of a well-understood pattern already proven by the Tasks flow. The new shared mechanism adds encoded-param matching, an idempotent cancel guard, and a retarget path tested end-to-end. No auth, data, or platform-specific code is touched. All public APIs are preserved, typecheck and the full test suite pass, and the fix was verified on a live iOS simulator. Files Needing Attention: No files require special attention. The module-level singleton in use-open-host-stack-route.ts is intentional and well-commented.
|
| Filename | Overview |
|---|---|
| mobile/src/navigation/host-stack-navigation.ts | New core module: mount-then-replace navigation mechanism extracted from Tasks and generalized for any host stack route. Logic is clean and well-guarded (idempotent dispose, encoded-param matching, hostRouteSeen safety exit). |
| mobile/src/navigation/use-open-host-stack-route.ts | New hook exposing the shared navigation mechanism. Uses a module-level singleton (intentionally documented) to coordinate Resume and Tasks taps; cleanup is idempotent and fires on HomeScreen unmount. |
| mobile/src/tasks/mobile-task-navigation.ts | Refactored to re-export types from host-stack-navigation and delegate to shared helpers. Public API shape is preserved; selectProvider is replaced by retarget internally with no external callers (typecheck confirms). |
| mobile/src/session/use-open-mobile-session.ts | New thin hook wiring mobileSessionRouteTarget into useOpenHostStackRoute. Clean and correct. |
| mobile/src/session/mobile-session-route.ts | createMobileSessionHref replaced by mobileSessionRouteTarget; pathname swapped for name, encoding delegated to the navigator. Falsy name omission is intentional per prior review thread. |
| mobile/app/index.tsx | Resume card onPress now calls openMobileSession instead of router.push(createMobileSessionHref(...)). Minimal and correct; source-guard test pins the new call shape. |
| mobile/src/navigation/host-stack-navigation.test.ts | New test suite covering commit detection, encoded-param matching, cancellation, and retarget coordination. |
| mobile/src/session/mobile-session-route.test.ts | Updated to test mobileSessionRouteTarget, mount-before-replace ordering, and source guard asserting openMobileSession is called (not router.push). |
Sequence Diagram
sequenceDiagram
participant Home as HomeScreen
participant Hook as useOpenHostStackRoute
participant Nav as host-stack-navigation
participant Router as expo-router
participant RN as React Navigation
Home->>Hook: "openMobileSession({ hostId, worktreeId, name })"
Hook->>Nav: coordinateHostStackNavigation(pending, navigation, router, hostId, target)
Nav->>Router: router.push("/h/encodedHostId")
Nav->>RN: navigation.addListener("state", onState)
Note over RN: Host stack mounts (index route)
RN-->>Nav: onState() fires
Nav->>Nav: mountedHostStack() checks [hostId]/index committed
Nav->>RN: "navigation.dispatch({ type: REPLACE, payload: sessionTarget })"
RN-->>Home: Session screen rendered with hostId + worktreeId
Reviews (4): Last reviewed commit: "test(mobile): model listener removal in ..." | Re-trigger Greptile
| const openHostStackRoute = useOpenHostStackRoute() | ||
|
|
||
| return useCallback( | ||
| (params) => { | ||
| openHostStackRoute(params.hostId, mobileSessionRouteTarget(params)) | ||
| }, | ||
| [openHostStackRoute] | ||
| ) |
There was a problem hiding this comment.
Independent pending refs don't cross-cancel between Session and Tasks
useOpenMobileSession and useOpenMobileTasks each instantiate their own useOpenHostStackRoute, so each gets a separate pendingRef. If both are called in rapid succession from HomeScreen — e.g., the user taps Tasks and then taps Resume before the first mount settles — two independent navigateToHostStackRoute invocations run concurrently, each pushing /h/[hostId] and listening for state commits. This is not a regression from the previous state (Resume previously fired router.push with no cleanup at all), but now that both paths share the same mechanism, a single shared useOpenHostStackRoute instance in HomeScreen (passed down or lifted) would let them coordinate the same way coordinateHostStackNavigation coordinates repeated taps on the same button.
|
Thanks both — pushed
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
mobile/src/navigation/host-stack-navigation.test.ts (1)
51-58: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert that replacement waits for the host mount.
The test only checks
dispatchaftersetState. An implementation that dispatches before thehroute mounts, then dispatches again after mounting, would pass. Assert zero dispatches beforesetState, then assert oneREPLACEaction with the host-stack target.Proposed test update
navigateToHostStackRoute(harness.navigation, { push }, 'host/one', TARGET) expect(push).toHaveBeenCalledWith(hostStackHostRoute('host/one')) + expect(harness.navigation.dispatch).not.toHaveBeenCalled() harness.setState(committedHostState(encodeURIComponent('host/one'))) - expect(harness.navigation.dispatch).toHaveBeenCalledWith( - expect.objectContaining({ source: 'host-index', payload: TARGET }) + expect(harness.navigation.dispatch).toHaveBeenCalledTimes(1) + expect(harness.navigation.dispatch).toHaveBeenCalledWith( + expect.objectContaining({ + type: 'REPLACE', + target: '/h', + source: 'host-index', + payload: TARGET + }) )
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 07d21215-f5af-4a5f-b923-1477d4c1534c
📥 Commits
Reviewing files that changed from the base of the PR and between 1bd184a4e06932def1256c4658368df51659499d and 339a0b7101f09d37a5df65b1a98ebf7792fe0244.
📒 Files selected for processing (4)
mobile/src/navigation/host-stack-navigation.test.tsmobile/src/navigation/host-stack-navigation.tsmobile/src/navigation/use-open-host-stack-route.tsmobile/src/session/mobile-session-route.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- mobile/src/navigation/use-open-host-stack-route.ts
- mobile/src/session/mobile-session-route.test.ts
- mobile/src/navigation/host-stack-navigation.ts
|
Both nitpicks applied in
Mobile suite green: 384 files, 2,866 passed / 3 skipped. Typecheck, lint, format and the changed-code quality gate clean. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
mobile/src/navigation/host-stack-navigation.test.ts (1)
15-34: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winModel listener removal in
navigationHarness.
unsubscribeis a no-op, andsetStateinvokes the listener after cancellation. The assertions at Line 93 and Lines 96-97 therefore verify only theactiveguard. They do not verify listener removal. A single callback slot can also hide duplicate registrations.Store active listeners in a
Set, remove each listener from the returned unsubscribe function, and notify only active listeners.Proposed test-harness fix
function navigationHarness(initialState: HostStackNavigationState) { - let stateListener = () => {} + const stateListeners = new Set<() => void>() let state = initialState const unsubscribe = vi.fn() const navigation = { addListener: vi.fn((_event: 'state', listener: () => void) => { - stateListener = listener - return unsubscribe + stateListeners.add(listener) + return () => { + unsubscribe() + stateListeners.delete(listener) + } }), dispatch: vi.fn(), getState: () => state @@ setState(nextState: HostStackNavigationState) { state = nextState - stateListener() + for (const listener of stateListeners) { + listener() + } } } }Also applies to: 82-98
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 23071bd8-5cdd-4e78-acc4-745d00f23f68
📥 Commits
Reviewing files that changed from the base of the PR and between 339a0b7101f09d37a5df65b1a98ebf7792fe0244 and 0514d511705874e875691b32179a304b2537d754.
📒 Files selected for processing (1)
mobile/src/navigation/host-stack-navigation.test.ts
|
Good catch — applied in Verified it has teeth: dropping the Mobile suite green: 384 files, 2,866 passed / 3 skipped. Typecheck, lint, format and the changed-code quality gate clean. |
|
can't wait for this merge ! |
Tapping Resume on Home landed on a blank host screen instead of the session. A cold push straight into the nested /h/[hostId] navigator resolves to the host index route without the dynamic id, so HostProtocolGate mounts with hostId undefined and never connects. Home already worked around this for the host editor (stablyai#11635) and Tasks (stablyai#11853) by mounting /h/[hostId] first and replacing it once the stack is committed. Extract that mechanism into host-stack-navigation so Resume uses the same transition instead of a direct push. The previous Resume fix (stablyai#11876) swapped the manual href for a typed dynamic href, but expo-router's encodeParam already applies encodeURIComponent to dynamic segments, so it resolved to the same URL the manual string produced and left the cold-navigator path unchanged. Claude-Session: https://claude.ai/code/session_01RMoaxp7MLg2ydP28KFLX7B
- match a host route committed as the encoded segment it was pushed as, so an id containing `/`, `#`, or `%` still triggers the REPLACE - share one pending transition across the Home entry points; per-hook refs let a Tasks tap and a Resume tap arm two pushes that could not cancel each other - assert the source markers before slicing in the Resume wiring test Claude-Session: https://claude.ai/code/session_01RMoaxp7MLg2ydP28KFLX7B
Assert the replace waits for the host mount (zero dispatches before it, exactly one after), and cover cancel/retarget — the paths the shared pending transition relies on.
A no-op unsubscribe let setState keep calling a canceled listener, so the teardown assertions only exercised the active guard. Dropping the unsubscribe call from dispose now fails the suite.
76ac490 to
cd97b2b
Compare
Home Resume/Tasks/Accounts and notification taps went back to a plain router.push into the nested host navigator. On the native build a cold push there resolves to the host index without the dynamic id, so HostProtocolGate mounts with hostId undefined and the host screen renders blank (the bug #12001 fixed by mounting /h/[hostId] first and replacing once its stack commits). navigateFromMobileHome now maps a MobileWebNavigationIntentTarget onto the matching HostStackRouteTarget and hands the deep ones (session, tasks, accounts) to coordinateHostStackNavigation via useOpenHostStackRoute. Host-index intents (newWorkspace, workspaceList) and the whole hybrid build keep their plain push, and the hybrid navigation intent is still published either way. The Resume card also regains the `name` param it lost, so the session header has a title before the workspace loads. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…tablyai#12001) * fix(mobile): open the Resume workspace through a mounted host stack Tapping Resume on Home landed on a blank host screen instead of the session. A cold push straight into the nested /h/[hostId] navigator resolves to the host index route without the dynamic id, so HostProtocolGate mounts with hostId undefined and never connects. Home already worked around this for the host editor (stablyai#11635) and Tasks (stablyai#11853) by mounting /h/[hostId] first and replacing it once the stack is committed. Extract that mechanism into host-stack-navigation so Resume uses the same transition instead of a direct push. The previous Resume fix (stablyai#11876) swapped the manual href for a typed dynamic href, but expo-router's encodeParam already applies encodeURIComponent to dynamic segments, so it resolved to the same URL the manual string produced and left the cold-navigator path unchanged. Claude-Session: https://claude.ai/code/session_01RMoaxp7MLg2ydP28KFLX7B * fix(mobile): harden the host-stack transition after bot review - match a host route committed as the encoded segment it was pushed as, so an id containing `/`, `#`, or `%` still triggers the REPLACE - share one pending transition across the Home entry points; per-hook refs let a Tasks tap and a Resume tap arm two pushes that could not cancel each other - assert the source markers before slicing in the Resume wiring test Claude-Session: https://claude.ai/code/session_01RMoaxp7MLg2ydP28KFLX7B * test(mobile): lock the host-stack transition state machine Assert the replace waits for the host mount (zero dispatches before it, exactly one after), and cover cancel/retarget — the paths the shared pending transition relies on. * test(mobile): model listener removal in the navigation harness A no-op unsubscribe let setState keep calling a canceled listener, so the teardown assertions only exercised the active guard. Dropping the unsubscribe call from dispose now fails the suite. --------- Co-authored-by: kaynan <[email protected]>
Summary
Tapping Resume on Home landed on a blank host screen instead of opening the workspace session. Resume now uses the same mount-then-replace transition Home already uses for the host editor (#11635) and Tasks (#11853).
Root cause
A cold push straight into the nested
/h/[hostId]navigator resolves to the host index route without the dynamic id — the same failure #11853 documented for Tasks.app/h/_layout.tsxthen mountsHostProtocolGatewithhostId: undefined, souseHostClient(undefined)never connects and the detail stack renders an empty host screen.#11876 addressed this by swapping the manual href for a typed dynamic href, but that did not change the resolved route.
expo-router'sresolveHref→encodeParamalready appliesencodeURIComponentto dynamic segments, so{ pathname: '/h/[hostId]/session/[worktreeId]', params }resolves to the same URL the manual string produced (/h/<host>/session/<encoded workspace id>; the workspace id was already passed throughencodeURIComponent). The direct cross-stack push — the actual cause — stayed in place.Change
mobile-task-navigationintosrc/navigation/host-stack-navigation: mount/h/[hostId], wait for that stack to commit, thenREPLACEits index route with the concrete target.[hostId]/session/[worktreeId]through the same transition viauseOpenMobileSession.REPLACEpayload — the navigator owns encoding, so an id containing/,::, or#reaches the session screen unescaped.Screenshots
Tapping Resume on a cold app start, on an iOS simulator paired to a headless desktop runtime. Before, the tap lands on a host screen with no host id and a disconnected dot; after, it opens the workspace session with the host connected. The "before" capture was taken by restoring
mobile/app/index.tsxandmobile/src/session/mobile-session-route.tsto theirb04c695state and letting fast refresh apply it, so it is the real prior behavior rather than a mock-up.No styling change — the Resume card and the session screen are unchanged; only the transition between them is.
Testing
pnpm lintpnpm typecheckpnpm test— 4,042 files and 42,934 tests passed. 5 failures in 2 files are pre-existing on this machine and unrelated:src/relay/agent-exec-handler.test.tsasserts on the spawnedcodexenvironment and picks up local shell variables, andconfig/scripts/check-root-directory-entries.test.mjsruns a shell guard against a throwaway git fixture that exits2here. Both fail identically at theb04c695merge-base, and the whole diff is confined tomobile/.pnpm build— not run locally; the change is confined tomobile/, which is a separate pnpm workspace and is not part of the desktop bundle.pnpm --dir mobile test— 383 files, 2,862 passed and 3 skippedpnpm --dir mobile typecheck,pnpm --dir mobile lint,pnpm --dir mobile format:checkpnpm run check:max-lines-ratchetpnpm run check:code-quality:changed— 0 new findings across the changed filesRegression coverage in
mobile/src/session/mobile-session-route.test.ts:/,::, and#raw in its params, and omitsnamewhen the workspace has nonenavigateToHostStackRoutewith the session target pushes/h/[hostId]first, dispatches nothing until the host stack commits, and only then replaces it with[hostId]/session/[worktreeId]openMobileSessionand no longer callsrouter.pushdirectly — the shape that regressedThe existing
mobile-task-navigationsuite still passes unchanged against the extracted mechanism, which is the intended proof that Tasks behavior is untouched.End-to-end on an iOS simulator paired to a headless desktop runtime (
node mobile/scripts/start-emulator.mjs): reproduced the blank host screen on theb04c695implementation, then applied the fix through fast refresh and confirmed the same tap opens the workspace session — the two captures above. Android was not exercised; the code path is platform-neutral React Navigation state, with no platform branches.AI Review Report
Reviewed with Claude Code. Risks checked and outcomes:
folder:ids), and the floating-workspace sentinel keep the branching that already exists in the session screen.pushthrows, or when the Home screen unmounts — the same lifecycle the Tasks flow already shipped. No polling, no work added to a hot path.docs/STYLEGUIDE.mdis not engaged.Flagged and resolved during review: the extraction had to keep
mobile-task-navigation's exported surface intact so the Tasks tests remain a real check rather than a rewritten one; the wrapper now re-exports its types and delegates, and its suite passes untouched.Security Audit
No follow-up needed.
Notes
navigateToMobileHostEditstill uses the olderrequestAnimationFramevariant of this transition rather than waiting for the host stack to commit. It could move ontohost-stack-navigationtoo, but that is a separate behavior change and belongs in its own PR.X handle: @KaynanSampaio1