perf(daemon): lazy-load Maestro in request binding; budget the daemon entry
Merged
TH
2mo ago+125+125+012345678901234567890123456789-39-39-01234567890123456789
Summary
Closes #3282 (part of #3276). 4 files.
- Maestro, now lazy. Request binding (
src/daemon/replay-device-selection.ts) imports@agent-device/maestrothrough a function-scopedawait import, reached only when the replay entry resolves to a Maestro flow..adreplays and other commands never load it. In the built output, daemon boot drops exactly 109 modules (37 maestro + 72 yaml): 209→201 files, 2.33→2.17 MB; a sourcemap diff shows no other module moves. - Gate.
src/daemon.tsjoinsHUB_ENTRY_FILES, under the merge-base no-growth rule (621→571 here). - provider-webdriver, not changed.
startDaemonRuntimeawaitscreateDaemonProviderRuntimeComposition→createDefaultRuntimes(env)before it listens (daemon-runtime.ts:361vs:602). A dynamic import loads the same chunk in the same phase and only lowers the static count; the chunk evaluates in ~1.4 ms, too little to justify making runtime construction lazy.
Validation
Commit 651c22ccb: AGENT_DEVICE_VITEST_MAX_WORKERS=2 pnpm check:affected --run — all runnable checks passed. CI at this head: all jobs green, incl. Compatibility & Provenance and live web smoke.
- Planted regression. Restoring the static import fails the
src/daemon.tshub-row no-growth check (621 vs 571, route printed); without the row, the plant passes. - Boot (built daemon, interleaved, n=40): spawn→ready median 149.4→140.2 ms.
- Maestro first request (n=30): spawn→first replay response 543.3→536.6 ms; the chunk costs +4.9 ms once.
- BrowserStack
lease_allocate(n=20): cold 297→295 ms, warm 86→87 ms. - Built chunks resolve at runtime: a maestro replay reaches step 1 (
DEVICE_NOT_FOUND);lease_allocatereaches the credential check. - Review follow-ups. Malformed wire bundles stay advisory (#1802): whole probe inside
readAdvisoryResolution, test mutation-proven at the pre-fix shape. Fallow complexity fixed by decomposition, no baseline change. - Web-smoke hang at
b27e310: not reproducible, not this change. The lane passes locally on the built output (n=2) and on CI atf9c9b82and651c22. Its artifact showsweb setupstalled mid managed-install download (nomanifest.json, no daemon ever started).web setupis CLI-local and never starts a daemon, so the lazy branches are off-path. Runner-network flake. - Risk. The CLI's 100 ms readiness poll can hide the boot gain for CLI-launched daemons.
🤖 Generated with Claude Code