Skip to content

WSL mover - move driver runs a WSL move end to end (stacked on D1b-8) - #31417

Closed
nwparker wants to merge 1 commit into
nwparker/wsl-mover-d1b-8-retain-reconcilefrom
nwparker/wsl-mover-d1b-driver
Closed

nwparker wants to merge 1 commit into
nwparker/wsl-mover-d1b-8-retain-reconcilefrom
nwparker/wsl-mover-d1b-driver

Conversation

@nwparker

@nwparker nwparker commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1483 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1476
Prod 23 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1664 $\color{#cf222e}{\Huge{\mathbf{−}}}$​10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1654

Stacked on D1b-8 (nwparker/wsl-mover-d1b-8-retain-reconcile). The chain is main → #31414 (exporter) → #29825 → 6d-1 → 7a → 7c → 7d → 7e #31232 → D1b-8 → this PR. Everything here is reachable only with the internal ORCA_INTERNAL_WSL_HOSTS=1 gate on. Not for merge by the agent.

ELI5

Orca can already do each step of "move my WSL projects to the WSL host" on its own: pause the terminals, write down where the move is, copy the saved state, switch over, and keep the old copy as a safety net. No code ran those steps in order yet. This PR adds the one piece that does, and gives the move dialog (D1b-9) a single call to start it and follow it.

What Changed

Before: the move existed only as parts. Every test fed those parts made-up facts, such as "this terminal is idle" or "no automation is running". The folder each paused terminal was in was kept only in memory, so a crash lost it.

After: one call in main runs the whole move. wslMove:preview shows what would move and what blocks it; wslMove:start runs it. The steps, in order:

  1. Plan with D1b-8's planWslMove: a first move, or a delta that takes only new projects. Only one move per distro runs at a time.
  2. Check terminals against real facts. Agent state comes from the hook server's status store, which is the only owner of agent status. Busy shells come from the same probe the close-tab warning uses. Running automation runs come from the store, and live orchestration dispatches from orchestration.db. Anything busy is returned as a blocker, and nothing is ended to make progress.
  3. Pause, then record the move. The gate runs again right before the first Sleep. The panes slept must be exactly the ones it passed; a terminal opened in between refuses the move. The projects' workspaces are then put to sleep and the move is written down. The record binds the saved-state snapshot once and can never re-bind it, so it has to be taken from the paused state. The existing quiesce then fences the projects, checks again, has the daemon prove every terminal exited, and saves each pane's last folder.
  4. Prove nothing changed under the fence. A second snapshot must have the same digest, no new blockers and the same list of automations to turn back on, or the move stops.
  5. Copy: stage on the host, send the scrollback and the files (restore folders, shell history), and ask for the commit only from blobs-transferred, as fix(wsl-mover): reset an interrupted move to zero, or finish it once the host proves a commit #29825 requires.
  6. Switch: run the desktop rewrite; the dialog then reloads the window (see below). Retention (D1b-8) then marks the old rows and the move reaches retained.

Failures. Any failure calls #29825's resetWslMoveToZero. Before the commit, that puts everything back. If the host did commit and only the reply was lost, the move goes forward instead. If the host can't answer, the projects stay read-only and the result says so. A new move first settles one that an interruption left short of commit.

Restore folders in the record. The quiesced record now carries terminalRestoreHints (optional, written once, invalid values read as absent). The restore-folder file is built from the record, so a crash after the pause no longer loses them.

Automations. A move can only carry automations switched off. The ones that were on here are listed in the record (automationsToReenable), and after the commit a tracked step (host-automations) asks the host to switch them back on. It skips any the user deleted, switched on, or edited on the host since the move (the row's updatedAt no longer matches what was moved). If the host refuses or can't be reached, the result lists them as still off (automationsPending) and wslMove:listUnfinished returns them for the UI. The step retries in the same run with backoff and again at every startup, and the move doesn't finish until the host confirms. They are never left off without saying so.

Snapshot. Built with #31414's exportWslMoveManifest, which lies under this PR in the stack. If the snapshot can't carry some of a project's state, the move refuses (wsl_move_export_incomplete) rather than moving without it.

Window reload. The rewrite happens under the open window, so a successful move returns reloadRequired: true. The dialog must then reload through the restart-preparation path (requestLazyChunkRecoveryReload), which backs up unsaved editors and lands the session checkpoint first. Main never does a bare reload.

IPC contract (for D1b-9)

Channel Params Returns
wslMove:preview {distro, repoIds?, folderWorkspaceIds?} {outcome:'ready', repoIds, folderWorkspaceIds, changed, heldByHost, refused, blockers[]} or a refusal
wslMove:start same {outcome:'moved', migrationId, phase, reloadRequired: true, automationsPending?}, {outcome:'reset'} (nothing moved), {outcome:'waiting-for-host'}, or a refusal
wslMove:cancel distro true if a run was stopped (allowed until the commit request)
wslMove:listUnfinished none committed moves whose automations are still off on the host
wslMove:progress (event) {distro, step: preparing | pausing-terminals | copying | switching | finishing | done, migrationId?, phase?, bytesSent?, bytesTotal?}

Refusal codes: wsl_move_unavailable (gate off, wrong window, malformed request), wsl_move_already_running, wsl_move_already_in_flight, wsl_move_nothing_new, wsl_move_host_unavailable, wsl_move_host_update_required, wsl_move_terminals_blocked (+blockers), wsl_move_export_incomplete (+reasons), wsl_move_manifest_too_large (+message, the text from #29825's first journal write), wsl_move_pause_failed (+detail), wsl_move_scope_changed (plan again), wsl_move_cancelled, wsl_move_finished_earlier_move (an interrupted, host-committed move was finished first: reload as for reloadRequired, then start again).

Why

  • Ports, not new plumbing. The run lives in one module behind ports (wsl-move-driver-ports.ts). Production wiring is one file, and tests swap in a fake world with failure points (the test(wsl-mover): crash a WSL move at every step and prove it ends at zero or fully moved #29826 pattern). The driver reuses the existing journal, fence, quiesce, exit proof, hints capture, blob coordinator, durable stage/commit helper, reset, desktop rewrite and retention, and adds no parallel versions.
  • Sleep before the snapshot. The alternative was letting the record re-bind its snapshot after the pause. That would weaken the journal's compare-and-swap binding, which fix(wsl-mover): reset an interrupted move to zero, or finish it once the host proves a commit #29825's recovery relies on. Pausing first, then proving the state unchanged under the fence, keeps that invariant.
  • Re-enabling automations as a tracked rewrite step. A fire-and-forget call after commit could be lost to a crash or an unreachable host. Tracking it in the ledger makes it crash-safe and retried, and the move can't report finished while automations are still off.

Linked Issue

Internal (WSL via orcad tracker, D1b driver wiring: the D1b-5 deferred items).

Visual Proof

N/A: main-process and IPC only; the UI is D1b-9.

Testing

  • wsl-move-driver.test.ts (fake host with failure points):
    • The happy path reaches retained.
    • The first Sleep is gated again, a pane set that changed refuses, and a re-export that gains blockers or automations resets.
    • A failure at stage, blob send and commit each resets to zero, with the host's staging aborted.
    • A lost stage reply recovers; a lost commit reply goes forward.
    • A failed exit proof lifts the fence.
    • A changed scope and a cancel each reset.
    • The too-large message surfaces from the first journal write.
    • A second concurrent move is refused, and the gate-off driver touches nothing.
    • Busy-terminal blockers show in the preview.
    • Automations: switched back on after commit; a host refusal and a lost reply both surface automationsPending, and the step retries after restart and with backoff in the same run.
    • A stuck earlier move is reset, carried forward, or kept fenced.
  • wsl-move-real-pause.test.ts: real shells on node-pty in a real in-process daemon. Sleep ends them, the daemon's census proves the exit, the journal holds each pane's folder from the daemon's checkpoint, and a new real shell opened there prints it. A pane another client still runs refuses the move and lifts the fence. On Windows it runs in the WSL orcad lane against a real distro through UNC paths (new step "WSL move: pause real distro terminals").
  • wsl-host-automation-enable.test.ts: only automations untouched since the move are switched back on, and a refusal stays pending and retries.
  • wsl-move-gate-facts.test.ts: maps hook status, the probe, runs and dispatches to gate verdicts (a stale agent row can't vouch for a dev server; an unknown scrollback size blocks).
  • Journal: hints are written once and read leniently; the automation list is immutable; a journal without either field (an older build) still parses.
  • wsl-move-driver-handlers.test.ts: with the gate off, nothing is built or run; another window and a malformed request are refused.
  • Checks: pnpm tc, the touched suites, check:code-quality:changed, and every ratchet, with no baseline changes.

Review

An adversarial review (crash safety, data loss, gate leaks) ran before opening. It found no gate leaks. Fixed in this PR:

  • The first Sleep now re-gates and checks its pane set.
  • The re-export compares blockers and automations, not just the digest.
  • Automation re-enable skips deleted or edited rows, and the step can't block the move forever.
  • The reload belongs to the renderer and goes through restart preparation.
  • Finishing an earlier move returns a distinct result instead of carrying on under a reloading window.
  • A refusal before the fence removes its record.
  • The retry timer stops once no main-side step is pending.
  • Cancel returns false once the commit was requested.

Left as residuals:

  • A downgrade to a pre-driver build that rewrites the journal mid-rewrite drops the two new optional fields. The pending automations would then go unlisted, though the desktop's retained copy keeps them enabled. Making the schema pass unknown fields through broke every journal reader's types.
  • At startup, a pending automation step may wake the distro's host.

Notes

Shared paths this touches (outside the gated mover folder):

  • src/main/runtime/orca-runtime-migration-catalog.ts: a new read-only listWslMoveLiveTerminals.
  • src/main/ipc/register-core-handlers/register-core-handlers.ts: passes the driver deps.
  • src/main/startup/main-process-ready-foundation.ts: registers the host-automations store and schedules the gated retry.
  • src/main/ipc/wsl-host-automation-enable.ts: new; the host calls automation.show and automation.update.
  • src/preload/api/wsl-move-bridge.ts and src/renderer/src/web/web-preload-api.ts: new bridge calls; the web build refuses them.
  • src/shared/wsl-move/wsl-move-cutover.ts: two optional journal fields.
  • src/main/persistence/moving-wsl-projects/wsl-move-delta-plan.ts (D1b-8's file): an optional automationsToReenable arg on journalWslMove.
  • .github/workflows/wsl-orcad-e2e.yml: one lane step and one path.

Other notes:

  • SSH: the SSH conversion and its manifest bytes are untouched.
  • Folder workspaces are moved as folder:<id> workspaces.
  • Windows children only go through @orca/process-host, and WSL argv only through buildWslExecArgs (in the lane test).
  • The move can't reach client-rewritten in production until 7f-2 flips WSL_MOVE_DESKTOP_REWRITE_REGISTRY_COMPLETE. Until then a committed move stays in its rewrite phase, which is expected.

Agent skill upstream boundary

  • Not applicable.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • N/A for visuals, with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path impact considered
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (typecheck, touched tests, changed-code quality and ratchets pass locally; CI covers the rest)

…duction gate facts and journaled restore folders

One entry point (and preview/start/cancel/listUnfinished IPC for D1b-9) plans the move, gates
terminals on the hook server's agent status, the close-tab process probe, running automation runs
and live dispatches, pauses and proves exit, stages, sends blobs, commits only from
blobs-transferred (#29825), and finishes on the desktop. Any failure resets to zero or goes forward
when the host committed. Restore folders and the automations to turn back on are kept in the
journal; the host turns those automations back on after commit, retried until it confirms.
A real-PTY test pauses daemon shells, and runs on a real distro in the WSL orcad lane.
@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