Repository navigation
fix(remote-workspace): host silence must not delete a local row it was never told about - #16748
Merged
Merged
Conversation
This was referenced Aug 27, 2026
nwparker
force-pushed
the
nwparker/ssh-02-normalizer-field
branch
from
August 27, 2026 09:49
80122bb to
a7f689a
Compare
nwparker
force-pushed
the
nwparker/ssh-03-merge-preserves-local
branch
from
August 27, 2026 09:49
344cc8d to
07710c8
Compare
nwparker
force-pushed
the
nwparker/ssh-02-normalizer-field
branch
from
August 27, 2026 09:52
a7f689a to
5e16b6c
Compare
nwparker
force-pushed
the
nwparker/ssh-03-merge-preserves-local
branch
from
August 27, 2026 09:53
07710c8 to
01862a3
Compare
nwparker
force-pushed
the
nwparker/ssh-02-normalizer-field
branch
from
August 28, 2026 02:41
5e16b6c to
13341a3
Compare
…s never told about Two fields in `mergeDirectSshRemoteWorkspaceSession` treated an absent remote entry as an authoritative delete. Both are records whose *absence* is meaningful, so deleting them on silence loses information the host never had. 1. The closed-last-terminal tombstone. `src/renderer/src/components/terminal/initial-terminal.ts:5` states the contract verbatim: "a missing row means never initialized; an explicit empty row records that the user closed the last terminal." `mergedWorktreeIds` was `keys(remote.tabsByWorktree)` union the replaced worktrees whose local tab list is NON-EMPTY (`:41-45`), so a worktree holding an explicit `[]` and absent from the host snapshot was excluded, `omitTargetWorktrees` stripped the key, and nothing re-added it. Measured before the fix: `Object.hasOwn(merged.tabsByWorktree, WORKTREE)` => false. Downstream, `worktree-initial-terminal-seeding.ts:125` computes `shouldHonourClosedTerminalTombstone = Object.hasOwn(store.tabsByWorktree, id) && ...` => false, so `shouldAutoCreateInitialTerminal(0, false)` => true and a terminal is created. The user closes their last terminal on an SSH workspace and it comes back on reconnect. The projection is innocent: `remote-workspace-session-projection.ts:47-59` and `:161-168` both round-trip an empty array faithfully. The row is lost only when the host snapshot has no entry for that worktree path at all -- a first sync, a snapshot predating the close, or `resolveWorktreeId(path)` returning null during startup. Fix: admit a replaced worktree whose local row EXISTS (`Object.hasOwn`) rather than whose local row is non-empty. That is the same "the host is authoritative for what it knows, not for what it has never been told" rule the rest of this function already applies to tabs. 2. `defaultTerminalTabsAppliedByWorktreeId`. This was the only field in the function with no preservation branch: `:257-260` deleted the local entry for every replaced worktree and trusted the remote snapshot to carry it. The marker is write-once and is the sole guard on `applyDefaultTerminalTabs` (`worktree-default-terminal-tabs.ts:34`), so deleting it re-applies the whole default-tab template over the user's tabs. Removal belongs to the worktree-teardown path, not to a reconnect. Why this shape rather than a revision counter: both are statements about what absence means, local to one function, so they survive the SSH-v3 consolidation unchanged. Neither adds a per-tab identity field. Deliberately not done: the `hostUnknown` preserve branch is untouched, and no close-suppression is added here -- that is the durable close tombstone, and it belongs on top of this rather than mixed into it. Before: 3 failed | 18 passed. After: 21 passed (45 across the wider merge, default-tabs and initial-terminal suites).
nwparker
force-pushed
the
nwparker/ssh-03-merge-preserves-local
branch
from
August 28, 2026 02:43
01862a3 to
903257d
Compare
nwparker
changed the base branch from
nwparker/ssh-02-normalizer-field
to
main
August 28, 2026 02:43
Contributor
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe direct-SSH reconnect merge preserves explicit empty ✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 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 |
paidaxingyo666
pushed a commit
to paidaxingyo666/Manta
that referenced
this pull request
Aug 30, 2026
…s never told about (stablyai#16748) Two fields in `mergeDirectSshRemoteWorkspaceSession` treated an absent remote entry as an authoritative delete. Both are records whose *absence* is meaningful, so deleting them on silence loses information the host never had. 1. The closed-last-terminal tombstone. `src/renderer/src/components/terminal/initial-terminal.ts:5` states the contract verbatim: "a missing row means never initialized; an explicit empty row records that the user closed the last terminal." `mergedWorktreeIds` was `keys(remote.tabsByWorktree)` union the replaced worktrees whose local tab list is NON-EMPTY (`:41-45`), so a worktree holding an explicit `[]` and absent from the host snapshot was excluded, `omitTargetWorktrees` stripped the key, and nothing re-added it. Measured before the fix: `Object.hasOwn(merged.tabsByWorktree, WORKTREE)` => false. Downstream, `worktree-initial-terminal-seeding.ts:125` computes `shouldHonourClosedTerminalTombstone = Object.hasOwn(store.tabsByWorktree, id) && ...` => false, so `shouldAutoCreateInitialTerminal(0, false)` => true and a terminal is created. The user closes their last terminal on an SSH workspace and it comes back on reconnect. The projection is innocent: `remote-workspace-session-projection.ts:47-59` and `:161-168` both round-trip an empty array faithfully. The row is lost only when the host snapshot has no entry for that worktree path at all -- a first sync, a snapshot predating the close, or `resolveWorktreeId(path)` returning null during startup. Fix: admit a replaced worktree whose local row EXISTS (`Object.hasOwn`) rather than whose local row is non-empty. That is the same "the host is authoritative for what it knows, not for what it has never been told" rule the rest of this function already applies to tabs. 2. `defaultTerminalTabsAppliedByWorktreeId`. This was the only field in the function with no preservation branch: `:257-260` deleted the local entry for every replaced worktree and trusted the remote snapshot to carry it. The marker is write-once and is the sole guard on `applyDefaultTerminalTabs` (`worktree-default-terminal-tabs.ts:34`), so deleting it re-applies the whole default-tab template over the user's tabs. Removal belongs to the worktree-teardown path, not to a reconnect. Why this shape rather than a revision counter: both are statements about what absence means, local to one function, so they survive the SSH-v3 consolidation unchanged. Neither adds a per-tab identity field. Deliberately not done: the `hostUnknown` preserve branch is untouched, and no close-suppression is added here -- that is the durable close tombstone, and it belongs on top of this rather than mixed into it. Before: 3 failed | 18 passed. After: 21 passed (45 across the wider merge, default-tabs and initial-terminal suites). (cherry picked from commit 8b99c83)
enrick-dev
pushed a commit
to enrick-dev/orca
that referenced
this pull request
Oct 15, 2026
…s never told about (stablyai#16748) Two fields in `mergeDirectSshRemoteWorkspaceSession` treated an absent remote entry as an authoritative delete. Both are records whose *absence* is meaningful, so deleting them on silence loses information the host never had. 1. The closed-last-terminal tombstone. `src/renderer/src/components/terminal/initial-terminal.ts:5` states the contract verbatim: "a missing row means never initialized; an explicit empty row records that the user closed the last terminal." `mergedWorktreeIds` was `keys(remote.tabsByWorktree)` union the replaced worktrees whose local tab list is NON-EMPTY (`:41-45`), so a worktree holding an explicit `[]` and absent from the host snapshot was excluded, `omitTargetWorktrees` stripped the key, and nothing re-added it. Measured before the fix: `Object.hasOwn(merged.tabsByWorktree, WORKTREE)` => false. Downstream, `worktree-initial-terminal-seeding.ts:125` computes `shouldHonourClosedTerminalTombstone = Object.hasOwn(store.tabsByWorktree, id) && ...` => false, so `shouldAutoCreateInitialTerminal(0, false)` => true and a terminal is created. The user closes their last terminal on an SSH workspace and it comes back on reconnect. The projection is innocent: `remote-workspace-session-projection.ts:47-59` and `:161-168` both round-trip an empty array faithfully. The row is lost only when the host snapshot has no entry for that worktree path at all -- a first sync, a snapshot predating the close, or `resolveWorktreeId(path)` returning null during startup. Fix: admit a replaced worktree whose local row EXISTS (`Object.hasOwn`) rather than whose local row is non-empty. That is the same "the host is authoritative for what it knows, not for what it has never been told" rule the rest of this function already applies to tabs. 2. `defaultTerminalTabsAppliedByWorktreeId`. This was the only field in the function with no preservation branch: `:257-260` deleted the local entry for every replaced worktree and trusted the remote snapshot to carry it. The marker is write-once and is the sole guard on `applyDefaultTerminalTabs` (`worktree-default-terminal-tabs.ts:34`), so deleting it re-applies the whole default-tab template over the user's tabs. Removal belongs to the worktree-teardown path, not to a reconnect. Why this shape rather than a revision counter: both are statements about what absence means, local to one function, so they survive the SSH-v3 consolidation unchanged. Neither adds a per-tab identity field. Deliberately not done: the `hostUnknown` preserve branch is untouched, and no close-suppression is added here -- that is the durable close tombstone, and it belongs on top of this rather than mixed into it. Before: 3 failed | 18 passed. After: 21 passed (45 across the wider merge, default-tabs and initial-terminal suites).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack: 3 of 6 — based on #16747.
ELI5
When you reconnect to an SSH machine, Orca merges what the remote machine remembers with what your laptop remembers.
The rule is "the remote is the boss for things it knows about." The bug is that Orca also treated silence as an instruction. If the remote said nothing about a workspace, Orca deleted your local record of it.
Two records were being lost that way:
The fix: silence is not a delete. Keep a record the remote simply hasn't heard about yet.
Safety: this only ever keeps things. It cannot cause a tab to disappear.
Two fields in
mergeDirectSshRemoteWorkspaceSessiontreated an absent remote entry as an authoritative delete. Both are records whose absence is itself meaningful, so deleting them on silence destroys information the host never had.Symptom 1 — the user closes their last terminal on an SSH workspace, and it comes back on reconnect
src/renderer/src/components/terminal/initial-terminal.ts:5states the contract verbatim:mergeDirectSshRemoteWorkspaceSessionviolated it.mergedWorktreeIdswas(
src/renderer/src/hooks/remote-workspace-session-merge.ts:41-45), so a worktree holding an explicit[]and absent from the host snapshot was excluded.omitTargetWorktrees(current.tabsByWorktree)then stripped the key and nothing re-added it. Proven by direct execution of the real function:Downstream,
worktree-initial-terminal-seeding.ts:125computes…and a terminal is created.
The projection is innocent.
remote-workspace-session-projection.ts:47-59and:161-168both round-trip an empty array faithfully. The row is lost only when the host snapshot has no entry for that worktree path at all — a first sync, a snapshot predating the close, orresolveWorktreeId(path)returning null during startup.Symptom 2 — a reconnect re-applies the default-tab template over the user's tabs
:257-260deleted the localdefaultTerminalTabsAppliedByWorktreeIdentry for every replaced worktree and trusted the remote snapshot to carry it. This was the only field in that function with no preservation branch. The marker is write-once and is the sole guard onapplyDefaultTerminalTabs(worktree-default-terminal-tabs.ts:34).Combined with PR #16747 of this stack: the marker's wire counterpart was also being stripped on every read, so the remote snapshot could never carry it back. Either half alone leaves the marker lossy — this is the client-side half.
The fix, and why this shape
hasLocalTabsRow(worktreeId)admits a replaced worktree whose local row EXISTS (Object.hasOwn) rather than whose local row is non-empty.localTabsForcannot tell an explicit[]from an absent one, which is exactly the distinction that matters.defaultTerminalTabsAppliedByWorktreeIddrops theomitTargetWorktrees(…)wrapper. Removal is the worktree-teardown path's job, not a reconnect's.Both are the same rule the rest of that function already applies to tabs: the host is authoritative for what it knows, not for what it has never been told. Both are statements about what absence means, local to one function, so they survive the SSH-v3 consolidation unchanged. Neither adds a per-tab identity or generation field — the redesign's Phase 3 deletes the eleven the codebase already carries (784 refs).
Evidence
Before (production hunks reverted to
main, tests present):After:
The closed-terminal-tombstone suite also covers the mirror risk directly: preserving the row must not resurrect tabs, and a never-initialized workspace must not acquire a tombstone it never earned.
Deliberately NOT done
hostUnknownpreserve branch is untouched. It already never deletes a local tab the host has not heard of, deliberately, to avoid killing live panes.Relationship to open PR #16571
#16571 implements tombstones keyed by tab id in this same function. It structurally cannot cover the case here: a worktree holding an explicit
[]has no tab ids left to tombstone, and the key itself goes missing. Complementary in behaviour, conflicting in text — its unchanged context includes the exactdefaultTerminalTabsAppliedByWorktreeIdlines this rewrites. Whoever lands second resolves.#15912 is the only other open PR touching
worktree-initial-terminal-seeding.ts; it changes the downstream consumer of the signal this repairs. The two must agree on what "empty worktree" means.One deliberate consequence, previously unmentioned
Preserving the write-once marker means a worktree deleted and recreated on the host at the same
path keeps its marker and never re-applies its default-tab template. That is narrow and
deliberate: the marker is keyed by worktree, removal belongs to the worktree-teardown path, and the
alternative — letting a reconnect clear it — is the bug this fixes. Naming it so a reviewer does not
have to find it.
Risk / blast radius
Renderer-side, one function, no wire change. The change is strictly preserving — it can only add keys to the merged result, never remove them. The failure mode of getting it wrong is a stale local row surviving a reconnect; the failure mode of
mainis a tab the user closed coming back and a template re-applied over their tabs.How to verify
To see it fail:
git checkout main -- src/renderer/src/hooks/remote-workspace-session-merge.tsand re-run.End-to-end verification
Specs this PR routes to
Under
main's router these three files route to[].remote-workspace-session-merge.tsis the single most load-bearing file in the direct-SSH restore path and it reached no e2e spec — the gap #16746 closes.ssh-reconnect-tab-destruction.spec.ts, the spec guarding this exact regression class, previously ran only if you edited that spec file.Lane result
Covered by the full Docker-SSH lane at the stack tip (below). The routed subset for this level can also be run directly:
The two lane failures, resolved — and one is now exempted:
mainssh-docker-bulk-open-freeze-reproTypeError: … reading 'workerIndex'atdocker-ssh-relay-target.ts:226ssh-port-forward-lifecyclessh-port-forward-lifecycle-evidence.ts:159waiting ongetByText('Ports')Port-forward was re-run at the same commit and build and passed in 59.6s. It is green on
main, green at the tip in isolation, and red only inside the full lane — it is the set's one@headfulspec and runs last. Called flaky in-lane rather than "unrelated": a real lane-ordering problem, pre-existing, and worth tracking.Build provenance
hasLocalTabsRowis a new identifier — 0 occurrences inmain's source, so any nonzero count proves the bundle carries this change. It survives the renderer build unmangled:Measured on the lane build:
hasLocalTabsRow=2is this level's symbol; the other three prove the rest of the stack is in the same build.What is NOT covered
resolveWorktreeId(path)returning null during startup. The routed specs do not construct that state; the direct proof is the two unit suites, which are genuine failing-first tests. The e2e run demonstrates no regression, not positive coverage of the failing path.defaultTerminalTabsAppliedByWorktreeIdlines. Complementary in behaviour, conflicting in text; whoever lands second resolves.Failing-first test
Yes.
with the production hunks reverted to
main; 21 passed restored. The suites also cover the mirror risk directly: preserving the row must not resurrect tabs, and a never-initialized workspace must not acquire a tombstone it never earned.