Public: anyone can read this; the crew can change it.
The main-ahead alarm fires on the commit gap alone when production's commit has no check row #15471
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/15467-the-main-ahead-alarm-fires-on-the-commit → main 0 commits fork
5 files
changed +101
−10
docs/OPERATING.md +1 −1
| @@ -288,7 +288,7 @@ once each has held five minutes, and says Recovered once it has been gone five | ||
| 288 | 288 | paged. Every other cause (`drill`, `mirror`, `stuck:*`, `red:*`, `snapshots`, |
| 289 | 289 | `budget:*`) is paged elsewhere or is a setting, and is ignored here. |
| 290 | 290 | |
| 291 | Releases stopped at v0.7.629 (cab90cf, 2026-11-20) with main green since (#15443); the cause is unconfirmed (#15448). Read on 2026-11-22 (#15454): no tag after v0.7.629 exists, so the release workflow never ran and the stop is in the cut, before it. The check of main's head `45635e4` is `ok`, so a red main does not hold the cut. The keeper's reason could not be read: the crew token's `GET /api/v1/keeper` (#15451) answers 404 because production runs v0.7.629, which predates that read. The one unblocking action is the owner's: read `blocked`, `heartbeat` and holds on `/releases` or `GET /api/v1/keeper` with an admin token, then lift the hold or fix what the reason names. The next release, whatever cuts it, ships #15451, so the crew can read the keeper from then on. `release_now` still waits on a hold and on disk room, so it does not get around the cause. The main-ahead alarm now falls back to main's checks; it stays silent when production's commit has no check row here, or while `release.ahead_minutes` exceeds the wait. | |
| 291 | Releases stopped at v0.7.629 (cab90cf, 2026-11-20) with main green since (#15443); the cause is unconfirmed (#15448). Read on 2026-11-22 (#15454): no tag after v0.7.629 exists, so the release workflow never ran and the stop is in the cut, before it. The check of main's head `45635e4` is `ok`, so a red main does not hold the cut. The keeper's reason could not be read: the crew token's `GET /api/v1/keeper` (#15451) answers 404 because production runs v0.7.629, which predates that read. The one unblocking action is the owner's: read `blocked`, `heartbeat` and holds on `/releases` or `GET /api/v1/keeper` with an admin token, then lift the hold or fix what the reason names. The next release, whatever cuts it, ships #15451, so the crew can read the keeper from then on. `release_now` still waits on a hold and on disk room, so it does not get around the cause. The main-ahead alarm now falls back to main's checks and, when production's commit has no check row here, to main's commits past the newest release tag (#15467), naming the gap in commits and the days since that tag; it stays silent while `release.ahead_minutes` exceeds the wait, and with no release tag at all. | |
| 292 | 292 | |
| 293 | 293 | ## A release proves itself |
| 294 | 294 |
src/flow/alarm_main_ahead.ts +34 −7
| @@ -14,6 +14,7 @@ import { neverTickedLine, outsideDependencies } from "../keeper/at_boot.ts"; | ||
| 14 | 14 | import { agoWords, lastBeat } from "../keeper/beat.ts"; |
| 15 | 15 | import { ownRepoPath } from "../kernel/own_repo.ts"; |
| 16 | 16 | import { running } from "../kernel/version.ts"; |
| 17 | import { tagAhead } from "../release/behind.ts"; | |
| 17 | 18 | import { waitingKeys, waitingRows } from "../release/landings.ts"; |
| 18 | 19 | |
| 19 | 20 | export const AHEAD_SETTING = "release.ahead_minutes"; |
| @@ -85,6 +86,23 @@ function checkedSince( | ||
| 85 | 86 | return row?.at == null || row.commits === 0 ? undefined : { at: row.at, commits: row.commits }; |
| 86 | 87 | } |
| 87 | 88 | |
| 89 | /** | |
| 90 | * Main's commits past the newest release tag, as the release watch last read them from the git | |
| 91 | * store: the count, when the oldest was committed (ISO), the tag's version and when it was cut. | |
| 92 | */ | |
| 93 | function tagGap(): { readonly since: string; readonly commits: number; readonly version: string; readonly at: number } | undefined { | |
| 94 | const newest = tagAhead(); | |
| 95 | const ahead = newest?.ahead; | |
| 96 | if (newest === undefined || ahead === undefined || ahead.commits < 1) return undefined; | |
| 97 | return { since: new Date(ahead.since).toISOString(), commits: ahead.commits, version: newest.version, at: newest.at }; | |
| 98 | } | |
| 99 | ||
| 100 | /** Whole days, "0 days", "1 day", "2 days": the age of the last tag. */ | |
| 101 | function daysWords(ms: number): string { | |
| 102 | const d = Math.max(0, Math.floor(ms / 86_400_000)); | |
| 103 | return `${d} ${d === 1 ? "day" : "days"}`; | |
| 104 | } | |
| 105 | ||
| 88 | 106 | export function mainAheadAlarm(db: Database, now: Date): MainAheadAlarm { |
| 89 | 107 | const quiet = { fired: false, says: "Production runs main's head, or main's head is not proven green." } as const; |
| 90 | 108 | // The cheap checks first: this runs on every /flow and home request, and the waiting pulls are read only once main's green head is not production's. |
| @@ -96,24 +114,33 @@ export function mainAheadAlarm(db: Database, now: Date): MainAheadAlarm { | ||
| 96 | 114 | const waiting = waitingRows(db); |
| 97 | 115 | // No landings read kept (a cold process, or one whose git read never resolves): the run table |
| 98 | 116 | // says what waits. |
| 99 | const checked = waiting.length === 0 && waitingKeys(db) === undefined ? checkedSince(db, green, prod.commit) : undefined; | |
| 100 | const sinceAt = waiting[0]?.at ?? checked?.at; | |
| 117 | const cold = waiting.length === 0 && waitingKeys(db) === undefined; | |
| 118 | const checked = cold ? checkedSince(db, green, prod.commit) : undefined; | |
| 119 | // Production's commit has no check row here either (#15467): the git store still says how far | |
| 120 | // main is past the newest release tag. No tag (a fresh forge, a fork) is no fallback. | |
| 121 | const tag = cold && checked === undefined ? tagGap() : undefined; | |
| 122 | const sinceAt = waiting[0]?.at ?? checked?.at ?? tag?.since; | |
| 101 | 123 | if (sinceAt === undefined) return quiet; |
| 102 | 124 | const wait = now.getTime() - Date.parse(sinceAt); |
| 103 | 125 | const limit = aheadMinutes(db) * 60_000; |
| 104 | 126 | if (!(wait > limit)) return { fired: false, since: sinceAt, says: `Main is ahead of production ${agoWords(wait).replace(" ago", "")}; not yet due.` }; |
| 105 | const commits = checked?.commits ?? (new Set(waiting.map((r) => r.oid).filter((o) => o !== "")).size || waiting.length); | |
| 127 | const commits = checked?.commits ?? tag?.commits ?? (new Set(waiting.map((r) => r.oid).filter((o) => o !== "")).size || waiting.length); | |
| 106 | 128 | const pulls = waiting.length; |
| 107 | 129 | const beat = lastBeat(db); |
| 108 | 130 | const tick = beat === null ? "never" : agoWords(now.getTime() - Date.parse(beat.at)); |
| 109 | const how = checked === undefined | |
| 110 | ? `${commits} ${commits === 1 ? "commit" : "commits"} and ${pulls} ${pulls === 1 ? "pull" : "pulls"}` | |
| 111 | : `${commits} checked ${commits === 1 ? "commit" : "commits"}`; | |
| 131 | // The tag fallback names the gap in commits and the days since the last tag. | |
| 132 | const tagged = tag === undefined ? undefined : `the last release tag, v${tag.version}, was cut ${daysWords(now.getTime() - tag.at)} ago`; | |
| 133 | const how = tag !== undefined | |
| 134 | ? `${commits} ${commits === 1 ? "commit" : "commits"}` | |
| 135 | : checked === undefined | |
| 136 | ? `${commits} ${commits === 1 ? "commit" : "commits"} and ${pulls} ${pulls === 1 ? "pull" : "pulls"}` | |
| 137 | : `${commits} checked ${commits === 1 ? "commit" : "commits"}`; | |
| 112 | 138 | const forHow = agoWords(wait).replace(" ago", ""); |
| 113 | 139 | const facts = [ |
| 114 | 140 | `production runs ${prod.version} at ${prod.commit.slice(0, 7)}`, |
| 115 | 141 | `main is green at ${head.slice(0, 7)}, ${how} ahead`, |
| 116 | 142 | `ahead since ${sinceAt}`, |
| 143 | ...(tag === undefined ? [] : [`the last release tag, v${tag.version}, was cut ${new Date(tag.at).toISOString()}`]), | |
| 117 | 144 | // Absolute times: the evidence is commented again only when it changes, not as the clock moves. |
| 118 | 145 | // The tick's reason stays out: these facts are a Sentinel issue's, which may be public; /releases shows it to its readers. |
| 119 | 146 | `the release tick was last heard from ${beat === null ? "never" : `${beat.at} (${beat.outcome})`}`, |
| @@ -125,7 +152,7 @@ export function mainAheadAlarm(db: Database, now: Date): MainAheadAlarm { | ||
| 125 | 152 | return { |
| 126 | 153 | fired: true, |
| 127 | 154 | since: sinceAt, |
| 128 | says: `Main is green and ${how} ahead of production (${prod.version} at ${prod.commit.slice(0, 7)}) for ${forHow}; the release tick was last heard from ${tick}${keeper === undefined ? "" : `; ${keeper}`}.`, | |
| 155 | says: `Main is green and ${how} ahead of production (${prod.version} at ${prod.commit.slice(0, 7)}) for ${forHow}${tagged === undefined ? "" : `; ${tagged}`}; the release tick was last heard from ${tick}${keeper === undefined ? "" : `; ${keeper}`}.`, | |
| 129 | 156 | facts, |
| 130 | 157 | ...(beat === null ? { neverHeard: true as const } : {}), |
| 131 | 158 | }; |
src/release/behind.ts +12
| @@ -135,6 +135,8 @@ export interface Watch { | ||
| 135 | 135 | tick(): Promise<void>; |
| 136 | 136 | /** The cause as of `now`, from what the last tick read. */ |
| 137 | 137 | need(now?: number): BehindNeed | undefined; |
| 138 | /** The newest release and main's commits past it, as the last tick read them. */ | |
| 139 | newest(): Newest | undefined; | |
| 138 | 140 | } |
| 139 | 141 | |
| 140 | 142 | export function watchBehind(o: { |
| @@ -153,6 +155,7 @@ export function watchBehind(o: { | ||
| 153 | 155 | } |
| 154 | 156 | }, |
| 155 | 157 | need: (now = clock()) => behindNeed(o.live(), newest, now), |
| 158 | newest: () => newest, | |
| 156 | 159 | }; |
| 157 | 160 | } |
| 158 | 161 | |
| @@ -167,3 +170,12 @@ export function setBehind(w: Watch | undefined): void { | ||
| 167 | 170 | export function behindStanding(now: number): BehindNeed | undefined { |
| 168 | 171 | return current?.need(now); |
| 169 | 172 | } |
| 173 | ||
| 174 | /** | |
| 175 | * The newest release tag and main's commits past it, from the watch's last read (#15467): the | |
| 176 | * main-ahead flow alarm's fallback when production's commit has no check row. Undefined with no | |
| 177 | * watch set or no tag, so a fresh forge or a fork with no tags stays quiet. | |
| 178 | */ | |
| 179 | export function tagAhead(): Newest | undefined { | |
| 180 | return current?.newest(); | |
| 181 | } |
test/flow-alarm-main-ahead-cold.test.ts +1 −1
| @@ -70,7 +70,7 @@ test("with no landings read kept, main's checks after production's commit fire t | ||
| 70 | 70 | expect(a.says).toContain("3 checked commits ahead"); |
| 71 | 71 | }); |
| 72 | 72 | |
| 73 | test("not yet due inside the limit, and a remaining silent path: quiet when production's commit was never checked here", () => { | |
| 73 | test("not yet due inside the limit, and quiet when production's commit was never checked here and no release tag was read", () => { | |
| 74 | 74 | reset(); |
| 75 | 75 | check(60, PROD); |
| 76 | 76 | check(30, "2".repeat(40)); |
test/release-behind-main-ahead.test.ts +53 −1
| @@ -1,7 +1,8 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * Production serving the newest release tag while main stands hundreds of commits past it is the |
| 3 | 3 | * one `release:behind` cause, read from the git store; a release cut at main's tip and served |
| 4 | * clears it (#15445: v0.7.629 live, main at v0.7.629-369). | |
| 4 | * clears it (#15445: v0.7.629 live, main at v0.7.629-369). The main-ahead flow alarm falls back to | |
| 5 | * the same count when production's commit has no check row here (#15467). | |
| 5 | 6 | */ |
| 6 | 7 | |
| 7 | 8 | import { afterAll, beforeAll, expect, test } from "bun:test"; |
| @@ -9,6 +10,10 @@ import { mkdtemp, rm } from "node:fs/promises"; | ||
| 9 | 10 | import { tmpdir } from "node:os"; |
| 10 | 11 | import { join } from "node:path"; |
| 11 | 12 | import { createApp, type App } from "../src/app.ts"; |
| 13 | import { createRepo } from "../src/core/repos.ts"; | |
| 14 | import { createUser } from "../src/core/users.ts"; | |
| 15 | import { mainAheadAlarm } from "../src/flow/alarm_main_ahead.ts"; | |
| 16 | import { id } from "../src/kernel/id.ts"; | |
| 12 | 17 | import { vitals } from "../src/kernel/vitals.ts"; |
| 13 | 18 | import { AHEAD_MS, behindNeed, readAhead, readNewest, setBehind, watchBehind } from "../src/release/behind.ts"; |
| 14 | 19 | import { setTagged } from "../src/release/shipped.ts"; |
| @@ -102,3 +107,50 @@ test("main past the served release for 12 h or less says nothing; one minute mor | ||
| 102 | 107 | // An unstamped forge says nothing, however far main is. |
| 103 | 108 | expect(behindNeed("dev", newest, T0 + 60_000)).toBeUndefined(); |
| 104 | 109 | }); |
| 110 | ||
| 111 | test("the flow alarm with no check row for production's commit falls back to main's commits past the newest tag (#15467)", async () => { | |
| 112 | const saved = { sentinel: process.env["FORGE_SENTINEL_REPO"], commit: process.env["FORGE_COMMIT"], version: process.env["FORGE_VERSION"] }; | |
| 113 | try { | |
| 114 | process.env["FORGE_SENTINEL_REPO"] = "trevato/forge"; | |
| 115 | process.env["FORGE_COMMIT"] = "cab90cf3a9749ab8ba5adfb68693b35c65af09b7"; | |
| 116 | process.env["FORGE_VERSION"] = "0.7.629"; | |
| 117 | const u = await createUser(app.db, { username: "trevato", email: "[email protected]", password: "a-good-passphrase", origin: "seed", trusted: true, adminIfFirst: true }); | |
| 118 | if (!u.ok) throw new Error(u.error); | |
| 119 | const repo = await createRepo(app.db, app.reposRoot, { ownerId: u.value.id, name: "forge", visibility: "public", description: "f" }); | |
| 120 | if (!repo.ok) throw new Error(repo.error); | |
| 121 | // Main's head is green; production's commit was never checked here. | |
| 122 | app.db | |
| 123 | .query(`INSERT INTO run (id, repo_id, kind, env, state, summary, check_detail, commit_oid, created_at, finished_at) VALUES (?1, ?2, 'check', ?3, 'ok', '', '{}', ?4, ?5, ?5)`) | |
| 124 | .run(id(), repo.value.id, repo.value.defaultBranch, "4".repeat(40), new Date(T0 - H).toISOString()); | |
| 125 | const now = new Date(T0); | |
| 126 | ||
| 127 | // No tag read (a fresh forge, a fork with no tags): quiet. | |
| 128 | setBehind(undefined); | |
| 129 | expect(mainAheadAlarm(app.db, now).fired).toBe(false); | |
| 130 | const none = watchBehind({ live: () => "0.7.629", read: async () => undefined, now: () => T0 }); | |
| 131 | setBehind(none); | |
| 132 | await none.tick(); | |
| 133 | expect(mainAheadAlarm(app.db, now).fired).toBe(false); | |
| 134 | ||
| 135 | // The tag read says main is 369 commits past v0.7.629, the oldest 21 h ago: fired, naming both. | |
| 136 | const watch = watchBehind({ | |
| 137 | live: () => "0.7.629", | |
| 138 | read: async () => ({ version: "0.7.629", at: T0 - 30 * H, ahead: (await readAhead(dir, "0.7.629"))! }), | |
| 139 | now: () => T0, | |
| 140 | }); | |
| 141 | setBehind(watch); | |
| 142 | await watch.tick(); | |
| 143 | const a = mainAheadAlarm(app.db, now); | |
| 144 | expect(a.fired).toBe(true); | |
| 145 | expect(a.since).toBe(new Date(secs(T0 - 21 * H) * 1000).toISOString()); | |
| 146 | expect(a.says).toContain("Main is green and 369 commits ahead of production (0.7.629 at cab90cf) for 21 h 0 min"); | |
| 147 | expect(a.says).toContain("the last release tag, v0.7.629, was cut 1 day ago"); | |
| 148 | expect(a.facts).toContain(`the last release tag, v0.7.629, was cut ${new Date(T0 - 30 * H).toISOString()}`); | |
| 149 | setBehind(undefined); | |
| 150 | } finally { | |
| 151 | for (const [k, v] of [["FORGE_SENTINEL_REPO", saved.sentinel], ["FORGE_COMMIT", saved.commit], ["FORGE_VERSION", saved.version]] as const) | |
| 152 | if (v === undefined) delete process.env[k]; | |
| 153 | else process.env[k] = v; | |
| 154 | setBehind(undefined); | |
| 155 | } | |
| 156 | }); |
new above
offline