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

Merged opened this

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

Merged

fix/daily-proof-settles → main 0 commits

  • Merged. fix/daily-proof-settles was merged into main as 8928766.

Review

Sign in to review this change.
3 files changed +94 −9
src/maintain/duties/daily_proof.ts +22 −5
@@ -9,7 +9,10 @@
99 * has recorded, `SETTLE_MS` after this process booted, so a broken sign-up or price is seen within
1010 * minutes rather than at the next daily tick. Keyed on the release id, never on boots, and tried
1111 * 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.
1316 */
1417
1518 import { ownRepoPath } from "../../kernel/own_repo.ts";
@@ -18,7 +21,7 @@ import { shortOf } from "../../kernel/version.ts";
1821 import { BUDGET_MS, lastRelease, proveDaily, recordRun, releaseDue, releaseId } from "../../release/daily_proof.ts";
1922 import { getSignup } from "../../settings/signup.ts";
2023 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";
2225 import type { Duty, Finding } from "../duty.ts";
2326
2427 export interface ProofClock {
@@ -30,6 +33,11 @@ export interface ProofClock {
3033 readonly bootedAt?: number;
3134 }
3235
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
3341 /** A release as a row says it: a commit by its short id, a version as it is. */
3442 const named = (release: string): string => (/^[0-9a-f]{40,64}$/.test(release) ? shortOf(release) : release);
3543
@@ -42,6 +50,8 @@ export function dailyProof(
4250 const bootedAt = clock.bootedAt ?? Date.now();
4351 // The release this process has started a proof of; a second is never due early.
4452 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;
4555 const knowsOrigin = (url: string | undefined): url is string => url !== undefined && url !== "";
4656 return {
4757 name: "daily-proof",
@@ -49,11 +59,12 @@ export function dailyProof(
4959 // The checks stop themselves at their budget; the runner waits a little past it for the lines.
5060 timeoutMs: BUDGET_MS + 5_000,
5161 budget: {
52 runsPerDay: 24,
62 runsPerDay: 48,
5363 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",
5565 },
5666 dueNow({ db, now, app }) {
67 if (release !== null && settling?.release === release && now.getTime() >= settling.at && knowsOrigin(app?.config.url)) return true;
5768 if (release === null || tried === release || !knowsOrigin(app?.config.url)) return false;
5869 return releaseDue(db, release, bootedAt, now.getTime());
5970 },
@@ -85,7 +96,13 @@ export function dailyProof(
8596 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() },
8697 }));
8798 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] };
89106 },
90107 };
91108 }
src/release/v1_checks.ts +10 −1
@@ -33,6 +33,15 @@ import { SIGNUP_CLOSED_MESSAGE } from "../settings/signup.ts";
3333
3434 export type Verdict = "PASS" | "FAIL" | "UNKNOWN";
3535
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
3645 export interface Line {
3746 readonly item: string;
3847 readonly verdict: Verdict;
@@ -314,7 +323,7 @@ export async function probe(
314323 } else say("stranger journey green on a release", "UNKNOWN", checkPath, `${why}; a person must open ${tagName}'s check and see the stranger tests green`);
315324 } 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`);
316325 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}`);
318327 }
319328
320329 // 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";
1414 import { createApp, type App } from "../src/app.ts";
1515 import { firedAlarms, FORGE_BROKEN } from "../src/flow/alarms.ts";
1616 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";
1818 import { startMaintain } from "../src/maintain/runner.ts";
1919 import type { DutyResult } from "../src/maintain/duty.ts";
2020 import { lastRun, openAsks, plainEvidence, proofAlarm, proofAnswer, proveDaily, recordRun, SETTLE_MS, tallyWords } from "../src/release/daily_proof.ts";
2121 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";
2323 import { getSignup, setSignup } from "../src/settings/signup.ts";
2424 import { Session } from "../src/tui/forge.ts";
2525 import { statusLines } from "../src/tui/screens/status.ts";
@@ -47,6 +47,8 @@ interface World {
4747 signupBroken?: boolean;
4848 /** The call (1-based) that never answers and aborts the budget instead. */
4949 hangAt?: number;
50 /** The release's check, as the releases tool states it: `ok` unless a test says otherwise. */
51 checkState?: string;
5052 }
5153
5254 /** 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
8385 case "/mcp": {
8486 const call = JSON.parse(String(init?.body)) as { method: string };
8587 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" } });
8789 return json({ jsonrpc: "2.0", id: 2, result: { content: [{ type: "text", text }] } });
8890 }
8991 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)", () => {
278280 });
279281 });
280282
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
281340 describe("a line that got no answer is UNKNOWN, never FAIL (#15947)", () => {
282341 /** The green stub forge, with `/healthz` swapped for `healthz`. */
283342 const withHealthz = (healthz: () => Promise<Response>) => {

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

Keyboard shortcuts

Docs