Repository navigation
fix(session): an emptied workspace still survives the reconnect merge - #19944
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthrough
Priority: ⬇️ Low 🚥 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.
✅ No new issues found.
Reviewed changes
Corrects mergeDirectSshRemoteWorkspaceSession so that a workspace the user has just emptied (its last terminal closed, leaving an explicit empty tabsByWorktree row) still survives the reconnect merge as the active workspace.
- Presence over length in
localActiveWorkspaceSurvives— the predicate switches from(tabsByWorktree[current.activeWorktreeId]?.length ?? 0) > 0toObject.hasOwn(tabsByWorktree, current.activeWorktreeId), so an explicitly-empty row (the "user closed the last terminal" tombstone) no longer reads as "did not survive", which was dropping the user onto the home screen. - Comment capturing the reasoning — documents that the same presence-not-length reading
hasLocalTabsRowalready applies is now applied to the assembled map. - Two tests pin the boundary —
keeps the user standing in the workspace they emptied(the regression) and a counterweightstill lets the host move the user off a workspace it does name one for, so presence does not become "never follow the host".
Verified the fix is sound: I mutated the predicate back to the length check and confirmed the single new regression test fails while nothing else in the merge suite moves, and the surviving merge test files stay green. The new predicate checks tabsByWorktree (the merged map), which is exactly the "demonstrably still exists in the merged result" target the surrounding comment already describes.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
5925d0b to
0737d45
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Re-reviewed the delta since the prior pullfrog review (a5d6bd21). The only PR-authored change is a test-only commit; the production fix is unchanged.
- Boundary test for the presence rule —
0737d45baddsdoes not stand the user in a workspace that survived in neither side, asserting that when neither side carries a row for the local active worktree, the merge does not preserve it. This is the case the commit message calls out: wideninglocalActiveWorkspaceSurvivesto "always preserve" previously passed the whole file, because the existing counterweight rides on host-precedence ordering rather than the predicate itself. - Fix unchanged since approval — the predicate change and its comment are identical to the previously reviewed head; the source file's only other difference is main's recovery-ledger code picked up in the rebase, which this PR does not author.
Verified locally: all 24 tests in the file pass, and mutating the predicate to drop the Object.hasOwn check fails exactly this new test — real coverage, not a tautology. No open pullfrog threads remained to retire.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
localActiveWorkspaceSurvives decided whether the workspace the user is standing in still exists by counting its tabs. A workspace they had just closed the last terminal in reads as zero, so it "did not survive", the host's null activeWorktreeId was taken literally, and the reconnect dropped them onto the home screen -- for closing a tab. An explicit empty tabsByWorktree row is the record that the user closed the last terminal, not the absence of a workspace (initial-terminal.ts). hasLocalTabsRow two hundred lines up in this same function already draws that distinction with Object.hasOwn; this line was simply missed. The counterweight is pinned too: presence must not turn into "never follow the host", so a host that does name an active worktree still wins over the emptied local one.
Widening the predicate to "always survives" passed the whole file — the counterweight rides on the host-precedence ordering, not on the predicate, so nothing objected to dropping the rule entirely. An emptied row is evidence the workspace exists; no row on either side is not.
0737d45 to
eccd9ac
Compare

Defect
Reconnect an SSH workspace after closing its last terminal and you land on the home screen.
mergeDirectSshRemoteWorkspaceSessiondecides whether to honour the host'sactiveWorktreeIdverbatim or keep the local one. Anullfrom the host is not evidence that no workspace is active — it is what a snapshot carries when the host never named the workspace or its path did not resolve — so the local value is preserved when the workspace the user is standing in still exists in the merged result. That existence check counted tabs:A workspace the user has just emptied has a present, empty row. It reads as zero, so it "did not survive", the host's
nullis taken literally, and the user is thrown out of the workspace — for closing a tab.Why this is an oversight, not a design choice
The correct predicate already exists 200 lines above in this same function, with the reasoning spelled out:
The tombstone distinction — a missing row means never initialized, an explicit empty row means the user closed the last terminal (
initial-terminal.ts) — was applied to the row-assembly pass and missed on the active-workspace line. This PR applies the same reading in the one place it was skipped.Fix
One line. No new concept: it is
hasLocalTabsRow's rule, one level up, on the map this function has already assembled.Tests
Two cases in
remote-workspace-session-merge-local-survival.test.ts, in thelocal rows the snapshot carries no answer forblock that already pins the tombstone's survival intabsByWorktree. That block asserted the row survived but never that the user did, which is the assertion gap this defect lived in.activeWorktreeId,activeWorkspaceKeyandactiveRepoIdall still describe it.Mutation testing
(tabsByWorktree[id]?.length ?? 0) > 0hooks/files, exactlykeeps the user standing in the workspace they emptiedNot a whole-change revert: the assertion the mutation targets is the specific regression, and nothing else in the suite moves.
How this was found
Adversarial testing of a fourteen-PR integration stack, looking for interactions no single PR's suite could cover. Two PRs read the same empty
tabsByWorktreerow with opposite meanings — one writes[]as a "user closed the last terminal" tombstone, the other reads an empty row as a gap to fill. Walking the readers of that row, three decision-making ones still collapse absent into empty. I verified each: this one and the publish gate below by test, the activation gate structurally. This is the only one of the three that is both unambiguously a defect and safe to fix in isolation. (A prior pass reported six such readers with three already fixed; I did not re-derive that count, so it is not claimed here.)The other two are deliberately not fixed here, for stated reasons:
remote-workspace-target-sync.ts) never publishes an emptied workspace. Measured: a populated row publishes, a tombstoned row and an absent row both push nothing. Publishing[]into a revision-0 host is exactly the SSH host session partitions are written but never read — tab lists round-trip as empty and remote sync permanently deletes them #12721 shape, and perdocs/reference/remote-wire-compatibility.mdchanging what we publish reaches old clients with no wire change. That needs a negotiated capability, not a predicate swap.ensureWebRuntimeWorktreeTerminalAfterWakeis called unconditionally fromactivateAndRevealWorktreeand cannot receive the caller'sprovidesInitialSurfacesignal.worktree-activation.tsalready documents this as a known caveat; changing it affects six call sites and is a product decision rather than a bug fix.Gates
pnpm tcclean.pnpm test src/renderer/src/hooks— 155 files, 1004 passing, 0 failures (log grepped, not trusted to the wrapper exit code).pnpm run check:code-quality:changed— 0 new findings across 2 changed files.pnpm format.Rebase record (2026-09-11)
Rebased onto
mainat5fa62feda7c264c6eda99ba4788ffebab9aae26c. No conflicts; all 1 commit(s) replayed as-is.a5d6bd21fc419ce1a24be6454adb5141b2e50cc95925d0b7e4bdac1766c4e6cf3fdc3c25d0602366