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

With the weekly window full, the forge runs a model-free measurement and /week counts it #16783

Merged opened this

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

Merged

scout/forge:scout/15911-with-the-weekly-window-full-the-forge-ru → main 0 commits fork 1 thread · 1 unresolved

  • Merged. scout/15911-with-the-weekly-window-full-the-forge-ru was merged into main as 7bffc31.

Review

Sign in to review this change.
3 files changed +76 −7
src/checks/full_window_recheck.ts +44 −3
@@ -7,6 +7,7 @@
77 *
88 * Once per green main commit: a pull is rechecked once after each commit of `main` that checked
99 * green, timed by that commit's first green run, so a re-run of one green commit queues nothing.
10 * Beside it, once a day, the full suite runs on main's head ({@link measureWhenFull}, #15911).
1011 * `/week` reads {@link whileFull} back.
1112 */
1213
@@ -16,6 +17,8 @@ import { listOpenPulls } from "../core/pulls.ts";
1617 import type { Repo } from "../core/repos.ts";
1718 import { getHold } from "../core/holds.ts";
1819 import { crewWeekFor } from "../crew/week_read.ts";
20 import { runGit } from "../git/env.ts";
21 import { repoDir } from "../git/repos.ts";
1922 import { checksFor } from "./service.ts";
2023
2124 /** The reason of the check this queues. */
@@ -79,9 +82,41 @@ export async function recheckWhenFull(app: App, repo: Repo, now: Date): Promise<
7982 return crewWeekFor(app, repo, now)?.slots === 0 ? recheckStaleReds(app, repo) : [];
8083 }
8184
85 /** The reason of the full suite this runs on main's head: the one measurement of a full-window day. */
86 export const MEASURE_REASON = "full_window_measure";
87
88 /** Whether a measurement was already queued today (UTC), so one full-window day holds one at most. */
89 function measuredToday(db: Database, repoId: string, now: Date): boolean {
90 const day = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate())).toISOString();
91 const row = db
92 .query<{ n: number }, [string, string]>(
93 `SELECT COUNT(*) AS n FROM run WHERE repo_id = ?1 AND kind = 'check' AND reason = '${MEASURE_REASON}'
94 AND created_at >= ?2`,
95 )
96 .get(repoId, day);
97 return (row?.n ?? 0) > 0;
98 }
99
100 /**
101 * Run the full suite on main's head, once a day while the week has no slot: it needs no model, and
102 * its time and result are what the forge knows of itself while it waits. True when one was queued.
103 */
104 export async function measureWhenFull(app: App, repo: Repo, now: Date): Promise<boolean> {
105 if (crewWeekFor(app, repo, now)?.slots !== 0) return false;
106 const checks = checksFor(app);
107 if (checks === undefined || measuredToday(app.db, repo.id, now)) return false;
108 const bare = repoDir(app.reposRoot, repo.ownerName, repo.name);
109 const tip = await runGit(["rev-parse", "--verify", "--quiet", `refs/heads/${repo.defaultBranch}^{commit}`], { cwd: bare });
110 const oid = tip.ok ? tip.value.trim() : "";
111 if (!/^[0-9a-f]{40,64}$/.test(oid)) return false;
112 const run = await checks.request(repo, repo.defaultBranch, oid, MEASURE_REASON);
113 return run?.reason === MEASURE_REASON;
114 }
115
82116 export interface WhileFull {
83117 readonly rechecks: number;
84118 readonly landed: number;
119 readonly measurements: number;
85120 }
86121
87122 /**
@@ -98,12 +133,18 @@ export function whileFull(db: Database, repoId: string, now: Date): WhileFull {
98133 WHERE r.repo_id = ?1 AND r.kind = 'check' AND r.reason = '${STALE_RED_REASON}' AND r.created_at >= ?2`,
99134 )
100135 .get(repoId, since);
101 return { rechecks: row?.n ?? 0, landed: row?.landed ?? 0 };
136 const m = db
137 .query<{ n: number }, [string, string]>(
138 `SELECT COUNT(*) AS n FROM run WHERE repo_id = ?1 AND kind = 'check' AND reason = '${MEASURE_REASON}'
139 AND created_at >= ?2`,
140 )
141 .get(repoId, since);
142 return { rechecks: row?.n ?? 0, landed: row?.landed ?? 0, measurements: m?.n ?? 0 };
102143 }
103144
104145 /** The `/week` line, or null when nothing ran. */
105146 export function whileFullLine(w: WhileFull): string | null {
106 if (w.rechecks === 0) return null;
147 if (w.rechecks === 0 && w.measurements === 0) return null;
107148 const s = (n: number, one: string, many: string) => `${n} ${n === 1 ? one : many}`;
108 return `While the window was full: ${s(w.rechecks, "recheck", "rechecks")}, ${w.landed} landed.`;
149 return `While the window was full: ${s(w.rechecks, "recheck", "rechecks")}, ${w.landed} landed${w.measurements > 0 ? `, ${s(w.measurements, "measurement", "measurements")}` : ""}.`;
109150 }
src/crew/autonomy.ts +8 −1
@@ -161,7 +161,7 @@ import { sweepRepeats } from "./repeat_checks.ts";
161161 import { breathe } from "../kernel/breathe.ts";
162162 import { keepBatch } from "../flow/red_batches.ts";
163163 import { recordQueueFlakes } from "../checks/flake.ts";
164 import { recheckWhenFull } from "../checks/full_window_recheck.ts";
164 import { measureWhenFull, recheckWhenFull } from "../checks/full_window_recheck.ts";
165165 import { sharedVitals, vitalsMisses, vitalsWords } from "../flow/vitals.ts";
166166 import { moveRequested, tallyRequested, tallyWords } from "./requested.ts";
167167 import { passLanded } from "./box_pass.ts";
@@ -1414,6 +1414,13 @@ export async function autonomyTick(
14141414 error: String(error),
14151415 });
14161416 });
1417 // And once a day the full suite on main's head, so the idle week still measures (#15911).
1418 await measureWhenFull(app, current, now).catch((error) => {
1419 log.error("full-window measurement failed", {
1420 repo: `${repo.ownerName}/${repo.name}`,
1421 error: String(error),
1422 });
1423 });
14171424 // What reviewers keep asking for becomes an issue to automate it (#8716).
14181425 try {
14191426 await sweepRepeats(app, current, now);
test/full-window-recheck.test.ts +24 −3
@@ -11,7 +11,7 @@ import { openIssue } from "../src/actions/issues.ts";
1111 import { openPull } from "../src/actions/pulls.ts";
1212 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
1313 import { provideChecksForTest, type ChecksHandle } from "../src/checks/service.ts";
14 import { recheckStaleReds, recheckWhenFull, STALE_RED_REASON, whileFull, whileFullLine } from "../src/checks/full_window_recheck.ts";
14 import { measureWhenFull, MEASURE_REASON, recheckStaleReds, recheckWhenFull, STALE_RED_REASON, whileFull, whileFullLine } from "../src/checks/full_window_recheck.ts";
1515 import { getPull } from "../src/core/pulls.ts";
1616 import type { Repo } from "../src/core/repos.ts";
1717 import { createUser, type User } from "../src/core/users.ts";
@@ -121,8 +121,29 @@ test("the line counts rechecks and the one that landed, on the page's wording an
121121 expect(w.landed).toBe(1);
122122 const line = `While the window was full: ${rows.length} rechecks, 1 landed.`;
123123 expect(whileFullLine(w)).toBe(line);
124 expect(whileFullLine({ rechecks: 1, landed: 0 })).toBe("While the window was full: 1 recheck, 0 landed.");
125 expect(whileFullLine({ rechecks: 0, landed: 0 })).toBeNull();
124 expect(whileFullLine({ rechecks: 1, landed: 0, measurements: 0 })).toBe("While the window was full: 1 recheck, 0 landed.");
125 expect(whileFullLine({ rechecks: 0, landed: 0, measurements: 0 })).toBeNull();
126126 // Both doors print the same words: the terminal's lines are the line.
127127 expect(fullWindowLines({ db: app.db }, repo)).toEqual([line]);
128128 });
129
130 const measures = () =>
131 app.db.query<{ n: number }, []>(`SELECT COUNT(*) AS n FROM run WHERE reason = '${MEASURE_REASON}'`).get()!.n;
132
133 test("a measurement is queued once a day with the window full, never with a free slot", async () => {
134 spendWeek(10);
135 expect(await measureWhenFull(app, repo, new Date())).toBe(false);
136 expect(measures()).toBe(0);
137 spendWeek(100);
138 expect(await measureWhenFull(app, repo, new Date())).toBe(true);
139 expect(measures()).toBe(1);
140 expect(await measureWhenFull(app, repo, new Date())).toBe(false);
141 expect(measures()).toBe(1);
142 });
143
144 test("the line counts the measurement", () => {
145 const w = whileFull(app.db, repo.id, new Date());
146 expect(w.measurements).toBe(1);

This test passes only because the previous test ran first and queued the measurement. Seed a run here so it stands alone.

147 expect(whileFullLine({ rechecks: 6, landed: 2, measurements: 1 })).toBe("While the window was full: 6 rechecks, 2 landed, 1 measurement.");
148 expect(whileFullLine({ rechecks: 0, landed: 0, measurements: 2 })).toBe("While the window was full: 0 rechecks, 0 landed, 2 measurements.");
149 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs