Repository navigation
Preserve local SSH terminal splits during reconnect - #22991
Conversation
66bfe29 to
6d4b493
Compare
There was a problem hiding this comment.
ℹ️ Minor suggestions only — one guard gap and two small follow-ups.
Reviewed changes
- Pending local-edit ledger —
pendingDirectSshLayoutEditsByTabIdrecords{ targetId, root }for each local structural terminal-layout edit on an SSH-hosted workspace, and is cleared on tab/worktree/target teardown (terminal-layout-state.ts,terminal-state.ts, and the teardown paths). - Preserve through snapshot merge — direct-SSH snapshot apply passes the pending-layout tab ids into
mergeDirectSshRemoteWorkspaceSession, so a local split wins over the host's older layout (remote-workspace-snapshot-apply.ts,remote-workspace-session-merge.ts). - Acknowledge on upload — both upload paths clear a pending entry once the host echoes back a matching root, returning ownership to the host (
use-app-session-persistence.ts,remote-workspace-target-sync.ts). - Tests — merge preservation with a
missing/outdatedhost layout, reference- and target-guarded acknowledgement, and target-scoped cleanup.
ℹ️ Nitpicks
buildOrphanTerminalCleanupPatch(store/slices/terminal-orphan-helpers.ts) deletes tab rows andterminalLayoutsByTabIdentries but notpendingDirectSshLayoutEditsByTabId, unlike the teardown paths this PR updates. It is a session-bounded leak with no behavioral impact (the preserve set is live-tab-scoped), so it is optional — but adding the same omission keeps the sweep families in lockstep.- No test exercises the acknowledgement round-trip end to end (upload echoes the root → entry clears → a later host layout can win). The slice-level test pins the identity/target guard, but the two ack call sites and the clear itself are untested, so a regression there would not trip CI.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
6d4b493 to
24ada45
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes (delta since the prior pullfrog review at 66bfe29)
- Target-scoped preservation — the snapshot-apply preserve set now filters on
pendingDirectSshLayoutEditsByTabId[tab.id]?.targetId === authority.targetId, matching the two acknowledgement checks. This closes the stale-host-entry veto raised in the previous review. - Pre-push capture in the blank-host acknowledgement —
remote-workspace-target-sync.tsnow capturespendingDirectSshLayoutEditsByTabIdbefore the upload and acknowledges the captured references, so a newer same-root (e.g. null-root) edit arriving during the async push is no longer cleared by the delayed ack. - Coverage — new test
remote-workspace-target-sync.test.ts:48pins the captured-identity acknowledgement; the harness now seedspendingDirectSshLayoutEditsByTabIdandacknowledgeDirectSshLayoutEdits.
All four focused test files pass locally (44 tests). The two non-blocking notes from the prior review (capture-time leaf normalization and the orphan-cleanup omission) still stand but are unchanged by this delta.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes (delta since the prior pullfrog review at 6d4b493)
- Test-only refinement —
remote-workspace-target-sync.test.tsnow declares its ownacknowledgeDirectSshLayoutEdits = vi.fn()and asserts the acknowledged call argument (firstEdit) directly, rather than relying on the harness default mock. Behavior under test is unchanged; the assertion is marginally more explicit. - Production code is unchanged from the previous review, where the target-scoped preserve filter and the pre-push capture of
pendingDirectSshLayoutEditsByTabIdwere verified.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 📝 WalkthroughWalkthroughThe renderer now tracks structural terminal layout edits by tab and SSH target. Snapshot merging preserves layouts for tabs with pending edits. Successful uploads acknowledge captured edits only when the target and uploaded layout match. Target, tab, and worktree cleanup removes associated pending edits. Tests cover upload races and reconnects with missing or outdated remote layouts. Priority: ➖ Normal Merge Risk: 🔵 Low · up to A narrow reconnect case can leave a local terminal layout protected after it has been uploaded. The issue is recoverable through another structural edit or tab deletion, but should be fixed or accepted before merging. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change is limited to terminal layout synchronization and does not show a new remotely reachable operation or a verified security finding. Its protection appears to depend on state that may not survive an application restart, so recovery remains uncertain. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: cabc8c39-afda-4a63-a269-5b5ed8271018
📒 Files selected for processing (18)
src/renderer/src/app-shell/use-app-session-persistence.tssrc/renderer/src/hooks/__tests__/remote-workspace-target-sync-test-harness.tssrc/renderer/src/hooks/remote-workspace-session-merge.tssrc/renderer/src/hooks/remote-workspace-snapshot-apply-deferred-session-write.test.tssrc/renderer/src/hooks/remote-workspace-snapshot-apply.tssrc/renderer/src/hooks/remote-workspace-target-sync.test.tssrc/renderer/src/hooks/remote-workspace-target-sync.tssrc/renderer/src/store/slices/ssh-target-cleanup.test.tssrc/renderer/src/store/slices/ssh-target-cleanup.tssrc/renderer/src/store/slices/terminal-write-identity-bailouts.test.tssrc/renderer/src/store/slices/terminals.tssrc/renderer/src/store/slices/worktrees/teardown/remove-worktree-store-cleanup.tssrc/renderer/src/store/slices/worktrees/teardown/worktree-purge-state.tssrc/renderer/src/store/terminals/terminal-actions.tssrc/renderer/src/store/terminals/terminal-layout-state.tssrc/renderer/src/store/terminals/terminal-state.tssrc/renderer/src/store/terminals/terminal-tab-close.tssrc/renderer/src/store/terminals/workspace-terminal-hydration-patch.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
| const structuralEdit = !terminalLayoutNodeEqual(existing?.root, normalized.snapshot.root) | ||
| const workspaceId = structuralEdit | ||
| ? Object.keys(s.tabsByWorktree).find((id) => | ||
| s.tabsByWorktree[id].some((tab) => tab.id === tabId) | ||
| ) | ||
| : undefined | ||
| const tracksRemoteEdit = workspaceId && getConnectionIdFromState(s, workspaceId) | ||
| return { | ||
| terminalLayoutsByTabId: { ...s.terminalLayoutsByTabId, [tabId]: normalized.snapshot } | ||
| terminalLayoutsByTabId: { ...s.terminalLayoutsByTabId, [tabId]: normalized.snapshot }, | ||
| ...(tracksRemoteEdit | ||
| ? { | ||
| pendingDirectSshLayoutEditsByTabId: { | ||
| ...s.pendingDirectSshLayoutEditsByTabId, | ||
| [tabId]: { targetId: tracksRemoteEdit, root: normalized.snapshot.root } | ||
| } | ||
| } | ||
| : {}) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '70,155p' src/renderer/src/store/terminals/terminal-layout-state.ts
rg -n 'normalizeTerminalLayoutSnapshot|pendingDirectSshLayoutEditsByTabId|hydrateWorkspaceSession' src/renderer/src/store/terminals src/renderer/src/hooks/remote-workspace-snapshot-apply.ts src/renderer/src/app-shell/use-app-session-persistence.tsRepository: stablyai/orca
Length of output: 7003
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- terminal layout state imports and definitions ---'
sed -n '1,155p' src/renderer/src/store/terminals/terminal-layout-state.ts
printf '%s\n' '--- normalization definitions and usages ---'
rg -n -C 8 'function normalizeTerminalLayoutSnapshot|const normalizeTerminalLayoutSnapshot|normalizeTerminalLayoutSnapshot|normalizeTerminalLayoutPtyOwnership' src/renderer/src/store/terminals
printf '%s\n' '--- remote snapshot application ---'
sed -n '145,225p' src/renderer/src/hooks/remote-workspace-snapshot-apply.ts
printf '%s\n' '--- hydration implementation ---'
sed -n '1,240p' src/renderer/src/store/terminals/workspace-terminal-hydration.ts
printf '%s\n' '--- hydration patch ---'
sed -n '1,230p' src/renderer/src/store/terminals/workspace-terminal-hydration-patch.ts
printf '%s\n' '--- acknowledgement callers ---'
rg -n -C 10 'acknowledgeDirectSshLayoutEdits|pendingDirectSshLayoutEditsByTabId' src/renderer/src --glob '!**/*.test.*'
printf '%s\n' '--- PR diff summary and changed file diff ---'
git diff --stat e785cacb67ac0fbc69cc9aa41ddee3af6fa08ce3 24ada4517df1dfae93c5115febb3efdfc0c109bb -- src/renderer/src/store/terminals/terminal-layout-state.ts src/renderer/src/hooks/remote-workspace-snapshot-apply.ts src/renderer/src/store/terminals/workspace-terminal-hydration.ts src/renderer/src/store/terminals/workspace-terminal-hydration-patch.ts
git diff --unified=35 e785cacb67ac0fbc69cc9aa41ddee3af6fa08ce3 24ada4517df1dfae93c5115febb3efdfc0c109bb -- src/renderer/src/store/terminals/terminal-layout-state.ts src/renderer/src/hooks/remote-workspace-snapshot-apply.tsRepository: stablyai/orca
Length of output: 41793
🤖 get_repo_knowledge executed:
get_repo_knowledge stablyai/orca /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions
Length of output: 36929
🏁 Script executed:
#!/bin/bash
set -e
sed -n '1,155p' src/renderer/src/store/terminals/terminal-layout-state.ts
rg -n -C 12 'normalizeTerminalLayoutSnapshot|normalizeTerminalLayoutPtyOwnership|pendingDirectSshLayoutEditsByTabId|acknowledgeDirectSshLayoutEdits' src/renderer/src/store/terminals src/renderer/src/hooks/remote-workspace-snapshot-apply.ts
sed -n '150,220p' src/renderer/src/hooks/remote-workspace-snapshot-apply.ts
sed -n '1,230p' src/renderer/src/store/terminals/workspace-terminal-hydration.ts
sed -n '1,220p' src/renderer/src/store/terminals/workspace-terminal-hydration-patch.ts
rg -n -C 12 'acknowledgeDirectSshLayoutEdits' src/renderer/src
git diff --stat e785cacb67ac0fbc69cc9aa41ddee3af6fa08ce3 24ada4517df1dfae93c5115febb3efdfc0c109bb -- src/renderer/src/store/terminals/terminal-layout-state.ts src/renderer/src/hooks/remote-workspace-snapshot-apply.ts src/renderer/src/store/terminals/workspace-terminal-hydration.ts src/renderer/src/store/terminals/workspace-terminal-hydration-patch.ts
git diff --unified=35 e785cacb67ac0fbc69cc9aa41ddee3af6fa08ce3 24ada4517df1dfae93c5115febb3efdfc0c109bb -- src/renderer/src/store/terminals/terminal-layout-state.ts src/renderer/src/hooks/remote-workspace-snapshot-apply.tsRepository: stablyai/orca
Length of output: 42485
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- merge definition and callers ---'
rg -n -C 18 'function mergeDirectSshRemoteWorkspaceSession|const mergeDirectSshRemoteWorkspaceSession|mergeDirectSshRemoteWorkspaceSession' src/renderer/src
printf '%s\n' '--- leaf-id normalization definition ---'
rg -n -C 25 'normalizeTerminalLayoutSnapshot' src/renderer/src/components src/renderer/src/lib src/shared
printf '%s\n' '--- layout plan full relevant range ---'
sed -n '1,150p' src/renderer/src/store/terminals/workspace-terminal-layout-plan.ts
printf '%s\n' '--- hydration patch relevant ranges ---'
sed -n '130,205p' src/renderer/src/store/terminals/workspace-terminal-hydration-patch.ts
printf '%s\n' '--- upload capture and both acknowledgement paths ---'
sed -n '80,185p' src/renderer/src/app-shell/use-app-session-persistence.ts
sed -n '175,230p' src/renderer/src/hooks/remote-workspace-target-sync.ts
printf '%s\n' '--- relevant type definitions ---'
rg -n -C 10 'DirectSshLayoutEdit|TerminalLayoutSnapshot|leafId' src/shared/terminal-tab-types.ts src/renderer/src/store/terminals/terminal-state.ts src/renderer/src/components/terminal-pane/terminal-layout-leaf-ids.tsRepository: stablyai/orca
Length of output: 42045
🏁 Script executed:
#!/bin/bash
set -e
rg -n -C 18 'function mergeDirectSshRemoteWorkspaceSession|const mergeDirectSshRemoteWorkspaceSession|mergeDirectSshRemoteWorkspaceSession' src/renderer/src
rg -n -C 25 'normalizeTerminalLayoutSnapshot' src/renderer/src/components src/renderer/src/lib src/shared
sed -n '1,150p' src/renderer/src/store/terminals/workspace-terminal-layout-plan.ts
sed -n '130,205p' src/renderer/src/store/terminals/workspace-terminal-hydration-patch.ts
sed -n '80,185p' src/renderer/src/app-shell/use-app-session-persistence.ts
sed -n '175,230p' src/renderer/src/hooks/remote-workspace-target-sync.ts
rg -n -C 10 'DirectSshLayoutEdit|TerminalLayoutSnapshot|leafId' src/shared/terminal-tab-types.ts src/renderer/src/store/terminals/terminal-state.ts src/renderer/src/components/terminal-pane/terminal-layout-leaf-ids.tsRepository: stablyai/orca
Length of output: 42647
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- direct SSH merge body ---'
sed -n '29,240p' src/renderer/src/hooks/remote-workspace-session-merge.ts
printf '%s\n' '--- layout plan ---'
sed -n '12,100p' src/renderer/src/store/terminals/workspace-terminal-layout-plan.ts
printf '%s\n' '--- hydration layout-plan invocation and patch ---'
rg -n -C 12 'buildWorkspaceTerminalLayoutPlan|targetScopedWorkspaceHydrationPatch|terminalLayoutsByTabId' src/renderer/src/store/terminals/workspace-terminal-hydration.ts src/renderer/src/store/terminals/workspace-terminal-hydration-patch.ts
printf '%s\n' '--- persistence capture helper and upload path ---'
rg -n -C 18 'captureUploadedDirectSshLayoutEdits|pendingLayoutEdits|setForConnectedTargets|acknowledgeDirectSshLayoutEdits' src/renderer/src/app-shell/use-app-session-persistence.ts src/renderer/src/hooks/remote-workspace-target-sync.tsRepository: stablyai/orca
Length of output: 42109
🏁 Script executed:
#!/bin/bash
set -e
sed -n '29,240p' src/renderer/src/hooks/remote-workspace-session-merge.ts
sed -n '12,100p' src/renderer/src/store/terminals/workspace-terminal-layout-plan.ts
rg -n -C 12 'buildWorkspaceTerminalLayoutPlan|targetScopedWorkspaceHydrationPatch|terminalLayoutsByTabId' src/renderer/src/store/terminals/workspace-terminal-hydration.ts src/renderer/src/store/terminals/workspace-terminal-hydration-patch.ts
rg -n -C 18 'captureUploadedDirectSshLayoutEdits|pendingLayoutEdits|setForConnectedTargets|acknowledgeDirectSshLayoutEdits' src/renderer/src/app-shell/use-app-session-persistence.ts src/renderer/src/hooks/remote-workspace-target-sync.tsRepository: stablyai/orca
Length of output: 41868
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- remaining merge layout/session sweeps ---'
sed -n '240,430p' src/renderer/src/hooks/remote-workspace-session-merge.ts
printf '%s\n' '--- setTabLayout callers ---'
rg -n -C 8 'setTabLayout\(' src/renderer/src --glob '!**/*.test.*'Repository: stablyai/orca
Length of output: 42041
🏁 Script executed:
#!/bin/bash
set -e
sed -n '240,430p' src/renderer/src/hooks/remote-workspace-session-merge.ts
rg -n -C 8 'setTabLayout\(' src/renderer/src --glob '!**/*.test.*'Repository: stablyai/orca
Length of output: 41238
Normalize leaf IDs before recording the pending edit.
setTabLayout normalizes PTY ownership but not leaf IDs. Hydration later normalizes the preserved layout and can rewrite duplicate or invalid leaf IDs. The pending root then differs from the uploaded root, so both acknowledgement paths retain the pending entry. Later snapshots can continue preserving the local layout until another structural edit or tab deletion.
Suggested fix
+import { normalizeTerminalLayoutSnapshot } from '`@/components/terminal-pane/terminal-layout-leaf-ids`'
import {
- normalizeTerminalLayoutPtyOwnership,
resolveTerminalLayoutPtyOwnershipTransfers
} from '`@/components/terminal-pane/terminal-layout-pty-ownership`'
...
- const normalized = normalizeTerminalLayoutPtyOwnership(layout)
+ const normalized = normalizeTerminalLayoutSnapshot(layout)This correction is separate from the target-scoping fix. Target scoping preserves the local layout during merge; it does not update the pending root after hydration normalization.

ELI5
When a remote workspace reconnects while you are splitting a terminal, the reconnect can briefly report the older one-pane layout. Orca now keeps the local split until that exact edit has been uploaded to the SSH host.
What Changed
Before, a same-generation SSH snapshot could replace a local structural terminal layout before the normal 150ms session upload, reopening the tab as one pane while the remote shells remained alive. The renderer now records each local structural SSH layout edit with its target and a fresh entry identity, preserves those tabs during snapshot merge, acknowledges successful uploads from both normal persistence and blank-host seeding, and drops entries when tabs, worktrees, or SSH targets are removed. Host snapshots resume normal ownership after the matching upload acknowledgement.
Why
The fix stays in the existing client-side snapshot merge and upload acknowledgement paths, so it requires no new wire fields or broad sync redesign. Target-scoped entry identity prevents a delayed acknowledgement from clearing a newer edit, including reused roots and null roots, while still allowing legitimate host replacements after acknowledgement.
Linked Issue
Fixes #2323
Visual Proof
N/A — this is a state-recovery fix with no visual styling or interaction change.
Testing
Focused Vitest:
remote-workspace-target-sync.test.ts,remote-workspace-snapshot-apply-deferred-session-write.test.ts,terminal-write-identity-bailouts.test.ts, andssh-target-cleanup.test.ts(43 tests passed).pnpm tc:webandpnpm run check:code-quality:changedpassed.Review
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
The change preserves current process authority and remote mixed-version wire contracts. It does not change resource bounds or claim to fix unrelated PTY-count regressions.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)