Skip to content

perf(wsl): hold the distro alongside the read-only context probes - #35037

Merged
nwparker merged 3 commits into
mainfrom
nwparker/wsl-holder-overlap
Oct 28, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/wsl-holder-overlap

Conversation

@nwparker

@nwparker nwparker commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​147 $\color{#cf222e}{\Huge{\mathbf{−}}}$​11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​136
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​56 $\color{#cf222e}{\Huge{\mathbf{−}}}$​13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​43

ELI5

When a WSL distro restarts, the WSL host has to start a small "holder" process that keeps the distro running. Before this PR it waited for the holder to finish (~110–130 ms on CI) and only then started reading basic facts from the distro (platform, home directory, libc). Those reads don't need the holder, so now both happen at the same time. The holder is still in place before anything can start Orca's server.

What Changed

  • deployAndLaunchWslOrcad now calls holdWslDistroWithContext (new wsl-orcad-held-context.ts). That function runs the uname -r WSL 1 check as before, then Promise.all([holder.ensureHeld, resolveOrcadRemoteContext]).
  • Recovery (recoverInterruptedOrcadActivation, which can launch an orcad), adoption, deploy and wake still run only after the holder resolves. If the holder fails, the connect fails before recovery, as before.
  • isWsl1KernelRelease moved to the new module along with its test. This keeps wsl-orcad-deploy.ts under the line cap.
  • The Windows registry GUID read now starts just before the kernel probe instead of right after the holder. It is a local read and is awaited much later.

Why

The #35005 lane breakdown puts the holder at 111 / 117 / 132 ms (ubuntu / debian / fedora medians). It sat in series with the four read-only context probes (~60–100 ms). I chose this shape over starting the holder alongside the boot (uname -r). Measured, that could save at most the holder's ~120 ms, well below the 300 ms bar. And while the distro is still booting, the holder's "is it running" check would poll wsl.exe --list --running several times, adding wsl.exe spawns on EDR-scored machines. Here the kernel probe has already started the distro, so the holder's first check succeeds and nothing extra is spawned.

Flag-off: no change. deployAndLaunchWslOrcad runs only for WSL hosts (ORCA_INTERNAL_WSL_HOSTS).
User-risk: low. The holder is still acquired before anything may launch or wake orcad. The only change in order is that the read-only context probes no longer wait for it. The E9 no-boot path is unchanged: the manager's running gate still comes before the first spawn, and the deploy's second running check before a re-wake is untouched.

Linked Issue

Internal WSL-via-orcad tracker, D3 bar (restart → first usable prompt). Phase breakdown: #35005.

Visual Proof

N/A: no UI.

Testing

  • New: the context reads finish while the holder is still pending, and recovery doesn't start until the holder resolves (uname, hold-start, context, held, recover). A failing holder fails the connect with no recovery or deploy.
  • Existing ordering and WSL 1 refusal tests pass. The WSL 1 refusal still happens before any hold.
  • src/main/wsl/ suite: 547 passed. pnpm tc, typecheck:ci, code-quality, anti-slop and ast-grep pass locally.
  • Automated tests added/updated

Status

Ready. Expected saving is roughly min(holder, context probes) ≈ 60–100 ms per connect.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • N/A for visuals with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote impact considered (WSL-only file; SSH untouched)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (CI runs the rest)

@nwparker

Copy link
Copy Markdown
Contributor Author

STATUS: ready. Head d02db23. Checks run: pnpm tc, typecheck:ci, the src/main/wsl suite (547 passed), code-quality:changed, anti-slop, ast-grep. Open question: none. The WSL2 lane will show the holder/context overlap in the #35005 phase receipt once that PR is in main.

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: ba9f7f04-e111-4807-8366-76a1acef5835
Commits

Reviewing files that changed from the base of the PR and between a54e31b and df5845d.

Files selected for processing: 4
  • 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
Walkthrough

The deployment flow now uses holdWslDistroWithContext to obtain the distro hold and remote context. The helper checks the kernel release and rejects WSL 1 with a conversion command. For supported releases, it runs context probes while the holder starts and aborts those probes if holding fails. Tests cover these outcomes and verify that deployment recovery waits for the holder to succeed.

Priority: Low

Merge Risk: Low · previous review a54e3

A failed WSL connection can still start its distro afterward. This is a narrow lifecycle issue that should be fixed before merge, though it does not block other connections.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title "perf(wsl): hold the distro alongside the read-only context probes" matches the main change. The PR runs the distro holder in parallel with the read-only context probes, using the new holdWs…
Description check Passed The description follows the template. It has the ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, Checklist, and Notes sections. It explains the mechanism, the reason for the chosen appro…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "perf(wsl): hold the distro alongside the read-only context probes" matches the main change. The PR runs the distro holder in parallel with the read-only context probes, using the new holdWslDistroWithContext helper, instead of waiting for the holder first. The title is specific and concise, and it uses the conventional commit prefix.

Full details: Description check

Explanation

The description follows the template. It has the ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, Checklist, and Notes sections. It explains the mechanism, the reason for the chosen approach over the alternatives, the flag-off and user-risk status, and the measured saving. Two gaps exist. The Linked Issue section names only an internal tracker and phase breakdown (#35005) and has no 'Fixes #' issue reference, even though the template says an issue must always be linked for outside contributors. The AI Disclosure and Review sections are missing and the 'Agent skill upstream boundary' check is not marked. The Testing section does not name the platforms actually tested (macOS, Linux, Windows, SSH), and the pnpm lint, typecheck, test, and build checkbox is unchecked.

Resolution

Mostly complete. For a stronger submission, link a real issue in the Linked Issue section (for example, 'Fixes #NNNN'), state which platforms were tested, and tick or explain the remaining checklist items. The AI Disclosure section is optional for internal contributors and can be left out. The agent skill boundary item should be ticked or explained.

Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 4 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
⚔️ Resolve merge conflicts: 💡
  • Resolve merge conflict in branch nwparker/wsl-holder-overlap
  • 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.

@nwparker

Copy link
Copy Markdown
Contributor Author

STATUS: reviewer B's E9 fix is pushed. Head a54e31b.

What changed: the context probes now run under a child AbortController. It is linked to the connect's signal and aborted when ensureHeld rejects or when Promise.all rejects for any other reason.

New test: after the hold fails, the next probe exec is refused before it spawns, and nothing runs after the rejection. The test fails without the fix.

Checks run: pnpm tc, typecheck:ci, the src/main/wsl suite (554 passed), code-quality:changed, anti-slop, oxlint, ast-grep.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


Review info
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: 86500d07-8431-4dc4-9854-91d3793cdf3c
Commits

Reviewing files that changed from the base of the PR and between 2459222 and a54e31b.

Files selected for processing: 4
  • 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

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

const stopProbes = (): void => probes.abort(signal?.reason)
signal?.addEventListener('abort', stopProbes, { once: true })
try {
const [held, context] = await Promise.all([

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Stability & Availability · Quick win

Supported by static analysis

Script executed:

sed -n '1,115p' src/main/wsl/wsl-distro-holder.ts
sed -n '225,335p' src/main/wsl/wsl-distro-holder.ts
sed -n '120,170p' src/main/wsl/wsl-orcad-deploy.ts
sed -n '1,115p' src/main/wsl/wsl-orcad-held-context.ts

Repository: stablyai/orca

Length of output: 14174


Script executed:

nl -ba src/main/wsl/wsl-distro-holder.ts | sed -n '200,330p'
nl -ba src/main/wsl/wsl-orcad-deploy.ts | sed -n '80,120p'
git show 2459222db1422d836524fffe7ca482d6a8319450:src/main/wsl/wsl-orcad-deploy.ts | nl -ba | sed -n '115,155p'

Repository: stablyai/orca

Length of output: 9879


Wait for the holder promise before propagating a context failure.

Promise.all can reject while ensureHeld(name) is still pending. The holder can then spawn after the failed connect has returned and the transport has been disposed. Await the holder promise before rethrowing the context error.

Do not release the holder here. ensureHeld can adopt an existing holder, and the previous sequential flow already retained a successful holder when context resolution failed.

Suggested fix
+  let heldPromise: ReturnType<WslDistroHolder['ensureHeld']> | undefined
   try {
+    heldPromise = holder.ensureHeld(name).catch((error: unknown) => {
+      probes.abort(error)
+      throw error
+    })
+    const contextPromise = resolveOrcadRemoteContext(target, conn, probes.signal)
     const [held, context] = await Promise.all([
-      holder.ensureHeld(name).catch((error: unknown) => {
-        probes.abort(error)
-        throw error
-      }),
-      resolveOrcadRemoteContext(target, conn, probes.signal)
+      heldPromise,
+      contextPromise
     ])
     return { held, context }
   } catch (error) {
     probes.abort(error)
+    await heldPromise?.catch(() => undefined)
     throw error
   }

This is a localized minor stability fix. It may delay the failed connect until the holder operation settles, but it prevents a new holder spawn after rejection without requiring cancellation or release.

The kernel probe has already started the distro, so the holder now runs alongside the four
read-only context reads instead of before them; it is still held before recovery, which may
launch orcad. No new wsl.exe spawns. The WSL 1 check and the parallel hold move to
wsl-orcad-held-context.ts.

# Conflicts:
#	src/main/wsl/wsl-orcad-deploy.ts
A failed hold left the context probes running; after the deploy disposes its transport they fall
back to fresh wsl.exe execs, which could boot a distro that just went away (E9). The probes now
run under a child signal of the connect's, aborted on a hold failure or any other rejection.
Moves the ordering check out of the deploy suite, which is at its line cap after main's new
refusal tests, into the held-context suite.
@nwparker
nwparker force-pushed the nwparker/wsl-holder-overlap branch from a54e31b to df5845d Compare October 28, 2026 11:37
@nwparker
nwparker merged commit ce3c8d1 into main Oct 28, 2026
46 checks passed
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