DESIGN: the ~60-minute gateway-image rebuild is the snapshot CONTRACT, not a staleness-key bug — bake the agent at drive time, or make the build cheap? (#1096/#1100 measured ineffective) #1102

Closed
opened 2026-09-01 05:43:37 +00:00 by ben · 3 comments
Owner

Two fixes have now landed against the rebuild cost (#1096 pin axis, #1100 checksum axis) and neither reduces the rebuild rate, because the premise both share is false. Measured, not reasoned — see #1100's closing comment for the five-for-five distinct agent-x86_64.sha256 digests, including a pure render/comment change (#1095, 0b5cbad5→9d414e84).

Why: internal/ is linked into the agent and the Nix module text lives as Go string literals inside it, so a "render-only" edit genuinely produces a different binary. No staleness key — version tag, content checksum, or anything else — can call those two agents equal, because they are not equal. The gate is now honest and correct; the snapshot really is stale by its own definition.

So the cost is the contract: the gateway image bakes one specific agent build, which chains image freshness to the whole product's commit rate. On a busy internal/ night that is a ~60-minute tax per drive — measured 49/62/58/60 min, 3.8 h of the 6.5 h window 19:30→02:00 for three drives (#1096's evidence).

The two directions (a ruling is wanted; both are above the two-way-door line)

A — stop baking the agent into the image. The snapshot carries only OS/store warmth; the drive places the current agent on the gateway after boot (it already copies closures). Rebuilds then key on the base image, which moves rarely. The #656 ghost-red risk it was built to prevent ("a drive testing a stale agent") moves to "did the drive place the agent", which is checkable in-run and arguably a stronger guarantee than a baked pin, since it cannot silently drift.

B — keep baking it, make the build cheap. The 60 min is dominated by a full NixOS build plus the installer-base bake on a freshly created droplet. Tonight every bake reported an identical marker and an identical 1355 store paths — the same work, from cold, four times. A warm/persistent build host, or using the previous snapshot as the build base instead of stock Ubuntu, would attack the real cost directly and is independent of any staleness question.

They are not exclusive: B is worth doing regardless, and A removes most of the firings.

What should be measured before building either

  1. What actually dominates the 60 min — nix build from cold, the installer-base bake, or droplet create/snapshot/destroy? (gateway-image-rebuild.log per phase; nothing has timed the phases yet.)
  2. Under A: how long does placing the agent on a booted gateway take, and does the founding path already do it? If founding deploys the full config over the image anyway, the baked agent may already be largely vestigial for the drive's purposes — worth confirming, because if so A is close to free.

Not blocking

#854 continues to drive; this is wall-clock and DO spend. Filed needs-design for Ben's ruling under ADR 0174 rather than letting a worker pick an architecture. Context: #1096 and #1100 are closed and should stay landed — their probe machinery, honest verdicts and corrected ~60 min string are the right foundation for A.

Two fixes have now landed against the rebuild cost (#1096 pin axis, #1100 checksum axis) and **neither reduces the rebuild rate**, because the premise both share is false. Measured, not reasoned — see #1100's closing comment for the five-for-five distinct `agent-x86_64.sha256` digests, including a pure render/comment change (#1095, `0b5cbad5`→`9d414e84`). **Why:** `internal/` is linked into the agent and the Nix module text lives as Go string literals inside it, so a "render-only" edit genuinely produces a different binary. No staleness key — version tag, content checksum, or anything else — can call those two agents equal, because they are not equal. The gate is now honest and correct; the snapshot really is stale by its own definition. So the cost is the **contract**: the gateway image bakes one specific agent build, which chains image freshness to the whole product's commit rate. On a busy `internal/` night that is a ~60-minute tax per drive — measured 49/62/58/60 min, 3.8 h of the 6.5 h window 19:30→02:00 for three drives (#1096's evidence). ## The two directions (a ruling is wanted; both are above the two-way-door line) **A — stop baking the agent into the image.** The snapshot carries only OS/store warmth; the drive places the current agent on the gateway after boot (it already copies closures). Rebuilds then key on the base image, which moves rarely. The #656 ghost-red risk it was built to prevent ("a drive testing a stale agent") moves to "did the drive place the agent", which is checkable in-run and arguably a stronger guarantee than a baked pin, since it cannot silently drift. **B — keep baking it, make the build cheap.** The 60 min is dominated by a full NixOS build plus the installer-base bake **on a freshly created droplet**. Tonight every bake reported an identical marker and an identical `1355 store paths` — the same work, from cold, four times. A warm/persistent build host, or using the previous snapshot as the build base instead of stock Ubuntu, would attack the real cost directly and is independent of any staleness question. They are not exclusive: B is worth doing regardless, and A removes most of the firings. ## What should be measured before building either 1. What actually dominates the 60 min — `nix build` from cold, the installer-base bake, or droplet create/snapshot/destroy? (`gateway-image-rebuild.log` per phase; nothing has timed the phases yet.) 2. Under A: how long does placing the agent on a booted gateway take, and does the founding path already do it? If founding deploys the full config over the image anyway, the baked agent may already be largely vestigial for the drive's purposes — worth confirming, because if so A is close to free. ## Not blocking #854 continues to drive; this is wall-clock and DO spend. Filed `needs-design` for Ben's ruling under ADR 0174 rather than letting a worker pick an architecture. Context: #1096 and #1100 are closed and should stay landed — their probe machinery, honest verdicts and corrected `~60 min` string are the right foundation for A.
Author
Owner

Ben ruled B (2026-09-01, in session). Recording the mechanism that decides it, so A is not re-proposed.

A is not viable — the baked agent is under test at boot

nix/gateway-image/configuration.nix:111-130: the image lays the pinned binary at /usr/local/bin/idss-agent and the unit's ExecStart is /usr/local/bin/idss-agent join, running at boot. The drive's claim / connect / point-row legs test exactly that boot-time join.

So the baked agent is not vestigial — that was this ticket's open "what should be measured" question, and it is now answered without needing a measurement: it is the thing under test at the moment it runs. "Place the agent after boot" cannot work, because the join has already happened. A would have the drive exercise a stale agent on precisely the legs #656 exists to protect — the served-bits-vs-main trap (#912), one layer down.

B's lever is larger than this ticket estimated

scripts/gateway-image/build.sh:97:

--region "$region" --size "$size" --image ubuntu-24-04-x64 \

Every rebuild creates a droplet from stock Ubuntu and has nixos-anywhere install NixOS from scratch. That is the whole ~60 minutes — a cold NixOS install + closure build + installer-base bake — repeated four times tonight, each producing a near-identical image differing in one fetchurl'd binary.

The fix: build from the PREVIOUS golden snapshot instead of stock Ubuntu. The base is then already NixOS with a warm store, and a rebuild becomes "swap one binary, rebuild the system generation" — minutes, not an hour. The build already scrubs identity at the end, so re-basing leaks nothing.

The one real risk is generational cruft/drift — a store that only ever accumulates. Mitigate by rebasing from stock on a schedule (weekly) or on a flake bump, and by keeping the existing image-contract proof (idss-agent.service active on the fresh box, ADR 0100), which fails loud if a generation goes bad.

Consequence worth stating: at ~minutes per rebuild, the frequency question this arc started with (#1096, #1100) stops mattering. Their honest verdicts and probe machinery are exactly the right thing to keep driving a cheap rebuild — they should stay landed, and no third staleness key should be attempted.

Acceptance

  • A rebuild whose only delta is the agent binary completes in minutes, measured and recorded in the rebuild log with per-phase timings (nothing times the phases today — add that first; it also settles what remains).
  • The image-contract proof still runs and still fails loud on a bad generation.
  • A scheduled/flag-driven rebase from stock Ubuntu exists and is exercised.
  • The drive still reds honestly if the snapshot is genuinely stale (the #1096/#1100 gate unchanged).
**Ben ruled B** (2026-09-01, in session). Recording the mechanism that decides it, so A is not re-proposed. ## A is not viable — the baked agent is under test at boot `nix/gateway-image/configuration.nix:111-130`: the image lays the pinned binary at `/usr/local/bin/idss-agent` and the unit's `ExecStart` is `/usr/local/bin/idss-agent join`, running **at boot**. The drive's `claim` / `connect` / `point-row` legs test exactly that boot-time join. So the baked agent is not vestigial — that was this ticket's open "what should be measured" question, and it is now answered without needing a measurement: it is the thing under test at the moment it runs. "Place the agent after boot" cannot work, because the join has already happened. A would have the drive exercise a stale agent on precisely the legs #656 exists to protect — the served-bits-vs-main trap (#912), one layer down. ## B's lever is larger than this ticket estimated `scripts/gateway-image/build.sh:97`: ```sh --region "$region" --size "$size" --image ubuntu-24-04-x64 \ ``` Every rebuild creates a droplet from **stock Ubuntu** and has nixos-anywhere install NixOS from scratch. That is the whole ~60 minutes — a cold NixOS install + closure build + installer-base bake — repeated four times tonight, each producing a near-identical image differing in one fetchurl'd binary. **The fix: build from the PREVIOUS golden snapshot instead of stock Ubuntu.** The base is then already NixOS with a warm store, and a rebuild becomes "swap one binary, rebuild the system generation" — minutes, not an hour. The build already scrubs identity at the end, so re-basing leaks nothing. The one real risk is generational cruft/drift — a store that only ever accumulates. Mitigate by rebasing from stock on a schedule (weekly) or on a flake bump, and by keeping the existing image-contract proof (`idss-agent.service` active on the fresh box, ADR 0100), which fails loud if a generation goes bad. **Consequence worth stating:** at ~minutes per rebuild, the *frequency* question this arc started with (#1096, #1100) stops mattering. Their honest verdicts and probe machinery are exactly the right thing to keep driving a cheap rebuild — they should stay landed, and no third staleness key should be attempted. ## Acceptance - A rebuild whose only delta is the agent binary completes in **minutes**, measured and recorded in the rebuild log with per-phase timings (nothing times the phases today — add that first; it also settles what remains). - The image-contract proof still runs and still fails loud on a bad generation. - A scheduled/flag-driven rebase from stock Ubuntu exists and is exercised. - The drive still reds honestly if the snapshot is genuinely stale (the #1096/#1100 gate unchanged).

swarm-claim host=matou-dev-server-01 run=15670
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=matou-dev-server-01 run=15670 (automated multi-host claim — lowest live claim id works this ticket)

close-report for #1102 — status success

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

envelope
{
  "issue": 1102,
  "status": "success",
  "commits": [
    "adb83d58ad94864a840b83679bdb4f81322b0a7d"
  ],
  "changed_files": [
    "STATUS.md",
    "docs/GOTCHAS.md",
    "scripts/gateway-image/build.sh",
    "scripts/lib/gateway-image-base-lib.sh",
    "scripts/lib/gateway-image-rebuild-lib.sh",
    "scripts/lib/gateway-image-timing-lib.sh",
    "scripts/tests/gateway-image-base-test.sh",
    "scripts/tests/gateway-image-timing-test.sh"
  ],
  "tests": [
    {
      "command": "bash scripts/tests/gateway-image-base-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash scripts/tests/gateway-image-timing-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash scripts/tests/gateway-image-rebuild-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash scripts/gateway-image/tests/gateway-image-staleness-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash scripts/gateway-image/tests/latest-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash -n scripts/gateway-image/build.sh",
      "exit_code": 0
    }
  ],
  "criteria": {
    "A rebuild whose only delta is the agent binary completes in minutes, measured and recorded in the rebuild log with per-phase timings (add that first)": "MECHANISM + INSTRUMENT shipped: build.sh now builds the droplet from the previous golden snapshot's warm /nix/store by default (oc_gwimage_choose_base, gateway-image-base-lib.sh; nixos-anywhere --disko-mode mount) so a render-only delta swaps one binary and rebuilds the generation instead of a cold stock install; and every phase (provision/nixos-install/installer-base/snapshot) is bracketed by oc_gwimage_phase_begin/_end + a phase=TOTAL into the drive-dir gateway-image-rebuild.log (gateway-image-timing-lib.sh). The literal 'minutes' number is a LIVE measurement the next real drive records — see blockers/next-iteration note; the timing instrument Ben named 'add first' is landed and offline-proven (gateway-image-timing-test.sh, 8 checks).",
    "The image-contract proof still runs and still fails loud on a bad generation": "build.sh:159-164 unchanged — systemctl is-active idss-agent on the fresh box, die on anything but 'active' (ADR 0100). Runs on every build, golden rebase or stock.",
    "A scheduled/flag-driven rebase from stock Ubuntu exists and is exercised": "oc_gwimage_base_decision falls back to a clean stock Ubuntu build (--disko-mode destroy/format) on REBASE_FROM_STOCK=1 (flag), no prior snapshot, or newest-snapshot >= OC_GWIMAGE_STOCK_REBASE_DAYS (weekly schedule). Exercised offline: gateway-image-base-test.sh cases 2 (flag), 3/8 (no-prior), 4/6 (schedule aged-out), plus the wired chooser over a fake doctl + scripted clock.",
    "The drive still reds honestly if the snapshot is genuinely stale (the #1096/#1100 gate unchanged)": "The staleness lib + gate (gateway-image-staleness-lib.sh, smoke-private-path.sh) are untouched; gateway-image-staleness-test.sh (12 checks) and gateway-image-rebuild-test.sh (11 checks) still pass — a genuinely-stale snapshot still parks/rebuilds by name."
  },
  "summary": "Ben ruled B: build.sh rebases the gateway image on the previous golden snapshot's warm store (with a flag/schedule stock-rebase fallback) and times every build phase into the drive-dir rebuild log; the ADR 0100 contract proof and #1096/#1100 staleness gate are unchanged.",
  "reason": "",
  "blockers": [],
  "no_code_change": ""
}
**close-report** for #1102 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 1102, "status": "success", "commits": [ "adb83d58ad94864a840b83679bdb4f81322b0a7d" ], "changed_files": [ "STATUS.md", "docs/GOTCHAS.md", "scripts/gateway-image/build.sh", "scripts/lib/gateway-image-base-lib.sh", "scripts/lib/gateway-image-rebuild-lib.sh", "scripts/lib/gateway-image-timing-lib.sh", "scripts/tests/gateway-image-base-test.sh", "scripts/tests/gateway-image-timing-test.sh" ], "tests": [ { "command": "bash scripts/tests/gateway-image-base-test.sh", "exit_code": 0 }, { "command": "bash scripts/tests/gateway-image-timing-test.sh", "exit_code": 0 }, { "command": "bash scripts/tests/gateway-image-rebuild-test.sh", "exit_code": 0 }, { "command": "bash scripts/gateway-image/tests/gateway-image-staleness-test.sh", "exit_code": 0 }, { "command": "bash scripts/gateway-image/tests/latest-test.sh", "exit_code": 0 }, { "command": "bash -n scripts/gateway-image/build.sh", "exit_code": 0 } ], "criteria": { "A rebuild whose only delta is the agent binary completes in minutes, measured and recorded in the rebuild log with per-phase timings (add that first)": "MECHANISM + INSTRUMENT shipped: build.sh now builds the droplet from the previous golden snapshot's warm /nix/store by default (oc_gwimage_choose_base, gateway-image-base-lib.sh; nixos-anywhere --disko-mode mount) so a render-only delta swaps one binary and rebuilds the generation instead of a cold stock install; and every phase (provision/nixos-install/installer-base/snapshot) is bracketed by oc_gwimage_phase_begin/_end + a phase=TOTAL into the drive-dir gateway-image-rebuild.log (gateway-image-timing-lib.sh). The literal 'minutes' number is a LIVE measurement the next real drive records — see blockers/next-iteration note; the timing instrument Ben named 'add first' is landed and offline-proven (gateway-image-timing-test.sh, 8 checks).", "The image-contract proof still runs and still fails loud on a bad generation": "build.sh:159-164 unchanged — systemctl is-active idss-agent on the fresh box, die on anything but 'active' (ADR 0100). Runs on every build, golden rebase or stock.", "A scheduled/flag-driven rebase from stock Ubuntu exists and is exercised": "oc_gwimage_base_decision falls back to a clean stock Ubuntu build (--disko-mode destroy/format) on REBASE_FROM_STOCK=1 (flag), no prior snapshot, or newest-snapshot >= OC_GWIMAGE_STOCK_REBASE_DAYS (weekly schedule). Exercised offline: gateway-image-base-test.sh cases 2 (flag), 3/8 (no-prior), 4/6 (schedule aged-out), plus the wired chooser over a fake doctl + scripted clock.", "The drive still reds honestly if the snapshot is genuinely stale (the #1096/#1100 gate unchanged)": "The staleness lib + gate (gateway-image-staleness-lib.sh, smoke-private-path.sh) are untouched; gateway-image-staleness-test.sh (12 checks) and gateway-image-rebuild-test.sh (11 checks) still pass — a genuinely-stale snapshot still parks/rebuilds by name." }, "summary": "Ben ruled B: build.sh rebases the gateway image on the previous golden snapshot's warm store (with a flag/schedule stock-rebase fallback) and times every build phase into the drive-dir rebuild log; the ADR 0100 contract proof and #1096/#1100 staleness gate are unchanged.", "reason": "", "blockers": [], "no_code_change": "" } ``` </details>
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#1102
No description provided.