Repository navigation
fix(terminal): persist a parked remote pane's scrollback across a hard restart (#21295) - #21367
Conversation
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — the debounced session write now routes tab-keyed rows through the renderer's live tab catalogs when a patch names no tab rows, so a park capture's layouts-only patch reaches the remote host's partition instead of being pruned in local.
extendWorktreeIdByTabIdfallback (src/shared/workspace-session-host-records.ts): fills a payload-derived tab→worktree index from the livetabsByWorktree/unifiedTabsByWorktree, leaving payload rows authoritative via!byTab.has.splitWorkspaceSessionByHostoption (workspace-session-host-split.ts): accepts an optionalworktreeIdByTabId; the default staysbuildWorktreeIdByTabId(state), so orphan tabs still staylocal.- Write-path wiring (
workspace-session-host-persistence.ts):splitWorkspaceSessionForWritebuilds the extended index for all three write modes;HostPersistenceStatenow carries the catalog fields. Main needed no change because the runtime partition's owntabsByWorktreealready attributes the tab, and the prune fails open toward remote. - Unit coverage: layouts-only, remote-session-id-only, unified-only routing, payload-precedence, and orphan-stays-local cases. I ran the two touched suites locally: 42 passed.
- E2E (
paired-remote-terminal-parked-scrollback-restart.spec.ts+quitPreservingProfile): the hard-kill test's on-diskruntime:<id>oracle is contradiction-capable, and the clean-quit test is documented as harness sanity rather than proof.
I independently probed the routing change for moved tabs, unified id !== entityId, and contested/restored worktree ids; the fallback only fills keys the payload did not resolve and hostIdByWorktreeId retains the partition decision, so no misroute or cross-partition overwrite is reachable.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
1156da9 to
2a2c1a7
Compare
cdda9b2 to
1092e35
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — the commits since the prior pullfrog review add a session-addressed scrollback read, ratchet it to the cap's home list, and make the restart spec read both scrollback homes through the shared resolver. The routing fix itself is byte-identical after the rebase onto the newer base.
resolveTabScrollbackBuffers(leaf-scrollback-resolution.ts): addresses the existing two-home read by tab over a session-shaped record, typed offTERMINAL_SCROLLBACK_SESSION_HOMES.- Resolver ratchet (
leaf-scrollback-resolution.test.ts): enumerates the cap's home constant so a third home fails until the resolver reads it, alongside the existing precedence cases. - E2E debug handle (
terminal-parking-e2e-overrides.ts,env.d.ts):window.__terminalParkingDebug.resolveLeafScrollbackroutes the spec's store read through the same resolver instead of reading one home directly. - On-disk reader (
paired-remote-terminal-parked-scrollback-restart.spec.ts): readsterminalLayoutsByTabIdandlocalOnlyScrollbackByTabIdthroughresolveLeafScrollbackBuffers, so an ordinary park's bytes no longer read as a false zero. - Clean-quit control: swaps the flaky
tokenAfterRevealassertion forlocalPartitionDidNotKeepCapture, with the reason documented inline. - Normalization note (
terminal-session-cleanup.ts): documents whylocalOnlyScrollbackByTabIdstays out of the full-normalization trigger set.
Verified locally: leaf-scrollback-resolution.test.ts + terminal-parking-e2e-overrides.test.ts = 15 passed; oxlint clean on the six changed files; tc:web clean.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…ost's partition A park capture changes only terminalLayoutsByTabId, so its debounced session patch carries no tabsByWorktree. splitWorkspaceSessionByHost built its tab->worktree index from the patch alone, resolved nothing, and routed every layout to the 'local' partition, where main's pruneLocalTerminalScrollbackBuffers strips scrollback it cannot attribute to a remote worktree. The remote host's runtime:<id> partition never received the capture, so anything parked since the last clean checkpoint was lost on a crash, SIGKILL, or a forced kill during an app update (#21295). Route tab-keyed patch fields with the renderer's live tab catalogs as a fallback when the payload names no tab rows. Payload rows still win, so full-payload writes are byte-identical. Once routed to runtime:<id>, main merges the partition's own prior tabsByWorktree and the prune preserves. Proven by tests/e2e/paired-remote-terminal-parked-scrollback-restart.spec.ts: a hard kill (no checkpoint) then relaunch, asserting the capture is in the remote host's partition on disk. Mutation: reverting the routing fix turns that assertion red and fails the 3 catalog-dependent unit routing tests. (cherry picked from commit 58a344c)
…atchet the resolver to the cap's home list The restart spec read only buffersByLeafId, but the ordinary park now writes localOnlyScrollbackByTabId, so its own proof reported a false zero and both tests failed for the wrong reason. Both readers now go through resolveLeafScrollbackBuffers: the on-disk reader calls it directly (it is a pure function), and the store reader — which runs inside page.evaluate — reaches it through a new window.__terminalParkingDebug.resolveLeafScrollback(tabId) handle. resolveTabScrollbackBuffers is typed off TERMINAL_SCROLLBACK_SESSION_HOMES and its unit test enumerates that constant, so adding a third home fails to compile and fails a test until the resolver reads it — the 'no consumer reads a home directly' invariant becomes enforceable. The clean-quit control no longer asserts tokenAfterReveal (measured true, true, false on identical product code; the live host can serve the reveal from its own tail). It keeps the five deterministic fields and logs the reveal; the hard-kill test still asserts it, because there the host is forced unavailable and the reveal must come from the client copy. (cherry picked from commit 0cd3db1)
…de full normalization The two scrollback homes look symmetric (TERMINAL_SCROLLBACK_SESSION_HOMES), so the missing key reads as an oversight. It is load-bearing: adding it would route the field through the fail-closed strip and reintroduce the loss this branch fixes. The renderer prunes it with attribution before the patch is sent, so the cap still holds without main as a second line. (cherry picked from commit 1092e35)
1092e35 to
a6b4f34
Compare
|
Warning Review limit reachedNext included review available in 5 minutes. View limit detailsLimit details: You’ve used all 10 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (11)
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 |

The hop where the buffers are dropped
A parked remote-runtime terminal's scrollback is captured into the renderer store as
terminalLayoutsByTabId[tabId].buffersByLeafId, but the debounced session-patch writer routes it to the wrong host partition, where the main process then strips it.Instrumented on a real paired-desktop e2e run, one hop at a time:
A park capture changes only
terminalLayoutsByTabId, sobuildWorkspaceSessionPatchemits a patch with notabsByWorktree(workspace-session-patch.ts:66-71).splitWorkspaceSessionByHostbuilds its tab→worktree index from the patch alone (workspace-session-host-split.ts:179→buildWorktreeIdByTabId), finds nothing, and routes every layout to thelocalpartition (:141). Main receives alocalpatch andpruneLocalTerminalScrollbackBuffers(workspace-session-terminal-buffers.ts:80) can't resolve the tab's worktree inside the local partition, so it strips the buffers (:25-27). The remote host'sruntime:<id>partition on disk keeps its old bufferless layout.Root cause (not the symptom)
Tab-keyed patch fields (
terminalLayoutsByTabId,remoteSessionIdsByTabId) are routed by a tab→worktree index derived only from the patch payload. A debounced patch carries only the fields that changed, so a layouts-only or ptyIds-only patch has no tab rows to route by and every row falls intolocal.Only the beforeunload checkpoint masks this: it writes a full snapshot (
buildWorkspaceSessionHostSnapshots, replace mode) that includestabsByWorktree, so it routes correctly. That is why the loss depends on not getting a clean shutdown — a crash,SIGKILL, or a forced kill during an app update between the park and the next checkpoint loses everything captured since.A correction to the tracking measurement: the reported
onDiskAfterQuit: 0came from a reader that inspected only the localworkspaceSessionblob. On a clean quit the checkpoint does persist the capture toworkspaceSessionsByHostId['runtime:<id>']; the reader just never looked there. The genuine, reproducible loss is on the hot/debounced write path, realized by a hard kill.The fix
Route tab-keyed patch fields with the renderer's live tab catalogs as a fallback when the payload names no tab rows.
extendWorktreeIdByTabId(workspace-session-host-records.ts) fills the payload-derived index fromtabsByWorktree/unifiedTabsByWorktree. Payload rows win — main merges the payload's owntabsByWorktreeinto whichever partition the write lands in, so a layout must follow the tab row in this write.splitWorkspaceSessionByHosttakes an optional{ worktreeIdByTabId }; the default is unchanged so every other caller and the orphan-tab behaviour are byte-identical.splitWorkspaceSessionForWritepasses the extended index for all three write modes. No main-side change: once routed toruntime:<id>, main merges the partition's own priortabsByWorktreeand the prune preserves (a paired client'sreposis empty, which fails open toward "remote"; a hydrated runtime-host repo preserves for any non-local host).chooseRemoteTerminalLayoutre-evaluatedRe-checked now that persistence delivers the buffer to disk. #21285's
retainLocalScrollbackInRemoteLayoutcarry-through is present and the relaunch reveal works with it; no additional fix inchooseRemoteTerminalLayoutwas needed — the restart case is covered by that existing retention once the write path stops dropping the capture.Test
tests/e2e/paired-remote-terminal-parked-scrollback-restart.spec.ts— paired-desktop topology, real remote-runtime ptys, host forced to answer no snapshot (ORCA_E2E_FORCE_REMOTE_TERMINAL_SNAPSHOT_UNAVAILABLE=1).The load-bearing oracle is on disk, not the reveal: the paired host's pty stays alive across the restart and keeps a retained tail, so a reveal can be served by the host rather than by the client's persisted copy. The contradiction-capable signal is which partition on disk holds the buffer after a debounced write.
forceQuitElectronAppForE2E(SIGKILL, no beforeunload, no checkpoint) and relaunch on the same profile. Asserts the capture is in theruntime:<id>partition on disk and not stripped inlocal. Measured:storeAtPark 394 -> onDisk runtime bufferLength 394, local none -> relaunch reveal true.maintoo, so it is harness sanity, not proof.Result:
2 passed.Mutation results
workspace-session-host-persistence.test.ts): removing the catalog extension fails the 3 catalog-dependent routing tests (layouts-only,remote-session-id-only,unified-only) while the payload-carries-tabs test still passes and the split-primitive tests still pass — the mutation is caught exactly where the fix lives.runtimePartitionHoldsCapture(runtime partition on disk stays bufferless), confirming the assertion is not a survivor.Verification
pnpm tcclean;oxlint/oxfmtclean on changed files.ORCA_CODE_QUALITY_BASE=origin/main node config/scripts/check-changed-code-quality.mjs→ passed. The reader'sascasts were removed (rewritten with type guards) rather than suppressed.