Skip to content

fix(wsl-mover): fence terminals by folder during a move and re-prove exit before commit (audit addendum R45-R47) - #31952

Closed
nwparker wants to merge 4 commits into
nwparker/wsl-mover-d1b-7f2-registry-completefrom
nwparker/wsl-mover-audit-addendum
Closed

nwparker wants to merge 4 commits into
nwparker/wsl-mover-d1b-7f2-registry-completefrom
nwparker/wsl-mover-audit-addendum

Conversation

@nwparker

@nwparker nwparker commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Stacked PR. Base is 7f-2 (#31957), which is stacked on D1b-9 (#31429): D1b-9 → 7f-2 → this. Everything here is behind ORCA_INTERNAL_WSL_HOSTS. Do not merge yet.

ELI5

When Orca moves a WSL project to the host program running inside the distro, it first pauses every terminal in that project and checks they have all stopped. Then it copies the project's state, which can take a while, and only then switches over.

A terminal could still start during the copy without belonging to the project: a floating terminal, a Windows project's WSL tab, or orca terminal create --cwd pointed into the project's folder. Nothing stopped it, and nothing checked again before the switch. That terminal kept running on the old path after the move. An agent in it reported its status to the desktop under a project the desktop no longer owns, so two places claimed that agent's status.

This PR closes the gap two ways:

  • Such terminals are now refused while the move runs.
  • If one gets through anyway, the move checks again just before the switch, puts everything back, and tells the user nothing was moved.

What Changed

R46: terminals during a move (behaviour change, behind the gate)

  • The PTY spawn path refuses by folder (assertWorkspaceAcceptsNewPty in src/main/ipc/pty/host-env/spawn-cwd.ts, called from both the IPC and the runtime/CLI spawn preflight). A new local terminal whose requested folder is inside a project a move is taking is refused, whatever workspace it names. It gets the same "this project is moving" error the per-project fence already gives.
    • The folders come from the move journal's manifest (wslMoveScopeRootPaths): each moved repo, folder workspace, and carried worktree. They are fenced from source-fenced until the commit.
    • Paths are compared with the exit proof's own comparison, now shared in wsl-move-comparable-path.ts: wsl$/wsl.localhost aliases, distro case, Linux spelling, and trailing separators all count as the same folder.
    • Reattaching a session the daemon still runs is still allowed, as before.
    • SSH spawns never pass a folder to this check (localPtySpawnCwd).
    • macOS and Linux have no move journal, so nothing changes there.
  • The move driver re-runs the exit proof before the commit. It runs after the last blob is sent and before the journal records blobs-transferred. Only synchronous code runs between this census and the commit request.
    • If the verdict is not exited, the move resets to zero through resetWslMoveToZero (fix(wsl-mover): reset an interrupted move to zero, or finish it once the host proves a commit #29825), and the result is the existing refusal wsl_move_pause_failed, which the dialog already maps ("Orca could not pause the terminals in these projects, so nothing was moved…").
    • The detail says why: terminals-started-after-pause, or exit-unverifiable: <reason>, matching the wording of the quiesce-time proof.
    • Because the commit was never requested at that point, the reset never needs the host's answer and cannot leave the project waiting for it.
    • sendWslMoveBlobs no longer advances the journal; the driver does that after the proof. A cancel is also now checked before that advance, so a cancel there likewise resets without the host.

R45 and R47: tests only

  • R45: the WSL host browser cookie jar is pinned:

    • a new orcad key gives a new jar;
    • a renamed distro gives a new jar;
    • two distros with the same baked-in key get separate jars and separate pairings;
    • re-importing under the same name with the same key keeps the jar (accepted as Low).

    No distro registry-id check was added.

  • R47: two WSL moves with the same generation number but different migration ids and manifests stage, commit, abort, and keep receipts independently on the host.

Why

  • Why fence by folder rather than only re-checking before commit:
    • Refusing at spawn time gives the user an immediate, clear error.
    • Re-checking alone would throw away a finished copy.
    • The re-check is still needed as the backstop for anything the fence can't see, such as a shell that cds into a moved folder.
  • Why fence every workspace's spawn, not only spawns with no workspace: a floating terminal names a workspace id the per-project fence ignores. A terminal from another project pointed into the moving folder is counted by the exit proof as inside the move. Fencing only spawns with no workspace would let both through and fail the move after the copy.
  • Why the proof runs before blobs-transferred rather than literally just before the commit: from blobs-transferred on, a reset must ask the host whether the commit landed, and an unreachable host leaves the projects read-only until it answers. One phase earlier, no commit can exist, so a refusal always resets cleanly. Nothing awaits between the proof and the commit request.
  • Why reuse wsl_move_pause_failed: the copy already says nothing moved and to try again. wsl_move_terminals_blocked expects a list of blockers, which this case doesn't have.

Golden-image keypair finding (R45 follow-up)

  • Where the key lives. Orcad's identity key is ~/.orca/orca-e2ee-keypair.json, not ~/.orca-remote. loadOrCreateE2EEKeypair (src/main/runtime/e2ee-keypair.ts) creates it once if it is missing and reuses it if present. It has no per-machine salt. An image that bakes in ~/.orca therefore shares one orcad key across machines, along with its device registry.

  • Safe: pairing. Every desktop pairs with its own random device id and token, and WSL hosts are keyed by wsl:<distro>. Separate machines, and separate distros on one desktop, get separate pairings. Now pinned by a test.

  • Safe: browser jar. It hashes profile, environment id and key, so distros on one desktop never share a jar. Now pinned by a test.

  • Real, not fixed here (outside the mover):

    • (a) The cloud push gateway identifies a headless host by sha256(publicKey). Golden-image hosts on different machines look like the same host to it if phones pair with them directly.
    • (b) Adding a WSL distro is refused if the desktop already has a server paired by hand or over SSH that holds the same key (wsl-host-ssh-orcad-conflict.ts). That check exists to catch one orcad reached two ways, and a cloned key can't be told apart from that by key alone.
    • (c) Settings flags two such distros as "the same server paired twice", which is cosmetic.

    None of these is minimal to fix safely, because the fix would mean rotating per-install keys. Recommended as a follow-up.

Linked Issue

Internal: WSL-via-orcad audit addendum, risks R45, R46 and R47.

Visual Proof

N/A: nothing on screen changes. The refusal reuses existing dialog copy, and everything is behind the internal gate.

Testing

  • pnpm tc passes.

  • pnpm test passes for src/main/persistence/moving-wsl-projects, src/main/ipc/pty (spawn-cwd, the spawn preflight and the PTY spawn tests), the new browser jar and generation-reuse tests, runtime-environment-wsl-host-store, and persistence-orcad-migration-catalog: 153 files, 1556 tests.

  • check:code-quality:changed, the max-lines ratchet and the path-literal ratchet pass.

  • New tests:

    • spawn-cwd-wsl-move.test.ts: refused in the moving folder in UNC, wsl$, case-folded and Linux spellings, and for a floating terminal, another project, or a folder workspace started there. Allowed for a sibling with a shared prefix, the parent folder, another distro, a Windows drive, other Linux folders, no folder, and SSH. Reattaching a live session is still allowed, and the fence lifts at commit.
    • wsl-move-driver-commit-reproof.test.ts: the re-proof runs last before the commit with the quiesce's scope. A live or unverifiable result blocks the commit and resets both sides, including when the host is unreachable. The real fence refuses a spawn into the moved folder during the copy.
    • wsl-host-browser-jar-identity.test.ts, the new case in runtime-environment-wsl-host-store.test.ts, and persistence-orcad-migration-wsl-generation-reuse.test.ts.
  • An adversarial review covered over-refusal and the risk of a stuck move. Its two MEDIUM findings are fixed here: spawns that name a workspace are now fenced too, and the refusal now carries the proof's reason.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

Shared path touched: the PTY spawn admission check (assertWorkspaceAcceptsNewPty) on the IPC and runtime spawn paths. It is a no-op unless a move journal has a fenced move, which only ever exists on Windows behind the internal gate.

Terminals elsewhere in the same distro don't block a move. Both exit proofs (at the pause and before the commit) sort each live terminal with no workspace by its known folder. That folder is the shell's live working directory, reported by the shell itself.

  • A folder outside the move is ignored, even in the moving distro. Other projects in the same distro keep their terminals open through a move, including ones opened during the copy.
  • A folder inside the move blocks it.
  • unverifiable is reserved for a terminal whose folder is unknown, or a Linux path inside the move whose distro can't be told.

Before this, any terminal with no workspace in the moving distro counted as unknown, because it could have cd'd into a moved folder. Since the folder is the live one, a shell that later cds into a moved folder is now counted as inside the move.

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

  • Cross-platform: path handling goes through the shared WSL path helpers.
  • SSH: spawns that carry a connection are never checked by folder.
  • Wire compatibility: no wire change.

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
nwparker marked this pull request as ready for review October 22, 2026 10:05
@nwparker
nwparker force-pushed the nwparker/wsl-mover-audit-addendum branch from eb09014 to ee4517a Compare October 22, 2026 10:14
@nwparker
nwparker changed the base branch from nwparker/wsl-mover-d1b-9-move-ux to nwparker/wsl-mover-d1b-7f2-registry-complete October 22, 2026 10:15
@nwparker
nwparker force-pushed the nwparker/wsl-mover-audit-addendum branch from ee4517a to 21fb600 Compare October 22, 2026 10:27
@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