gateway-image: the installer-base bake re-copies ~2.2 GB the warm golden base already carries — 88% of the rebuild (36m50s of 41m54s measured) is redundant since #1102 changed the base #1108

Closed
opened 2026-09-01 07:33:46 +00:00 by ben · 4 comments
Owner

The measurement

#1102 landed (adb83d58) and works: the rebuild now rebases on the warm golden store and times every phase. First measured rebuild under it, build=adb83d58ad94 base=idss-gateway-953c92800329:

phase=provision       elapsed=68s    (1m08s)
phase=nixos-install   elapsed=166s   (2m46s)
phase=installer-base  elapsed=2210s  (36m50s)   <- 88% of the total
phase=snapshot        elapsed=70s    (1m10s)
phase=TOTAL           elapsed=2514s  (41m54s)

The phase that was the cost (nixos-install, ~45–50 min from stock Ubuntu) is now under three minutes. The installer-base bake is now 88% of the rebuild and the only thing standing between the drive and a ~5-minute snapshot refresh.

Why the bake is now redundant work

scripts/lib/gateway-image-installer-base-lib.sh:92-101, on the build droplet:

oc_gwib_ssh "$box" "mkdir -p /var/lib/idss && rm -rf '${OC_GWIB_CACHE}.staging' '${OC_GWIB_CACHE}'"
oc_gwib_scp 1 "$cache_src" "$box" "${OC_GWIB_CACHE}.staging"     # scp -r of the ~2.2 GB cache
oc_gwib_ssh "$box" "mv '${OC_GWIB_CACHE}.staging' '${OC_GWIB_CACHE}'"
oc_gwib_scp 0 "$marker_src" "$box" "${OC_GWIB_MARKER_FILE}"
oc_gwib_ssh "$box" "nix copy --no-check-sigs --from 'file://${OC_GWIB_CACHE}' --all"
oc_gwib_ssh "$box" "nix-store --add-root '${OC_GWIB_GCROOT}' --indirect --realise '${marker}'"

Under #1102 the box is installed from the previous golden snapshot, which already carries both halves — that is exactly what #1048 bakes in and what the staleness gate's installer-base marker axis (#1050) reads back. So on a rebase the sequence deletes the cache the base supplied, re-sends ~2.2 GB over the network, and re-imports store paths that are already valid.

This was correct and necessary when every build started from stock Ubuntu with an empty store. #1102 changed the base; the bake never learned.

Corroborating: the marker has been identical on every rebuild through the whole #854 arc — /nix/store/g9z22mi6…-nixos-system-nixos-installer-kexec-26.05pre-git, 1355 store paths, eleven rebuilds between 2026-08-31T10:20Z and 2026-09-01T06:07Z. Not once did the closure actually change; it was re-copied every time.

Fix

Make the bake present-check before it copies, using the probe the file already has as a post-condition (:106, nix path-info '${marker}'):

  • If the box's store already realises $marker and ${OC_GWIB_CACHE} exists and holds a usable cache, skip the rm -rf / scp -r / nix copy entirely and go straight to re-pinning the GC root and the existing post-condition proof.
  • Otherwise (a genuinely moved marker — a flake bump — or a cold/stock base) run the copy exactly as today.
  • Keep the post-condition unconditional: the marker path MUST be valid in the store before the snapshot is taken (ADR 0100), whichever branch ran. That is the no-op contract the supply/standing seed present-checks depend on, and it must never be weakened into "we assumed the base had it".
  • Log which branch was taken and the elapsed time, so the phase line stays honest (phase=installer-base … reused-base-closure vs … copied).

Expected effect: rebuild TOTAL from ~42 min to ~5 min, on top of #1102's 60→42. Combined with the honest staleness gate (#1096/#1100), a snapshot refresh stops being a thing the drive lane has to plan around at all.

Acceptance

  • A rebase whose base already carries the current marker logs the reuse branch and completes installer-base in seconds; TOTAL is minutes.
  • A rebuild whose marker genuinely moved (flake bump) still copies, and still passes the post-condition.
  • A build from a cold/stock base (the periodic rebase-from-stock #1102 provides) still copies.
  • The post-condition nix path-info $marker runs and fails loud in every branch — a base that turns out NOT to carry the closure must red the build, never produce a snapshot whose seed contract is broken.
  • Offline-provable in the existing bake/rebuild test shape.

Filed by the watching session from the #854 arc (ADR 0174) — measurement only, no code change from me; the bake has a real correctness surface (GC root, marker validity, the seed's no-op contract) where the existing tests should drive the change.

## The measurement #1102 landed (`adb83d58`) and works: the rebuild now rebases on the warm golden store and times every phase. First measured rebuild under it, `build=adb83d58ad94 base=idss-gateway-953c92800329`: ``` phase=provision elapsed=68s (1m08s) phase=nixos-install elapsed=166s (2m46s) phase=installer-base elapsed=2210s (36m50s) <- 88% of the total phase=snapshot elapsed=70s (1m10s) phase=TOTAL elapsed=2514s (41m54s) ``` The phase that *was* the cost (`nixos-install`, ~45–50 min from stock Ubuntu) is now under three minutes. **The installer-base bake is now 88% of the rebuild** and the only thing standing between the drive and a ~5-minute snapshot refresh. ## Why the bake is now redundant work `scripts/lib/gateway-image-installer-base-lib.sh:92-101`, on the build droplet: ```sh oc_gwib_ssh "$box" "mkdir -p /var/lib/idss && rm -rf '${OC_GWIB_CACHE}.staging' '${OC_GWIB_CACHE}'" oc_gwib_scp 1 "$cache_src" "$box" "${OC_GWIB_CACHE}.staging" # scp -r of the ~2.2 GB cache oc_gwib_ssh "$box" "mv '${OC_GWIB_CACHE}.staging' '${OC_GWIB_CACHE}'" oc_gwib_scp 0 "$marker_src" "$box" "${OC_GWIB_MARKER_FILE}" oc_gwib_ssh "$box" "nix copy --no-check-sigs --from 'file://${OC_GWIB_CACHE}' --all" oc_gwib_ssh "$box" "nix-store --add-root '${OC_GWIB_GCROOT}' --indirect --realise '${marker}'" ``` Under #1102 the box is installed **from the previous golden snapshot**, which already carries both halves — that is exactly what #1048 bakes in and what the staleness gate's installer-base marker axis (#1050) reads back. So on a rebase the sequence deletes the cache the base supplied, re-sends ~2.2 GB over the network, and re-imports store paths that are already valid. This was correct and necessary when every build started from stock Ubuntu with an empty store. #1102 changed the base; the bake never learned. Corroborating: the marker has been **identical on every rebuild** through the whole #854 arc — `/nix/store/g9z22mi6…-nixos-system-nixos-installer-kexec-26.05pre-git`, `1355 store paths`, eleven rebuilds between 2026-08-31T10:20Z and 2026-09-01T06:07Z. Not once did the closure actually change; it was re-copied every time. ## Fix Make the bake **present-check before it copies**, using the probe the file already has as a post-condition (`:106`, `nix path-info '${marker}'`): - If the box's store already realises `$marker` **and** `${OC_GWIB_CACHE}` exists and holds a usable cache, skip the `rm -rf` / `scp -r` / `nix copy` entirely and go straight to re-pinning the GC root and the existing post-condition proof. - Otherwise (a genuinely moved marker — a flake bump — or a cold/stock base) run the copy exactly as today. - Keep the post-condition unconditional: the marker path MUST be valid in the store before the snapshot is taken (ADR 0100), whichever branch ran. That is the no-op contract the supply/standing seed present-checks depend on, and it must never be weakened into "we assumed the base had it". - Log which branch was taken and the elapsed time, so the phase line stays honest (`phase=installer-base … reused-base-closure` vs `… copied`). **Expected effect:** rebuild TOTAL from ~42 min to ~5 min, on top of #1102's 60→42. Combined with the honest staleness gate (#1096/#1100), a snapshot refresh stops being a thing the drive lane has to plan around at all. ## Acceptance - A rebase whose base already carries the current marker logs the reuse branch and completes `installer-base` in seconds; TOTAL is minutes. - A rebuild whose marker genuinely moved (flake bump) still copies, and still passes the post-condition. - A build from a cold/stock base (the periodic rebase-from-stock #1102 provides) still copies. - The post-condition `nix path-info $marker` runs and fails loud in every branch — a base that turns out NOT to carry the closure must red the build, never produce a snapshot whose seed contract is broken. - Offline-provable in the existing bake/rebuild test shape. Filed by the watching session from the #854 arc (ADR 0174) — measurement only, no code change from me; the bake has a real correctness surface (GC root, marker validity, the seed's no-op contract) where the existing tests should drive the change.

swarm-claim host=elitebook-distributed-server-03 run=15727
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=elitebook-distributed-server-03 run=15727 (automated multi-host claim — lowest live claim id works this ticket)

close-report for #1108 — status success

⛔ close-report gates REFUSED this close — the following claims did not verify:

  • commit 1d239200b1 is not reachable from origin/main (not landed)
  • changed_files: 'scripts/lib/gateway-image-installer-base-lib.sh' is not in the diff of the claimed commits
  • changed_files: 'scripts/tests/gateway-image-installer-base-test.sh' is not in the diff of the claimed commits
  • changed_files: 'STATUS.md' is not in the diff of the claimed commits
envelope
{
  "issue": 1108,
  "status": "success",
  "commits": [
    "1d239200b128239f2e13018243a6b937177be00a"
  ],
  "changed_files": [
    "scripts/lib/gateway-image-installer-base-lib.sh",
    "scripts/tests/gateway-image-installer-base-test.sh",
    "STATUS.md"
  ],
  "tests": [
    {
      "command": "bash scripts/tests/gateway-image-installer-base-test.sh",
      "exit_code": 0
    }
  ],
  "criteria": {
    "A rebase whose base already carries the current marker logs the reuse branch and completes installer-base in seconds; TOTAL is minutes": "gateway-image-installer-base-lib.sh reuse branch: present-check (test -f <cache>/nix-cache-info && nix path-info <marker>) => branch=reused-base-closure skips rm/scp/import, logs it; proven by test scenario 4 (present_rc=0 => no scp/nix copy/rm -rf recorded)",
    "A rebuild whose marker genuinely moved (flake bump) still copies, and still passes the post-condition": "moved marker is not valid on the box => present-check fails => copied branch runs the full scp/nix copy; proven by test scenarios 1-3 (present_rc=1 => full layout landed) and post-condition asserted",
    "A build from a cold/stock base still copies": "a cold base has neither cache nor closure => present-check fails => copied branch; same copied path as the moved-marker case (test 1-3)",
    "The post-condition nix path-info runs and fails loud in every branch": "post-condition nix path-info <marker> is UNCONDITIONAL after both branches; proven by test scenario 5 (reuse branch, pathinfo_rc=1 => bake fails) and scenario 8 (copy branch, pathinfo_rc=1 => bake fails)",
    "Offline-provable in the existing bake/rebuild test shape": "scripts/tests/gateway-image-installer-base-test.sh runs offline (no DO/nix/scp), 8 checks pass"
  },
  "summary": "installer-base bake present-checks the box and skips the ~2.2 GB re-send on a golden rebase, keeping the GC-root re-pin and ADR 0100 post-condition unconditional in both branches.",
  "blockers": []
}
**close-report** for #1108 — status `success` :no_entry: **close-report gates REFUSED this close** — the following claims did not verify: - commit 1d239200b128239f2e13018243a6b937177be00a is not reachable from origin/main (not landed) - changed_files: 'scripts/lib/gateway-image-installer-base-lib.sh' is not in the diff of the claimed commits - changed_files: 'scripts/tests/gateway-image-installer-base-test.sh' is not in the diff of the claimed commits - changed_files: 'STATUS.md' is not in the diff of the claimed commits <details><summary>envelope</summary> ```json { "issue": 1108, "status": "success", "commits": [ "1d239200b128239f2e13018243a6b937177be00a" ], "changed_files": [ "scripts/lib/gateway-image-installer-base-lib.sh", "scripts/tests/gateway-image-installer-base-test.sh", "STATUS.md" ], "tests": [ { "command": "bash scripts/tests/gateway-image-installer-base-test.sh", "exit_code": 0 } ], "criteria": { "A rebase whose base already carries the current marker logs the reuse branch and completes installer-base in seconds; TOTAL is minutes": "gateway-image-installer-base-lib.sh reuse branch: present-check (test -f <cache>/nix-cache-info && nix path-info <marker>) => branch=reused-base-closure skips rm/scp/import, logs it; proven by test scenario 4 (present_rc=0 => no scp/nix copy/rm -rf recorded)", "A rebuild whose marker genuinely moved (flake bump) still copies, and still passes the post-condition": "moved marker is not valid on the box => present-check fails => copied branch runs the full scp/nix copy; proven by test scenarios 1-3 (present_rc=1 => full layout landed) and post-condition asserted", "A build from a cold/stock base still copies": "a cold base has neither cache nor closure => present-check fails => copied branch; same copied path as the moved-marker case (test 1-3)", "The post-condition nix path-info runs and fails loud in every branch": "post-condition nix path-info <marker> is UNCONDITIONAL after both branches; proven by test scenario 5 (reuse branch, pathinfo_rc=1 => bake fails) and scenario 8 (copy branch, pathinfo_rc=1 => bake fails)", "Offline-provable in the existing bake/rebuild test shape": "scripts/tests/gateway-image-installer-base-test.sh runs offline (no DO/nix/scp), 8 checks pass" }, "summary": "installer-base bake present-checks the box and skips the ~2.2 GB re-send on a golden rebase, keeping the GC-root re-pin and ADR 0100 post-condition unconditional in both branches.", "blockers": [] } ``` </details>

close-report for #1108 — status success

✅ close-report gates passed — every claim verified against main; issue closed.

envelope
{
  "issue": 1108,
  "status": "success",
  "commits": [
    "1d239200b128239f2e13018243a6b937177be00a"
  ],
  "changed_files": [
    "scripts/lib/gateway-image-installer-base-lib.sh",
    "scripts/tests/gateway-image-installer-base-test.sh",
    "STATUS.md"
  ],
  "tests": [
    {
      "command": "bash scripts/tests/gateway-image-installer-base-test.sh",
      "exit_code": 0
    }
  ],
  "criteria": {
    "A rebase whose base already carries the current marker logs the reuse branch and completes installer-base in seconds; TOTAL is minutes": "gateway-image-installer-base-lib.sh reuse branch: present-check (test -f <cache>/nix-cache-info && nix path-info <marker>) => branch=reused-base-closure skips rm/scp/import, logs it; proven by test scenario 4 (present_rc=0 => no scp/nix copy/rm -rf recorded)",
    "A rebuild whose marker genuinely moved (flake bump) still copies, and still passes the post-condition": "moved marker is not valid on the box => present-check fails => copied branch runs the full scp/nix copy; proven by test scenarios 1-3 (present_rc=1 => full layout landed) and post-condition asserted",
    "A build from a cold/stock base still copies": "a cold base has neither cache nor closure => present-check fails => copied branch; same copied path as the moved-marker case (test 1-3)",
    "The post-condition nix path-info runs and fails loud in every branch": "post-condition nix path-info <marker> is UNCONDITIONAL after both branches; proven by test scenario 5 (reuse branch, pathinfo_rc=1 => bake fails) and scenario 8 (copy branch, pathinfo_rc=1 => bake fails)",
    "Offline-provable in the existing bake/rebuild test shape": "scripts/tests/gateway-image-installer-base-test.sh runs offline (no DO/nix/scp), 8 checks pass"
  },
  "summary": "installer-base bake present-checks the box and skips the ~2.2 GB re-send on a golden rebase, keeping the GC-root re-pin and ADR 0100 post-condition unconditional in both branches.",
  "blockers": []
}
**close-report** for #1108 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 1108, "status": "success", "commits": [ "1d239200b128239f2e13018243a6b937177be00a" ], "changed_files": [ "scripts/lib/gateway-image-installer-base-lib.sh", "scripts/tests/gateway-image-installer-base-test.sh", "STATUS.md" ], "tests": [ { "command": "bash scripts/tests/gateway-image-installer-base-test.sh", "exit_code": 0 } ], "criteria": { "A rebase whose base already carries the current marker logs the reuse branch and completes installer-base in seconds; TOTAL is minutes": "gateway-image-installer-base-lib.sh reuse branch: present-check (test -f <cache>/nix-cache-info && nix path-info <marker>) => branch=reused-base-closure skips rm/scp/import, logs it; proven by test scenario 4 (present_rc=0 => no scp/nix copy/rm -rf recorded)", "A rebuild whose marker genuinely moved (flake bump) still copies, and still passes the post-condition": "moved marker is not valid on the box => present-check fails => copied branch runs the full scp/nix copy; proven by test scenarios 1-3 (present_rc=1 => full layout landed) and post-condition asserted", "A build from a cold/stock base still copies": "a cold base has neither cache nor closure => present-check fails => copied branch; same copied path as the moved-marker case (test 1-3)", "The post-condition nix path-info runs and fails loud in every branch": "post-condition nix path-info <marker> is UNCONDITIONAL after both branches; proven by test scenario 5 (reuse branch, pathinfo_rc=1 => bake fails) and scenario 8 (copy branch, pathinfo_rc=1 => bake fails)", "Offline-provable in the existing bake/rebuild test shape": "scripts/tests/gateway-image-installer-base-test.sh runs offline (no DO/nix/scp), 8 checks pass" }, "summary": "installer-base bake present-checks the box and skips the ~2.2 GB re-send on a golden rebase, keeping the GC-root re-pin and ADR 0100 post-condition unconditional in both branches.", "blockers": [] } ``` </details>
Author
Owner

Measured live — the reuse branch fires and the saving is real. First rebuild after this landed (build=ae94e1e21b3e base=idss-gateway-adb83d58ad94, triggered by #1114 touching internal/provision):

gateway-image: the base already realises marker /nix/store/g9z22mi6…-kexec-26.05pre-git
               and carries the on-box cache — skipping the ~2.2 GB re-copy (#1108)
gateway-image: warm installer-base baked into the snapshot store (… branch=reused-base-closure)
phase before #1102 after #1102 after #1108
provision — 68 s 68 s
nixos-install ~45–50 min 2 m 46 s 2 m 36 s
installer-base — 36 m 50 s 10 m 51 s
snapshot — 70 s 68 s
TOTAL ~60 min 41 m 54 s 15 m 43 s

So the rebuild tax across both tickets: ~60 min → 15 m 43 s, and the post-condition still ran (nix path-info on the marker) in the reuse branch, which is what makes the skip safe to take.

A further saving remains, noted rather than filed. The 10 m 51 s that is left is almost entirely local work on the executor that happens before the present-check: building the base kexec tarball, enumerating 1355 valid store paths, and staging them into /tmp/…/installer-base-cache as a file:// cache — all so a marker can be computed and a cache prepared that the reuse branch then does not send. Hoisting the marker resolution ahead of the staging (or caching the staged tree across builds, keyed on the marker) would cut most of that too.

I have not filed it: 15 minutes is no longer in the drive lane's way, and the remaining work has a sharper edge (the marker is what the present-check tests, so resolving it more cheaply must not weaken that test). Worth doing when someone is next in this file, or if rebuild frequency rises again.

**Measured live — the reuse branch fires and the saving is real.** First rebuild after this landed (`build=ae94e1e21b3e base=idss-gateway-adb83d58ad94`, triggered by #1114 touching `internal/provision`): ``` gateway-image: the base already realises marker /nix/store/g9z22mi6…-kexec-26.05pre-git and carries the on-box cache — skipping the ~2.2 GB re-copy (#1108) gateway-image: warm installer-base baked into the snapshot store (… branch=reused-base-closure) ``` | phase | before #1102 | after #1102 | after #1108 | |---|---|---|---| | provision | — | 68 s | 68 s | | nixos-install | ~45–50 min | 2 m 46 s | 2 m 36 s | | **installer-base** | — | **36 m 50 s** | **10 m 51 s** | | snapshot | — | 70 s | 68 s | | **TOTAL** | **~60 min** | **41 m 54 s** | **15 m 43 s** | So the rebuild tax across both tickets: **~60 min → 15 m 43 s**, and the post-condition still ran (`nix path-info` on the marker) in the reuse branch, which is what makes the skip safe to take. **A further saving remains, noted rather than filed.** The 10 m 51 s that is left is almost entirely *local* work on the executor that happens **before** the present-check: building the base kexec tarball, enumerating 1355 valid store paths, and staging them into `/tmp/…/installer-base-cache` as a `file://` cache — all so a marker can be computed and a cache prepared that the reuse branch then does not send. Hoisting the marker resolution ahead of the staging (or caching the staged tree across builds, keyed on the marker) would cut most of that too. I have not filed it: 15 minutes is no longer in the drive lane's way, and the remaining work has a sharper edge (the marker is what the present-check *tests*, so resolving it more cheaply must not weaken that test). Worth doing when someone is next in this file, or if rebuild frequency rises again.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
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#1108
No description provided.