Public: anyone can read this; the crew can change it.

Release reused an image built from an older commit: v0.7.646 shipped without the fix it was cut for #17028

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

torque/forge:torque/16349-release-reused-an-image-built-from-an-ol → main 0 commits fork 4 threads · 4 unresolved

  • Merged. torque/16349-release-reused-an-image-built-from-an-ol was merged into main as 1aaad2d.

Review

Sign in to review this change.
7 files changed +120 −0
Dockerfile +4
@@ -37,6 +37,10 @@ COPY templates ./templates
3737 ARG VERSION=dev
3838 ARG COMMIT=""
3939 LABEL org.opencontainers.image.version=$VERSION
40 # The commit this image was built from (#16349). A release that finds an image
41 # already tagged with its version reuses it only when this label equals the
42 # commit it is cutting; a tag built from an older trunk is rebuilt, not shipped.
43 LABEL forge.commit=$COMMIT
4044 ENV FORGE_VERSION=$VERSION FORGE_COMMIT=$COMMIT
4145 # Everything a forge instance is lives under FORGE_DATA — mount a volume there.
4246 # 8080 is the port the platform's edge admits.
docs/features/nightly-release.md +2
@@ -18,6 +18,8 @@ Any doubt is a hold: nothing is promoted, and an issue titled `The nightly relea
1818
1919 **Proven (2026-11-16, on the host):** the fetch, the comparison and the gate (1,524 tests, 0 failed, 86 s). **Not yet run unattended:** the tag, the build, the rig and the promote as one sequence; each is the script used by hand for every release since 2026-11-13. The first real run is the first morning main is ahead.
2020
21 **Reusing an image:** every image carries a `forge.commit` label, the commit it was built from. When an image already has the version's tag, the release reuses it only if that label is the commit being cut; a different commit, a label that is not a commit id (under 7 hex characters), no label or no image is a rebuild. The check is `bun src/release/reuse.ts <image> <commit>`: it prints `reuse` (exit 0) or `rebuild: <why>` (exit 1).
outdated

A requirement on a script outside the repository, with the incident narrative, is not a feature how-to. Describe what the release does, once the reuse check is in the repo.

22
2123 **Heartbeat:** the tick must post `outcome` and `reason` to `/api/v1/release/heartbeat` on every run (`release-heartbeat.md`); whether the host script does so is a host-side fact to confirm on the first run. The `release_quiet` alarm now waits 26 h (`SILENT_MS` = the daily `TICK_EVERY_MS` and a 2 h grace), so a daily beat is quiet and a missed day fires it. That alarm, with the held issues, is what watches the first unattended run; the held-issue path itself has not been exercised.
2224
2325 **To stop it:** `systemctl --user disable --now forge-release-tick.timer` on the host (also in `docs/SECURITY-RUNBOOK.md`; the Hold form on /releases is the forge-side stop).
scripts/unreached.ts +2
@@ -21,6 +21,8 @@ export const ENTRIES = [
2121 "src/chaos/worker.ts",
2222 "src/chaos/run.ts",
2323 "src/release/boot.ts",
24 // Run by the release tick: `bun src/release/reuse.ts <image> <commit>`.
25 "src/release/reuse.ts",
2426 "src/git/hook-entry.ts",
2527 // A runner's own process, started on its machine: `bun src/runner/main.ts`
2628 // (docs/features/runners.md).
src/release/reuse.ts added +64
@@ -0,0 +1,64 @@
1 /**
2 * Is the image already tagged with this version the one to ship? An image is
3 * reused only when its `forge.commit` label (the Dockerfile's `COMMIT`) is the
4 * commit being cut; a different commit's label, a label that is not a commit
5 * id (under 7 hex characters), no label, or no image at all is a rebuild. A tag proves a version

Non-blocking: this comment line wraps oddly mid-sentence. Re-flow it so the paragraph reads evenly.

6 * was built once, not from which tree.
7 *
8 * bun src/release/reuse.ts <image> <commit>
9 *
10 * Prints `reuse` (exit 0) or `rebuild: <why>` (exit 1); exit 2 for a bad
11 * argument. The release tick calls this where it used to take any image with
12 * the version's tag.
13 */
14
15 const SHA = /^[0-9a-f]{7,64}$/;
16
17 export type Reuse = { readonly reuse: true } | { readonly reuse: false; readonly why: string };
18
19 /**
20 * `label` is the image's forge.commit (null: no image, or an image without the label); `commit` the
21 * commit being cut.
22 */
23 export function reuseDecision(label: string | null, commit: string): Reuse {
24 const want = commit.trim().toLowerCase();
25 if (!SHA.test(want)) return { reuse: false, why: "the commit being cut is not a commit id" };
26 const have = (label ?? "").trim().toLowerCase();
27 if (have === "") return { reuse: false, why: "the image has no forge.commit label" };
28 // A short or non-hex label ("0", "a") would prefix-match nearly any commit.
outdated

A label shorter than 7 characters, or not hex, still matches by prefix here. Validate have against SHA before comparing, and test it.

29 if (!SHA.test(have)) return { reuse: false, why: "the forge.commit label is not a commit id" };
30 // Full ids compare whole; an abbreviation on either side matches by prefix.
31 if (have.startsWith(want) || want.startsWith(have)) return { reuse: true };
32 return { reuse: false, why: `the image was built from ${have.slice(0, 12)}, not ${want.slice(0, 12)}` };
33 }
34
35 /**
36 * The image's forge.commit label, or null when there is no such image or no label. No shell: the
37 * image name is one argv entry.
38 */
39 async function imageCommit(image: string): Promise<string | null> {
40 let out: string;
41 try {
42 const p = Bun.spawn(["docker", "image", "inspect", "-f", '{{index .Config.Labels "forge.commit"}}', image], {
43 stdout: "pipe",
44 stderr: "ignore",
45 });
46 out = await new Response(p.stdout).text();
47 if ((await p.exited) !== 0) return null;
48 } catch {
49 return null; // no docker here: nothing to reuse
50 }
51 const label = out.trim();
52 return label === "" || label === "<no value>" ? null : label;
53 }
54
55 if (import.meta.main) {
56 const [image, commit] = process.argv.slice(2);
57 if (!image || !commit || image.startsWith("-") || !/^[\w][\w./:@-]*$/.test(image)) {
58 console.error("usage: bun src/release/reuse.ts <image> <commit>");
59 process.exit(2);
60 }
61 const d = reuseDecision(await imageCommit(image), commit);
62 console.log(d.reuse ? "reuse" : `rebuild: ${d.why}`);
63 process.exit(d.reuse ? 0 : 1);
64 }
test/release-reuse.test.ts added +45
@@ -0,0 +1,45 @@
1 import { expect, test } from "bun:test";
2 import { reuseDecision } from "../src/release/reuse.ts";
3
4 const CUT = "00cdd46ca1f2e3d4c5b6a79881726354abcdef01";
5 const OLDER = "9f8e7d6c5b4a39281706f5e4d3c2b1a099887766";
6
7 test("an image built from another commit is rebuilt (#16349: v0.7.646)", () => {
8 const d = reuseDecision(OLDER, CUT);
9 expect(d.reuse).toBe(false);
10 expect(d.reuse === false && d.why).toContain("9f8e7d6c5b4a");
11 });
12
13 test("an image with no label, or no image, is rebuilt", () => {
14 expect(reuseDecision(null, CUT).reuse).toBe(false);
15 expect(reuseDecision(" ", CUT).reuse).toBe(false);
16 });
17
18 test("an image built from the commit being cut is reused, abbreviated or not, any case", () => {
19 expect(reuseDecision(CUT, CUT)).toEqual({ reuse: true });
20 expect(reuseDecision("00cdd46ca", CUT)).toEqual({ reuse: true });
21 expect(reuseDecision(CUT.toUpperCase(), "00cdd46ca")).toEqual({ reuse: true });
22 });
23
24 test("a commit that is not a commit id is never a reason to reuse", () => {
25 expect(reuseDecision("", "").reuse).toBe(false);
26 expect(reuseDecision("abc", "abc; rm").reuse).toBe(false);
27 });
28
29 test("a label too short or not hex is rebuilt, not prefix-matched", () => {
30 for (const label of ["0", "a", "00", "00cdd4", "zzzzzzz", "00cdd46g"]) {
31 expect(reuseDecision(label, CUT)).toEqual({ reuse: false, why: "the forge.commit label is not a commit id" });
32 }
33 });
34
35 test("the command line says rebuild with exit 1 and refuses a bad argument with 2", async () => {
36 const run = async (...args: string[]) => {
37 const p = Bun.spawn(["bun", "src/release/reuse.ts", ...args], { stdout: "pipe", stderr: "ignore", cwd: new URL("..", import.meta.url).pathname });
38 return { out: (await new Response(p.stdout).text()).trim(), code: await p.exited };
39 };
40 // No such image (or no docker here): no label, so a rebuild.
41 const none = await run("forge-no-such-image:0.0.0", CUT);
42 expect(none.code).toBe(1);
43 expect(none.out).toStartWith("rebuild: ");
44 expect((await run("--all", CUT)).code).toBe(2);
45 });
test/spawn-pipes.test.ts +1
@@ -46,6 +46,7 @@ const PIPING: Record<string, { sites: string[]; reason: string }> = {
4646 "src/release/devtools.ts": { sites: ["stderr"], reason: "stderr read for the DevTools address, then drained in a background loop; stdout ignored" },
4747 "src/release/launch.ts": { sites: ["stderr"], reason: "hear() reads stderr to its end for the release's life, passing every chunk through to ours and keeping the tail until ready; stdout inherited" },
4848 "src/release/boot.ts": { sites: ["stderr"], reason: "stderr read to its end in a background loop, awaited before the reason is read; stdout ignored" },
49 "src/release/reuse.ts": { sites: ["stdout"], reason: "stdout (the label) read to its end before the exit is awaited; stderr ignored" },
4950 "src/release/small_forge.ts": { sites: ["stderr", "stdout"], reason: "run() reads each git stderr to its end via Response.text() before the exit is awaited, stdout ignored; spawnSync buffers rev-parse stdout, stderr ignored" },
5051 "src/snapshot/kit.ts": { sites: ["stdout+stderr"], reason: "the restore child's stdout is read to its end for the restored snapshot id and stderr for the failure text, alongside the exit" },
5152 "src/sandbox/landlock_probe.ts": { sites: ["stdout+stderr"], reason: "the helper's --abi answer and its failure text are read to the end via Response.text() while the exit is awaited, under a kill deadline" },
test/spawn-sites.test.ts +2
@@ -85,6 +85,8 @@ const SITES: Record<string, string> = {
8585 "`git clone --quiet -- <bare> <partial>` between two paths the forge derived",
8686 "src/release/boot.ts":
8787 "bun (process.execPath) on the release tree's entry file",
88 "src/release/reuse.ts":
89 "`docker image inspect -f <label template> <image>`, the image name one validated argv entry",
8890 "src/release/checkout.ts":
8991 "bun (process.execPath) on the checkout's entry with a fixed `--preflight`",
9092 "src/release/devtools.ts":

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs