Skip to content

feat(wsl-mover): restore moved terminals from their own daemon checkpoint, once (restore redesign 1/3) - #32956

Closed
nwparker wants to merge 14 commits into
nwparker/wsl-mover-restore-basefrom
nwparker/wsl-mover-restore-pane-history
Closed

nwparker wants to merge 14 commits into
nwparker/wsl-mover-restore-basefrom
nwparker/wsl-mover-restore-pane-history

Conversation

@nwparker

@nwparker nwparker commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​455 $\color{#cf222e}{\Huge{\mathbf{−}}}$​326 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​129
Prod 32 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​609 $\color{#cf222e}{\Huge{\mathbf{−}}}$​376 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​233

Stacked for owner review. Do not merge. Behind the internal WSL hosts gate (ORCA_INTERNAL_WSL_HOSTS). Base: nwparker/wsl-mover-restore-base (#32923 at 6a4f795 plus the browser/draft commits).

Summary

First slice of the approved restore redesign (docs/design/wsl-via-orcad-restore-review.md). A moved terminal's history and folder now come from one source: the pane's own daemon checkpoint. The host's daemon restores it once, the same way it would after an app restart.

Before / after

  • Before: a moved pane's history went out as a renderer-style scrollback snapshot. The host painted it twice, once from a seeded legacy scrollback.bin and once from the window's ref-load, and added another copy on every reload. The pane also opened at its start folder instead of where the shell was.
  • After: each paused pane's checkpoint (screen, scrollback, cwd, size) travels as a new terminal-history blob. The host installs it as an interrupted session in its own daemon history folder, under an id derived from the pane. The pane's first start claims that session, and the daemon cold-restores it once. After that the daemon's own checkpoints take over, so a reload reattaches and a host restart restores the latest state, never the moved copy again.

Mechanism

  • New blob kind terminal-history: key = 16 hex of the pane key's sha256, capability orcad.migration-blob.terminal-history.v1, 16 MiB cap. A host without the capability refuses the move up front ("Update Orca on this host…"), so a mixed-version pair never loses history silently.
  • Desktop: readWslMoveSleptScrollbackFromHistory writes one document per pane (checkpoint plus Linux cwd: the guest probe's shell folder, else the checkpoint's). Those leaves are left out of the snapshot channel, so no ref or snapshot also paints them. The terminal-restore-hints blob is no longer sent; the folder is inside the checkpoint.
  • Host: installOrcadMigrationTerminalHistory writes checkpoint.json, then meta.json with endedAt: null, atomically and idempotently, after the commit is durable. A pre-commit content check validates the document and the checkpoint, and refuses a pane the manifest does not move. claimMovedPaneHistorySession replaces the fix(wsl-mover): a moved pane's stored history shows on every client #32789 seed in restored-pane-materialize.ts, and never runs over SSH.
  • Deleted: stored-scrollback-session-seed.ts and its ledger and runtime-store hook, wsl-move-restore-hints-blob.ts, and the slept-snapshot spooling (withSleptSnapshots, sleptScrollbackReader).
  • Kept: the host still installs terminal-restore-hints from older desktops.

Why this approach

Every earlier fix added another writer for the same field, and the awin rounds kept regressing (verify-4 to verify-6). Daemon cold restore is the path an app restart already proves on awin. It replays once and rewrites the checkpoint itself.

The host's saved layout can't carry bindings: the shared manifest validation forbids ptyIdsByLeafId, and older hosts read it. So the session id is derived from the pane key on both sides instead.

Testing

  • New round-trip unit test: a real source history folder goes through the desktop reader, the blob, and the host installer, then a real HistoryReader on the host. All 2,000 lines come back once, in the shell folder, and a retry after the pane has started never rewinds it.
  • Updated tests:
    • driver, kill-rig and host-change suites (fault injection now at blob:terminal-history);
    • capability list;
    • host restore-hints compatibility test.
  • Results: 968 tests in moving-wsl-projects, migrating-orcad-catalog, session-lifecycle, shared/orcad-migration and ssh/orcad-migration pass. The changed-code quality gate is clean.
  • Not run yet: the WSL fake-transport e2e and awin. They need a built app and come with the verify-7 build.
  • Self-review: done by hand, because this agent can't spawn reviewers.

Not in this PR (next slices)

  • Hold-and-reload: replaces the three re-apply files from fix(wsl-mover): moved browser tabs and drafts survive the moving window #32668. Depends on the sleep-lifecycle PR's persistence barrier.
  • Undo retention: keep the local history folders, and freeze panes as slept.
  • The ~1,000-line view: the remote client's resync cap (TERMINAL_MULTIPLEX_RECOVERY_SCROLLBACK_ROWS) is shared by every SSH and WSL host terminal. This stack leaves it unchanged; raising it is a separate owner decision.

nwparker and others added 14 commits October 25, 2026 05:06
…nal-history blob the host restores once

Replaces the host-side stored-scrollback seed (#32789) with an installed interrupted session the pane's first start claims.

Co-Authored-By: Claude <[email protected]>
…ts terminal-history blob

Drops the snapshot-ref spooling and the restore-hints blob for moved panes: one source (the pane's daemon checkpoint) carries history and folder.

Co-Authored-By: Claude <[email protected]>
Keeps register-core-handlers under the max-lines limit.
…ign deletes

The moved pane's history now comes from its own checkpoint; wsl-move-restore-lifecycle.spec.ts
covers it once, across reloads.

Co-Authored-By: Claude <[email protected]>
…til 2/3 deletes them

Main's layout-writer ratchet now counts main-process writers; wsl-move-echoed-browser-tabs.ts, the
file the hold-and-reload in 2/3 deletes, writes two. Restore redesign 2/3 removes the entry.

Co-Authored-By: Claude <[email protected]>
…ts own focus

The carried session named this desktop's focus, and a host that already focused another project
refused it (orcad_migration_dormant_focus_conflict:activeRepoId), so moving the project you had
open reset with "Nothing was moved" (awin verify-7 N1). The desktop's focus names nothing on the
host and the desktop rewrites its own focus after the move, so the export now carries none and
the host keeps its own. The reset result also says why the move stopped.

Co-Authored-By: Claude <[email protected]>
… journal dropped

A run killed mid-pause is reset at the next startup without its process, so its export documents
(25 KB per pane on awin verify-7) stayed under wsl-move-slept-scrollback for good.

Co-Authored-By: Claude <[email protected]>
…oves it gone

The cold restore checked a WSL pane's folder with stat over \\wsl.localhost, which waits for a
stopped distro and fails for reasons other than absence. After a rollback the pane stayed blank
about 15 s, then opened at the project root without its folder (awin verify-7, 5e). It now uses
the bounded wsl.exe probe every other restore uses, which keeps the folder unless proven missing.

Co-Authored-By: Claude <[email protected]>
The carried screen ends on the old shell's prompt with the cursor after it, so the host's new
shell printed its prompt beside it (`$ $`, awin verify-7). The exported checkpoint now ends the
normal screen with a line break; a TUI's screen and an unfinished escape are left as they are.

Co-Authored-By: Claude <[email protected]>
… instead of sleeps

Main's flaky-test ratchet flags the mover's tests:
- The browser-draft and pane-history e2e slept fixed seconds. They now wait on what they slept
  for: the host's tabs mirrored, the host terminal's last line, the moved tabs shown, the pane
  painted.
- The journal sweep test read the wall clock; it runs on a fixed fake time.
- Each longer per-test timeout says why it needs the time.

Co-Authored-By: Claude <[email protected]>
The mover's startup (rewrite stores, interrupted-move recovery, retention, retry) lived inline in
main-process-ready-foundation.ts. With main, the host reconnect and D1c branches each adding a
few lines on top, the file passed the max-lines limit in the combined build. It moves as one
unit to wsl-move-startup.ts; the foundation keeps the one call and its ordering.

Co-Authored-By: Claude <[email protected]>
@nwparker
nwparker force-pushed the nwparker/wsl-mover-restore-pane-history branch from 96acf50 to 46a13cd Compare October 25, 2026 12:15
@nwparker

Copy link
Copy Markdown
Contributor Author

Contained in the dark landing PR #34059 (its head commit is an ancestor of the landing branch). Closing in favour of it; branch kept.

@nwparker nwparker closed this Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant