Repository navigation
Conversation
On direct-SSH targets, every connect/reconnect/wake pulled the remote workspace snapshot and replaced local tab state whenever its revision was > 0, even when the remote had not changed since this client last synced. Tabs closed while the target was offline (or while a push was suppressed) came back on the next reconnect — e.g. launching a quick command spawned a terminal, triggered the connect, and re-opened every previously closed tab. Three coordinated fixes: - Track the last fully synced remote revision per target (recorded on every 'synced' push/pull status) and, on reconnect, push local state instead of pulling when the remote revision did not advance. Local offline edits win over an unchanged remote snapshot. - Ignore unsolicited workspace.changed snapshots at or below the last synced revision so late/out-of-order notifications cannot stomp newer local state. - Defer session writes blocked by an in-flight snapshot apply instead of dropping them; a tab closed during the apply window now persists to the local session file and the remote mirror once the apply ends. Fixes stablyai#10342 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
📝 WalkthroughWalkthroughThe SSH slice tracks the last successfully synchronized remote workspace revision per target and removes that data during target cleanup. Remote workspace synchronization uploads local state when no newer remote revision exists and ignores stale unsolicited snapshots. Session persistence retains changes and pending debounce work while scheduling is blocked, then flushes them when scheduling reopens. Tests cover revision tracking, synchronization decisions, cleanup, deferred persistence, and terminal-tab closure during reconnection. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
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: Pro Plus
Run ID: b9bf25f9-c68d-4b3e-9dbd-05e6fa0c76a3
📒 Files selected for processing (7)
src/renderer/src/hooks/remote-workspace-target-sync.test.tssrc/renderer/src/hooks/remote-workspace-target-sync.tssrc/renderer/src/lib/session-write-subscriber.test.tssrc/renderer/src/lib/session-write-subscriber.tssrc/renderer/src/store/slices/ssh-target-cleanup.tssrc/renderer/src/store/slices/ssh.test.tssrc/renderer/src/store/slices/ssh.ts
Docker-SSH E2E for the stablyai#10342 scenario: commit three tabs to the relay workspace, latch the push path in 'conflict' (the stablyai#2323 C2 stale-revision state), close two tabs through the real tab-bar buttons while the target is disconnected, then reconnect. Without the reconnect arbitration the stale relay snapshot is pulled and both closed tabs re-materialize in the tab bar (verified failing on the pre-fix sources); with it the client uploads local state instead and the relay mirror converges to the surviving tab. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
E2E verification (A/B against a real Electron app + dockerized SSH host)Added Without the fix (same spec run with the four fixed source files reverted to their parent-commit state): With the fix: The spec pins the arbitration itself ( |
Review follow-up (PR stablyai#12339): pushLocalSession only checked preparation-token currency, so an older syncAfterConnect attempt resolving after a newer one could report its stale upload result and regress the sync status and last-synced revision. Gate the upload on arrival currency before and after the request, matching the pull path's fencing. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/hooks/remote-workspace-target-sync.test.ts (1)
274-278: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winAssert that the stale upload does not regress
lastSyncedRemoteWorkspaceRevisionByTargetId.
setRemoteWorkspaceSyncStatus(..., { phase: 'synced', revision: 6 })also writesstate.lastSyncedRemoteWorkspaceRevisionByTargetId[owner.targetId] = 6, so this test can pass while dropping the stored revision from7to6. Add an assertion afterawait firstthat the stored revision remains7.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 0735abee-ee19-469c-bfea-5df83c16d0d3
📒 Files selected for processing (2)
src/renderer/src/hooks/remote-workspace-target-sync.test.tssrc/renderer/src/hooks/remote-workspace-target-sync.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/renderer/src/hooks/remote-workspace-target-sync.ts
|
Closing as superseded by merged #16752 and #16969. #16752 makes an unacknowledged remote terminal close survive reconnect through persisted tombstones and includes Docker SSH coverage; #16969 ensures closes made during snapshot application are persisted instead of dropped. Those are the two failure paths documented when #10342 was closed, and they cover this PR’s resurrection scenario without the older revision-arbitration approach. |
Fixes #10342. Related: #2323 (item C2), #9352 (paired-viewer sibling), #11729 / #12264 (complementary main-process lease path — no file overlap).
Summary
On a direct-SSH workspace, closing terminal tabs doesn't stick: closed tabs re-materialize the next time a terminal is opened (e.g. launching a quick command), on reconnect, or on system wake.
Mechanism. Orca mirrors the tab session to the SSH host as a revisioned snapshot (
workspace.get/workspace.patch), and every connect/reconnect/wake runssyncAfterConnect, which pulled the snapshot and replaced local tab state wheneverrevision > 0— with no check for whether the remote had actually changed since this client last synced (src/renderer/src/hooks/remote-workspace-target-sync.ts). Any close that never reached the remote mirror (target offline, push conflict latch per #2323-C2, or the write-drop below) was resurrected by the next pull. Opening a quick-command terminal triggers the SSH connect, hence "open new terminal → all my closed tabs come back" (#10342).Compounding it, the session-write subscriber dropped (not deferred) pending changes while a snapshot apply was in flight — a window up to ~30s after each reconnect (
createSessionWriteSubscriber+ theshouldSchedulePersistgate inApp.tsx). A tab closed in that window never persisted to the local session file or the remote mirror at all.Fixes
lastSyncedRemoteWorkspaceRevisionByTargetId(recorded on every'synced'push/pull status; cleared on target removal). InsyncAfterConnect, if the remote revision did not advance past it, skip the pull and push local state instead — local offline edits win over an unchanged remote snapshot. A genuinely newer revision (another device wrote) still pulls and merges as before.workspace.changedsnapshots at or below the last synced revision, so late or out-of-order notifications can't stomp newer local state.Test plan
remote-workspace-target-sync.test.ts,session-write-subscriber.test.ts,ssh.test.ts)oxlint,typecheck:web,check:max-lines-ratchetcleanGenerated with Devin