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

The release keeper cuts main's verify short: its cut never waits for main's r… #17314

opened this in answer to

Merged 41h 48m ago, live in production

torque/forge:torque/17311-the-release-keeper-cuts-main-s-verify-sh → main 0 commits fork

  • Merged. torque/17311-the-release-keeper-cuts-main-s-verify-sh was merged into main as faab496.

Review

Sign in to review this change.
5 files changed +76 −12
docs/features/release-keeper.md +10 −2
@@ -98,12 +98,20 @@ files one issue, `Release <version> was dark for <n> s`.
9898 (`release_hold {lift: <id>}`, the card's Lift button, `h` then `lift N`) — one function, `holdAs`/`liftAs`, behind all three.
9999 It needs a person who may roll back (MCP: on an admin-scope token); an agent never can.
100100
101 ## A cut waits for main's check (#16966)
102
103 A swap aborts the hour-long verify and queues it again from nothing, so the
104 keeper does not cut while a check of main (its own, the verify or a bisect step)
105 runs: from the first tick that found it, for at most two hours
106 (`MAIN_CHECK_WAIT_MS`, the landing path's). The beat line says `main's check is
107 running (69m of 120m)`.
108
101109 ## A hotfix does not wait (#11839)
102110
103111 `release_now {reason}` (MCP, admin scope), the **Release now** form on the
104112 `/releases` card: a person who may roll back (never an agent) asks for a cut at
105 the next tick. It skips the 30-minute spacing, a running merge queue and a
106 snapshot; it still waits for a release in flight to be proven, for a hold and
113 the next tick. It skips the 30-minute spacing, a running merge queue, a
114 snapshot and main's running check (#16966); it still waits for a release in flight to be proven, for a hold and
107115 for room on the disk. The request lapses after an hour if main had nothing to
108116 cut; the reason is kept on the release (`hotfix`) and shown on the card.
109117
src/keeper/cadence.ts +12
@@ -8,6 +8,8 @@
88 * ∧ no merge-queue gate is running (the queue is not mid-landing)
99 * ∧ no snapshot is being taken, unless it has run `SNAPSHOT_WAIT_MS`
1010 * ∧ no crew run is running, unless the keeper has waited on them `CREW_WAIT_MS`
11 * ∧ no check of main is running, unless the keeper has waited on it `MAIN_CHECK_WAIT_MS`
12 * (#16966: a swap cuts the hour-long verify and queues it again from nothing)
1113 * ∧ now − the last cut ≥ the minimum interval, or `PAUSE_CADENCE_FACTOR` × the last
1214 * release's write pause when that is longer (#7836)
1315 * ∧ no hold stands (a failed verify's, or an owner's)
@@ -21,6 +23,7 @@
2123 export const MIN_INTERVAL_MS = 30 * 60_000;
2224
2325 import { pauseWords } from "./pause.ts";
26 import { MAIN_CHECK_WAIT_MS } from "../release/main_check_idle.ts";
2427
2528 /**
2629 * The next cut waits this many times the last release's write pause (#7836): 12 minutes held is
@@ -70,6 +73,10 @@ export interface CadenceInput {
7073 readonly crewRuns?: number | undefined;
7174 /** When the keeper first found crew runs running, epoch ms, in the stretch it is still in. */
7275 readonly crewSince?: number | undefined;
76 /** A check of main is running now: its own, the verify or a bisect step. */
77 readonly mainChecking?: boolean | undefined;
78 /** When the keeper first found main's check running, epoch ms, in the stretch it is still in. */
79 readonly mainCheckSince?: number | undefined;
7380 /** When the keeper last cut, epoch ms. */
7481 readonly lastCutAt: number | undefined;
7582 /** The reason of a standing hold, when one stands. */
@@ -121,6 +128,11 @@ export function decideCut(input: CadenceInput): Cadence {
121128 if (waited < CREW_WAIT_MS)
122129 return no(`waiting on ${runs} crew run${runs === 1 ? "" : "s"} (${Math.floor(waited / 60_000)}m of ${CREW_WAIT_MS / 60_000}m)`);
123130 }
131 if (!hotfix && input.mainChecking === true) {
132 const waited = Math.max(0, input.now - (input.mainCheckSince ?? input.now));
133 if (waited < MAIN_CHECK_WAIT_MS)
134 return no(`main's check is running (${Math.floor(waited / 60_000)}m of ${MAIN_CHECK_WAIT_MS / 60_000}m); a release would cut it short`);
135 }
124136 if (input.diskUsed !== undefined && input.diskUsed >= RELEASE_DISK_USED_MAX)
125137 return no(`the disk is ${Math.round(input.diskUsed * 100)}% full; releases pause at ${RELEASE_DISK_USED_MAX * 100}% until room is made`);
126138 const floor = input.minIntervalMs ?? MIN_INTERVAL_MS;
src/keeper/keeper.ts +17 −10
@@ -66,6 +66,8 @@ export interface KeeperPorts {
6666 readonly snapshotting?: () => number | undefined;
6767 /** Crew runs running now, which a release would cut short (#11918); none when unset. */
6868 readonly crewRuns?: () => number;
69 /** A check of main is running, which a release would cut short (#16966); none when unset. */
70 readonly mainChecking?: () => boolean;
6971 /** The share of the forge's disk in use, 0..1; undefined when unread (#11686). */
7072 readonly diskUsed?: () => number | undefined;
7173 readonly deployer: Deployer;
@@ -91,20 +93,21 @@ export interface KeeperPorts {
9193 }
9294
9395 /**
94 * When the keeper first found crew runs running, per forge database (#11918):
95 * the wait counts from there, and starts over once none run.
96 * When the keeper first found crew runs (#11918) or main's check (#16966) running, per forge
97 * database: the wait counts from there, and starts over once none run.
9698 */
9799 const crewSeen = new WeakMap<Database, number>();
100 const mainSeen = new WeakMap<Database, number>();
98101
99 /** The first tick of this stretch that found `runs` running; undefined when none run. */
100 function crewSince(db: Database, runs: number, now: number): number | undefined {
101 if (runs <= 0) {
102 crewSeen.delete(db);
102 /** The first tick of this stretch that found it running; undefined when it is not. */
103 function since(seen: WeakMap<Database, number>, db: Database, running: boolean, now: number): number | undefined {
104 if (!running) {
105 seen.delete(db);
103106 return undefined;
104107 }
105 const since = crewSeen.get(db) ?? now;
106 crewSeen.set(db, since);
107 return since;
108 const first = seen.get(db) ?? now;
109 seen.set(db, first);
110 return first;
108111 }
109112
110113 /** Pulls of the forge's repository merged since `since`: number, title and body. */
@@ -284,6 +287,7 @@ export async function tickStep(p: KeeperPorts): Promise<Step> {
284287 const last = listKeeperReleases(p.db, 1)[0];
285288 const asked = pendingNow(p.db, p.now());
286289 const crewRuns = p.crewRuns?.() ?? 0;
290 const mainChecking = p.mainChecking?.() ?? false;
287291 const decision = decideCut({
288292 main: main ?? "",
289293 newest,
@@ -293,7 +297,9 @@ export async function tickStep(p: KeeperPorts): Promise<Step> {
293297 gating: p.gating(),
294298 snapshotMs: p.snapshotting?.(),
295299 crewRuns,
296 crewSince: crewSince(p.db, crewRuns, p.now()),
300 crewSince: since(crewSeen, p.db, crewRuns > 0, p.now()),
301 mainChecking,
302 mainCheckSince: since(mainSeen, p.db, mainChecking, p.now()),
297303 diskUsed: p.diskUsed?.(),
298304 lastCutAt: last === undefined ? undefined : Date.parse(last.cutAt),
299305 writePauseMs: last?.writePauseMs ?? undefined,
@@ -315,6 +321,7 @@ export async function tickStep(p: KeeperPorts): Promise<Step> {
315321 const r = recordCut(p.db, { version: decision.version, sha: main, knownGood, at: p.now(), ...(asked === undefined ? {} : { hotfix: `${asked.reason} (${asked.by})` }) });
316322 if (asked !== undefined) clearNow(p.db, asked);
317323 crewSeen.delete(p.db);
324 mainSeen.delete(p.db);
318325 const tagRefused = await tagged(p, r);
319326 if (tagRefused !== undefined) return { line: tagRefused, outcome: "failed" };
320327 const sent = await promote(p, r.version, refFor(p, image, r.version, main));
src/keeper/wire.ts +2
@@ -32,6 +32,7 @@ import { running } from "../kernel/version.ts";
3232 import { compareVersions } from "../kernel/versions.ts";
3333 import { readTags, recordFor } from "../release/shipped.ts";
3434 import { checkoutRelease, preflightRelease } from "../release/checkout.ts";
35 import { mainCheckRunning } from "../release/main_check_idle.ts";
3536 import { handover } from "../release/swap.ts";
3637 import { runningChildren } from "../boards/sampler.ts";
3738 import { snapshotsOf } from "../snapshot/service.ts";
@@ -161,6 +162,7 @@ export function keeperPorts(app: App, input: { forgeUrl: string; deployment: str
161162 gating: gatesInFlight,
162163 snapshotting: () => snapshotsOf(app)?.takingMs(),
163164 crewRuns: () => runningChildren(app.db).agents,
165 mainChecking: () => mainCheckRunning(app.db, repo.id, repo.defaultBranch),
164166 diskUsed: () => {
165167 const disk = diskUnder(app.config.dataDir);
166168 return disk === undefined || !(disk.totalBytes > 0) || roomy(disk) ? undefined : 1 - disk.freeBytes / disk.totalBytes;
test/release-keeper-cadence.test.ts +35
@@ -1,6 +1,9 @@
11 // When the release keeper cuts (#7557): each rule refuses on its own, and a cut is a tag, never a commit to main.
22 import { describe, expect, test } from "bun:test";
33 import { CREW_WAIT_MS, decideCut, MIN_INTERVAL_MS, nextVersion, RELEASE_DISK_USED_MAX, SNAPSHOT_WAIT_MS, type CadenceInput } from "../src/keeper/cadence.ts";
4 import { MAIN_CHECK_WAIT_MS } from "../src/release/main_check_idle.ts";
5 import { VERIFY_ENV } from "../src/checks/verify.ts";
6 import { claimRun, createRun, finishRun } from "../src/core/runs.ts";
47 import { tick } from "../src/keeper/keeper.ts";
58 import { askNow } from "../src/keeper/now.ts";
69 import { listKeeperReleases, recordCut } from "../src/keeper/record.ts";
@@ -79,6 +82,38 @@ describe("cadence", () => {
7982 expect(await tick({ ...h.ports, crewRuns: () => 3 })).toContain("cut 0.7.284");
8083 });
8184
85 test("main's running check holds the cut two hours from the first tick that found it; a hotfix is not held (#16966)", async () => {
86 expect(MAIN_CHECK_WAIT_MS).toBe(2 * 3_600_000);
87 expect(decideCut({ ...ready, mainChecking: true, mainCheckSince: NOW - 69 * 60_000 })).toEqual({ cut: false, why: "main's check is running (69m of 120m); a release would cut it short" });
88 expect(decideCut({ ...ready, mainChecking: true, mainCheckSince: NOW - MAIN_CHECK_WAIT_MS })).toEqual({ cut: true, version: "0.7.284" });
89 expect(decideCut({ ...ready, mainChecking: false })).toEqual({ cut: true, version: "0.7.284" });
90 expect(decideCut({ ...ready, mainChecking: true, mainCheckSince: NOW, hotfix: true })).toEqual({ cut: true, version: "0.7.284" });
91
92 const f = await keeperForge();
93 let checking = true;
94 const ports = { ...f.ports, mainChecking: () => checking };
95 expect(await tick(ports)).toBe("main's check is running (0m of 120m); a release would cut it short");
96 f.world.now += 69 * 60_000;
97 expect(await tick(ports)).toBe("main's check is running (69m of 120m); a release would cut it short");
98 expect(f.world.tags).toEqual([]);
99 expect(f.state.set).toEqual([]);
100 // The verify finished: the next tick cuts.
101 checking = false;
102 expect(await tick(ports)).toContain("cut 0.7.284");
103 });
104
105 test("the forge's keeper reads main's running check for the rule", async () => {
106 const f = await keeperForge();
107 const ports = keeperPorts(f.app, { forgeUrl: "http://forge.test", deployment: "forge", container: "forge", swap: true });
108 if (typeof ports === "string") throw new Error(ports);
109 expect(ports.mainChecking?.()).toBe(false);
110 const verify = createRun(f.app.db, { repoId: f.repo.id, kind: "check", env: VERIFY_ENV, commitOid: B });
111 claimRun(f.app.db, verify.id);
112 expect(ports.mainChecking?.()).toBe(true);
113 finishRun(f.app.db, verify.id, { state: "ok", summary: "" });
114 expect(ports.mainChecking?.()).toBe(false);
115 });
116
82117 test("at 80% of the disk used no release is cut; under it, or unread, the cut goes (#11686)", async () => {
83118 expect(RELEASE_DISK_USED_MAX).toBe(0.8);
84119 expect(decideCut({ ...ready, diskUsed: 0.8 })).toEqual({ cut: false, why: "the disk is 80% full; releases pause at 80% until room is made" });

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

Keyboard shortcuts

Docs