Repository navigation
fix(ssh): contain reattach to existing panes, quarantine orphans - #12743
AmethystLiang wants to merge 4 commits into
Conversation
Replace dry-run persistPtyBinding with explicit resolveExistingSshPtyBinding to validate pane identity exists and is unique. Support resolving incomplete legacy leases by matching against durable terminal layout state. Properly quarantine and block duplicates by deleting ownership records.
The renderer partitions SSH worktrees by hostId but collapses repo-only ownership onto the local partition. When resolving panes for reattach, search both the target and local partitions and bind each pane back to the partition where it was found. Batch quarantine writes per reattach pass to avoid per-pane I/O overhead.
- Add compare-and-set validation to persistPtyBinding for stale detection - Refuse reattach when pane was replaced or reassigned during resolution - Reject conflicting pane copies across host partitions - Coalesce duplicate remote PTY identities - Make quarantine async and transactional with rollback
📝 WalkthroughWalkthroughThis change updates SSH PTY reattach and reconnect handling. The store now coalesces remote PTY leases by identity, enforces monotonic lease finality, resolves durable pane bindings across host partitions, and supports guarded 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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 (3)
src/main/persistence.ts (1)
6648-6661: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueExtract the resolved-binding shape into a named type.
The same six-field object shape is declared inline at Line 6654 and again at Line 6698.
src/main/ssh/ssh-relay-session.tsthen derivesResolvedSshPtyBindingfromReturnType<Store['resolveExistingSshPtyBinding']>. A named exported type keeps the public and private shapes from drifting apart.♻️ Proposed refactor
+export type ResolvedSshPtyBinding = { + worktreeId: string + tabId: string + leafId: string + hostId: ExecutionHostId + ptyId: string + incarnationId?: string +} + resolveExistingSshPtyBinding(args: { targetId: string ptyId: string worktreeId?: string tabId?: string leafId?: string - }): { - worktreeId: string - tabId: string - leafId: string - hostId: ExecutionHostId - ptyId: string - incarnationId?: string - } | null { + }): ResolvedSshPtyBinding | null {src/main/ssh/ssh-relay-session.ts (1)
2342-2348: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winTreating a thrown
persistPtyBindingas'bound'bypasses the containment guarantee.When
persistPtyBindingthrows, the compare-and-set result is unknown. This code then continues as if the guarded bind succeeded, registers runtime state at Line 2351, and the caller sets PTY ownership at Line 2237. That is the cross-wiring case this change is meant to prevent.The opposite choice also has a cost: a transient write failure would quarantine a pane whose remote shell is still running. If the current behavior is the intended trade-off, add a short
Whycomment stating it, because the surrounding code refuses every other unverified path.src/main/ssh/ssh-relay-session-test-fixtures.ts (1)
30-40: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winThe binding mock cannot detect a wrong PTY id form.
The mock echoes
binding.ptyIdback in the result. It accepts both the relay-form id (pty-live) and the app-form id (ssh:target-1@@pty-live). Production code calls this resolver with both forms, so the mock hides an id-form mismatch. Make the mock resolve only the app-form id, so a caller that passes a relay-form id getsnull.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 814e8b84-2bfe-4a9b-bb07-4dbac9b92040
📒 Files selected for processing (9)
src/main/persistence-ssh-reattach-containment.test.tssrc/main/persistence.tssrc/main/ssh/ssh-relay-session-reattach-quarantine.test.tssrc/main/ssh/ssh-relay-session-reconnect-incarnation.test.tssrc/main/ssh/ssh-relay-session-test-fixtures.tssrc/main/ssh/ssh-relay-session.test.tssrc/main/ssh/ssh-relay-session.tssrc/main/ssh/ssh-remote-pty-lease-selection.test.tssrc/main/ssh/ssh-remote-pty-lease-selection.ts
|
@coderabbitai Fixing. Will be in the next commit |
|
Tip For best results, initiate chat on the files or code changes.
You are interacting with an AI system. |
|
Heads up — I've opened #13111 against the same defect, and I want to be upfront about the overlap rather than have two branches drift. Your design caught a bug in mine. I was arbitrating duplicate leases by recency alone. Your
What's different in #13111: it's rebased on current What you have that I don't: host-partition resolution (target vs local spill, and conflicting copies across partitions), and rollback when a durable write fails mid-quarantine. Those are real gaps in mine. Happy to go either way — fold your partition/rollback coverage into #13111, or rebase this one and close mine. Your call as the author; I'd rather not duplicate the work. |
|
SSH still works: Orca connects to the host over SSH and routes workspace operations through the managed remote Orca server (orcad). These merges remove the legacy SSH relay, not SSH support. Closing as obsolete after the merged SSH relay retirement in #27214 and #27215. This PR concerns the SSH relay PTY attach, recovery, replay, or lease lifecycle. #27214 removed the desktop relay connection/fallback path; #27215 deleted the SSH relay server, deployment assets, and relay-only tests. SSH hosts now use the managed Orca server (orcad), and unsupported hosts fail explicitly, so this relay-specific work is no longer planned. This closes the proposed relay implementation; it does not claim that any independent local, WSL, or managed-server behavior was fixed. |
Summary
SSH reattach now validates each remote PTY lease against durable pane state before restoring it, preventing cross-wiring to wrong panes or creating phantom entries. Unverified leases are quarantined to prevent revival on reconnect.
Changes
resolveExistingSshPtyBinding(): Searches both SSH target and local partitions for durable pane bindings, preferring target partition when both existquarantineSshRemotePtyLeasesAsync(): Marks orphaned leases asexpiredin one batched write per reattach passpersistPtyBinding(): AddedmayCreate: falseoption to refuse creating panes during reattach; compare-and-set withexpectedBindingdetects post-attach racesssh-remote-pty-lease-selection.ts: Coalesces duplicate remote PTY identities and selects winner lease for reattachFixes
STA-3077: Reattach no longer cross-wires to wrong panes or creates orphaned entries. Resolves incomplete legacy leases to pane identity before reattach. Prevents duplicate remote PTY identities from interfering with active sessions.
Testing
pnpm lintpnpm typecheckpnpm test— added comprehensive tests for lease coalescing, partition-aware pane resolution, quarantine rollback on failure, compare-and-set races, legacy lease resolution, and duplicate blocking across reconnectspnpm buildNotes