Repository navigation
feat(sandbox): golden node_modules cache via reflink (skip install on hit) - #4357
Conversation
… hit) A fresh sandbox pod runs a full `bun install` for every new branch. This keeps a per-(repo, packageManager, lockfile) "golden" node_modules on the shared node-local hostPath (DEPS_CACHE_ROOT) and, on a hit, `cp --reflink=always`s it into the repo — a copy-on-write clone that's near-instant regardless of tree size (~1s for 700MB on prod xfs) and skips `bun install` entirely. On a miss the normal install runs, then publishes its result as the golden for next time. Safety mirrors the depsCache per-repo key (the sole cross-repo isolation boundary — bun does not re-verify cache content): goldens are keyed by the credential-stripped cloneUrl, so repos never share one. reflink is CoW, so a pod mutating its own node_modules never writes through to the shared golden. Only used when golden and node_modules share a filesystem (reflink needs it); every failure path falls back to a normal install, so worst case it's a no-op. - setup/golden-cache.ts: keying, same-fs gate, reflink restore/publish (atomic temp+rename), all best-effort. - orchestrator.stepInstall: restore before install, publish after a miss. Validation status: the reflink mechanism (speed + CoW isolation) is verified on prod xfs; the daemon lifecycle wiring is unit-tested but not yet exercised end-to-end in a pod. Kind can't test the fast path (ext4 → reflink fails → fallback); a prod-xfs pod is needed for the hit path.
|
Prod cross-mount reflink confirmed — the one real open risk is closed. The concern was that Verified on a live Remaining gate before merge: exercise the daemon lifecycle (hit→skip→publish) through a live prod boot. |
…e dev starts Addresses the two pre-merge risks on the golden node_modules cache: 1. Independent off-switch. Golden touches the boot install path, so it no longer activates just because DEPS_CACHE_ROOT is set — it requires GOLDEN_CACHE_ENABLED (chart: `depsCache.golden`, default false). Ships dormant; toggle without redeploying or rolling back the daemon image. 2. Publish/dev-server race. `publishGolden` is now awaited before stepStart spawns the dev server, so the reflink snapshot is taken while node_modules is quiescent — previously it raced Vite writing node_modules/.vite and could capture an inconsistent tree. Miss-path only (~1s), no effect on warm boots. Also corrects the depsCache comment in values.yaml (same false "bun's lockfile integrity check catches tampering" claim fixed in install.ts by the sibling PR — bun does not re-verify; the per-repo key is the sole boundary) and drops the now-stale "near-instant needs a separate design" note (this is that design).
|
Addressed the two pre-merge risks (kill switch + publish race):
Also corrected the same false "bun re-verifies cache integrity" claim in the Remaining, documented as follow-ups (not blockers now that it's opt-in + dormant):
Still gated on a live prod-xfs boot before enabling ( |
…ky bad goldens) Addresses the two residual risks on the golden node_modules cache. Sticky bad golden — a golden built from a broken-but-exit-0 install used to be publishable and would then be reused by every later branch. Publishing now happens only after the dev server is confirmed healthy: stepInstall records a pending publish, and the probe's `running` transition (entry.ts) triggers publishPendingGolden(). A boot that never comes up never publishes, so a bad install can't become a sticky golden. Snapshot also strips pod-local runtime caches (.vite/.cache) — they churn and are per-pod — which also removes the publish/dev-server write race (publish no longer needs to beat dev startup). GC — goldens (≈ a full node_modules each) accrued on the node hostPath unreaped. pruneGoldens() drops goldens past a TTL (7d) then caps per repo (newest 5), run opportunistically after each publish; restore touches a golden's mtime so an active lockfile never ages out. Safe to race a restore: an in-flight reflink from a pruned golden just fails → fallback install, and completed CoW clones are independent of the source. 19 unit tests (keying, lockfile hash, kill switch, TTL/cap/tmp-skip/per-repo prune). Orchestrator suite green, typecheck clean, daemon builds.
|
GC + sticky-bad-golden addressed. Sticky bad golden — killed at the source. Publishing no longer happens right after install; it's deferred to when the dev server is confirmed healthy. GC. Tests: 19 unit (keying, lockfile hash, kill switch, and TTL / per-repo-cap / .tmp-skip / per-repo-independence for prune). Orchestrator suite green, typecheck clean, daemon builds. Remaining follow-up (minor): non-hoisted workspace/monorepo repos — only the install-root |
…emplate (#4360) The golden node_modules changes (#4357) added the depsCache.golden env to the SandboxTemplate but left Chart.yaml at 0.9.1. The release-sandbox-charts workflow skips republishing an existing version, so OCI 0.9.1 still lacks the template. Bump to 0.9.2 so it publishes; consumers then move targetRevision to 0.9.2 to pick it up (golden stays off by default).
…#4361) The release-tagging job pushes a `[release]:` version-bump commit straight to main. Two merges landing seconds apart (e.g. #4357 and #4360) each triggered a run, and the second lost the push with `! [rejected] (fetch first)`. Re-running can't recover it: the job checks out the original trigger commit, which is now behind main, so the push is a permanent non-fast-forward. Two fixes: - concurrency group (cancel-in-progress: false) serializes runs so bumps queue instead of racing. - the push rebases its bump onto the latest main and retries (up to 5x) instead of failing on non-fast-forward. The bump only touches version manifests, so it rebases cleanly over unrelated merges (the actual failure here: #4360 touched a Helm chart, not package.json). A genuine same-manifest conflict still fails loudly rather than guessing.
…TS.md (#4475) Mined ~300 merged PRs for the delta between the first PR proposal and the work added before merge. The dominant shape: a first draft ships the happy path, then a hardening pass (often a different engineer who takes over the branch and merges — the vibecoder→engineer handoff) adds the same categories every time. Encoded those 9 categories as an actionable first-pass checklist, each citing a real PR (#4008, #4230, #4365, #4409, #4426, #4445, #4357, #4355, #4449, #4350, #4373, #4416, #4446, #4461, #4134, #4469). Covers: variant/edge-case handling, tenant/permission scoping, concurrency & silent-data-loss, test-per-fix + invert-bug-tests + real-PG, dead-code/knip, lifecycle symmetry + state reset, kill-switch/GC/git-exclude for risky infra, input validation vs over-engineering, compile-time type-safety. Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
What
The reflink "last mile" on top of the deps cache (#4352): a per-
(repo, packageManager, lockfile)golden node_modules on the shared node-local hostPath. On a hit,cp -a --reflink=alwaysclones it into the repo — a copy-on-write clone that's near-instant regardless of tree size and skipsbun installentirely. On a miss, the normal install runs and publishes its result as the golden for next time.Proven on prod xfs earlier this session: reflink clone of a 686MB
node_modulestook ~1s, and it's write-safe (writing the clone left the source intact — CoW).Why reflink, not hardlink
Hardlinking from a shared cache would hit the same ~1s but is unsafe here: shared inodes + uid-1000 pods running untrusted code + bun-doesn't-re-verify (see #4356) = one repo can poison another's packages. reflink is copy-on-write, so a pod's writes never reach the shared golden. It's the fast and safe option.
Safety
st_devmatch) before any reflink — else skip and install normally.rms and falls back tobun install; publish is background, idempotent, atomic (temp + rename). Worst case: a no-op, never a broken boot.Changes
setup/golden-cache.ts— keying (lockfileHash,goldenNodeModulesPath),sameFilesystem,tryRestoreGolden,publishGolden. Useschild_process.spawn("cp", [...])(args array, no shell). Independent ofinstall.tsso it doesn't conflict with docs(sandbox): correct deps-cache isolation comment — per-repo key is load-bearing #4356.orchestrator.stepInstall— restore before install (hit → skip + mark succeeded), publish after a successful miss (async, best-effort).Testing / validation status
Follow-up (not in this PR): golden GC (stale lockfile dirs accrue until node recycle, same as the deps cache).
🤖 Generated with Claude Code
Summary by cubic
Adds a golden
node_modulescache using reflink to skip installs on cache hits. Publishing is now gated on a healthy dev server and the cache is pruned to prevent disk growth.DEPS_CACHE_ROOT/golden/...keyed by a credential‑stripped repo URL.cp -a --reflink=alwayswhen cache and workdir share a filesystem; on hit, skipbun install.cpexit code is authoritative; any failure falls back to a normal install..vite/.cache, uses atomic temp+rename, and is best‑effort. After each publish,pruneGoldens()drops entries older than 7d and keeps the newest 5 per repo; restore touches mtime to keep active ones fresh.GOLDEN_CACHE_ENABLED=1|true(HelmdepsCache.golden: true). Requires a reflink‑capable filesystem shared with/app; otherwise it falls back to a normal install.Written for commit 0c69ccc. Summary will update on new commits.