bug(dev): make fresh worktree frontend bootstrap deterministic and reusable
Bug
Fresh AO worktrees repeatedly spend several minutes preparing the frontend before a small UI change can be tested. In a recent macOS arm64 worker session, the checkout started with Node 18, had no frontend dependencies, and required installing roughly 1,183 packages. After switching runtimes, npm twice omitted required host-native packages, requiring manual binding repair before Vitest could run.
This makes setup dominate implementation time and recurs because each isolated worktree starts without node_modules.
Source: AO worker session report on 2026-08-25
Analyzed against: 5761cedf5 on Untrivial-ai/agent-orchestrator:main
Environment: macOS arm64; fresh Git worktree; initial shell runtime Node 18; frontend CI currently uses Node 24
Confidence: High
Priority: P2 — development workflow is degraded; manual recovery exists
Reproduction
- Create a fresh AO worktree from current
main. - Start from a shell whose default runtime is Node 18.
- Attempt to run a frontend test from
frontend/. - Discover that the repository does not select a supported Node runtime and the worktree has no installed dependencies.
- Switch to Node 24 and run
npm ci. - On affected installs, a required macOS native optional package is absent even though platform-specific bindings are represented in
frontend/package-lock.json; repair or reinstall before tests can start. - Repeat in another fresh worktree and pay the installation/materialization cost again.
Current state
- Current
mainhas no.nvmrc,.node-version,.tool-versions, or equivalent runtime selector. - Root and frontend
package.jsonfiles do not declare a Node engine/package-manager contract. - CI workflows use a mixture of Node 20, 22, and 24; the primary frontend workflow uses Node 24.
- npm download caching does not avoid recreating the full per-worktree
node_modulestree. - There is no single idempotent bootstrap command that validates the runtime, installs all required package roots, and verifies host-native bindings.
Proposed fix
Phase 1: deterministic bootstrap
- Standardize the supported development Node/npm versions and use the same versions in relevant CI workflows.
- Add repository runtime metadata such as
.nvmrc/.node-version,engines, andpackageManager. - Add one documented, idempotent bootstrap command for fresh worktrees.
- Make the bootstrap fail early with a clear runtime mismatch message.
- Verify that required native modules can load after installation and provide an automatic retry or precise recovery path when npm omits one.
Phase 2: reusable worktree dependency cache
- Let AO restore a prepared dependency snapshot keyed by OS, architecture, Node/npm version, and lockfile hash.
- On APFS, consider copy-on-write cloning rather than sharing a mutable
node_modulesdirectory. - Validate the restored tree and fall back to the normal clean install when the cache key changes or validation fails.
Directly symlinking mutable node_modules across branches should be avoided because lockfile changes and native ABI differences can contaminate sibling worktrees. A shared content-addressed package-manager store is another longer-term option.
Acceptance criteria
- A fresh worktree selects or clearly requests the supported runtime before dependency installation.
- One documented command prepares the frontend without manual native-binding repair.
- Repeating setup with an unchanged lockfile on the same OS/architecture is substantially faster than a full install.
- Cache invalidation is deterministic when the lockfile, runtime, OS, or architecture changes.
- Linux, Windows, and macOS CI cover the bootstrap behavior at the appropriate level.
Related
- #1296 tracks a broader hot-reload / fast-test workflow for agent worktrees.
- #2206 tracks an Electron installation failure on Windows and includes related Node-version guardrail discussion.
I’d like to work on this. I’ll keep the first PR to the deterministic-bootstrap phase: align the documented Node/package-manager contract, add an idempotent validation/bootstrap entry point, and test clear failure for unsupported runtimes. I will not introduce a shared mutable node_modules tree.