Skip to content

fix(wsl): fail closed on an unreadable distro registration and gate browser start on it - #31289

Closed
nwparker wants to merge 5 commits into
nwparker/stable-runtime-browser-partitionfrom
nwparker/wsl-browser-partition-fail-closed
Closed

nwparker wants to merge 5 commits into
nwparker/stable-runtime-browser-partitionfrom
nwparker/wsl-browser-partition-fail-closed

Conversation

@nwparker

@nwparker nwparker commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​356 $\color{#cf222e}{\Huge{\mathbf{−}}}$​11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​345
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​162 $\color{#cf222e}{\Huge{\mathbf{−}}}$​36 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​126

Stacked on #29610 (base: nwparker/stable-runtime-browser-partition, base sha 0ad75ffcc6f). It follows up #29610's re-review notes. WSL only. SSH, managed SSH, and manually paired hosts behave exactly as before. Not to be merged by the agent.

Shared paths this PR touches

  • The in-app browser session start path: startPairedRuntimeBrowserClientHost (the call runtimeEnvironments:prepareBrowserClientHostPlacement makes) now takes userDataPath. For WSL environments only, it waits for the distro's registration read before it picks a partition. Other hosts return immediately and nothing about them changes.
  • The WSL connection record path: persistWslHostConnection now also runs on a dropped connection (null) so it can forget that connection's registry read. WslHostService.handleConnectionChange calls it with null too.

ELI5

The risk: a WSL distro that was re-imported, or whose registration Orca couldn't read, could reuse another distro's browser logins.

#29610 gives each WSL host's in-app browser a cookie jar keyed by the distro's Windows registration ID. A distro that is unregistered and re-imported under the same name gets a new ID, and so a new, empty jar. #29610 had a hole, though. When the registry read failed, Orca used the ID it had saved earlier. That saved ID could belong to the distro that existed before the re-import, so the new distro could open the old one's signed-in jar.

With this PR the browser trusts the ID only when Orca has just read it from the registry and it matches what's saved. Otherwise the browser falls back to today's per-pairing jar and takes nothing over from the stable one.

What Changed

  • Fail closed (paired-runtime-browser-authority-identity.ts):
    • The WSL identity now needs a liveWslDistroId: the registration ID this process read from the registry.
    • The stable partition is used only when that live read equals the GUID the record names now.
    • A failed, timed-out, missing or different read keeps today's revision-scoped identity and adopts nothing into the stable partition.
    • The input is required, not optional, so a future caller can't skip it by accident.
  • The live read (wsl-host-connection-record.ts):
    • Each connection update starts a registry read. This process remembers the latest read per environment.
    • Reads go straight to the registry, not through the 30s shared cache. A cached read could predate an unregister and re-import.
    • A dropped connection forgets its read.
    • When the latest read failed, the next browser start tries again, so one transient reg.exe failure doesn't keep the user on the fallback jar for the whole connection.
  • Ordering (paired-runtime-browser-client-host-runtime.ts):
    • For a WSL environment, browser host start waits for the read that's in flight, or starts one.
    • The wait is capped at 6s; reg.exe itself times out at 5s. On timeout or failure the start takes the fail-closed path, so the browser never hangs.
    • It then re-reads the environment record, which the read may just have updated. If the pairing changed during the wait, it refuses with browser_client_host_pairing_changed, the same error placement already uses.
  • I fixed the misleading comment on observeWslHostRegistration. It claimed an unreadable registry "changes nothing, so identity fails closed", but the saved GUID was still used.

When the registry read recovers

  • The stable jar was already in use: a later good read goes straight back to it, with its cookies. Logins made in the fallback jar during the outage stay in that jar. They aren't merged or deleted.
  • The first good read comes after the fallback jar was used (e.g. the first browser open after the upgrade happened during an outage): the stable identity re-adopts the fallback jar, through fix(browser): keep in-app browser logins when a WSL or managed SSH host re-pairs #29610's normal adoption. That's safe because the fallback jar belongs to the current pairing, and adoption still requires that pairing to have been made under the GUID the registry now confirms.
  • The recovered read names a different registration (a re-import): nothing is adopted, and the user gets a fresh jar.
  • A host that was already running when the read failed: the next page open picks a different identity. The registry then restarts the browser host, so open pages for that WSL host reload into the fallback jar. The same happens when the identity switches back after recovery.

Why

  • Why not keep the saved GUID: a GUID read earlier is exactly the stale value that can name a since-re-imported distro. Keying the jar on it can join the wrong jar.
  • Why wait at start rather than in the connection: saving the pairing must not wait on reg.exe, so the read stays fire-and-forget there. Browser start is the only consumer that needs the result, so it waits there, bounded.
  • Why fail closed on timeout instead of failing the start: a failed start leaves the user without a browser. The fallback jar is today's behaviour and can't leak another distro's logins.

Known limitations

  • Timeout followed by success: if the first browser start times out and the read succeeds later, the next start switches to the stable identity and restarts the host.
  • Re-import that changes nothing else (from fix(browser): keep in-app browser logins when a WSL or managed SSH host re-pairs #29610, not this PR): a re-import that keeps orcad's key, device and pairing doesn't restart a browser host that's already running. That host keeps its partition until the next start. New starts see the new GUID and fail closed or get a fresh jar.

Linked Issue

N/A (maintainer; follow-up to #29610's re-review).

Visual Proof

N/A: no UI change. The behaviour is in partition selection, which the tests cover.

Testing

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

Automated tests:

  • Identity:
    • A failed read with a recorded GUID gives the revision-scoped identity and nothing adoptable.
    • So does a read that names a different registration.
    • A confirmed read gives the stable identity.
  • Partitions and cookies:
    • A failed read doesn't open or alias the confirmed jar.
    • Recovery returns to the confirmed jar and leaves the fallback jar's cookies apart.
    • The first confirmed read after a fallback adopts the fallback jar.
    • A recovered read naming another registration adopts nothing.
  • Start gate (real environment store):
    • A start racing ahead of the in-flight read waits for it, then uses the GUID it recorded.
    • A rejected read fails closed.
    • A read that never settles fails closed after the bound (fake timers).
    • A later failed read fails closed despite the GUID an earlier one recorded.
  • Read bookkeeping:
    • A start reuses the latest good read.
    • A dropped connection forces a fresh read.
    • A failed read is retried.

Verification:

  • pnpm tc
  • pnpm test src/main/browser src/main/wsl src/main/ipc/runtime-environments (3082 passed)
  • pnpm run check:code-quality:changed

Review: an adversarial review found two MEDIUM issues (the 30s shared cache, and a failed read pinning the fallback jar for the whole connection). Both are fixed here. Its LOW notes are listed above as known limitations.

Platforms: macOS locally (unit level). WSL behaviour is covered by tests with the registry read injected. ORCA_INTERNAL_WSL_HOSTS was not enabled.

Review

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: this closes a possible way for one WSL distro registration to open another's cookies.
  • SSH: no change; non-WSL hosts return before any wait.
  • Windows-only behaviour: the registry read is Windows-only and returns null elsewhere.
  • Performance: one reg.exe per WSL connection update, plus a retry only after a failure.

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)

…e-pair, and backfill the WSL registration id
…ngrades, and remember several re-pairs

- A WSL pairing only hands its cookie jar to the stable identity when it was made under the same
  registration GUID. Pairings now record their GUID; ones that recorded none count only when the
  GUID was captured when the host was added. A GUID backfilled later, or a re-import observed from
  the registry, starts a fresh jar.
- Adoption adds the stable fingerprint as an alias on the existing binding instead of overwriting
  it, so an older build still resolves the same partition with no binding conflict.
- Keep up to four replaced pairings, so repeated re-pairs before the first page still adopt the
  original jar.
…t on the registration read

A WSL host's browser partition now trusts the distro's registration GUID only when this
process just read it from the registry and it matches the record. A failed, timed-out,
or mismatched read keeps the revision-scoped identity and adopts nothing. Starting the
browser host for a WSL environment waits (bounded) for that read, then re-reads the
record it may have updated.
@nwparker
nwparker force-pushed the nwparker/stable-runtime-browser-partition branch 2 times, most recently from a27588f to b77de09 Compare October 21, 2026 01:20
@nwparker
nwparker force-pushed the nwparker/stable-runtime-browser-partition branch from b77de09 to 57fe0cd Compare October 21, 2026 01:39
@nwparker

Copy link
Copy Markdown
Contributor Author

Superseded by #29610: the browser partition identity no longer uses the WSL registration GUID; it keys on the environment id and the server's pinned key, so this gate is no longer needed.

@nwparker nwparker closed this Oct 21, 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