Skip to content

perf(wsl): take one activation fence on a same-version connect - #35708

Merged
nwparker merged 2 commits into
mainfrom
nwparker/wsl-single-fence
Oct 29, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/wsl-single-fence

Conversation

@nwparker

@nwparker nwparker commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​257 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​257
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​150 $\color{#cf222e}{\Huge{\mathbf{−}}}$​45 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​105

ELI5

When a WSL distro restarts and you reconnect on the same Orca version, the host takes a lock on the distro twice. The first time is only to read "this version is already active". The second time is to start the server. Each lock costs several round trips into the distro. Now one lock does both jobs. Any case that isn't plain "same version, nothing else going on" still takes the old two-lock path.

What Changed

The lock is the activation fence: a directory inside the distro that serialises updates and starts.

  • Before: on a same-version WSL connect:
    1. deployOrcad acquired the fence, re-read orcad-active.json, saw "already active", and released the fence.
    2. wakeStoppedManagedOrcad then re-read the record, checked liveness, probed the fence, and acquired it again to start the stopped slot, then released it.
  • After:
    • deployOrcad takes a new WSL-only option, sameVersionFencedByCaller. With it, once the slot is confirmed installed, a deploy whose pre-read record already names this version returns "already active" without taking the fence. The caller promises the decision is re-checked under a fence. The option is dropped on the cleared-fence retry, like preRead.
    • The new wakeExpectedOrcadUnderOneFence in orcad-managed-wake.ts takes one fence. Under it, it re-reads the record, checks the slot's liveness, and starts the slot if proven stopped. It uses the same per-host queue and interrupted-wake token bookkeeping as wakeStoppedManagedOrcad.
      • If another version is active by then, it answers replan.
      • If the fence is busy, it answers fenced.
      • In both cases deployWslOrcadWithOneFence runs the full deploy and wake, without hints.
    • The WSL connect takes this path only when perf(wsl): read a connect's pre-fence activation state in one command #35591's snapshot saw the fence open. Otherwise it runs the two-fence path unchanged.
    • readRestoredRecord moved unchanged into wsl-orcad-update-admission.ts, as readRestoredWslOrcadRecord, to keep wsl-orcad-deploy.ts under its line cap.

Why

The first fence decided nothing the second fence doesn't re-check. Merging them removes one acquire, one release, the deploy's fenced record read, and the wake's three pre-fence reads. That is about six round trips per same-version restart.

The launch still happens only under a held fence, after a fenced record re-read and liveness check. We kept the rule that nothing launches before the fence: no speculative launch.

I chose to skip the deploy's fence rather than move the wake into deployOrcad. That keeps SSH's deploy untouched, and confines the new behaviour to one opt-in option and one new function.

Flag-off: the WSL host path only runs with ORCA_INTERNAL_WSL_HOSTS set; with it unset nothing here runs. SSH never sets the option and never calls the new wake, so its commands are unchanged.
User-risk: moderate code area (activation fence), low behaviour risk. Every decision and the launch stay under the guarded fence. Anything unexpected falls back to the existing two-fence path.

Linked Issue

N/A (internal performance work: fold B of the WSL cold-start plan).

Visual Proof

N/A: no UI.

Testing

New orcad-managed-wake-one-fence.test.ts (fake host, with exclusive mkdir) pins the invariants:

  • the fence acquire is the first and only step before the guarded reads and the launch;
  • every command after it runs while the fence is held, behind the owner guard;
  • the record is unchanged before launch, and the fence is released after;
  • another version active: replan, no launch;
  • a live slot: serving, no launch;
  • a busy fence: fenced, the other owner's fence untouched;
  • two concurrent connects in one app, or in two apps sharing no in-process queue: exactly one launch;
  • a failed acquire: an error, no lock left, no launch.

Other tests:

  • orcad-activation-crash-recovery.test.ts:

    • the deploy skips its fence only with the option and a same-version record;
    • without the option it fences as before;
    • with another version active it fences as before.
  • New wsl-orcad-one-fence-deploy.test.ts:

    • the one-fence path;
    • replan and fenced fall back to the full deploy without hints;
    • a held fence or no hints keeps the two-fence path;
    • a version change wakes nothing.
  • All 22 test files that cover deploy, wake, admission and the WSL connect pass. pnpm tc, pnpm run typecheck:ci, the changed-code quality gate, anti-slop oxlint and oxlint all pass.

  • The lane run on this PR re-measures pre-launch round trips and ms per family.

  • I manually tested these changes locally

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

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

  • SSH: unchanged.
  • Wire: no change.
  • E9: no new background path; the wake runs on the connect, under its signal, after the holder.

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)

A same-version WSL connect fenced twice: the deploy took the activation
fence only to read that the version was already active, released it, and
the wake took it again to start the stopped slot. Now the deploy skips its
fence for that case (WSL-only, when the connect snapshot saw the fence
open), and one wake fence re-reads the record, checks liveness and starts
the slot under its owner guard. Another version active by then, or a busy
fence, runs the full deploy and wake as before. SSH is unchanged.
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 4 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 42fbdefd-57bb-4178-a767-a43b1e306a76
Commits

Reviewing files that changed from the base of the PR and between 3b9c1d3 and 3a3b4cb.

Files selected for processing: 8
  • src/main/managed-server/activation/orcad-activation-crash-recovery.test.ts
  • src/main/managed-server/lifecycle/orcad-managed-wake-one-fence.test.ts
  • src/main/managed-server/lifecycle/orcad-managed-wake.ts
  • src/main/ssh/orcad-remote-deploy.ts
  • src/main/wsl/wsl-orcad-deploy.ts
  • src/main/wsl/wsl-orcad-one-fence-deploy.test.ts
  • src/main/wsl/wsl-orcad-one-fence-deploy.ts
  • src/main/wsl/wsl-orcad-update-admission.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable new issue was found.

Summary

Same-version WSL connects can confirm the active version and start its stopped server under one activation fence.

  • Same-version WSL reconnects check and wake Orcad under one activation fence.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[WSL connect with open-fence snapshot] --> B[Confirm slot is installed]
  B --> C[Wake under one fence]
  C --> D{Earlier wake token exists?}
  D -->|Yes| E[Keep token and use full deploy path]
  D -->|No| F[Acquire fence and recheck active version]
  F -->|Same version| G[Check liveness and start only if stopped]
  F -->|Changed or busy| E
Loading

Reviews (2) · Last reviewed commit: "fix(wsl): leave an interrupted wake's fe..." · Reviewed by Greptile

…aim it

The one-fence wake recorded its own token over an earlier interrupted
wake's, so the full wake could no longer prove that fence its own and the
host stayed fenced until stale recovery. With an interrupted wake on
record, the one-fence path now answers 'fenced' and the full wake runs.
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