Repository navigation
fix(mobile): restore terminal input when reopening worktrees - #16239
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: Team Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughThe transport context now stores and exposes the shared client's Merge Risk: 🟡 Moderate · up to Terminal input may still be sent under a mismatched identity after a host rebind, which could affect commands entered immediately during reconnection. This should be resolved before merge. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the problem, implementation, rationale, testing, risk areas, and validation status. However, the required Linked Issue section does not contain an issue link or a
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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
mobile/app/h/[hostId]/session/[worktreeId].tsx (1)
3044-3065: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick winKeep the RPC client and client ID from the same binding. If rebinding occurs while dictation waits for
flushPendingLiveInputBeforeExternalSend, the oldsendLiveTerminalInputclosure can use the newclientRef.currentwith its oldclientId. If rebinding occurs while terminal creation awaits its response, the initial prompt can use the old capturedclientwith the newclientIdRef.current. Both paths can send under the wrong identity instead of dropping the delayed input.
mobile/app/h/[hostId]/session/[worktreeId].tsx#L3044-L3065: Read the client ID from the same current binding asrpc, or snapshot and validate both values before sending.mobile/app/h/[hostId]/session/[worktreeId].tsx#L3783-L3791: Snapshot the client and client ID before the create request, then drop the initial prompt when either current ref no longer matches the snapshot.Add a deferred-rebind regression test for both paths.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 28ba4c74-b4d9-44d8-a999-28f2a773171f
📥 Commits
Reviewing files that changed from the base of the PR and between afd76a4 and 2f480b2aff9d3f4654f21c4e47888bafcccde582.
📒 Files selected for processing (7)
mobile/app/h/[hostId]/session/[worktreeId].tsxmobile/src/session/mobile-session-startup-source.test.tsmobile/src/transport/client-context.test.tsmobile/src/transport/client-context.tsxmobile/src/transport/host-client-context-state.tsmobile/src/transport/host-entry-opener.tsmobile/src/transport/rpc-client-context-contract.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
|
Review status: LAND AFTER REVIEW (native mobile QA remains blocked)
Conclusion: the code review is clean and the implementation is the correct root-cause shape, but native iOS repro/visual proof is the remaining validation gap before calling this fully merge-verified. |
|
Direct validation complete on PR #16239 (commit
The native flow was initially blocked by an unavailable pairing endpoint, but succeeded after refreshing the simulator attachment and pairing through the supported flow. No pairing credentials are included here. |
|
Follow-up status: GitHub currently reports the PR as |
2f480b2 to
af62015
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
|
Conflict resolution complete. I rebased the PR onto current Validation after the rebase:
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: 4b8d0f68-78bc-4654-8daf-89c97ad1d59c
📒 Files selected for processing (10)
mobile/src/session/mobile-session-startup-source.test.tsmobile/src/session/use-mobile-session-foundation.tsmobile/src/session/use-mobile-session-lifecycle.tsmobile/src/session/use-mobile-session-terminal-runtime.tsmobile/src/session/use-mobile-session-terminal-subscription.tsmobile/src/transport/client-context.test.tsmobile/src/transport/client-context.tsxmobile/src/transport/host-client-context-state.tsmobile/src/transport/host-entry-opener.tsmobile/src/transport/rpc-client-context-contract.ts
🚧 Files skipped from review as they are similar to previous changes (5)
- mobile/src/transport/rpc-client-context-contract.ts
- mobile/src/transport/client-context.tsx
- mobile/src/transport/host-entry-opener.ts
- mobile/src/transport/client-context.test.ts
- mobile/src/transport/host-client-context-state.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.
| }, | ||
| [ | ||
| client, | ||
| clientId, |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
# Expect: the rebind path unsubscribes existing handles and resubscribes them with the new clientId.
rg -n -P -C 12 '\b(clientId|subscribeToTerminal|unsubscribeTerminal|terminalUnsubsRef)\b' \
mobile/src/session --glob 'use-mobile-session-*.ts'Repository: stablyai/orca
Length of output: 50370
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
echo '--- subscription hook outline ---'
ast-grep outline mobile/src/session/use-mobile-session-terminal-subscription.ts
echo '--- subscription hook: state, subscription, cleanup, dependencies ---'
rg -n -C 10 'terminalUnsubsRef|subscribingHandlesRef|useEffect|useCallback|subscribeToTerminal|unsubscribeTerminal|clientId' \
mobile/src/session/use-mobile-session-terminal-subscription.ts
echo '--- stream display outline and identity-related effects ---'
ast-grep outline mobile/src/session/use-mobile-session-terminal-stream-display.ts
rg -n -C 12 'terminalUnsubsRef|subscribeToTerminal|unsubscribeTerminal|useEffect|clientId|client' \
mobile/src/session/use-mobile-session-terminal-stream-display.tsRepository: stablyai/orca
Length of output: 11164
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
echo '--- native chat stream hook ---'
fd -i 'native-chat-terminal-stream|mobile-session.*(screen|route|hook)|use-mobile-session' mobile/src/session -t f | sort
echo '--- client identity and terminal subscription composition ---'
rg -n -C 12 'useMobileNativeChatTerminalStream|useMobileSessionTerminalSubscription|useMobileSessionTerminalStreamDisplay|clientId|terminalUnsubsRef' \
mobile/src/session \
--glob '*.ts' --glob '*.tsx' \
| rg -v 'use-mobile-session-keyboard-state|use-mobile-session-terminal-list|use-mobile-session-tab-switching|use-mobile-session-tab-application|use-mobile-session-terminal-create-actions'Repository: stablyai/orca
Length of output: 50369
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
echo '--- native chat stream hook implementation ---'
cat -n mobile/src/session/use-mobile-native-chat-terminal-stream.ts
echo '--- cache cleanup callers and identity transitions ---'
rg -n -C 18 'clearTerminalCache|clientId' mobile/src/session \
--glob '*.ts' --glob '*.tsx' \
| grep -E 'clearTerminalCache|clientId|useEffect|return \(\)|unsubscribeTerminal|subscribeToTerminal' \
| head -n 260
echo '--- controller composition ---'
rg -n -C 20 'useMobileSessionTerminalSubscription|useMobileSessionTerminalStreamDisplay|useMobileSessionTerminalSubscriptionFoundation|useMobileSessionFoundation' \
mobile/src/session/use-mobile-session-controller.ts \
mobile/src/session/use-mobile-session-*.tsx \
mobile/src/session/use-mobile-session-*.tsRepository: stablyai/orca
Length of output: 50369
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
echo '--- native-chat action contract ---'
cat -n mobile/src/session/mobile-native-chat-terminal-stream.ts | sed -n '1,180p'
echo '--- startup effects and cleanup ---'
cat -n mobile/src/session/use-mobile-session-startup.ts | sed -n '1,125p'
echo '--- exact cache cleanup implementation ---'
cat -n mobile/src/session/use-mobile-session-terminal-subscription-foundation.ts | sed -n '29,90p'Repository: stablyai/orca
Length of output: 12262
Rebind active terminal subscriptions when clientId changes.
useMobileNativeChatTerminalStream preserves an active non-lease stream, so an A → null → B transition can leave terminalUnsubsRef holding a stream bound to A. The new subscribeToTerminal closure then returns already-subscribed and cannot bind the stream to B. Unsubscribe active handles on identity changes, then resubscribe when clientId is available. Add a regression test for this transition.
|
Review status: ready for merge.
A/B note: I could not honestly reproduce the old failure on the parent build. Its paired-host/runtime path never became usable (the app remained unable to connect), so any apparent missing input would be indistinguishable from host unavailability. The old-build failure remains an explicit reproduction gap; the fixed branch behavior is validated independently. |
|
Independent Fable review and A/B reproduction completed at HEAD b6055cb.
This is an induced reproduction of the production timing race, not a claim that the uninstrumented simulator naturally reproduced it. |
|
Thanks for the PR @shaharmor ! |
Resolves #16239's shared-client terminal identity against the hybrid split: the hosted page has no native client, so identity readiness is a flag (hostClientIdentityReady) rather than a non-null clientId, and the bridge terminal operations keep their workspaceId/terminalId/clientId contract. Adds getClientId to the disabled hosted client context and keeps the mobile-web extra resource alongside main's new emoji shortcode dataset. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…i#16239) * fix(mobile): restore terminal input when reopening worktrees * test(mobile): update session parity facts * refactor(mobile): split host client hooks * chore: restore localization formatter scope * fix(mobile): retain RpcClient type import --------- Co-authored-by: Merge Sim <sim@local>
ELI5
Returning to a worktree on iPhone no longer leaves its terminal zoomed out with a keyboard that cannot send input. The terminal now waits for the identity already attached to its live host connection instead of racing a second credential lookup.
What Changed
Why
A reopened worktree could hydrate its terminal before an asynchronous Keychain-backed host lookup repopulated the screen-local device token. The host rejected that identity-less subscription, so the terminal received neither phone-fit geometry nor mobile input ownership; tapping the tab title happened to retry after the token had loaded.
Publishing the connection identity from the same context entry as the client removes that race and keeps reconnect or route-reuse transitions fail-closed.
Linked Issue
Reported directly; no existing issue.
Visual Proof
N/A — there is no static visual change to capture. This fixes an iPhone worktree-reopen interaction; a full Xcode/iOS simulator is not installed on the validation machine.
Testing
Validated after rebasing onto current
upstream/main:pnpm --dir mobile test— 458 files passed; 3,674 tests passed, 3 skippedpnpm --dir mobile typecheck— passedpnpm --dir mobile lint— passedpnpm --dir mobile format:check— passedpnpm run check:max-lines-ratchet— passed with no new bypassesgit diff --check upstream/main...HEAD— passedReview
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Physical iOS validation remains the explicit gap. Mixed-version desktop/mobile compatibility is unchanged because the RPC payload values and shapes are unchanged.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (mobile-scoped equivalents pass; CI will run repository-wide checks)