Skip to content

fix(wsl-host): prove an unrecorded orcad by kernel identity before adopting it - #31685

Merged
nwparker merged 4 commits into
mainfrom
nwparker/wsl-orcad-adoption-lock-identity
Oct 22, 2026
Merged

nwparker merged 4 commits into
mainfrom
nwparker/wsl-orcad-adoption-lock-identity

Conversation

@nwparker

@nwparker nwparker commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​73 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​72
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​48 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​42

ELI5

When you connect a WSL distro, Orca checks whether an Orca server it doesn't know about is still running there, for example one a failed Remove left behind. If so, Orca adopts it instead of starting a second one. The "is it still running?" check only asked whether that process ID existed. After a distro restart, process IDs are handed out again from the start, so an unrelated program could hold the old number, and Orca would "adopt" a server that was gone. Orca now checks that the process really is that server.

What Changed

  • Before: adoptUnrecordedWslOrcad read the data root's instance lock and ran kill -0 <pid>.
    • Any process with that PID counted as live, including a zombie or a process a distro restart handed the same PID.
    • A leftover lock and a leftover readiness file both name the same old PID, so the rest of the proof passed. The activation record was then rewritten to point at the dead build, and its rollback snapshot was dropped.
    • A permission error read as "dead".
  • After: the lock holder counts as live only when the guest kernel reports the same boot id and process start ticks the lock recorded. This is the identity check orcad's own instance lock uses, compareOrcadProcessIdentity, fed from the existing one-exec WSL guest identity read.
    • Exited: the PID is gone, or another process now holds it.
    • Unverifiable: a guest that doesn't answer, or a lock from an older writer without those fields.
    • Only a live holder is adopted. In the other cases nothing is rewritten or stopped, and the launch's own instance lock decides on the host.

Why

PID reuse is the case this check exists for. The shared identity comparison already solves it for orcad's lock, so the fix reuses it rather than hardening the shell probe (for example a ps command-line match). Losing contact with the guest is never treated as the process exiting: it is unverifiable, and the code declines to act.

The report described this as WSL Remove's check. In code it is the adoption step of a WSL connect, which recovers from an orcad that a failed Remove left running. Remove itself does not use this check.

Linked Issue

None; found by the SSH cleanup pass (maintainer work).

Visual Proof

N/A: no UI change; this changes when a leftover WSL server is adopted on connect.

Testing

  • I manually tested these changes locally

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

  • A reused PID (same number, different start ticks) and an unanswered guest were both adopted as live on main. Both tests fail there and pass here.

  • An older lock without the kernel identity is unverifiable and is not adopted.

  • Holder changes under the fence still refuse.

  • Ran the WSL adoption, guest identity and deploy suites, pnpm tc:node and the changed-code gates. The WSL orcad E2E lane runs in CI.

  • Verified live: nothing beyond CI (this machine has no WSL).

Mixed versions: every orcad build that WSL can deploy writes the boot id and start ticks into its lock. An older lock is left to the launch's own lock handling rather than adopted.

Review

Codex review and an independent 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

WSL only. The live/unverifiable/exited vocabulary is kept, and loss of contact is unverifiable.

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)

@coderabbitai

coderabbitai Bot commented Oct 21, 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 3 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
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 662088aa-91cd-4954-8616-ca78115cf5d8
📥 Commits

Reviewing files that changed from the base of the PR and between 094d078 and 0d766cd.

📒 Files selected for processing: 3
  • src/main/wsl/wsl-guest-process-identity.ts
  • src/main/wsl/wsl-orcad-instance-adoption.test.ts
  • src/main/wsl/wsl-orcad-instance-adoption.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fbe3c71a-4d9b-4271-a4e6-efb19f48ef5b
📥 Commits

Reviewing files that changed from the base of the PR and between 7e2dbc83b9f3ed8a9529693283093c5f624df71c and 094d078.

📒 Files selected for processing: 2
  • src/main/wsl/wsl-orcad-instance-adoption.test.ts
  • src/main/wsl/wsl-orcad-instance-adoption.ts

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

📝 Walkthrough

WSL Orcad lock adoption now checks the guest-reported process incarnation instead of relying on kill -0. The check uses process start ticks and distro boot ID. Adoption treats missing or unverifiable identity as insufficient proof of a live holder. Tests cover PID reuse after a distro restart, unanswered guest commands, legacy locks without identity fields, and liveness changes during fenced adoption.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 094d0

No merge-blocking issue was identified with the WSL server adoption change; it is ready for normal merge checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 3 files. 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 clearly and concisely identifies the WSL adoption fix: validating an unrecorded Orca process by kernel identity before adoption.
Description check Passed The description follows the required template and explains the user impact, implementation, rationale, testing, compatibility considerations, review status, and checklist. The missing linked issue is …
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: Description check

Explanation

The description follows the required template and explains the user impact, implementation, rationale, testing, compatibility considerations, review status, and checklist. The missing linked issue is explicitly explained as maintainer work, which the template allows.

✨ Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • 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.

…opting it

A WSL connect adopted the orcad named by a leftover instance lock whenever a
bare kill -0 found its PID. After a distro restart PIDs are reused, and a stale
lock plus a stale readiness file that name the same PID passed every other
check, so the record was repointed at a dead build. The holder is now live only
when the lock's boot id and start ticks match the PID's; an unanswered guest or
an older lock without them is unverifiable and is never adopted.
@nwparker
nwparker force-pushed the nwparker/wsl-orcad-adoption-lock-identity branch from 7e2dbc8 to 094d078 Compare October 22, 2026 00:15
@nwparker
nwparker merged commit 75e1f1c into main Oct 22, 2026
45 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