Skip to content

perf(orcad): qualify a bundled slot once per unchanged host instead of every launch - #35064

Merged
nwparker merged 4 commits into
mainfrom
nwparker/orcad-startup-qualified-once
Oct 28, 2026
Merged

nwparker merged 4 commits into
mainfrom
nwparker/orcad-startup-qualified-once

Conversation

@nwparker

@nwparker nwparker commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​194 $\color{#cf222e}{\Huge{\mathbf{−}}}$​8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​186
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​117 $\color{#cf222e}{\Huge{\mathbf{−}}}$​8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​109

ELI5

Every time Orca's server (orcad) starts from an installed slot, it first starts a second, throwaway copy of itself to check that the install works. Then it waits for that copy to finish. After a WSL distro restart this check costs 0.7–1.4 s, about a quarter of the wait before the first terminal. This PR keeps the check the first time a slot starts on a host. After a start that reaches readiness, later starts on the same, unchanged host skip it.

What Changed

  • orcad-startup-qualification.ts (new).
    • orcadStartupQualificationKey: a key built from the artifact version, each installed artifact file's [size, mtime, ctime, inode], the pinned runtime identity, process.versions.node, the host ABI from detectNativeHostAbi() (platform, arch, libc, glibc runtime version, Node ABI) and os.release() (the kernel).
    • consumeOrcadStartupQualification: returns true only if the slot's .orcad-startup-qualified marker equals the key, and deletes the marker when it does.
    • recordOrcadStartupQualification: writes the marker through a temp file and a rename. Any error is swallowed.
  • preflightBundledOrcadStartup. The version-file check still runs first. If the key computes and a matching marker is consumed, the preflight child is skipped. Otherwise the child runs as before. On Windows the child always runs (see the table below).
  • main.ts. After main() resolves, meaning readiness was published, confirmBundledOrcadStartupQualified() writes the marker. A launch that fails before readiness never writes it. A launch that crashes before readiness also leaves no marker, because it was consumed at start. So the next launch re-qualifies.
  • listOrcadArtifactFilenames. Extracted from readOrcadArtifactIdentity, so the key and the hash cover the same files.

What the preflight checks, and why skipping it is safe after one success

The skipped child (runOrcadProfilePreflight with nativeFeatures: false) checks the following:

What the child checks Why skipping it is safe after one success on an unchanged host
Artifact delivery. It re-hashes every installed artifact and compares the result with VERSION, which catches partial or altered installs. The key includes each artifact's size, mtime, ctime and inode. Replacing, rewriting, truncating or deleting a file changes the key (a missing file makes the key fail, so the child runs). The launcher still sha256-checks orcad-server.js on every launch. VERSION is still read and validated before any marker. The one thing no longer caught is bit rot inside a file whose metadata didn't change.
Runtime identity. The child must report the pinned Node. The key includes the runtime identity and process.versions.node. assertOrcadServerRuntime (Node ≥ 24, the bundled runtime, the pinned version) still runs in-process on every launch.
SQLite and worker threads. It opens a throwaway profile DB, commits through the writer worker, runs the backup worker and reads the backup back. With identical bytes, Node, glibc and kernel this result doesn't change; all four are in the key.
Windows process identity table (preflightOrcadNativeRuntime, the only native check at startup). Not skipped. It depends on host services, not on the slot, so Windows always runs the child.
Environment: a writable tmpdir, free disk. This isn't a property of the install. If it goes bad, the real profile open fails the startup with an error. The marker was already consumed, so the next launch runs the full preflight.

The marker stores success only. It is consumed at the start of each launch and written back only after readiness, so a host that went bad is re-qualified on its next launch. Write failures, read failures and parse mismatches all mean "run the preflight". The marker sits in the version slot, so version GC deletes it along with the version.

Hardening (reviewer follow-ups)

  • A failed preflight voids the marker. If the child fails or answers with the wrong identity, the marker is deleted before the error is thrown. That covers a concurrent launch that would otherwise rely on it.
  • Only managed slots hold a marker. A marker is read or written only when orcad was launched as a managed slot: ORCA_ORCAD_MANAGED_ACTIVATION_ROOT is set, which is the same gate the compile cache uses, and the slot is not under process.resourcesPath. Every other bundled launch runs the preflight as before and never touches a marker.
  • The launch environment is in the key. A hash of NODE_OPTIONS, LD_PRELOAD, LD_LIBRARY_PATH and TMPDIR, as orcad sees them, is part of the key. Changing, adding or removing any of them re-qualifies.

Which paths run bundled orcad, and which can use the marker:

Path Where the slot lives Marker
SSH managed slot (Linux, macOS) ~/.orca-remote/orcad-<version>/ on the remote, launched by orcadLaunchCommand with the managed activation root Yes
WSL host slot ~/.orca-remote/orcad-<version>/ in the distro, same launch path (setsid) Yes
SSH managed slot on Windows the remote .orca-remote slot No: the preflight always runs on Windows
Local orca serve with a pinned-Node slot a materialized slot under the desktop's userData, launched without the managed activation root No
Packaged app resources (template dirs) under process.resourcesPath, never written to No, by both the env gate and the path check

Why

The #35043 lane profile shows the startup preflight child taking 701 / 1438 / 1101 ms (ubuntu / debian / fedora) after a distro restart, ahead of orcad's own startup. Desktop-side fixes save tens of milliseconds; this is the largest single item on the D3 path.

I considered and rejected running the child alongside orcad's imports. The startup contract is "qualify packaged startup before touching profile indexes, data-root locks or imports", and overlapping would break it.

Flag-off: this is shared orcad code, so it applies whether or not ORCA_INTERNAL_WSL_HOSTS is set. It affects every bundled orcad launch: WSL hosts, SSH managed slots and the desktop's bundled orcad. Two reviewers, please.
User-risk: low to medium. The first launch of a slot on a host is checked exactly as before. Later launches skip a check whose result can't differ with the same bytes, runtime, libc and kernel. On Windows nothing changes. Remote wire: unchanged; the readiness payload is not touched.

Linked Issue

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

Visual Proof

N/A: no UI.

Testing

  • orcad-startup-qualification.test.ts (real temp dir): the key changes with the version and with a replaced file; a missing file fails the key; the marker is consumed once; a different, missing or torn marker never matches; the write is atomic and leaves no temp file; writing into an unwritable slot fails open.
  • orcad-profile-preflight.test.ts: a matching marker skips the child and records only on confirm; no marker means the child runs and is recorded after readiness; a failed child records nothing; a key error runs the child and records nothing; Windows always runs the child; the version check is never skipped.
  • Hardening: the marker is voided after a failed child and after a wrong-identity reply; nothing is read or written outside a managed slot; each of the four env vars re-qualifies when changed or removed; isQualifiableOrcadSlot refuses resources and unmanaged launches.
  • main-preflight-order.test.ts: qualification is recorded after main(), and never when startup fails.
  • src/main/orcad and src/main/managed-server/install suites pass, except the macOS-only /private/tmp failures in orcad-forked-child-paths, which this PR doesn't touch. pnpm tc, typecheck:ci, code-quality, anti-slop and ast-grep pass.
  • Automated tests added/updated

Status

Ready for two reviewers. The WSL2 lane should show the restart's orcad startup dropping by about 0.7–1.4 s, and the measurement on this PR's run will confirm it. It also adds the one-line comment the #35027 reviewers asked for to wsl-orcad-version-gc-memo.ts: a distro shared with another Orca, or a rolled-back activation, can leave a stale dir behind until the next launch.

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 (Windows excluded; SSH slots benefit; readiness payload unchanged)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (CI runs the rest)

@nwparker
nwparker force-pushed the nwparker/orcad-startup-qualified-once branch from 92f6d71 to 644af0e Compare October 28, 2026 11:47
@nwparker

Copy link
Copy Markdown
Contributor Author

STATUS: ready for two reviewers. Head 644af0e, rebased on main after #35027 merged. This push adds the #35027 memo comment.

Checks run: pnpm tc, typecheck:ci, the orcad preflight/qualification suites and the memo suite (50 passed), code-quality:changed, anti-slop, ast-grep. The src/main/orcad suite also passes apart from orcad-forked-child-paths, which fails only on macOS (the /private/tmp path) and isn't touched by this PR.

Open question: none.

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent 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: 6604d88f-0ca7-4442-afa4-12bc3efda47f
Commits

Reviewing files that changed from the base of the PR and between 19e0b84 and 644af0e.

Files selected for processing: 8
  • src/main/orcad/main-preflight-order.test.ts
  • src/main/orcad/main.ts
  • src/main/orcad/orcad-artifact-identity.ts
  • src/main/orcad/orcad-profile-preflight.test.ts
  • src/main/orcad/orcad-profile-preflight.ts
  • src/main/orcad/orcad-startup-qualification.test.ts
  • src/main/orcad/orcad-startup-qualification.ts
  • src/main/wsl/wsl-orcad-version-gc-memo.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

The change adds an Orcad startup qualification key based on installed artifact identity and runtime details. Preflight can consume a matching marker on non-Windows platforms; otherwise it runs the child preflight. A successful child preflight sets a pending qualification, which the main startup path records only after main() resolves. Tests cover key generation, marker persistence, platform behavior, and startup ordering.

Priority: Low

Merge Risk: Minimal · up to 644af

Unchanged hosts can reuse startup qualification. No merge-blocking risk is established.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Description check Warning The PR description follows the repository template closely. It has the ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, Status, and Checklist sections. It explains the mechanism in detail…
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title names the main change: a bundled orcad slot is qualified once per unchanged host, so later launches skip the startup preflight child. It also carries the perf(orcad) scope. The title is shor…
Docstring Coverage Passed Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentati…
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 names the main change: a bundled orcad slot is qualified once per unchanged host, so later launches skip the startup preflight child. It also carries the perf(orcad) scope. The title is short, specific, and matches the changeset.

Full details: Docstring Coverage

Explanation

Docstring coverage is 87.50% which is sufficient. 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 8 functions across 8 files.

Full details: Description check

Explanation

The PR description follows the repository template closely. It has the ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, Status, and Checklist sections. It explains the mechanism in detail: the startup qualification marker, the key inputs, the consume-and-record flow, the Windows exclusion, and the managed-slot gate. It also lists the paths that can and cannot use the marker, and it gives a clear testing list. Gaps: the Linked Issue section names an internal tracker and cites #35005 and #35043, but it does not use the 'Fixes #' form the template asks for. The Review section and Agent skill upstream boundary checkbox from the template are missing. The AI Disclosure section is absent. The unchecked 'pnpm lint, pnpm typecheck, pnpm test, and pnpm build' item is left open, which the author explains as CI coverage. The Testing section does not state which platforms were manually tested (macOS, Linux, Windows, SSH), and the manual-test checkbox is not ticked.

Finishing Touches
📝 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.

…f every launch

Every bundled orcad launch ran a second full orcad-server.js process (the startup preflight)
before serving: 0.7-1.4 s after a WSL distro restart. Once a launch with the same key reaches
readiness, the slot records a marker; the next launch with that key skips the child. The key
covers the artifact version, each installed file's stat identity, the runtime identity, Node
version, libc and kernel. The marker is consumed at startup and rewritten only after readiness,
so a launch that fails or crashes before readiness re-qualifies; it is written via temp + rename,
and any read, parse or write problem falls back to the preflight.
There the child also proves the process identity table, which depends on host services rather
than on the slot's bytes.
- A failed preflight child deletes any marker, so a concurrent launch cannot rely on it.
- Only managed slots (launched with the managed activation root, as for the compile cache)
  outside process.resourcesPath ever read or write a marker.
- The key fingerprints NODE_OPTIONS, LD_PRELOAD, LD_LIBRARY_PATH and TMPDIR as orcad sees them.
@nwparker
nwparker force-pushed the nwparker/orcad-startup-qualified-once branch from 644af0e to 3daabed Compare October 28, 2026 12:02
@nwparker

Copy link
Copy Markdown
Contributor Author

STATUS: the reviewer hardenings are pushed. Head 3daabed, rebased on main.

  1. A failed preflight child, or one that answers with the wrong identity, now deletes the marker.
  2. A marker is only read or written in a managed slot (managed activation root env set, outside process.resourcesPath).
  3. The key now includes a hash of NODE_OPTIONS, LD_PRELOAD, LD_LIBRARY_PATH and TMPDIR.

Each change has a test, and the PR body now lists the paths that run bundled orcad.

Checks run: pnpm tc, typecheck:ci, code-quality:changed, anti-slop, oxlint, ast-grep. In src/main/orcad, 742 passed and 5 failed. Four are the orcad-forked-child-paths failures, caused by the macOS /private/tmp path and not touched by this PR. The fifth is orcad-push-startup, which timed out under load and passes on its own (7/7).

@nwparker
nwparker merged commit 938286e into main Oct 28, 2026
60 of 61 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