Public: anyone can read this; the crew can change it.
Daily proof waits for the release's check: a pending line is proved again until it settles #16890
Check · Review · Land · Live done — Landed and live in production.
fix/daily-proof-settles → main 0 commits
3 files
changed +94
−9
src/maintain/duties/daily_proof.ts +22 −5
| @@ -9,7 +9,10 @@ | ||
| 9 | 9 | * has recorded, `SETTLE_MS` after this process booted, so a broken sign-up or price is seen within |
| 10 | 10 | * minutes rather than at the next daily tick. Keyed on the release id, never on boots, and tried |
| 11 | 11 | * at most once per release in this process, so neither a crash loop nor a run that cannot record |
| 12 | * repeats it. | |
| 12 | * repeats it. A line that is UNKNOWN only because the release's check has not finished yet | |
| 13 | * (`stillSettling`: queued, pending, running) is proved again every `SETTLE_RETRY_MS`, up to | |
| 14 | * `SETTLE_TRIES` runs of that release, so the row says what the check said rather than "pending" | |
| 15 | * until the next day. | |
| 13 | 16 | */ |
| 14 | 17 | |
| 15 | 18 | import { ownRepoPath } from "../../kernel/own_repo.ts"; |
| @@ -18,7 +21,7 @@ import { shortOf } from "../../kernel/version.ts"; | ||
| 18 | 21 | import { BUDGET_MS, lastRelease, proveDaily, recordRun, releaseDue, releaseId } from "../../release/daily_proof.ts"; |
| 19 | 22 | import { getSignup } from "../../settings/signup.ts"; |
| 20 | 23 | import { IN_PROCESS, ownFetcher } from "../../release/own_fetch.ts"; |
| 21 | import type { Fetcher, Line, OwnRules } from "../../release/v1_checks.ts"; | |
| 24 | import { stillSettling, type Fetcher, type Line, type OwnRules } from "../../release/v1_checks.ts"; | |
| 22 | 25 | import type { Duty, Finding } from "../duty.ts"; |
| 23 | 26 | |
| 24 | 27 | export interface ProofClock { |
| @@ -30,6 +33,11 @@ export interface ProofClock { | ||
| 30 | 33 | readonly bootedAt?: number; |
| 31 | 34 | } |
| 32 | 35 | |
| 36 | /** How long a release's proof waits before it reads a still-settling line again. */ | |
| 37 | export const SETTLE_RETRY_MS = 10 * 60_000; | |
| 38 | /** The most runs one release's proof makes while a line still settles: 40 minutes of retries. */ | |
| 39 | export const SETTLE_TRIES = 5; | |
| 40 | ||
| 33 | 41 | /** A release as a row says it: a commit by its short id, a version as it is. */ |
| 34 | 42 | const named = (release: string): string => (/^[0-9a-f]{40,64}$/.test(release) ? shortOf(release) : release); |
| 35 | 43 | |
| @@ -42,6 +50,8 @@ export function dailyProof( | ||
| 42 | 50 | const bootedAt = clock.bootedAt ?? Date.now(); |
| 43 | 51 | // The release this process has started a proof of; a second is never due early. |
| 44 | 52 | let tried: string | null = null; |
| 53 | // While a line of this release's proof still settles: how many runs it has had, and when the next. | |
| 54 | let settling: { readonly release: string; readonly runs: number; readonly at: number } | null = null; | |
| 45 | 55 | const knowsOrigin = (url: string | undefined): url is string => url !== undefined && url !== ""; |
| 46 | 56 | return { |
| 47 | 57 | name: "daily-proof", |
| @@ -49,11 +59,12 @@ export function dailyProof( | ||
| 49 | 59 | // The checks stop themselves at their budget; the runner waits a little past it for the lines. |
| 50 | 60 | timeoutMs: BUDGET_MS + 5_000, |
| 51 | 61 | budget: { |
| 52 | runsPerDay: 24, | |
| 62 | runsPerDay: 48, | |
| 53 | 63 | dollarsPerDay: 1, |
| 54 | reason: "one a day on the clock, and one per release that goes live (#15937), each release once; 24 is room for a busy day of releases and restarts, and a run spends no money, only one minute of reads of the forge's own public pages", | |
| 64 | reason: "one a day on the clock, and one per release that goes live (#15937), each release once, then up to four more while its check has not finished; 48 is room for a busy day of releases and restarts, and a run spends no money, only one minute of reads of the forge's own public pages", | |
| 55 | 65 | }, |
| 56 | 66 | dueNow({ db, now, app }) { |
| 67 | if (release !== null && settling?.release === release && now.getTime() >= settling.at && knowsOrigin(app?.config.url)) return true; | |
| 57 | 68 | if (release === null || tried === release || !knowsOrigin(app?.config.url)) return false; |
| 58 | 69 | return releaseDue(db, release, bootedAt, now.getTime()); |
| 59 | 70 | }, |
| @@ -85,7 +96,13 @@ export function dailyProof( | ||
| 85 | 96 | probe: { kind: "measurement", what: `${l.url}: ${l.verdict === "FAIL" ? "1 is a failure" : "1 is unknown where it passed the day before"}`, number: 1, at: now.toISOString() }, |
| 86 | 97 | })); |
| 87 | 98 | const proved = release === null ? [] : [fresh ? `proved release ${named(release)}, new since the run before` : `proved release ${named(release)}`]; |
| 88 | return { findings, actions: [...proved, ...done.said] }; | |
| 99 | // A line waiting on the release's check is read again soon, a bounded number of times. | |
| 100 | const pending = lines.filter(stillSettling).map((l) => l.item); | |
| 101 | const runs = release !== null && settling?.release === release ? settling.runs + 1 : 1; | |
| 102 | const again = release !== null && pending.length > 0 && runs < SETTLE_TRIES; | |
| 103 | settling = again ? { release, runs, at: now.getTime() + SETTLE_RETRY_MS } : null; | |
| 104 | const waits = again ? [`${pending.join(", ")} still settling: proving release ${named(release)} again at ${new Date(now.getTime() + SETTLE_RETRY_MS).toISOString().slice(11, 16)} UTC`] : []; | |
| 105 | return { findings, actions: [...proved, ...done.said, ...waits] }; | |
| 89 | 106 | }, |
| 90 | 107 | }; |
| 91 | 108 | } |
src/release/v1_checks.ts +10 −1
| @@ -33,6 +33,15 @@ import { SIGNUP_CLOSED_MESSAGE } from "../settings/signup.ts"; | ||
| 33 | 33 | |
| 34 | 34 | export type Verdict = "PASS" | "FAIL" | "UNKNOWN"; |
| 35 | 35 | |
| 36 | /** How a release's check that has not finished is said: `<tag> check is <state>`. */ | |
| 37 | const CHECK_IS = "check is"; | |
| 38 | ||
| 39 | /** | |
| 40 | * Whether a line is UNKNOWN only because the release's check has not finished yet (queued, pending | |
| 41 | * or running): read again a little later, it settles to PASS or FAIL (`maintain/duties/daily_proof.ts`). | |
| 42 | */ | |
| 43 | export const stillSettling = (l: Line): boolean => l.verdict === "UNKNOWN" && new RegExp(`\\b${CHECK_IS} (?!ok$|failed$)\\w+$`).test(l.evidence); | |
| 44 | ||
| 36 | 45 | export interface Line { |
| 37 | 46 | readonly item: string; |
| 38 | 47 | readonly verdict: Verdict; |
| @@ -314,7 +323,7 @@ export async function probe( | ||
| 314 | 323 | } else say("stranger journey green on a release", "UNKNOWN", checkPath, `${why}; a person must open ${tagName}'s check and see the stranger tests green`); |
| 315 | 324 | } else if (c.state === "ok") say("stranger journey green on a release", "PASS", checkPath, `${tagName} (${tagCommit.slice(0, 9)}) full check ok, run ${String(c.runId)}, which runs the stranger tests`); |
| 316 | 325 | else if (c.state === "failed") say("stranger journey green on a release", "FAIL", checkPath, `${tagName} check failed, run ${String(c.runId)}`); |
| 317 | else say("stranger journey green on a release", "UNKNOWN", checkPath, `${tagName} check is ${c.state}`); | |
| 326 | else say("stranger journey green on a release", "UNKNOWN", checkPath, `${tagName} ${CHECK_IS} ${c.state}`); | |
| 318 | 327 | } |
| 319 | 328 | |
| 320 | 329 | // 4. /changelog, /changelog.atom and production's version agree with the newest release. |
test/daily-proof.test.ts +62 −3
| @@ -14,12 +14,12 @@ import { join } from "node:path"; | ||
| 14 | 14 | import { createApp, type App } from "../src/app.ts"; |
| 15 | 15 | import { firedAlarms, FORGE_BROKEN } from "../src/flow/alarms.ts"; |
| 16 | 16 | import { serve, type Servers } from "../src/http/server.ts"; |
| 17 | import { dailyProof } from "../src/maintain/duties/daily_proof.ts"; | |
| 17 | import { dailyProof, SETTLE_RETRY_MS, SETTLE_TRIES } from "../src/maintain/duties/daily_proof.ts"; | |
| 18 | 18 | import { startMaintain } from "../src/maintain/runner.ts"; |
| 19 | 19 | import type { DutyResult } from "../src/maintain/duty.ts"; |
| 20 | 20 | import { lastRun, openAsks, plainEvidence, proofAlarm, proofAnswer, proveDaily, recordRun, SETTLE_MS, tallyWords } from "../src/release/daily_proof.ts"; |
| 21 | 21 | import { IN_PROCESS, ownFetcher } from "../src/release/own_fetch.ts"; |
| 22 | import { HEALTHZ_MS, OUT_OF_BUDGET, type Line } from "../src/release/v1_checks.ts"; | |
| 22 | import { HEALTHZ_MS, OUT_OF_BUDGET, stillSettling, type Line } from "../src/release/v1_checks.ts"; | |
| 23 | 23 | import { getSignup, setSignup } from "../src/settings/signup.ts"; |
| 24 | 24 | import { Session } from "../src/tui/forge.ts"; |
| 25 | 25 | import { statusLines } from "../src/tui/screens/status.ts"; |
| @@ -47,6 +47,8 @@ interface World { | ||
| 47 | 47 | signupBroken?: boolean; |
| 48 | 48 | /** The call (1-based) that never answers and aborts the budget instead. */ |
| 49 | 49 | hangAt?: number; |
| 50 | /** The release's check, as the releases tool states it: `ok` unless a test says otherwise. */ | |
| 51 | checkState?: string; | |
| 50 | 52 | } |
| 51 | 53 | |
| 52 | 54 | /** A forge over a stubbed fetch, answering what the v1 checks read, and recording every call. */ |
| @@ -83,7 +85,7 @@ function stubForge(world: () => World, now: () => number, calls: Calls[], budget | ||
| 83 | 85 | case "/mcp": { |
| 84 | 86 | const call = JSON.parse(String(init?.body)) as { method: string }; |
| 85 | 87 | if (call.method === "tools/call") { |
| 86 | const text = JSON.stringify({ version: "1.0.0", commit: COMMIT, releases: [{ repo: "o/forge", version: "1.0.0", commit: COMMIT }], check: { commit: COMMIT, state: "ok", runId: "r1" } }); | |
| 88 | const text = JSON.stringify({ version: "1.0.0", commit: COMMIT, releases: [{ repo: "o/forge", version: "1.0.0", commit: COMMIT }], check: { commit: COMMIT, state: w.checkState ?? "ok", runId: "r1" } }); | |
| 87 | 89 | return json({ jsonrpc: "2.0", id: 2, result: { content: [{ type: "text", text }] } }); |
| 88 | 90 | } |
| 89 | 91 | return json({ jsonrpc: "2.0", id: 1, result: { serverInfo: { name: "forge", version: "1.0.0" } } }); |
| @@ -278,6 +280,63 @@ describe("once after each release goes live (#15937)", () => { | ||
| 278 | 280 | }); |
| 279 | 281 | }); |
| 280 | 282 | |
| 283 | describe("a release's check that has not finished is read again until it settles, a bounded number of times", () => { | |
| 284 | const A = "d".repeat(40); | |
| 285 | const B = "e".repeat(40); | |
| 286 | const journey = (db: App["db"]) => lastRun(db)!.lines.find((l) => l.item === "stranger journey green on a release")!; | |
| 287 | ||
| 288 | test("pending, then ok: the release is proved again after SETTLE_RETRY_MS and the line reads PASS; no run after", async () => { | |
| 289 | const sub = createApp({ dataDir: join(dir, "settle-app"), port: 0, url: `${BASE}/`, forgeRepo: "o/forge" }); | |
| 290 | sub.db.run("INSERT INTO keeper_release (version, sha, known_good_version, known_good_image, stage, cut_at) VALUES ('1.0.0', ?1, '', '', 'verified', '2026-11-01T00:00:00Z')", [COMMIT]); | |
| 291 | const runs = () => (sub.db.query("SELECT COUNT(*) AS n FROM daily_proof_run").get() as { n: number }).n; | |
| 292 | let clock = T0; | |
| 293 | let state = "pending"; | |
| 294 | const budget = new AbortController(); | |
| 295 | const duty = dailyProof(stubForge(() => ({ checkState: state }), () => clock, [], budget), () => budget.signal, { release: A, bootedAt: T0 }); | |
| 296 | const m = startMaintain(sub, { duties: [duty], everyMs: 1e9 }); | |
| 297 | m.stop(); | |
| 298 | const tick = (at: number) => m.tick(new Date((clock = at))); | |
| 299 | ||
| 300 | await tick(T0 + SETTLE_MS); | |
| 301 | expect(runs()).toBe(1); | |
| 302 | expect(journey(sub.db)).toMatchObject({ verdict: "UNKNOWN", evidence: "v1.0.0 check is pending" }); | |
| 303 | // Not before the retry is due. | |
| 304 | await tick(T0 + SETTLE_MS + SETTLE_RETRY_MS - 1); | |
| 305 | expect(runs()).toBe(1); | |
| 306 | // The check finished meanwhile: the next proof reads it, and nothing is pending after. | |
| 307 | state = "ok"; | |
| 308 | await tick(T0 + SETTLE_MS + SETTLE_RETRY_MS); | |
| 309 | expect(runs()).toBe(2); | |
| 310 | expect(journey(sub.db).verdict).toBe("PASS"); | |
| 311 | await tick(T0 + SETTLE_MS + 3 * SETTLE_RETRY_MS); | |
| 312 | expect(runs()).toBe(2); | |
| 313 | sub.close(); | |
| 314 | }); | |
| 315 | ||
| 316 | test("a check that stays pending is proved SETTLE_TRIES times for the release, then waits for the daily tick", async () => { | |
| 317 | const sub = createApp({ dataDir: join(dir, "settle-cap-app"), port: 0, url: `${BASE}/`, forgeRepo: "o/forge" }); | |
| 318 | const runs = () => (sub.db.query("SELECT COUNT(*) AS n FROM daily_proof_run").get() as { n: number }).n; | |
| 319 | let clock = T0; | |
| 320 | const budget = new AbortController(); | |
| 321 | const duty = dailyProof(stubForge(() => ({ checkState: "running" }), () => clock, [], budget), () => budget.signal, { release: B, bootedAt: T0 }); | |
| 322 | const m = startMaintain(sub, { duties: [duty], everyMs: 1e9 }); | |
| 323 | m.stop(); | |
| 324 | for (let i = 0; i <= SETTLE_TRIES + 2; i++) await m.tick(new Date((clock = T0 + SETTLE_MS + i * SETTLE_RETRY_MS))); | |
| 325 | expect(runs()).toBe(SETTLE_TRIES); | |
| 326 | expect(journey(sub.db).evidence).toBe("v1.0.0 check is running"); | |
| 327 | sub.close(); | |
| 328 | }); | |
| 329 | ||
| 330 | test("only a check not yet finished settles; an UNKNOWN for any other reason, ok or failed, does not", () => { | |
| 331 | const line = (verdict: Line["verdict"], evidence: string): Line => ({ item: "x", verdict, url: "/", evidence }); | |
| 332 | expect(stillSettling(line("UNKNOWN", "v1.0.0 check is pending"))).toBe(true); | |
| 333 | expect(stillSettling(line("UNKNOWN", "v1.0.0 check is queued"))).toBe(true); | |
| 334 | expect(stillSettling(line("UNKNOWN", "no heartbeat yet: the release tick has not reported"))).toBe(false); | |
| 335 | expect(stillSettling(line("PASS", "v1.0.0 check is pending"))).toBe(false); | |
| 336 | expect(stillSettling(line("UNKNOWN", "v1.0.0 check is ok"))).toBe(false); | |
| 337 | }); | |
| 338 | }); | |
| 339 | ||
| 281 | 340 | describe("a line that got no answer is UNKNOWN, never FAIL (#15947)", () => { |
| 282 | 341 | /** The green stub forge, with `/healthz` swapped for `healthz`. */ |
| 283 | 342 | const withHealthz = (healthz: () => Promise<Response>) => { |
new above
offline