perf(daemon): lazy-load Maestro in request binding; budget the daemon entry

Merged
TH
2mo ago
+125-39

Summary

Closes #3282 (part of #3276). 4 files.

  • Maestro, now lazy. Request binding (src/daemon/replay-device-selection.ts) imports @agent-device/maestro through a function-scoped await import, reached only when the replay entry resolves to a Maestro flow. .ad replays 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.ts joins HUB_ENTRY_FILES, under the merge-base no-growth rule (621→571 here).
  • provider-webdriver, not changed. startDaemonRuntime awaits createDaemonProviderRuntimeComposition → createDefaultRuntimes(env) before it listens (daemon-runtime.ts:361 vs :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.ts hub-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_allocate reaches 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 at f9c9b82 and 651c22. Its artifact shows web setup stalled mid managed-install download (no manifest.json, no daemon ever started). web setup is 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