Skip to content

feat(wsl-mover): mark the desktop rewrite registry complete, with a coverage proof and stale-window re-apply (D1b-7f-2) - #31957

Closed
nwparker wants to merge 5 commits into
nwparker/wsl-mover-d1b-9-move-uxfrom
nwparker/wsl-mover-d1b-7f2-registry-complete
Closed

nwparker wants to merge 5 commits into
nwparker/wsl-mover-d1b-9-move-uxfrom
nwparker/wsl-mover-d1b-7f2-registry-complete

Conversation

@nwparker

@nwparker nwparker commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​730 $\color{#cf222e}{\Huge{\mathbf{−}}}$​14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​716
Prod 15 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​345 $\color{#cf222e}{\Huge{\mathbf{−}}}$​71 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​274

ELI5

Moving WSL projects onto the WSL host has a last step: rewriting this computer's own records (sidebar order, focus, saved tabs, history, browser logins and so on) so they point at the host. Until every one of those rewriters existed, the move was held at that last step on purpose: it never finished, and you could never move the same distro again. All of them now exist, so this PR lets the move finish. Everything stays behind the internal ORCA_INTERNAL_WSL_HOSTS gate, which is off for everyone.

What Changed

Before (gate on): a move copied everything to the host and switched over. Its journal then stayed at destination-committed forever, because WSL_MOVE_DESKTOP_REWRITE_REGISTRY_COMPLETE was false. A second move of that distro was refused with "A move of is still finishing."

After (gate on): the move goes destination-committed → client-rewritten → retained, and a later move of the distro is accepted once the earlier one is retained. Gate off: nothing changes.

How it works:

  1. The flag is now true (wsl-move-desktop-rewrite-stores.ts). The journal and the rewrite driver still refuse client-rewritten until every registered store has a ledger entry.
  2. One registration entry point: registerWslMoveDesktopRewriteRegistry. Startup calls it once, after the fence and before the first rewrite pass. It registers the stores in run order: ui-routing, session-globals and host-session-seed (7c); orchestration-history (7e); the three renderer localStorage stores (7d); host-automations (driver); and browser-cookies (7f), which is last.
  3. Completeness proof: wsl-move-rewrite-store-coverage.test.ts. It has no allowlist or skip list, and it checks four things:
    • every disposition row marked rewrite-desktop or rewriteDesktopCopy maps to a store id;
    • every mapped row exists;
    • every registered store is mapped, and every mapped store is registered, all through the production entry point;
    • the profile-backed stores (ui-routing and session-globals) really do write each UI and session field they are mapped to, given state that names a moved project.
  4. A missing store, added: ui.automationHostFilter was marked as a rewrite, but nothing rewrote it. It is single-select, so a filter set to "this desktop" would hide every automation the move carried. ui-routing now widens that filter to All hosts, once, and only if the move carried automations.
  5. Two disposition rows corrected: nothing rewrites these, and neither needs a rewrite:
    • ui.trustedOrcaHooks becomes not-applicable. It is keyed by repo id, which the move keeps. The 7d prune guard (wsl-moved-repo-ui-retention.ts) still protects it.
    • persisted.remoteLayoutSnapshots becomes rederive. It is a display-only cache whose one reader has no caller. The recorder rebuilds it from the host's first tab stream, and first paint comes from the seeded workspaceSessionsByHostId.
  6. Correcting stale writes after the rewrite (audit requirement; wsl-move-stale-window-reapply.ts). The window that was open during the move hydrated before the rewrite, so until it reloads it can write the old focus back.
    • Focus, every time: at every startup (fence → recovery → this → rewrite pass), and at every unload checkpoint after the window's state is staged and before the flush, focus is re-applied for each committed or retained move. That covers ui.lastActiveWorktreeId and the local session's active worktree, key and host. It only ever redirects a moved local project to the host, so it can't override a later choice.
    • Additive rewrites, once: host copies of UI rows, the WSL host added to visible-host lists, and the host partition's seed are redone once, at the unload of a window that was open while that move was rewritten. Redoing them on every start would undo a later choice, such as hiding the WSL host.
    • No journal writes: neither correction touches the journal, so the ledger can't gain duplicate entries.

Shared paths this touches:

  • Startup: main-process-ready-foundation.ts, which registers the stores and passes the recovery and re-apply steps to runWslMoveStartupRewrite.
  • Session persistence: renderer-shutdown-checkpoint.ts gains an optional afterStage hook, wired through app.ts and register-core-handlers.ts. With the gate closed the hook returns immediately.

Why

  • Why flip now: no real-host move can finish without the flip, so it is the next merge in the mover plan (audit 2026-10-22, 7c).
  • Why a mapping test, not a flag someone remembers to flip: a new desktop-rewrite row with no store now fails CI. The behavioural check stops a row from being "covered" by a store that never touches it.
  • Why reclassify two rows instead of adding stores: a store that writes nothing, just so a test passes, would be the escape hatch the proof exists to prevent. Both reclassifications are listed above so a reviewer can veto them.
  • Why focus every time but additive rewrites only once: focus fixes are purely corrective. The additive ones are a fresh choice the user can later reverse.
  • Alternative considered: delay the ledgered rewrite until a post-move window has loaded. That changes the driver's finish path (D1b-8/9) and leaves the move unfinished until the user reloads.

Linked Issue

Internal WSL mover stack (D1b-7f-2), stacked on #31429.

Visual Proof

N/A. No visible change: everything is behind the internal gate, which is off by default. With it on, the one visible difference is that a second move of a distro is no longer refused once the first is retained, and the unit tests cover that.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

New tests:

  • wsl-move-registry-complete.test.ts (real SQLite, listed in vitest-sqlite-runtime-files.mjs). It runs against the real registry and profile store:
    • a committed move goes destination-committed → client-rewritten → retained, with each store in the ledger exactly once;
    • a later move is refused before retention and accepted after it;
    • with the gate closed, or with no journal, nothing changes;
    • a stale focus written after the rewrite (client-rewritten and retained) survives a restart and is corrected at startup, idempotently, with the journal unchanged;
    • a focus the user moved elsewhere is left alone;
    • the additive rewrites are redone once at a stale window's unload, and are not redone afterwards.
  • wsl-move-rewrite-store-coverage.test.ts (the proof), wsl-move-automation-filter-rewrite.test.ts, and an afterStage ordering test in renderer-shutdown-checkpoint.test.ts.
  • Existing tests updated for the flipped flag: the ledger test now sets the registry incomplete explicitly, and the main-stores test now expects client-rewritten.
  • Ran locally: pnpm tc, pnpm test on the moving-wsl-projects, shared/wsl-move, renderer-shutdown-checkpoint, app, register-core-handlers and automation-wsl-move-refusal suites, pnpm run check:code-quality:changed, and the layout-writer, focus-read and other ratchets. No baseline changed: the re-apply reuses the existing session-globals and host-session-seed write call sites.

AI Disclosure

Review

An adversarial review focused on store coverage, ledger duplication and startup ordering found no HIGH issues. Its two MEDIUM findings are fixed:

  • a window left open after the move could undo the additive rewrites (fixed by the one-shot unload re-apply);
  • the coverage test only checked names (it now has the behavioural check).

Open LOWs:

  • The unload re-apply runs on the shutdown path. It returns at once with the gate closed, and with the gate open it only reads the journal without copying it.
  • If the app crashes, rather than quits, while a pre-move window is open, the next start only re-applies focus.
  • "Use on this computer again" ends the re-apply by deleting the move's record. If it ever keeps the record, the re-apply needs a different stop condition.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Security: no new inputs.
  • Cross-platform: the mover is Windows-only behind the gate, and the code is path-agnostic.
  • SSH: untouched; the re-apply only reads WSL move journals.
  • Mobile: unaffected.
  • Backwards compatibility: no journal schema change and no new journal field.
  • Performance: with the gate closed, startup and unload do no extra work.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@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