Public: anyone can read this; the crew can change it.
Production is 366 commits behind main: find why releases stopped and why the behind-main alarm stayed quiet #15446
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15443-production-is-366-commits-behind-main-fi → main 0 commits fork 1 thread · 1 unresolved
3 files
changed +163
−14
docs/OPERATING.md +2
| @@ -288,6 +288,8 @@ 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), and the way to find it is `keeper_beat_tick`'s last reason on `/releases` as the owner. 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. | |
| 292 | ||
| 291 | 293 | ## A release proves itself |
| 292 | 294 | |
| 293 | 295 | A new version proves itself once per version: after a boot that changes |
src/flow/alarm_main_ahead.ts +50 −14
| @@ -14,7 +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 { waitingRows } from "../release/landings.ts"; | |
| 17 | import { waitingKeys, waitingRows } from "../release/landings.ts"; | |
| 18 | 18 | |
| 19 | 19 | export const AHEAD_SETTING = "release.ahead_minutes"; |
| 20 | 20 | export const AHEAD_DEFAULT_MIN = 90; |
| @@ -40,8 +40,17 @@ export function aheadMinutes(db: Database): number { | ||
| 40 | 40 | return Number.isInteger(n) && n >= 1 && n <= 10_080 ? n : AHEAD_DEFAULT_MIN; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | /** The commit of the last finished check of the forge's default branch, when that check passed. */ | |
| 44 | function greenHead(db: Database): string | undefined { | |
| 43 | /** | |
| 44 | * The forge's own repository and the commit of its default branch's last finished check, when that | |
| 45 | * check passed. | |
| 46 | */ | |
| 47 | interface GreenHead { | |
| 48 | readonly repoId: string; | |
| 49 | readonly branch: string; | |
| 50 | readonly head: string; | |
| 51 | } | |
| 52 | ||
| 53 | function greenHead(db: Database): GreenHead | undefined { | |
| 45 | 54 | const [owner, name] = ownRepoPath().split("/"); |
| 46 | 55 | const repo = owner && name ? getRepo(db, owner, name) : undefined; |
| 47 | 56 | if (repo === undefined) return undefined; |
| @@ -52,7 +61,28 @@ function greenHead(db: Database): string | undefined { | ||
| 52 | 61 | ORDER BY id DESC LIMIT 1`, |
| 53 | 62 | ) |
| 54 | 63 | .get(repo.id, repo.defaultBranch); |
| 55 | return last?.state === "ok" ? last.commit_oid : undefined; | |
| 64 | return last?.state === "ok" ? { repoId: repo.id, branch: repo.defaultBranch, head: last.commit_oid } : undefined; | |
| 65 | } | |
| 66 | ||
| 67 | /** | |
| 68 | * What waits, from the run table alone (#15443): the main checks made after the newest check of | |
| 69 | * production's commit, as when they began and how many commits. Read only while no landings | |
| 70 | * read has been kept, so a git read that never resolves cannot keep the alarm quiet for days; | |
| 71 | * undefined when production's commit was never checked here. | |
| 72 | */ | |
| 73 | function checkedSince( | |
| 74 | db: Database, | |
| 75 | g: Pick<GreenHead, "repoId" | "branch">, | |
| 76 | prod: string, | |
| 77 | ): { readonly at: string; readonly commits: number } | undefined { | |
| 78 | const row = db | |
| 79 | .query<{ at: string | null; commits: number }, [string, string, string]>( | |
| 80 | `SELECT MIN(created_at) AS at, COUNT(DISTINCT commit_oid) AS commits FROM run | |
| 81 | WHERE repo_id = ?1 AND kind = 'check' AND issue_id IS NULL AND env = ?2 AND substr(commit_oid, 1, length(?3)) != ?3 | |
| 82 | AND id > (SELECT MAX(id) FROM run WHERE repo_id = ?1 AND kind = 'check' AND issue_id IS NULL AND env = ?2 AND substr(commit_oid, 1, length(?3)) = ?3)`, | |
| 83 | ) | |
| 84 | .get(g.repoId, g.branch, prod); | |
| 85 | return row?.at == null || row.commits === 0 ? undefined : { at: row.at, commits: row.commits }; | |
| 56 | 86 | } |
| 57 | 87 | |
| 58 | 88 | export function mainAheadAlarm(db: Database, now: Date): MainAheadAlarm { |
| @@ -60,24 +90,30 @@ export function mainAheadAlarm(db: Database, now: Date): MainAheadAlarm { | ||
| 60 | 90 | // 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. |
| 61 | 91 | const prod = running(); |
| 62 | 92 | if (prod.commit === null) return quiet; |
| 63 | const head = greenHead(db); | |
| 64 | if (head === undefined || head.startsWith(prod.commit) || prod.commit.startsWith(head)) return quiet; | |
| 93 | const green = greenHead(db); | |
| 94 | const head = green?.head; | |
| 95 | if (green === undefined || head === undefined || head.startsWith(prod.commit) || prod.commit.startsWith(head)) return quiet; | |
| 65 | 96 | const waiting = waitingRows(db); |
| 66 | const first = waiting[0]; | |
| 67 | if (first === undefined) return quiet; | |
| 68 | const wait = now.getTime() - Date.parse(first.at); | |
| 97 | // No landings read kept (a cold process, or one whose git read never resolves): the run table | |
| 98 | // 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; | |
| 101 | if (sinceAt === undefined) return quiet; | |
| 102 | const wait = now.getTime() - Date.parse(sinceAt); | |
| 69 | 103 | const limit = aheadMinutes(db) * 60_000; |
| 70 | if (!(wait > limit)) return { fired: false, since: first.at, says: `Main is ahead of production ${agoWords(wait).replace(" ago", "")}; not yet due.` }; | |
| 71 | const commits = new Set(waiting.map((r) => r.oid).filter((o) => o !== "")).size || waiting.length; | |
| 104 | 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); | |
| 72 | 106 | const pulls = waiting.length; |
| 73 | 107 | const beat = lastBeat(db); |
| 74 | 108 | const tick = beat === null ? "never" : agoWords(now.getTime() - Date.parse(beat.at)); |
| 75 | const how = `${commits} ${commits === 1 ? "commit" : "commits"} and ${pulls} ${pulls === 1 ? "pull" : "pulls"}`; | |
| 109 | const how = checked === undefined | |
| 110 | ? `${commits} ${commits === 1 ? "commit" : "commits"} and ${pulls} ${pulls === 1 ? "pull" : "pulls"}` | |
| 111 | : `${commits} checked ${commits === 1 ? "commit" : "commits"}`; | |
| 76 | 112 | const forHow = agoWords(wait).replace(" ago", ""); |
| 77 | 113 | const facts = [ |
| 78 | 114 | `production runs ${prod.version} at ${prod.commit.slice(0, 7)}`, |
| 79 | 115 | `main is green at ${head.slice(0, 7)}, ${how} ahead`, |
| 80 | `ahead since ${first.at}`, | |
| 116 | `ahead since ${sinceAt}`, | |
| 81 | 117 | // Absolute times: the evidence is commented again only when it changes, not as the clock moves. |
| 82 | 118 | // The tick's reason stays out: these facts are a Sentinel issue's, which may be public; /releases shows it to its readers. |
| 83 | 119 | `the release tick was last heard from ${beat === null ? "never" : `${beat.at} (${beat.outcome})`}`, |
| @@ -88,7 +124,7 @@ export function mainAheadAlarm(db: Database, now: Date): MainAheadAlarm { | ||
| 88 | 124 | if (keeper !== undefined) facts.push(keeper); |
| 89 | 125 | return { |
| 90 | 126 | fired: true, |
| 91 | since: first.at, | |
| 127 | since: sinceAt, | |
| 92 | 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}`}.`, |
| 93 | 129 | facts, |
| 94 | 130 | ...(beat === null ? { neverHeard: true as const } : {}), |
test/flow-alarm-main-ahead-cold.test.ts added +111
| @@ -0,0 +1,111 @@ | ||
| 1 | /** | |
| 2 | * The main-ahead alarm with no landings read kept (#15443): production stood 366 commits behind | |
| 3 | * main for a day and a half and the alarm said nothing. With no read of what the running commit | |
| 4 | * contains, the run table still says main moved on: the checks after production's own. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 7 | import { mkdtempSync, rmSync } from "node:fs"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { createApp, type App } from "../src/app.ts"; | |
| 11 | import { createRepo } from "../src/core/repos.ts"; | |
| 12 | import { createUser } from "../src/core/users.ts"; | |
| 13 | import { mainAheadAlarm } from "../src/flow/alarm_main_ahead.ts"; | |
| 14 | import { id } from "../src/kernel/id.ts"; | |
| 15 | import { forgetLive, keepLive } from "../src/release/landings.ts"; | |
| 16 | ||
| 17 | const NOW = new Date("2026-11-22T02:00:00.000Z"); | |
| 18 | const ago = (m: number) => new Date(NOW.getTime() - m * 60_000).toISOString(); | |
| 19 | const PROD = "cab90cf3a9749ab8ba5adfb68693b35c65af09b7"; | |
| 20 | ||
| 21 | let root: string; | |
| 22 | let app: App; | |
| 23 | let repoId: string; | |
| 24 | let branch: string; | |
| 25 | let n = 0; | |
| 26 | const saved = { sentinel: process.env["FORGE_SENTINEL_REPO"], commit: process.env["FORGE_COMMIT"], version: process.env["FORGE_VERSION"] }; | |
| 27 | ||
| 28 | beforeAll(async () => { | |
| 29 | process.env["FORGE_SENTINEL_REPO"] = "trevato/forge"; | |
| 30 | process.env["FORGE_COMMIT"] = PROD; | |
| 31 | process.env["FORGE_VERSION"] = "0.7.629"; | |
| 32 | root = mkdtempSync(join(tmpdir(), "forge-main-ahead-cold-")); | |
| 33 | app = createApp({ dataDir: root, port: 0 }); | |
| 34 | const u = await createUser(app.db, { username: "trevato", email: "[email protected]", password: "a-good-passphrase", origin: "seed", trusted: true, adminIfFirst: true }); | |
| 35 | if (!u.ok) throw new Error(u.error); | |
| 36 | const repo = await createRepo(app.db, app.reposRoot, { ownerId: u.value.id, name: "forge", visibility: "public", description: "f" }); | |
| 37 | if (!repo.ok) throw new Error(repo.error); | |
| 38 | repoId = repo.value.id; | |
| 39 | branch = repo.value.defaultBranch; | |
| 40 | }); | |
| 41 | afterAll(() => { | |
| 42 | forgetLive(app.db); | |
| 43 | app.close(); | |
| 44 | rmSync(root, { recursive: true, force: true }); | |
| 45 | for (const [k, v] of [["FORGE_SENTINEL_REPO", saved.sentinel], ["FORGE_COMMIT", saved.commit], ["FORGE_VERSION", saved.version]] as const) | |
| 46 | if (v === undefined) delete process.env[k]; | |
| 47 | else process.env[k] = v; | |
| 48 | }); | |
| 49 | ||
| 50 | function check(minAgo: number, oid: string, state: "ok" | "failed" = "ok"): void { | |
| 51 | app.db | |
| 52 | .query(`INSERT INTO run (id, repo_id, kind, env, state, summary, check_detail, commit_oid, created_at, finished_at) VALUES (?1, ?2, 'check', ?3, ?4, '', '{}', ?5, ?6, ?6)`) | |
| 53 | .run(`${String(++n).padStart(4, "0")}${id()}`, repoId, branch, state, oid, ago(minAgo)); | |
| 54 | } | |
| 55 | const reset = () => { | |
| 56 | app.db.query(`DELETE FROM run`).run(); | |
| 57 | forgetLive(app.db); | |
| 58 | }; | |
| 59 | ||
| 60 | test("with no landings read kept, main's checks after production's commit fire the alarm", () => { | |
| 61 | reset(); | |
| 62 | check(2000, PROD); | |
| 63 | check(1990, "2".repeat(40)); | |
| 64 | check(600, "3".repeat(40), "failed"); | |
| 65 | check(5, "4".repeat(40)); | |
| 66 | const a = mainAheadAlarm(app.db, NOW); | |
| 67 | expect(a.fired).toBe(true); | |
| 68 | expect(a.since).toBe(ago(1990)); | |
| 69 | expect(a.says).toContain("0.7.629 at cab90cf"); | |
| 70 | expect(a.says).toContain("3 checked commits ahead"); | |
| 71 | }); | |
| 72 | ||
| 73 | test("not yet due inside the limit, and a remaining silent path: quiet when production's commit was never checked here", () => { | |
| 74 | reset(); | |
| 75 | check(60, PROD); | |
| 76 | check(30, "2".repeat(40)); | |
| 77 | const a = mainAheadAlarm(app.db, NOW); | |
| 78 | expect(a.fired).toBe(false); | |
| 79 | expect(a.since).toBe(ago(30)); | |
| 80 | reset(); | |
| 81 | check(500, "2".repeat(40)); | |
| 82 | expect(mainAheadAlarm(app.db, NOW).fired).toBe(false); | |
| 83 | }); | |
| 84 | ||
| 85 | test("a kept read that finds nothing on its way is believed over the run table", () => { | |
| 86 | reset(); | |
| 87 | check(2000, PROD); | |
| 88 | check(1990, "2".repeat(40)); | |
| 89 | keepLive(app.db, "trevato/forge", [], NOW.getTime()); | |
| 90 | expect(mainAheadAlarm(app.db, NOW).fired).toBe(false); | |
| 91 | }); | |
| 92 | ||
| 93 | test("the remaining silent paths: a high release.ahead_minutes holds it until the wait passes it", () => { | |
| 94 | reset(); | |
| 95 | check(2000, PROD); | |
| 96 | check(1990, "2".repeat(40)); | |
| 97 | app.db | |
| 98 | .query( | |
| 99 | `INSERT INTO forge_setting (key, value, updated_by, updated_at) VALUES ('release.ahead_minutes', '10080', 'test', 'now') | |
| 100 | ON CONFLICT (key) DO UPDATE SET value = excluded.value`, | |
| 101 | ) | |
| 102 | .run(); | |
| 103 | try { | |
| 104 | const a = mainAheadAlarm(app.db, NOW); | |
| 105 | expect(a.fired).toBe(false); | |
| 106 | expect(a.since).toBe(ago(1990)); | |
| 107 | } finally { | |
| 108 | app.db.query(`DELETE FROM forge_setting WHERE key = 'release.ahead_minutes'`).run(); | |
| 109 | } | |
| 110 | expect(mainAheadAlarm(app.db, NOW).fired).toBe(true); | |
| 111 | }); |
new above
offline
This reads as a settled cause, but the pull says it was not confirmed: the stop is one of a standing hold, a stuck gate, a rolling release or a dead keeper. Mark it unconfirmed, or name the real one. The issue asked for a line; this is a paragraph. Also: the alarm now falls back to main checks, so say which silent paths remain.