Skip to content

perf(wsl): read a connect's pre-fence activation state in one command - #35591

Merged
nwparker merged 1 commit into
mainfrom
nwparker/wsl-connect-state-snapshot
Oct 29, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/wsl-connect-state-snapshot

Conversation

@nwparker

@nwparker nwparker commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​221 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​215
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​226 $\color{#cf222e}{\Huge{\mathbf{−}}}$​17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​209

ELI5

Before the WSL host starts, Orca checks a few files inside the distro: what version is active, whether an update was interrupted, whether another Orca holds the update lock, and whether an orcad is already running. Each check was a separate command into the distro, and some ran twice. Now one command reads all of them. Later steps use the answers only to skip a check whose answer was "nothing going on". Anything else is re-checked as before.

What Changed

  • Before: on every WSL connect, before taking the activation fence (the lock that serialises updates), the host made these separate guest commands:
    • read orcad-active.json;
    • recovery read transaction.json, then probed the fence;
    • adoption read orcad.lock;
    • the deploy re-read orcad-active.json and probed the fence again.
      The lane counted 20 pre-launch commands per restart.
  • After:
    • The first orcad-active.json read, which the context already does, becomes one command. It reads the record, the journal, the fence and the instance lock (src/main/wsl/wsl-orcad-connect-state-snapshot.ts).
    • Recovery returns "nothing to recover" without reads only when the snapshot saw no journal and an open fence. Otherwise it reads both, as before.
    • Adoption starts from the snapshot's orcad.lock. Its proof of liveness and its fenced re-check still read the host.
    • The deploy's pre-upload record read is skipped. Its fence probe is skipped only when the snapshot saw the fence open. Everything under the fence is re-read as before.
  • Hints stop as soon as recovery, adoption or admission replaces the activation record. A deploy retry after a cleared fence drops them.
  • If the snapshot's output has an unexpected shape, the connect falls back to the plain record read and does every read as before. An unreadable or oversized record still fails closed.

Why

Each guest command costs a round trip through the stdio bridge, and those added up to roughly 270–600 ms per restart on the lane. Folding the reads into the command the context already makes removes about five round trips without adding one.

A hint only lets a step skip a read when the answer would have let it continue unchanged. So a stale hint can at worst delay a refusal until the fenced re-read. It can never authorise a step: every fenced decision is untouched.

I chose this over caching state across connects, which would trust answers from an earlier session, and over moving the checks under the fence, which would serialise every connect behind it.

Flag-off: the WSL host path only runs with ORCA_INTERNAL_WSL_HOSTS set; with it unset nothing here runs. SSH passes no snapshot and sends exactly the same commands as before.
User-risk: low. Wrong hints are bounded by the fenced re-reads; an unrecognised snapshot falls back to today's reads.

Linked Issue

N/A (internal performance work, batch (b) of the WSL cold-start plan).

Visual Proof

N/A: guest command batching, no UI.

Testing

  • New wsl-orcad-connect-state-snapshot.test.ts runs the real command in /bin/sh against a temporary home:

    • a fresh host is read in one command;
    • record, journal, lock and held fence are all read together;
    • an oversized record still fails closed;
    • unrecognised output falls back to the plain read;
    • truncated answers are rejected;
    • hints stop once the record changes.
  • orcad-activation-crash-recovery.test.ts: an idle snapshot sends no host commands, and any other answer still finds and commits an interrupted run.

  • orcad-remote-deploy.test.ts: the snapshot removes exactly one record read and one fence probe, and a fence seen held is probed again.

  • wsl-orcad-deploy.test.ts: the connect hands the snapshot to recovery, adoption and deploy, and with no snapshot the deploy gets no hint.

  • All tests that cover the context, recovery, adoption and deploy for SSH and WSL pass. pnpm tc, pnpm run typecheck:ci, the changed-code quality gate, anti-slop oxlint and oxlint pass.

  • The lane re-measures pre-launch command count and time on this PR's run.

  • 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: no change. The new parameters are optional, and only the WSL connect passes them.
  • Wire: no change.
  • E9: no new background path; the snapshot rides the existing context read, under the same abort signal.

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 WSL connect read the activation record, the transaction journal, the
activation fence and orcad's instance lock in separate guest commands,
some of them twice, before taking the fence. Read them once, alongside
the record the context already read, and hand that snapshot to recovery,
adoption and the deploy's pre-upload checks as a hint. A hint only skips
a read whose answer would let the step continue unchanged; anything else,
and every fenced decision, still reads the host. SSH passes nothing.
@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 16 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: f9159237-3034-49b0-bad0-e3725e106aad
Commits

Reviewing files that changed from the base of the PR and between 366eaff and d1bd812.

Files selected for processing: 13
  • src/main/managed-server/activation/orcad-activation-crash-recovery.test.ts
  • src/main/managed-server/activation/orcad-activation-record-store.ts
  • src/main/managed-server/activation/orcad-activation-recovery.ts
  • src/main/managed-server/install/orcad-remote-context.ts
  • src/main/ssh/orcad-remote-deploy.test.ts
  • src/main/ssh/orcad-remote-deploy.ts
  • src/main/wsl/wsl-orcad-connect-state-snapshot.test.ts
  • src/main/wsl/wsl-orcad-connect-state-snapshot.ts
  • src/main/wsl/wsl-orcad-deploy.test.ts
  • src/main/wsl/wsl-orcad-deploy.ts
  • src/main/wsl/wsl-orcad-held-context.test.ts
  • src/main/wsl/wsl-orcad-held-context.ts
  • src/main/wsl/wsl-orcad-instance-adoption.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] This PR appears safe to merge; the saved answers do not replace the checks required before changing the host.

Summary

This PR batches WSL’s initial activation checks into one guest command.

  • WSL connects read activation state in one guest command.
  • Recovery skips idle-state reads when the snapshot shows no pending work.
  • WSL adoption starts from the instance lock already read at connect.
  • Deploy reuses the connect's record and open-fence answer before upload.

No actionable issues were found. Tests were reviewed but not run.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[WSL connect] --> B[Read activation, journal, fence and instance lock]
  B --> C{Recognized answer?}
  C -->|No| D[Use existing record reader]
  C -->|Yes| E[Reuse preliminary answers]
  D --> F[Recovery, adoption and deploy]
  E --> F
  F --> G[Acquire activation lock]
  G --> H[Read current state before changes]
Loading

Reviews (1) · Last reviewed commit: "perf(wsl): read a connect's pre-fence ac..." · Reviewed by Greptile

@nwparker
nwparker merged commit eef196d into main Oct 29, 2026
63 checks passed
@nwparker

Copy link
Copy Markdown
Contributor Author

STATUS: lane re-measure. Run 40803604529 at head d1bd812 is green on all three distros.

Pre-launch guest commands per restart went from 20 to 15 on every distro. This is compared with #35530's run 40797934871 (medians of 3). The five reads removed are:

  • recovery's journal read and fence probe;
  • adoption's instance-lock read;
  • the deploy's pre-upload record read and fence probe.
ms (median) first output ensure pre-launch checks
ubuntu-24.04 3556 → 4009 2741 → 3171 407 → 400
debian-12 2728 → 3102 2042 → 2402 267 → 311
fedora-41 4283 → 3339 3498 → 2656 599 → 370

The millisecond changes are within runner noise; even the bare wsl.exe floor moved 593→726 on ubuntu and 656→239 on fedora. So the reliable effect is the 5 fewer round trips.

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