Skip to content

perf(wsl): read the kernel, login home and platform in one exec - #35070

Merged
nwparker merged 2 commits into
mainfrom
nwparker/wsl-context-one-probe
Oct 28, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/wsl-context-one-probe

Conversation

@nwparker

@nwparker nwparker commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​161 $\color{#cf222e}{\Huge{\mathbf{−}}}$​17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​144
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​69 $\color{#cf222e}{\Huge{\mathbf{−}}}$​10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​59

ELI5

When Orca connects to a WSL distro, it first asks the distro a few basic questions: the kernel version, the user's home folder, and the CPU and OS. It used to ask each one in a separate trip into the distro. Now one trip answers all three, which removes two of the ~24 trips that happen before the server starts.

What Changed

  • holdWslDistroWithContext (WSL only) replaces its uname -r exec with one exec. That exec prints the kernel release, $HOME, and the usual marker-backed uname -sm platform probe. The kernel line still drives the WSL 1 refusal and the missing-distro mapping. The proven platform and the login home go to resolveOrcadRemoteContext.
  • resolveOrcadRemoteContext takes an optional knownLoginHome and passes it to resolveOrcadMachineHome. Only login-home placement uses it (WSL and Windows hosts). Machine-keyed SSH homes ignore it. The existing detectedHost parameter now gets the platform.
  • ssh-remote-platform-detection.ts exports the probe command it already ran (UNAME_PLATFORM_PROBE_COMMAND) and remoteHostPlatformFromUnameProbe, which runs the existing marker parser on that output. detectRemoteHostPlatform uses the same constant.
  • The facts are parsed by structure. Each value is printed after its own marker, and the output is accepted only in its exact shape: kernel line, home line, blank separator, platform line. Anything else (stdout noise, a $HOME containing a newline) means a separate uname -r exec for the WSL 1 check, as before, and undefined for both platform and home, so the context runs its own probes. An unsupported platform or an empty $HOME also passes undefined for that value. The WSL 1 check reads only the separately trimmed kernel value.

Why

After #35005 and #35037, the 24 serial checks before launch are the second-biggest desktop-side cost (340–630 ms). This is batch (a) from the batching proposal: the low-risk part. It needs no change to anything read under the activation fence. Batches (b) and (c) are on hold until this and #35064 land and the restart is re-measured.

SSH blast radius: none in behavior. SSH callers pass neither new argument, so detectRemoteHostPlatform and echo $HOME/the machine-home probe run exactly as before. The shared files only gain an optional parameter and two exports, and the existing probe command text is unchanged.
Flag-off: no change. The folded probe is only reached through the WSL host deploy (ORCA_INTERNAL_WSL_HOSTS).
User-risk: low. The same commands run, in one shell instead of three. The platform is still accepted only from the marker-backed line, so other output folded into the same exec can't be mistaken for it. Validation of the home path is unchanged.

Linked Issue

Internal WSL-via-orcad tracker, D3 bar (restart → first usable prompt). Batching proposal: batch (a).

Visual Proof

N/A: no UI.

Testing

  • wsl-orcad-held-context.test.ts: one host-facts exec feeds the context the platform and home. Unproven facts fall back to the context's own probes. WSL 1 is refused from the kernel line before any hold or probe. The existing hold-ordering and E9 abort tests are updated to the new probe set.
  • Structural parse: a $HOME containing a newline falls back to the probes (no truncated path); leading stdout noise falls back without throwing; the real sh output of the facts command parses (a non-Windows test).
  • orcad-remote-primitives.test.ts: a WSL context given a platform and home runs neither the platform probe nor $HOME.
  • ssh-remote-platform-detection.test.ts: the marker parser works on folded output and rejects unmarked or unsupported lines.
  • src/main/wsl, src/main/managed-server/install and src/main/ssh suites: 3679 passed. pnpm tc, typecheck:ci, code-quality, anti-slop and ast-grep pass.
  • Automated tests added/updated

Status

Ready. Expected saving is two loop round trips, about 30–50 ms. The WSL2 lane phase receipt (preLaunchCommands) should drop from 24 to 22.

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 (SSH passes no new arguments)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (CI runs the rest)

@nwparker

Copy link
Copy Markdown
Contributor Author

STATUS: ready. Head f7960c4, on main after #35037 merged.

Checks run: pnpm tc, typecheck:ci, the wsl, managed-server/install and ssh suites (3679 passed), code-quality:changed, anti-slop, ast-grep.

Open question: none. The lane receipt should show preLaunchCommands go from 24 to 22.

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The changes add a reusable parser for marker-backed remote platform probe output and let remote context resolution accept a known login home. WSL holding now retrieves kernel, home, and platform facts in one command when output matches the expected format, then passes available values to the context resolver. If parsing fails, it falls back to the kernel-only probe. Tests cover parsing, context handoff, fallback, and WSL 1 rejection.

Priority: Low

Merge Risk: Low · up to 0204d

A kernel-probe failure can let an unsupported WSL 1 deployment proceed. The risk is limited to that failure path.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 44.44% 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): read the kernel, login home and platform in one exec" matches the main change. The WSL held-context path now gets the kernel release, $HOME, and the uname platform probe from one…
Description check Passed The description follows the template's main sections: ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, Checklist. It explains the before and after, the mechanism, the SSH and flag-off imp…
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): read the kernel, login home and platform in one exec" matches the main change. The WSL held-context path now gets the kernel release, $HOME, and the uname platform probe from one exec instead of several serial calls. It uses a conventional type(scope) prefix and states the mechanism and scope. It is specific and does not rely on file lists or vague wording.

Full details: Description check

Explanation

The description follows the template's main sections: ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, Checklist. It explains the before and after, the mechanism, the SSH and flag-off impact, and the fallback behavior. It states that the N/A visual proof has a reason. Gaps: the Linked Issue section has no real GitHub issue reference ("Fixes #" is blank and it cites an internal tracker), which the template says is required for outside contributors. The template's AI Disclosure and Agent skill upstream boundary sections are missing. The lint/typecheck/test/build checklist item is unchecked, with a note that CI covers it. The Review and Notes sections are not filled in.

Resolution

Optional: add a real linked issue number in the Linked Issue section (the template requires one for outside contributors), fill in the AI Disclosure section if applicable, and complete or remove the 'Agent skill upstream boundary' checkbox. Run or confirm the lint, typecheck, test, and build checks before merge.

Full details: Docstring Coverage

Explanation

Docstring coverage is 44.44% 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 9 functions across 7 files.

Resolution

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

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • 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.

The WSL connect's first exec now prints the kernel release, $HOME and the marker-backed uname
platform probe together, and hands the platform and home to resolveOrcadRemoteContext, which
then skips its own uname and $HOME probes: two fewer serial guest round trips per connect. SSH
passes neither, so its probes are unchanged.
Each fact now prints after its own marker, and the output is used only when it has exactly the
kernel line, the home line, the blank separator and the platform line. Anything else (stdout
noise, a HOME containing a newline) falls back to reading the kernel alone and lets the context
probe the platform and home itself, so no truncated path is ever used.
@nwparker
nwparker force-pushed the nwparker/wsl-context-one-probe branch from f7960c4 to 0204d9b Compare October 28, 2026 12:14
@nwparker

Copy link
Copy Markdown
Contributor Author

STATUS: reviewer B's structural-parse fix is pushed. Head 0204d9b, rebased on main.

What changed: each fact is now printed after its own marker, and the output is accepted only in its exact shape. Anything else falls back to a separate uname -r exec plus the context's own probes. The WSL 1 check uses only the trimmed kernel value.

New tests: a HOME containing a newline falls back (no truncated path); leading noise falls back without throwing; the real sh output of the facts command parses.

Checks run: pnpm tc, typecheck:ci, the wsl, managed-server/install and ssh suites (3685 passed), code-quality:changed, anti-slop, 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: 73072422-9656-4430-b31b-ce08e808dee7
Commits

Reviewing files that changed from the base of the PR and between 48b62d9 and 0204d9b.

Files selected for processing: 7
  • src/main/managed-server/install/orcad-remote-context.ts
  • src/main/managed-server/install/orcad-remote-primitives.test.ts
  • src/main/ssh/ssh-remote-platform-detection.test.ts
  • src/main/ssh/ssh-remote-platform-detection.ts
  • src/main/wsl/wsl-orcad-deploy.test.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.

Comment on lines +18 to +46
type WslHostFacts = { kernel: string; loginHome?: string; platform?: RemoteHostPlatform }

/**
* Accepts only the exact shape the facts command prints; anything else (startup noise, a HOME
* with a newline) returns null so the caller probes each fact on its own.
*/
export function readWslHostFacts(output: string): WslHostFacts | null {
const lines = output.split('\n')
const [kernelLine = '', homeLine = '', gap, platformLine = '', ...rest] = lines
if (
!kernelLine.startsWith(KERNEL_MARKER) ||
!homeLine.startsWith(HOME_MARKER) ||
gap !== '' ||
!platformLine.startsWith(UNAME_PLATFORM_PROBE_MARKER) ||
rest.some((line) => line.trim() !== '')
) {
return null
}
const loginHome = homeLine.slice(HOME_MARKER.length)
return {
kernel: kernelLine.slice(KERNEL_MARKER.length).trim(),
...(loginHome.trim() ? { loginHome } : {}),
...withPlatform(remoteHostPlatformFromUnameProbe(`\n${platformLine}`))
}
}

function withPlatform(platform: RemoteHostPlatform | null): { platform?: RemoteHostPlatform } {
return platform ? { platform } : {}
}

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 · Functional Correctness · Quick win

Supported by static analysis

Script executed:

sed -n '1,115p' src/main/wsl/wsl-orcad-held-context.ts
git show f231d1cde623d1ad2c85bd066af0f65078131070:src/main/wsl/wsl-orcad-held-context.ts | sed -n '1,115p'

Repository: stablyai/orca

Length of output: 6268


Script executed:

set -o pipefail
printf '%s\n' '--- platform detection references ---'
rg -n -F --glob '*.ts' -e 'UNAME_PLATFORM_PROBE_COMMAND' -e 'UNAME_PLATFORM_PROBE_MARKER' -e 'remoteHostPlatformFromUnameProbe' src/main/ssh src/main/wsl
printf '%s\n' '--- execCommand definition ---'
rg -n -F --glob '*.ts' -e 'export async function execCommand' -e 'function execCommand' -e 'const execCommand' src/main/ssh
printf '%s\n' '--- hold/read facts usages and tests ---'
rg -n -F --glob '*.ts' -e 'holdWslDistroWithContext' -e 'readWslHostFacts' -e 'WSL_HOST_FACTS_COMMAND' src tests || test "$?" -eq 1
printf '%s\n' '--- relevant source blocks ---'
sed -n '1,180p' src/main/ssh/ssh-remote-platform-detection.ts
sed -n '1,220p' src/main/ssh/remote-exec/remote-exec-command.ts

Repository: stablyai/orca

Length of output: 19647


Script executed:

set -o pipefail
printf '%s\n' '--- deployment caller ---'
sed -n '105,165p' src/main/wsl/wsl-orcad-deploy.ts
printf '%s\n' '--- held-context tests ---'
sed -n '1,275p' src/main/wsl/wsl-orcad-held-context.test.ts
printf '%s\n' '--- remote command close/exit handling ---'
sed -n '220,390p' src/main/ssh/remote-exec/remote-exec-command.ts

Repository: stablyai/orca

Length of output: 15191


Reject an empty kernel fact.

If uname -r fails without stdout but uname -sm succeeds, the combined command returns valid platform output. readWslHostFacts accepts the empty kernel, so holdWslDistroWithContext skips the WSL 1 refusal and continues deployment.

Suggested fix
   const loginHome = homeLine.slice(HOME_MARKER.length)
+  const kernel = kernelLine.slice(KERNEL_MARKER.length).trim()
+  if (!kernel) {
+    return null
+  }
   return {
-    kernel: kernelLine.slice(KERNEL_MARKER.length).trim(),
+    kernel,
Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
type WslHostFacts = { kernel: string; loginHome?: string; platform?: RemoteHostPlatform }
/**
* Accepts only the exact shape the facts command prints; anything else (startup noise, a HOME
* with a newline) returns null so the caller probes each fact on its own.
*/
export function readWslHostFacts(output: string): WslHostFacts | null {
const lines = output.split('\n')
const [kernelLine = '', homeLine = '', gap, platformLine = '', ...rest] = lines
if (
!kernelLine.startsWith(KERNEL_MARKER) ||
!homeLine.startsWith(HOME_MARKER) ||
gap !== '' ||
!platformLine.startsWith(UNAME_PLATFORM_PROBE_MARKER) ||
rest.some((line) => line.trim() !== '')
) {
return null
}
const loginHome = homeLine.slice(HOME_MARKER.length)
return {
kernel: kernelLine.slice(KERNEL_MARKER.length).trim(),
...(loginHome.trim() ? { loginHome } : {}),
...withPlatform(remoteHostPlatformFromUnameProbe(`\n${platformLine}`))
}
}
function withPlatform(platform: RemoteHostPlatform | null): { platform?: RemoteHostPlatform } {
return platform ? { platform } : {}
}
type WslHostFacts = { kernel: string; loginHome?: string; platform?: RemoteHostPlatform }
/**
* Accepts only the exact shape the facts command prints; anything else (startup noise, a HOME
* with a newline) returns null so the caller probes each fact on its own.
*/
export function readWslHostFacts(output: string): WslHostFacts | null {
const lines = output.split('\n')
const [kernelLine = '', homeLine = '', gap, platformLine = '', ...rest] = lines
if (
!kernelLine.startsWith(KERNEL_MARKER) ||
!homeLine.startsWith(HOME_MARKER) ||
gap !== '' ||
!platformLine.startsWith(UNAME_PLATFORM_PROBE_MARKER) ||
rest.some((line) => line.trim() !== '')
) {
return null
}
const loginHome = homeLine.slice(HOME_MARKER.length)
const kernel = kernelLine.slice(KERNEL_MARKER.length).trim()
if (!kernel) {
return null
}
return {
kernel,
...(loginHome.trim() ? { loginHome } : {}),
...withPlatform(remoteHostPlatformFromUnameProbe(`\n${platformLine}`))
}
}
function withPlatform(platform: RemoteHostPlatform | null): { platform?: RemoteHostPlatform } {
return platform ? { platform } : {}
}

@nwparker
nwparker merged commit 8857567 into main Oct 28, 2026
65 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