Skip to content

fix(mobile): replay terminal creates killed by transport cutover - #9796

Closed
brennanb2025 wants to merge 4 commits into
mainfrom
brennanb2025/fix-mobile-quick-command
Closed

brennanb2025 wants to merge 4 commits into
mainfrom
brennanb2025/fix-mobile-quick-command

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Tapping a quick command on mobile shortly after opening a session over relay could fail with a bare "Couldn't run codex review" toast. Desktop-side there was zero trace — no PTY, no tab, nothing in the daemon log: the request never arrived.

Root cause: the relay→direct cutover (migrateTo in stable-logical-rpc-client.ts) rejects all in-flight requests with LogicalClientCutoverError while connState stays 'connected'. The cutover fires seconds after connecting over relay — exactly when a quick command gets tapped after opening a session. Same mechanism as the capability-probe loss addressed in #9794.

Fix

  • Replay session.tabs.createTerminal with the same clientMutationId when a cutover kills it, bounded to five authenticated cutovers.
  • Keep mutation-keyed creates host-owned when the original socket closes, so a replay joins the in-flight create instead of starting a second terminal. Non-idempotent creates retain their existing disconnect cancellation.
  • Advertise session.tabs.create-terminal-idempotency.v1 only with that disconnect-safe behavior, and require this exact capability before mobile replays. Hosts that only advertise Quick Commands fail closed rather than risking a duplicate terminal.
  • Surface the underlying RPC/transport reason in the launch error and report a disconnected tap explicitly.

Timeout-shaped losses that are not identified as cutovers are intentionally not replayed.

Reliability contract

  • Invariant: terminal-session.create-cutover-idempotency — one mutation creates at most one terminal across relay/direct connection migration.
  • Failure source: an authenticated transport replacement rejects a client request while the old host request may be absent, in flight, or already committed.
  • Oracle: fault-injected tests abort the original request, replay the same mutation, and require exactly one renderer terminal:requestTabCreate; client tests require the same key, explicit capability, non-cutover propagation, and a six-attempt hard ceiling.
  • Gate: accepted manifest gap; no exact config/reliability-gates.jsonc entry exists yet. Deterministic mobile and host unit contracts cover this PR.
  • Provider/platform coverage: the ownership/dedupe logic is provider- and platform-neutral and runs before local, daemon, SSH, or WSL terminal realization. Mobile/relay cutover is covered deterministically; no filesystem, path, shell, or desktop-only assumption was added.
  • Performance budget: ordinary launches remain one RPC. Only explicit authenticated cutovers can add work, capped at five replays; the host emits one renderer create for a shared mutation. No polling, sleeps, scans, subprocesses, provider fanout, or persistent listeners were added.
  • Diagnostics: failure toasts retain the action label and append the transport/RPC reason.
  • Residual gap: no packaged-device live relay→direct cutover artifact is attached; old hosts without the new capability retain the original fail-safe error rather than replaying.

Verification

  • Mobile: 304 files, 2,178 tests passed.
  • Host/runtime: 3 focused files, 819 tests passed, including the full orca-runtime.test.ts.
  • Mobile and Node TypeScript checks passed.
  • Full mobile lint and changed-file host lint passed.
  • Reliability manifest and max-lines ratchet checks passed.

A quick command tapped right after opening a session over relay could fail
with a bare "Couldn't run <label>" toast: the relay→direct cutover
(migrateTo in stable-logical-rpc-client) rejects in-flight requests with
LogicalClientCutoverError while connState stays 'connected', so the
session.tabs.createTerminal RPC died client-side and the desktop never saw
it. Same mechanism proven for the capability probe in #9794.

Fix: replay the create with the SAME clientMutationId on cutover (bounded,
immediate — the replacement session is already authenticated), mirroring
tasks/worktree-create-retry.ts. The host has deduped createTerminal by
mutation id (e253d46) since before it advertised
terminal.quick-commands.v1 (5fcf777), so gating the replay on that
capability provably cannot double-create on older hosts.

Also stop masking the underlying failure: the toast now appends the real
RPC/transport reason, and tapping a quick command while disconnected says
so instead of doing nothing.
@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 171be5b4-797f-40f4-bcee-71a7029d3199

📥 Commits

Reviewing files that changed from the base of the PR and between a02521e and 9a47f9c.

📒 Files selected for processing (1)
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • mobile/app/h/[hostId]/session/[worktreeId].tsx

📝 Walkthrough

Walkthrough

Adds a runtime capability for idempotent session terminal creation and preserves mutation-based terminal work across interrupted connections. Mobile terminal creation now uses capability-gated, bounded retries with the same mutation ID after cutover errors. The session screen tracks runtime support, formats terminal creation failures, extends error toast duration, and reports disconnected quick-command launches explicitly. Tests cover runtime replay, retry behavior, capability gating, error formatting, and retry bounds.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is informative, but it doesn't follow the required template sections like Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes. Reformat the PR body to match the template and add the missing sections, including screenshots/No visual change, test checklist, AI review, security audit, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main mobile fix: replaying terminal creates across transport cutover.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
mobile/src/session/session-terminal-create-retry.ts (1)

14-42: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract the shared cutover-retry loop. sendSessionTerminalCreateResilient uses the same bounded, capability-gated cutover retry pattern as sendWorktreeCreateResilient; a shared helper would keep the retry budget and error classification from drifting.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 12f2d807-a18d-4f5a-adb5-60940157472f

📥 Commits

Reviewing files that changed from the base of the PR and between 71bbfa0 and 3cc5ed2.

📒 Files selected for processing (9)
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • mobile/src/session/session-terminal-create-retry.test.ts
  • mobile/src/session/session-terminal-create-retry.ts
  • mobile/src/terminal/quick-commands.test.ts
  • mobile/src/terminal/quick-commands.ts
  • mobile/src/transport/stable-logical-rpc-client.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/shared/protocol-version.ts

…le-quick-command

# Conflicts:
#	mobile/app/h/[hostId]/session/[worktreeId].tsx
#	mobile/src/transport/stable-logical-rpc-client.ts
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Manual QA evidence

Validated the mobile Quick Command flow against this branch using an iPhone 17 Pro simulator paired to the branch-specific Electron dev app. One tap created exactly one new terminal (1 → 2 tabs), selected Terminal 2, and ran echo mobile-quick-command-ok. Electron independently showed the same second terminal and output.

Mobile

Mobile Quick Command result

Electron

Electron confirmation

Post-conflict validation: mobile tests 2,186 passed (2 skipped), mobile typecheck/lint passed, and runtime/protocol tests 810 passed.

brennanb2025 added a commit that referenced this pull request Jul 22, 2026
…gration (#9798)

Opening the Quick Commands sheet right after connecting over relay races
the relay->direct cutover, which rejects the in-flight one-shot
settings.getTerminalQuickCommands with LogicalClientCutoverError while
connState stays 'connected'. The sheet then strands on "RPC interrupted
by connection migration" with an empty list until closed and reopened.

The read is side-effect-free, so replay it on cutover (capped at 5,
cancelled if the sheet closes or the client is replaced). Same failure
class and pattern as #9794 (capability probe) and #9796 (terminal
create).
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Close this older implementation after creating a GitHub issue for terminal creation interrupted by a phone connection change. Keep safe retries and useful failure feedback in the current host launch path.

The remaining problem is tracked in #27646.

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…gration (stablyai#9798)

Opening the Quick Commands sheet right after connecting over relay races
the relay->direct cutover, which rejects the in-flight one-shot
settings.getTerminalQuickCommands with LogicalClientCutoverError while
connState stays 'connected'. The sheet then strands on "RPC interrupted
by connection migration" with an empty list until closed and reopened.

The read is side-effect-free, so replay it on cutover (capped at 5,
cancelled if the sheet closes or the client is replaced). Same failure
class and pattern as stablyai#9794 (capability probe) and stablyai#9796 (terminal
create).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant