Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
fix(cli): hardlink bun installs off macOS; document the cross-drive cache build tax
trohitg62a0857349f8
diff --git a/cli/commands/build.py b/cli/commands/build.pyindex b39b789a..d8700f27 100644--- a/cli/commands/build.py+++ b/cli/commands/build.py@@ -228,7 +228,14 @@ def build_command() -> None:if not is_postinstall:console.log("[1/6] Installing dependencies...")- run(["bun", "install"], cwd=root)+ # Hardlink from the cache instead of copying (bun's documented+ # default on Linux/Windows, but observed to fall back to copies on+ # Windows). Copies re-write ~600 MB per install, which Defender+ # then first-touch-scans on the next Vite build. macOS keeps its+ # faster clonefile default. Cross-drive caches still copy — see+ # errors.md "bun install copies / slow first build".+ backend = [] if sys.platform == "darwin" else ["--backend=hardlink"]+ run(["bun", "install", *backend], cwd=root)else:console.log("[1/6] Dependencies already installed by package manager")diff --git a/cli/tests/test_build_compile_pipeline.py b/cli/tests/test_build_compile_pipeline.pyindex 791ac211..79f50a05 100644--- a/cli/tests/test_build_compile_pipeline.py+++ b/cli/tests/test_build_compile_pipeline.py@@ -113,6 +113,26 @@ def test_source_dirs_constant_covers_runtime_modules():assert "constants.py" in actual+# ---------------------------------------------------------------------------+# Install step ([1/6])+# ---------------------------------------------------------------------------+++def test_install_uses_hardlink_backend_off_macos(tmp_path: Path):+ """Copies re-write ~600 MB per install and get first-touch-scanned on+ the next build; hardlinks don't. macOS keeps bun's clonefile default."""+ import sys++ captured = _run_build_capture_invocations(tmp_path)+ match = _find_call(captured, lambda c: c[:2] == ["bun", "install"])+ assert match is not None, "expected a `bun install` invocation"+ argv = match[1]["argv"]+ if sys.platform == "darwin":+ assert "--backend=hardlink" not in argv+ else:+ assert "--backend=hardlink" in argv++# ---------------------------------------------------------------------------# Sidecar bundle step ([3/6])# ---------------------------------------------------------------------------diff --git a/docs-internal/errors.md b/docs-internal/errors.mdindex 65ded37d..4861e3e7 100644--- a/docs-internal/errors.md+++ b/docs-internal/errors.md@@ -357,3 +357,11 @@ The "auth successful" line fires even when you only *initiated* the login and neSo an incomplete login against a config left over from a previous session was reported as success.**Fix** (landed at tag v0.0.88): `nodes/stripe/_handlers.py` snapshots `config.toml`'s mtime at step 1 (`pre_mtime`), threads it into `_complete_login(binary, next_step, pre_mtime)`, and requires `post_mtime > pre_mtime AND is_logged_in()` to declare success. The mtime advance is ground truth for "*this* attempt wrote fresh credentials". The `exceeded max attempts` stderr is forgiven only when the mtime actually advanced.++## 11. `bun install` Copies Every Package / 2-Minute First Vite Build (Windows)++**Symptom**: After a fresh install, `company build` step `[1/6]` takes ~70 s and step `[2/6]` (Vite) takes ~2 min, while a second Vite build on the same tree takes ~35 s. The same `build.log` shows uv complaining `Failed to hardlink files; falling back to full copy ... different filesystems`. Under pnpm the same cycle was ~15 s + ~16 s.++**Root cause**: installs that *write* files instead of linking them. pnpm keeps its store per drive on the project's drive (`D:\.pnpm-store`) and hardlinks from it, so a fresh install wrote no new bytes and Windows Defender's real-time first-touch scan had nothing new to scan on the next build. bun's cache lives under the user profile on `C:`; with the project on `D:` NTFS cannot hardlink across volumes, and bun 1.4.0 was also observed to copy on Windows even from a same-drive cache unless `--backend=hardlink` is forced. Every install therefore re-writes ~600 MB into `node_modules/.bun/`, and the first build pays the Defender scan on all of it (measured: 626 MB store, one hardlink path per file). uv has the identical cross-drive problem (`%LOCALAPPDATA%\uv\cache` on `C:`).++**Fix**: `company build` passes `--backend=hardlink` on Linux/Windows. That only helps when the cache is on the project's drive, which is a per-machine setting — set user environment variables `BUN_INSTALL_CACHE_DIR` (e.g. `D:\startup\projects\.bun-cache`) and `UV_CACHE_DIR` on the same drive as the checkout. Measured after both: purge → `bun install` 15 s (files show two hardlink paths: cache + store) → first Vite build 41 s. A Defender exclusion for the checkout removes the first-touch tax for whatever still gets written.diff --git a/docs-internal/performance.md b/docs-internal/performance.mdindex d308398c..dbada76b 100644--- a/docs-internal/performance.md+++ b/docs-internal/performance.md@@ -46,13 +46,32 @@ timestamped console output right after the switch to [email protected]:| `company dev` — Vite `ready in` | — | 8.4 s || `company dev` — backend Application startup complete | — | 12.4 s |-No change attributable to bun: it only installs the workspace and-launches the `company` CLI; everything after spawn (uvicorn imports,-lifespan, Vite on Node 22) is byte-identical. The sub-second prod delta-is machine-load variance, and the dev-mode rows were never benchmarked-before (Vite and uvicorn compete for I/O during a dev boot, so they are-not comparable to the prod numbers). The headline baselines above still-stand.+None of the boot delta is attributable to bun: it only installs the+workspace and launches the `company` CLI; everything after spawn+(uvicorn imports, lifespan, Vite on Node 22) is byte-identical. The+extra ~0.7 s sits entirely in the import phase — "all imports complete"+at 3.29 s vs 1.98 s in the May timeline, and the routers + plugin-walker+segment at 1.83 s vs 0.84 s — because the walker now loads **184**+plugin modules against the **137** it walked in May. Lifespan cost is+unchanged. The dev-mode rows were never benchmarked before (Vite and+uvicorn compete for I/O during a dev boot, so they are not comparable+to the prod numbers), and the first dev boot after a reinstall also+rebuilds Vite's dep cache.++**Build time is a different story.** A fresh `company build` after the+migration measured `bun install` **74 s** and the Vite client build+**124 s** (vs `~16 s` in the table above, recorded 2026-05-06). Neither+is bun's resolver or layout: the same tree rebuilt warm in **32–37 s**+under both the isolated and hoisted linkers, and CI on Linux got faster+(install 10 s → 7 s, full build 45 s → 28 s). The 16 → 35 s warm gap is+codebase growth since May (main bundle 234 → 288 KB gz, 16 chunks). The+rest is Windows Defender first-touch scanning of freshly *written*+package files: pnpm hardlinked from a per-drive store and wrote nothing,+bun copied ~600 MB per install (cache on `C:`, checkout on `D:`; copies+even from a same-drive cache unless `--backend=hardlink`). With the+cache on the checkout's drive and the hardlink backend, purge → install+→ first build measures **15 s + 41 s**. Details and the per-machine+fix in [errors.md §11](errors.md#11-bun-install-copies-every-package--2-minute-first-vite-build-windows).## Optimisation history