Repository navigation
perf(orcad): qualify a bundled slot once per unchanged host instead of every launch - #35064
Conversation
92f6d71 to
644af0e
Compare
|
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. |
|
No actionable comments were generated in the recent review.
|
…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.
644af0e to
3daabed
Compare
|
STATUS: the reviewer hardenings are pushed. Head 3daabed, rebased on main.
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). |
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 fromdetectNativeHostAbi()(platform, arch, libc, glibc runtime version, Node ABI) andos.release()(the kernel).consumeOrcadStartupQualification: returns true only if the slot's.orcad-startup-qualifiedmarker 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. Aftermain()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 fromreadOrcadArtifactIdentity, 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 (
runOrcadProfilePreflightwithnativeFeatures: false) checks the following:VERSION, which catches partial or altered installs.orcad-server.json every launch.VERSIONis still read and validated before any marker. The one thing no longer caught is bit rot inside a file whose metadata didn't change.process.versions.node.assertOrcadServerRuntime(Node ≥ 24, the bundled runtime, the pinned version) still runs in-process on every launch.preflightOrcadNativeRuntime, the only native check at startup).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)
ORCA_ORCAD_MANAGED_ACTIVATION_ROOTis set, which is the same gate the compile cache uses, and the slot is not underprocess.resourcesPath. Every other bundled launch runs the preflight as before and never touches a marker.NODE_OPTIONS,LD_PRELOAD,LD_LIBRARY_PATHandTMPDIR, 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:
~/.orca-remote/orcad-<version>/on the remote, launched byorcadLaunchCommandwith the managed activation root~/.orca-remote/orcad-<version>/in the distro, same launch path (setsid).orca-remoteslotorca servewith a pinned-Node slotprocess.resourcesPath, never written toWhy
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_HOSTSis 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.isQualifiableOrcadSlotrefuses resources and unmanaged launches.main-preflight-order.test.ts: qualification is recorded aftermain(), and never when startup fails.src/main/orcadandsrc/main/managed-server/installsuites pass, except the macOS-only/private/tmpfailures inorcad-forked-child-paths, which this PR doesn't touch.pnpm tc,typecheck:ci, code-quality, anti-slop and ast-grep pass.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
N/Afor visuals with reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (CI runs the rest)