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
Merged 41h 48m ago, live in production
torque/forge:torque/17311-the-release-keeper-cuts-main-s-verify-sh → main 0 commits fork
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`. | ||
| 98 | 98 | (`release_hold {lift: <id>}`, the card's Lift button, `h` then `lift N`) — one function, `holdAs`/`liftAs`, behind all three. |
| 99 | 99 | It needs a person who may roll back (MCP: on an admin-scope token); an agent never can. |
| 100 | 100 | |
| 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 | ||
| 101 | 109 | ## A hotfix does not wait (#11839) |
| 102 | 110 | |
| 103 | 111 | `release_now {reason}` (MCP, admin scope), the **Release now** form on the |
| 104 | 112 | `/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 | |
| 107 | 115 | for room on the disk. The request lapses after an hour if main had nothing to |
| 108 | 116 | cut; the reason is kept on the release (`hotfix`) and shown on the card. |
| 109 | 117 |
src/keeper/cadence.ts +12
| @@ -8,6 +8,8 @@ | ||
| 8 | 8 | * ∧ no merge-queue gate is running (the queue is not mid-landing) |
| 9 | 9 | * ∧ no snapshot is being taken, unless it has run `SNAPSHOT_WAIT_MS` |
| 10 | 10 | * ∧ 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) | |
| 11 | 13 | * ∧ now − the last cut ≥ the minimum interval, or `PAUSE_CADENCE_FACTOR` × the last |
| 12 | 14 | * release's write pause when that is longer (#7836) |
| 13 | 15 | * ∧ no hold stands (a failed verify's, or an owner's) |
| @@ -21,6 +23,7 @@ | ||
| 21 | 23 | export const MIN_INTERVAL_MS = 30 * 60_000; |
| 22 | 24 | |
| 23 | 25 | import { pauseWords } from "./pause.ts"; |
| 26 | import { MAIN_CHECK_WAIT_MS } from "../release/main_check_idle.ts"; | |
| 24 | 27 | |
| 25 | 28 | /** |
| 26 | 29 | * 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 { | ||
| 70 | 73 | readonly crewRuns?: number | undefined; |
| 71 | 74 | /** When the keeper first found crew runs running, epoch ms, in the stretch it is still in. */ |
| 72 | 75 | 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; | |
| 73 | 80 | /** When the keeper last cut, epoch ms. */ |
| 74 | 81 | readonly lastCutAt: number | undefined; |
| 75 | 82 | /** The reason of a standing hold, when one stands. */ |
| @@ -121,6 +128,11 @@ export function decideCut(input: CadenceInput): Cadence { | ||
| 121 | 128 | if (waited < CREW_WAIT_MS) |
| 122 | 129 | return no(`waiting on ${runs} crew run${runs === 1 ? "" : "s"} (${Math.floor(waited / 60_000)}m of ${CREW_WAIT_MS / 60_000}m)`); |
| 123 | 130 | } |
| 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 | } | |
| 124 | 136 | if (input.diskUsed !== undefined && input.diskUsed >= RELEASE_DISK_USED_MAX) |
| 125 | 137 | return no(`the disk is ${Math.round(input.diskUsed * 100)}% full; releases pause at ${RELEASE_DISK_USED_MAX * 100}% until room is made`); |
| 126 | 138 | const floor = input.minIntervalMs ?? MIN_INTERVAL_MS; |
src/keeper/keeper.ts +17 −10
| @@ -66,6 +66,8 @@ export interface KeeperPorts { | ||
| 66 | 66 | readonly snapshotting?: () => number | undefined; |
| 67 | 67 | /** Crew runs running now, which a release would cut short (#11918); none when unset. */ |
| 68 | 68 | readonly crewRuns?: () => number; |
| 69 | /** A check of main is running, which a release would cut short (#16966); none when unset. */ | |
| 70 | readonly mainChecking?: () => boolean; | |
| 69 | 71 | /** The share of the forge's disk in use, 0..1; undefined when unread (#11686). */ |
| 70 | 72 | readonly diskUsed?: () => number | undefined; |
| 71 | 73 | readonly deployer: Deployer; |
| @@ -91,20 +93,21 @@ export interface KeeperPorts { | ||
| 91 | 93 | } |
| 92 | 94 | |
| 93 | 95 | /** |
| 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. | |
| 96 | 98 | */ |
| 97 | 99 | const crewSeen = new WeakMap<Database, number>(); |
| 100 | const mainSeen = new WeakMap<Database, number>(); | |
| 98 | 101 | |
| 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); | |
| 103 | 106 | return undefined; |
| 104 | 107 | } |
| 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; | |
| 108 | 111 | } |
| 109 | 112 | |
| 110 | 113 | /** 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> { | ||
| 284 | 287 | const last = listKeeperReleases(p.db, 1)[0]; |
| 285 | 288 | const asked = pendingNow(p.db, p.now()); |
| 286 | 289 | const crewRuns = p.crewRuns?.() ?? 0; |
| 290 | const mainChecking = p.mainChecking?.() ?? false; | |
| 287 | 291 | const decision = decideCut({ |
| 288 | 292 | main: main ?? "", |
| 289 | 293 | newest, |
| @@ -293,7 +297,9 @@ export async function tickStep(p: KeeperPorts): Promise<Step> { | ||
| 293 | 297 | gating: p.gating(), |
| 294 | 298 | snapshotMs: p.snapshotting?.(), |
| 295 | 299 | 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()), | |
| 297 | 303 | diskUsed: p.diskUsed?.(), |
| 298 | 304 | lastCutAt: last === undefined ? undefined : Date.parse(last.cutAt), |
| 299 | 305 | writePauseMs: last?.writePauseMs ?? undefined, |
| @@ -315,6 +321,7 @@ export async function tickStep(p: KeeperPorts): Promise<Step> { | ||
| 315 | 321 | const r = recordCut(p.db, { version: decision.version, sha: main, knownGood, at: p.now(), ...(asked === undefined ? {} : { hotfix: `${asked.reason} (${asked.by})` }) }); |
| 316 | 322 | if (asked !== undefined) clearNow(p.db, asked); |
| 317 | 323 | crewSeen.delete(p.db); |
| 324 | mainSeen.delete(p.db); | |
| 318 | 325 | const tagRefused = await tagged(p, r); |
| 319 | 326 | if (tagRefused !== undefined) return { line: tagRefused, outcome: "failed" }; |
| 320 | 327 | 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"; | ||
| 32 | 32 | import { compareVersions } from "../kernel/versions.ts"; |
| 33 | 33 | import { readTags, recordFor } from "../release/shipped.ts"; |
| 34 | 34 | import { checkoutRelease, preflightRelease } from "../release/checkout.ts"; |
| 35 | import { mainCheckRunning } from "../release/main_check_idle.ts"; | |
| 35 | 36 | import { handover } from "../release/swap.ts"; |
| 36 | 37 | import { runningChildren } from "../boards/sampler.ts"; |
| 37 | 38 | import { snapshotsOf } from "../snapshot/service.ts"; |
| @@ -161,6 +162,7 @@ export function keeperPorts(app: App, input: { forgeUrl: string; deployment: str | ||
| 161 | 162 | gating: gatesInFlight, |
| 162 | 163 | snapshotting: () => snapshotsOf(app)?.takingMs(), |
| 163 | 164 | crewRuns: () => runningChildren(app.db).agents, |
| 165 | mainChecking: () => mainCheckRunning(app.db, repo.id, repo.defaultBranch), | |
| 164 | 166 | diskUsed: () => { |
| 165 | 167 | const disk = diskUnder(app.config.dataDir); |
| 166 | 168 | 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 @@ | ||
| 1 | 1 | // When the release keeper cuts (#7557): each rule refuses on its own, and a cut is a tag, never a commit to main. |
| 2 | 2 | import { describe, expect, test } from "bun:test"; |
| 3 | 3 | 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"; | |
| 4 | 7 | import { tick } from "../src/keeper/keeper.ts"; |
| 5 | 8 | import { askNow } from "../src/keeper/now.ts"; |
| 6 | 9 | import { listKeeperReleases, recordCut } from "../src/keeper/record.ts"; |
| @@ -79,6 +82,38 @@ describe("cadence", () => { | ||
| 79 | 82 | expect(await tick({ ...h.ports, crewRuns: () => 3 })).toContain("cut 0.7.284"); |
| 80 | 83 | }); |
| 81 | 84 | |
| 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 | ||
| 82 | 117 | test("at 80% of the disk used no release is cut; under it, or unread, the cut goes (#11686)", async () => { |
| 83 | 118 | expect(RELEASE_DISK_USED_MAX).toBe(0.8); |
| 84 | 119 | expect(decideCut({ ...ready, diskUsed: 0.8 })).toEqual({ cut: false, why: "the disk is 80% full; releases pause at 80% until room is made" }); |
new above
offline