Skip to content

fix(mobile): survive connection-migration cutovers during worktree create - #9234

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/fix-worktree-rpc-connection
Jul 17, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/fix-worktree-rpc-connection

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Problem

On mobile (relay, shoddy cellular), creating a workspace fails with "RPC interrupted by connection migration" and the Create Workspace modal stays open — yet the worktrees actually got created on the desktop.

Root cause: the stable logical RPC client rejects any in-flight request with LogicalClientCutoverError ("RPC interrupted by connection migration") whenever the endpoint supervisor migrates the underlying transport — relay↔direct hand-off, relay lease rotation, or relay recovery after a cellular blip. A worktree.create in flight during a migration rejects on the client even though the host already ran it, so the modal surfaces the raw error while the worktree exists. A naive client retry is unsafe: worktree.create isn't idempotent, so it hits "branch already exists" → suffix bump → a duplicate worktree (matching the reporter seeing several created).

Fix

Mirror the codebase's existing precedent — mobile terminal creation already dedupes reconnect-replays via a clientMutationId (createMobileSessionTerminal) — and apply the same shape to worktree.create:

  1. Schema — worktree.create accepts an optional clientMutationId.
  2. Host idempotency — OrcaRuntimeService.dedupeWorktreeCreate wraps the create handler: a retry with the same key returns the in-flight (or just-finished, 60s TTL) worktree instead of spawning a duplicate; failures drop immediately so a genuine retry starts fresh. No key (desktop/CLI) runs unchanged.
  3. Mobile cutover retry — createWorktreeWithNameRetry mints one key per candidate name and re-issues the create on a LogicalClientCutoverError (bounded, 5×). The shared key makes the retry idempotent; a name-collision bump still gets a fresh key. Both create paths (blank + composer/source) funnel through this one function.

Net effect: a migration mid-create transparently re-lands on the fresh session and returns the existing worktree — the user gets past the screen with no duplicate.

Tests

  • Client (worktree-create-retry.test.ts): cutover retry reuses the same key then succeeds; budget exhaustion rethrows; ordinary transport errors are not treated as cutovers; a name collision mints a fresh key per candidate; clientMutationId is stamped on the request.
  • Host (orca-runtime.test.ts): dedupeWorktreeCreate coalesces concurrent same-key creates, reuses a settled success within TTL, drops failures for a fresh retry, and never dedupes across repos or without a key.

All green: mobile pnpm test (143), runtime worktree/schemas/dedup suites; typecheck:node + mobile typecheck; oxlint (incl. max-lines gate) + oxfmt.

Cross-cutting notes

  • SSH / relay: this is a relay/remote fix; the dedup lives host-side so it works across the transport the client migrates onto.
  • Git providers / platforms: no provider- or OS-specific behavior; clientMutationId is an opaque optional string.
  • Backward compatible: the field is optional — desktop/CLI callers omit it and run the create path unchanged.

QA note

The normal create flow is covered by the tests above. The actual fix — recovery from a live QUIC/relay connection migration — can't be reproduced deterministically in a simulator (needs live pairing + a real network hand-off), so it's validated at the unit level rather than via screenshot.

@coderabbitai

coderabbitai Bot commented Jul 17, 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: c5308dbb-c7b0-4751-a5e6-2a3ef62fa790

📥 Commits

Reviewing files that changed from the base of the PR and between dc6c8b9 and fe5c374.

📒 Files selected for processing (11)
  • mobile/src/components/NewWorktreeModal.tsx
  • mobile/src/tasks/blank-workspace-create.test.ts
  • mobile/src/tasks/blank-workspace-create.ts
  • mobile/src/tasks/source-workspace-create.test.ts
  • mobile/src/tasks/source-workspace-create.ts
  • mobile/src/tasks/worktree-create-capability.test.ts
  • mobile/src/tasks/worktree-create-capability.ts
  • mobile/src/tasks/worktree-create-retry.test.ts
  • mobile/src/tasks/worktree-create-retry.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/shared/protocol-version.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • mobile/src/tasks/worktree-create-retry.test.ts

📝 Walkthrough

Walkthrough

Adds optional clientMutationId validation for worktree.create, runtime promise deduplication with a 60-second success retention period, and handler integration around worktree creation and provenance cleanup. Mobile worktree creation now detects runtime support, generates per-candidate mutation IDs, and retries logical cutover failures with the same ID. Tests cover capability probing, request stamping, retry behavior, collision handling, runtime deduplication, failure cleanup, and mocked RPC dispatch.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description uses custom sections and omits required template sections like Summary, Screenshots, AI Review Report, Security Audit, and Notes. Rewrite it to match the template with Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes sections, plus the required details.
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main mobile worktree-create cutover fix.
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)
src/main/runtime/orca-runtime.test.ts (1)

1406-1417: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Cover successful-entry expiry, not only reuse.

This proves retention but not eviction after the 60-second TTL. Permanent caching would still pass, retaining promises and returning stale results for reused keys. Add a clock-controlled assertion that a post-TTL call runs the factory again.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 256f8b03-fcda-4aa2-b9c6-d367da979450

📥 Commits

Reviewing files that changed from the base of the PR and between f544820 and 3065e9c.

📒 Files selected for processing (8)
  • mobile/src/tasks/blank-workspace-create.test.ts
  • mobile/src/tasks/worktree-create-retry.test.ts
  • mobile/src/tasks/worktree-create-retry.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/rpc/methods/worktree-schemas.ts
  • src/main/runtime/rpc/methods/worktree.test.ts
  • src/main/runtime/rpc/methods/worktree.ts

…eate

A worktree.create in flight when the mobile transport migrates (relay/direct
hand-off on shoddy cellular, relay lease rotation, relay recovery) rejects with
"RPC interrupted by connection migration" even though the host completed it —
leaving the Create Workspace modal stuck while the worktree exists on desktop.
A naive retry hits a name collision and spawns a duplicate.

Mirror the existing mobile terminal-create idempotency: worktree.create now
accepts an optional clientMutationId that the host dedupes (in-flight + brief
post-success TTL), and mobile mints one key per candidate name and re-issues
the create on a cutover so the retry reconciles instead of duplicating.
@brennanb2025
brennanb2025 force-pushed the brennanb2025/fix-worktree-rpc-connection branch from 3065e9c to dc6c8b9 Compare July 17, 2026 21:52
@brennanb2025
brennanb2025 merged commit e719ef1 into main Jul 17, 2026
2 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…eate (stablyai#9234)

* fix(mobile): survive connection-migration cutovers during worktree create

A worktree.create in flight when the mobile transport migrates (relay/direct
hand-off on shoddy cellular, relay lease rotation, relay recovery) rejects with
"RPC interrupted by connection migration" even though the host completed it —
leaving the Create Workspace modal stuck while the worktree exists on desktop.
A naive retry hits a name collision and spawns a duplicate.

Mirror the existing mobile terminal-create idempotency: worktree.create now
accepts an optional clientMutationId that the host dedupes (in-flight + brief
post-success TTL), and mobile mints one key per candidate name and re-issues
the create on a cutover so the retry reconciles instead of duplicating.

* fix(mobile): gate worktree cutover replay by capability

* fix(mobile): await worktree replay capability
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