Repository navigation
perf(orcad): spawn the terminal daemon as soon as the login env lands - #35341
Conversation
orcad started its terminal daemon only after the secret store, profile and hook server were up. The daemon (and every PTY) inherits process.env, which startup changes only through the login-shell env adoption, so it now spawns as soon as that resolves, in parallel with the stores and the hook server, and startup awaits it where it did before. A cleanup waits for an in-flight spawn to settle before disconnecting. The login-env adoption and its logging move into adoptWslHostLoginEnvironmentLogged.
|
STATUS: ready for two reviewers. Head 545e708. Checks run: pnpm tc, typecheck:ci, code-quality:changed, anti-slop, oxlint, ast-grep and its gates, plus each touched orcad suite run on its own (push-startup 9/9). Open question: none. I'll post the lane re-measure of the orcad startup phase on this PR when the run finishes. |
|
Warning Review limit reachedYou'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 22 minutes. View limit details
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. Comment |
[Medium impact] The latest change adds no blocking issue; the earlier cleanup gap remains non-blocking. Findings
SummaryStarts the terminal daemon after the login environment is ready, alongside other startup work.
Reviews (2) · Last reviewed commit: "fix(orcad): observe the daemon startup p..." · Reviewed by Greptile |
| const { startOrcadDaemon, stopOrcadDaemon } = await import('./orcad-daemon-supervision') | ||
| // The daemon and its PTYs inherit the adopted login env and nothing later startup writes, so it | ||
| // spawns as soon as that lands, in parallel with the stores and the hook server. Never rejects. | ||
| const daemonStartup = loginEnvironment.then(() => timed('daemon', () => startOrcadDaemon())) |
There was a problem hiding this comment.
daemonStartup now starts before its cleanup is registered. If one of the following imports fails, startup runs cleanup without waiting for or disconnecting the daemon. The pending work can then install a provider after startup has failed and released the host lock.
Register cleanup before yielding to those imports, and add a test for that failure window.
An early abort may never reach the await, so a future change that makes the spawn reject must not surface as an unhandled rejection.
|
STATUS: lane re-measure, run 40766963243 at 6273490, compared with main run 40763093979. The daemon now starts with the cli-launcher and overlaps the profile, as intended. For example, ubuntu runs went from daemon 773–962 to daemon 972–1245, where cli-launcher starts at 967. The net saving is small:
Expected was 100–150 ms. |
ELI5
When Orca's server (orcad) starts, it also starts a background "terminal daemon" that owns the terminals. Today it waits to start the daemon until its settings store and hook server are up, even though the daemon doesn't need either. This starts the daemon earlier, at the same time as those, so orcad is ready sooner after a WSL distro restart or an SSH host reconnect.
What Changed
startOrcadRuntimenow startsstartOrcadDaemon()as soon as the login-shell environment adoption resolves. That runs in parallel with the CLI launcher, secret store, profile store and hook server startup. Startup still awaits the daemon at the same point as before, before PTY handlers register, so the provider is installed before the first PTY call, as today.stopOrcadDaemon()disconnects.adoptWslHostLoginEnvironmentLogged()(same behavior). This keepsorcad-entry.tsunder its line cap.Why
orcad startup is now the dominant phase on the WSL host restart path: 1.1–1.75 s to readiness on lane run 40763093979. The daemon step takes 190–250 ms of that and depended on nothing between the login env and its old position:
process.envat spawn. I checked every productionprocess.envwrite, and between orcad's start and the old daemon position the only one is the login-shell env overlay (adoptWslHostLoginEnvironment). The daemon still waits for it.initDaemonPtyProviderreads no profile settings and no hook-server state. PTY hook coordinates are injected per spawn, later.Terminal restore: unchanged. Adoption of surviving daemon sessions happens inside the same
startOrcadDaemon(), and reconciliation (reconcileLegacyWorkerTerminals,refreshRestoredOrchestrationAuthority) still runs after it, at the same point. Only the daemon's spawn and connect move earlier.Failure ordering:
startOrcadDaemonreportsunavailable/degradedwithout throwing, which startup reads at the old await point, as before. If it does throw (only mocks do), startup fails at that await, as before. The existing test covers this..catch(() => {})) as soon as it is created, so a future change that makes it reject can't become an unhandled rejection on an early abort.SSH effect: orcad-wide. Managed SSH hosts get the same saving on every orcad (re)start. Terminal adoption, the env the daemon inherits and failure reporting are unchanged.
Flag-off: applies whether or not
ORCA_INTERNAL_WSL_HOSTSis set, because orcad on SSH hosts and the desktop's bundled orcad run this code.User-risk: low to medium. This is an ordering change in orcad startup. The daemon's inputs are unchanged, and the await point that gates PTY routing is unchanged. Two reviewers, please.
Linked Issue
Internal WSL-via-orcad tracker, D3 bar (restart → first usable prompt).
Visual Proof
N/A: no UI.
Testing
orcad-push-startup.test.ts:pnpm tc,typecheck:ci, code-quality, anti-slop, ast-grep and the ast-grep gates pass.orcadStartuptiming:daemonstart right afterlogin-env) andmedianHostPhases.orcadStartupMsshould drop by about 100–150 ms. I'll post the numbers here.Status
Ready for two reviewers. Waiting for the lane re-measure.
Checklist
N/Afor visuals with reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (CI runs the rest)