sandcastle: persistent /nix across worker containers — the Go gate re-downloads the pinned toolchain every run #249

Closed
opened 2026-07-31 23:52:56 +00:00 by ben · 1 comment
Owner

Why (measured 2026-07-31)

Worker wall-clock regressed from 43 min avg on 07-25 (24 runs, max 64) to 50–73 min avg this week with a new pathological tail (110, 116, 161-minute runs). The tail correlates exactly with nix activity in the worker logs:

run duration nix develop calls flake refs
07-30 00:38 (#180) 161 min 27 48
07-30 03:38 (#175) 110 min 19 34
07-31 22:16 (#231) 39 min 17 51

Meanwhile non-Go tickets still run at last week's pace (07-31: #234 = 14 min, #218 = 18 min, #233 = 25 min) — the harness is not uniformly slower; the Go path is.

Root cause: .sandcastle/main.mts persists only the pnpm store across containers:

  • mounts has .sandcastle/pnpm-store → /home/agent/.pnpm-store — and nothing for nix.
  • The Dockerfile creates /nix empty in the image (single-user install at build time installs the nix binaries, not the dev-shell closure).
  • So every worker container starts with a cold store: the #198 pre-push gate's nix develop .#go-ci re-evaluates the flake and re-substitutes the entire pinned toolchain (go, golangci-lint, deps) from the binary cache — per container, and again on every gate retry after a rebase. The Dockerfile comment's claim that the go-ci shell "warms in seconds from the binary cache" is contradicted by the logs.

Compounding: gate re-runs per worker grew from 2–20 (07-25) to 20–72 (07-31) as rebase/retry loops multiplied, so the cold-store cost is paid many times per slice.

Acceptance criteria

  1. Persist the nix store across worker containers, following the existing pnpm-store precedent in main.mts mounts (e.g. host .sandcastle/nix-store (or /nix volume) → container /nix, readonly: false; run-swarm.sh creates the dir beside pnpm-store the same way it does today for pnpm). Concurrent access is already fenced: the global swarm flock admits one heavy worker per host.
  2. Ownership/perms survive: /nix must remain owned by the agent UID/GID (Dockerfile currently chowns it at build; the mount must not undo that — match the pnpm-store handling).
  3. First-run warm-up documented or automated: either the first Go gate of a fresh host populates the store (acceptable), or the image build / a one-time host step pre-warms .#go-ci (better). Non-fatal on failure, same posture as the existing nix install (gate fails closed, main stays green).
  4. Verify with numbers: after landing, a Go-slice worker log shows the gate entering .#go-ci without mass substitution (seconds, not minutes) on the second and subsequent runs; note before/after in the ticket comment.
  5. Mirror the change in Matou/matou-app's .sandcastle if/when its slices grow a nix-gated toolchain (or fold into the shared-harness extraction — see #238's open question).

Non-goals

  • Queue serialization / starvation — that is #238 (flock -n, capacity).
  • Reducing gate re-runs from rebase loops — worth its own look later if the numbers stay high after this lands.

Pointers

  • .sandcastle/main.mts (mounts), .sandcastle/Dockerfile (nix section, lines ~44–66), .sandcastle/run-swarm.sh (pnpm-store dir creation), .sandcastle/gate.sh / #198 (nix develop .#go-ci), ADR 0040 (one pinned toolchain)
  • Evidence logs on matou-workstation: .sandcastle/logs/main-sandcastle-worker-20260730-003838-*, -20260730-033857-*, -20260731-221636-*
## Why (measured 2026-07-31) Worker wall-clock regressed from **43 min avg on 07-25** (24 runs, max 64) to 50–73 min avg this week with a new pathological tail (**110, 116, 161-minute runs**). The tail correlates exactly with nix activity in the worker logs: | run | duration | `nix develop` calls | flake refs | |---|---|---|---| | 07-30 00:38 (#180) | 161 min | 27 | 48 | | 07-30 03:38 (#175) | 110 min | 19 | 34 | | 07-31 22:16 (#231) | 39 min | 17 | 51 | Meanwhile non-Go tickets still run at last week's pace (07-31: #234 = 14 min, #218 = 18 min, #233 = 25 min) — the harness is not uniformly slower; the Go path is. **Root cause:** `.sandcastle/main.mts` persists only the pnpm store across containers: - `mounts` has `.sandcastle/pnpm-store → /home/agent/.pnpm-store` — and nothing for nix. - The Dockerfile creates `/nix` **empty** in the image (single-user install at build time installs the nix binaries, not the dev-shell closure). - So every worker container starts with a cold store: the #198 pre-push gate's `nix develop .#go-ci` re-evaluates the flake and re-substitutes the entire pinned toolchain (`go`, `golangci-lint`, deps) from the binary cache — per container, and again on every gate retry after a rebase. The Dockerfile comment's claim that the go-ci shell "warms in seconds from the binary cache" is contradicted by the logs. Compounding: gate re-runs per worker grew from 2–20 (07-25) to 20–72 (07-31) as rebase/retry loops multiplied, so the cold-store cost is paid many times per slice. ## Acceptance criteria 1. **Persist the nix store across worker containers**, following the existing pnpm-store precedent in `main.mts` `mounts` (e.g. host `.sandcastle/nix-store` (or `/nix` volume) → container `/nix`, readonly: false; `run-swarm.sh` creates the dir beside `pnpm-store` the same way it does today for pnpm). Concurrent access is already fenced: the global swarm flock admits one heavy worker per host. 2. **Ownership/perms survive**: `/nix` must remain owned by the agent UID/GID (Dockerfile currently `chown`s it at build; the mount must not undo that — match the pnpm-store handling). 3. **First-run warm-up documented or automated**: either the first Go gate of a fresh host populates the store (acceptable), or the image build / a one-time host step pre-warms `.#go-ci` (better). Non-fatal on failure, same posture as the existing nix install (gate fails closed, main stays green). 4. **Verify with numbers**: after landing, a Go-slice worker log shows the gate entering `.#go-ci` without mass substitution (seconds, not minutes) on the second and subsequent runs; note before/after in the ticket comment. 5. Mirror the change in `Matou/matou-app`'s `.sandcastle` if/when its slices grow a nix-gated toolchain (or fold into the shared-harness extraction — see #238's open question). ## Non-goals - Queue serialization / starvation — that is #238 (`flock -n`, capacity). - Reducing gate re-runs from rebase loops — worth its own look later if the numbers stay high after this lands. ## Pointers - `.sandcastle/main.mts` (`mounts`), `.sandcastle/Dockerfile` (nix section, lines ~44–66), `.sandcastle/run-swarm.sh` (pnpm-store dir creation), `.sandcastle/gate.sh` / #198 (`nix develop .#go-ci`), ADR 0040 (one pinned toolchain) - Evidence logs on matou-workstation: `.sandcastle/logs/main-sandcastle-worker-20260730-003838-*`, `-20260730-033857-*`, `-20260731-221636-*`
Author
Owner

Landed in d883076 on main.

What shipped

  • main.mts: bind-mount a persistent host nix store (.sandcastle/nix-store → /nix, writable) beside the pnpm-store precedent, so the .#go-ci closure survives across worker containers (AC #1). Concurrent writes are fenced by the existing global swarm flock (one heavy worker per host).
  • run-swarm.sh: creates the store dir beside pnpm-store, then seeds it from the freshly built image's own /nix once — a bare empty mount would hide Nix itself (/nix holds the single-user install, not just a cache), so cp -a /nix/. → nix-store; runs as the host uid:gid, keeping the store agent-owned (AC #2). Then best-effort pre-warms .#go-ci under a 900s timeout so even the first worker gate is warm (AC #3, the better path). Both docker runs override the image sleep infinity ENTRYPOINT. All steps non-fatal, matching the nix-install posture (failed seed → gate fails closed, main stays green; the first real gate populates the store either way).
  • Dockerfile: corrected the warms in seconds from the binary cache claim the ticket flagged — now accurate only because the store is persisted.
  • .gitignore: nix-store/ + pnpm-store/ (never committed). README.md: documents both persistent stores + the seed-from-image requirement.
  • tests/nix-store-test.sh (new offline seam test, 2 groups, green): pins the empty-dir seed guard and the sandcastle:<basename> image-name replica of @ai-hero/sandcastle's defaultImageName (drift there would seed the wrong image and leave every worker cold). Bodies kept byte-identical to run-swarm.sh per the debounce-test contract.

AC #4 (before/after numbers) — deferred to the first post-merge host run. A worker sandbox has no docker, so the mechanism could not be exercised end-to-end here. On the next Go-slice run on matou-workstation, read the worker log: on the 2nd+ run the gate should enter nix develop .#go-ci in seconds with no mass substitution. Please note the before/after here once observed.

AC #5: no matou-app mirror is due — these files are repo-specific (off harness-manifest) and matou-app's gate is TS-only, no nix-gated toolchain yet.

Verification: all offline .sandcastle/tests/* green (nix-store-test.sh new); pre-push gate classified the change TS-only and passed.

Landed in d883076 on `main`. **What shipped** - `main.mts`: bind-mount a persistent host nix store (`.sandcastle/nix-store` → `/nix`, writable) beside the pnpm-store precedent, so the `.#go-ci` closure survives across worker containers (AC #1). Concurrent writes are fenced by the existing global swarm flock (one heavy worker per host). - `run-swarm.sh`: creates the store dir beside `pnpm-store`, then **seeds** it from the freshly built image's own `/nix` once — a bare empty mount would hide Nix itself (`/nix` holds the single-user install, not just a cache), so `cp -a /nix/. → nix-store`; runs as the host `uid:gid`, keeping the store agent-owned (AC #2). Then best-effort pre-warms `.#go-ci` under a 900s timeout so even the first worker gate is warm (AC #3, the `better` path). Both docker runs override the image `sleep infinity` ENTRYPOINT. All steps non-fatal, matching the nix-install posture (failed seed → gate fails closed, main stays green; the first real gate populates the store either way). - `Dockerfile`: corrected the `warms in seconds from the binary cache` claim the ticket flagged — now accurate only because the store is persisted. - `.gitignore`: `nix-store/` + `pnpm-store/` (never committed). `README.md`: documents both persistent stores + the seed-from-image requirement. - `tests/nix-store-test.sh` (new offline seam test, 2 groups, green): pins the empty-dir seed guard and the `sandcastle:<basename>` image-name replica of @ai-hero/sandcastle's `defaultImageName` (drift there would seed the wrong image and leave every worker cold). Bodies kept byte-identical to `run-swarm.sh` per the debounce-test contract. **AC #4 (before/after numbers) — deferred to the first post-merge host run.** A worker sandbox has no docker, so the mechanism could not be exercised end-to-end here. On the next Go-slice run on matou-workstation, read the worker log: on the 2nd+ run the gate should enter `nix develop .#go-ci` in seconds with no mass substitution. Please note the before/after here once observed. **AC #5:** no matou-app mirror is due — these files are repo-specific (off `harness-manifest`) and matou-app's gate is TS-only, no nix-gated toolchain yet. Verification: all offline `.sandcastle/tests/*` green (`nix-store-test.sh` new); pre-push gate classified the change TS-only and passed.
ben closed this issue 2026-08-01 00:36:35 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Matou/idss#249
No description provided.