Public: anyone can read this; the crew can change it.
The throughput keeper says red pulls on the flow panel and never files a builder issue for them #16121
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/16117-the-throughput-keeper-says-red-pulls-on → main 0 commits fork
6 files
changed +90
−25
docs/features/keeper.md +2 −2
| @@ -8,12 +8,12 @@ The forge watches its own landing rate, names the one thing binding it, and acts | ||
| 8 | 8 | |
| 9 | 9 | 1. **Measure** (`keeper_rate.ts`): pulls landed per hour over the last 3 h against the best 3 h rate of the week before, and the share of the last 24 hours that ran (a landing or a builder run started). Low is under half the best and under one an hour. |
| 10 | 10 | 2. **Find** (`keeper_cause.ts`): the first of `ceiling`, `usage` ("resets at HH:MM UTC"), `unassigned`, `empty_pillar`, `stale_reds`, `red_checks`, `stale_pile`, `capacity`. It asks the dispatcher's own questions (`heldNow`, `atCeiling`, `pace`). `empty_pillar` binds only when no ready issue is held by a run or an open pull: those issues exist, and the pile behind them is named instead (`stale_pile`). |
| 11 | 3. **Act**: `unassigned` sweeps assigned issues with no run. `empty_pillar`, `red_checks` and `stale_pile` become one filed issue in the forge's own repository, once a week per cause (`stale_pile`'s issue lists the ten oldest pulls waiting on a reviewer or a builder, red and conflicted ones left out, and only counts those waiting on the merge, which is a person's act). `ceiling`, `usage`, `capacity` and `stale_reds` (the crew's red-pull sweep is already at it) are only said. | |
| 11 | 3. **Act**: `unassigned` sweeps assigned issues with no run. `empty_pillar` and `stale_pile` become one filed issue in the forge's own repository, once a week per cause (`stale_pile`'s issue lists the ten oldest pulls waiting on a reviewer or a builder, red and conflicted ones left out, and only counts those waiting on the merge, which is a person's act). `ceiling`, `usage`, `capacity`, `stale_reds` (the crew's red-pull sweep is already at it) and `red_checks` are only said. | |
| 12 | 12 | 4. **Check** after 2 h: landings rose and the act stands, or it is undone, the cause is left alone for 6 h and the owner is asked one question with one button (`POST /flow/keeper/answer`). |
| 13 | 13 | |
| 14 | 14 | Where it shows: one line on home and on the boards panel, `keeper` in the MCP `flow` report, the terminal's Flow dialog (the line, the question, and `l` for its one button after a confirm) and its crew scorecard ("Forge per day" rows), and "Forge per day" (hours running, landed) on the crew scorecard and in `scorecard` (`keeperDays`). Every attempt is a row in `keeper_attempt`. |
| 15 | 15 | |
| 16 | A `red_checks` issue lists the red pulls, oldest first, so whoever picks it up knows which to rework. | |
| 16 | Red pulls are said, not filed (#16117). A red crew pull is already worked by its own builder and by the stale-reds sweep, so a filed "N open crew pulls have a red check" issue gave a builder nothing to push: by the time one read it, the listed pulls were green, unchecked or running (#16104 was parked twice for that). The `red_checks` line on the keeper panel names the five oldest red pulls instead (`redPulls` in `pile.ts`) and counts the rest; a reader who is not a site admin reads it with no repository named. | |
| 17 | 17 | |
| 18 | 18 | An `empty_pillar` issue lists the ready issues and the hold on each (`landed`, `open_pull`, `stalled`...), so a person sees why nothing can start. |
| 19 | 19 |
src/flow/keeper.ts +2 −4
| @@ -19,7 +19,7 @@ import { KEEPER_CAUSES, pickCause, readKeeperFacts, type KeeperCause, type Keepe | ||
| 19 | 19 | import { measuresCached, type KeeperMeasures } from "./keeper_measures.ts"; |
| 20 | 20 | import { isLow, landedBetween, readRate, type Rate } from "./keeper_rate.ts"; |
| 21 | 21 | import { HOLDS, heldNow, heldWords } from "../crew/held.ts"; |
| 22 | import { oldestWaitingOn, redPulls } from "./pile.ts"; | |
| 22 | import { oldestWaitingOn } from "./pile.ts"; | |
| 23 | 23 | import { during } from "../perf/jobs.ts"; |
| 24 | 24 | |
| 25 | 25 | const log = createLog("keeper"); |
| @@ -134,8 +134,6 @@ export function fileOnce(app: App, found: { cause: KeeperCause; says: string }, | ||
| 134 | 134 | waiting.length === 0 |
| 135 | 135 | ? "" |
| 136 | 136 | : `${oldest.length === 0 ? "" : `\n\nOldest waiting, start here:\n${oldest.map((s) => `- ${s.ref} (waits on ${s.on})`).join("\n")}`}${onMerge === 0 ? "" : `\n\n${onMerge} more ${onMerge === 1 ? "waits" : "wait"} on the merge, a person's act, and ${onMerge === 1 ? "is" : "are"} not listed.`}`; |
| 137 | const reds = found.cause === "red_checks" ? redPulls(app.db, 10, repo.visibility !== "private") : []; | |
| 138 | const redList = reds.length === 0 ? "" : `\n\nRed, oldest first, start here:\n${reds.map((r) => `- ${r}`).join("\n")}`; | |
| 139 | 137 | const held = found.cause === "empty_pillar" ? heldNow(app, repo) : undefined; |
| 140 | 138 | const heldList = held |
| 141 | 139 | ? `\n\nReady issues and what holds them (${heldWords(held)}):\n${HOLDS.flatMap((h) => held.by[h].slice(0, 5).map((i) => `- #${i.number} (${h})`)).slice(0, 10).join("\n")}` |
| @@ -144,7 +142,7 @@ export function fileOnce(app: App, found: { cause: KeeperCause; says: string }, | ||
| 144 | 142 | repoId: repo.id, |
| 145 | 143 | authorId: repo.ownerId, |
| 146 | 144 | title: `Throughput: ${found.says}`.slice(0, 200), |
| 147 | body: `The throughput keeper found this binding landings (${rate.recent.toFixed(1)} an hour against a best of ${rate.best.toFixed(1)}) and cannot act on it itself.\n\n${found.says}${list}${redList}${heldList}\n\nFiles: docs/features/keeper.md`, | |
| 145 | body: `The throughput keeper found this binding landings (${rate.recent.toFixed(1)} an hour against a best of ${rate.best.toFixed(1)}) and cannot act on it itself.\n\n${found.says}${list}${heldList}\n\nFiles: docs/features/keeper.md`, | |
| 148 | 146 | }); |
| 149 | 147 | if (!made.ok) return; |
| 150 | 148 | app.bus.append({ kind: "issue.opened", repoId: repo.id, payload: { number: made.value.number } }); |
src/flow/keeper_cause.ts +21 −3
| @@ -16,7 +16,7 @@ import { slottedRuns } from "../crew/autonomy.ts"; | ||
| 16 | 16 | import { weekSpent } from "../crew/week_read.ts"; |
| 17 | 17 | import { heldNow } from "../crew/held.ts"; |
| 18 | 18 | import { pace } from "../crew/pacing.ts"; |
| 19 | import { readPile } from "./pile.ts"; | |
| 19 | import { readPile, redPulls } from "./pile.ts"; | |
| 20 | 20 | import { readStaleReds } from "./stale_reds.ts"; |
| 21 | 21 | |
| 22 | 22 | export const KEEPER_CAUSES = [ |
| @@ -60,6 +60,10 @@ export interface KeeperFacts { | ||
| 60 | 60 | readonly red: number; |
| 61 | 61 | /** Red pulls with no run for 30 min and no person holding them. */ |
| 62 | 62 | readonly staleReds?: number; |
| 63 | /** | |
| 64 | * The red pulls, oldest first, as `owner/repo#n` (`redPulls`): named when `red_checks` is said. | |
| 65 | */ | |
| 66 | readonly redRefs?: readonly string[]; | |
| 63 | 67 | readonly stale: number; |
| 64 | 68 | } |
| 65 | 69 | |
| @@ -75,6 +79,8 @@ export interface Found { | ||
| 75 | 79 | export const STALE_PULLS = 20; |
| 76 | 80 | export const RED_PULLS = 5; |
| 77 | 81 | export const STALE_REDS = 3; |
| 82 | /** How many red pulls the `red_checks` sentence names. */ | |
| 83 | export const RED_NAMED = 5; | |
| 78 | 84 | |
| 79 | 85 | const hhmm = (iso: string): string => `${iso.slice(11, 16)} UTC`; |
| 80 | 86 | |
| @@ -119,7 +125,16 @@ export function pickCause(f: KeeperFacts, skip: ReadonlySet<KeeperCause> = new S | ||
| 119 | 125 | if (found) return found; |
| 120 | 126 | } |
| 121 | 127 | if (first && f.red >= RED_PULLS) { |
| 122 | const found = hit({ cause: "red_checks", move: "file", repoId: first.repoId, says: `${f.red} open crew pulls have a red check.` }); | |
| 128 | // Said, not filed (#16117): each red pull is already its builder's and the stale-reds sweep's, | |
| 129 | // so a filed issue gives a builder nothing to push and is stale by the time it is read. | |
| 130 | const named = (f.redRefs ?? []).slice(0, RED_NAMED); | |
| 131 | const list = named.length === 0 ? "" : ` Oldest first: ${named.join(", ")}${f.red > named.length ? ` and ${f.red - named.length} more` : ""}.`; | |
| 132 | const found = hit({ | |
| 133 | cause: "red_checks", | |
| 134 | move: "say", | |
| 135 | repoId: first.repoId, | |
| 136 | says: `${f.red} open crew pulls have a red check: their builders and the stale-reds sweep rework them.${list}`, | |
| 137 | }); | |
| 123 | 138 | if (found) return found; |
| 124 | 139 | } |
| 125 | 140 | if (first && f.stale >= STALE_PULLS) { |
| @@ -171,5 +186,8 @@ export function readKeeperFacts(app: App, now: Date): KeeperFacts { | ||
| 171 | 186 | }); |
| 172 | 187 | } |
| 173 | 188 | const pile = readPile(db); |
| 174 | return { repos, red: pile.red, staleReds: readStaleReds(db, now).count, stale: pile.awaitingReview + pile.changesAsked + pile.approved }; | |
| 189 | // The sentence naming them is read only by a site admin (`readKeeper(db, full)`), so private | |
| 190 | // pulls are named too; everyone else reads the generic line. | |
| 191 | const redRefs = pile.red >= RED_PULLS ? redPulls(db, RED_NAMED, false) : []; | |
| 192 | return { repos, red: pile.red, redRefs, staleReds: readStaleReds(db, now).count, stale: pile.awaitingReview + pile.changesAsked + pile.approved }; | |
| 175 | 193 | } |
src/flow/pile.ts +2 −2
| @@ -110,8 +110,8 @@ export function oldestWaitingOn(db: Database, limit: number, publicOnly = true): | ||
| 110 | 110 | |
| 111 | 111 | /** |
| 112 | 112 | * The open crew pulls whose latest check on the current head failed, oldest |
| 113 | * first, each as `owner/repo#n`. A filed "red check" issue names them so the | |
| 114 | * one who picks it up knows which pulls to rework. Private repositories are | |
| 113 | * first, each as `owner/repo#n`. The keeper's `red_checks` line names them on | |
| 114 | * the panel (#16117); no issue is filed for them. Private repositories are | |
| 115 | 115 | * left out unless `publicOnly` is false. |
| 116 | 116 | */ |
| 117 | 117 | export function redPulls(db: Database, limit: number, publicOnly = true): string[] { |
test/flow-keeper.test.ts +42
| @@ -338,3 +338,45 @@ test("the terminal shows the keeper line and its one button on Flow, and Forge p | ||
| 338 | 338 | expect(tui.screen.toText()).toContain("Forge 20"); |
| 339 | 339 | expect(tui.screen.toText()).toContain("running"); |
| 340 | 340 | }); |
| 341 | ||
| 342 | test("red_checks is said, not filed: no builder issue opens, and the panel names the red pulls oldest first (#16117)", () => { | |
| 343 | const facts: KeeperFacts = { | |
| 344 | repos: [{ repoId: "r", slug: "a/b", startable: 0, inFlight: 3, running: 0, slots: 4, atCeiling: false, noHeadroom: false, resetsAt: null }], | |
| 345 | red: 7, | |
| 346 | redRefs: ["a/b#3", "a/b#9", "a/b#12", "a/b#20", "a/b#21"], | |
| 347 | stale: 0, | |
| 348 | }; | |
| 349 | expect(pickCause(facts)).toMatchObject({ | |
| 350 | cause: "red_checks", | |
| 351 | move: "say", | |
| 352 | says: "7 open crew pulls have a red check: their builders and the stale-reds sweep rework them. Oldest first: a/b#3, a/b#9, a/b#12, a/b#20, a/b#21 and 2 more.", | |
| 353 | }); | |
| 354 | ||
| 355 | // The whole tick: five red crew pulls in alice/engine, nothing else binding. | |
| 356 | app.db.query("DELETE FROM keeper_attempt").run(); | |
| 357 | app.db.query("UPDATE issue SET state = 'closed' WHERE repo_id = ?1 AND kind != 'pull'").run(repo.id); | |
| 358 | const mason = app.db.query<{ id: string }, []>("SELECT id FROM user WHERE username = 'mason'").get()!.id; | |
| 359 | const t = Date.now() + 2000 * EFFECT_MS; | |
| 360 | // Nothing is ready, and that was filed already this week: the next cause is the red pile. | |
| 361 | app.db | |
| 362 | .query("INSERT INTO keeper_attempt (at, cause, action, repo_id, says, outcome, check_at) VALUES (?1, 'empty_pillar', 'file', ?2, 'Filed #1', 'filed', 0)") | |
| 363 | .run(t, repo.id); | |
| 364 | for (let n = 0; n < 5; n++) { | |
| 365 | const issue = `red-${n}`; | |
| 366 | app.db | |
| 367 | .query(`INSERT INTO issue (id, repo_id, number, kind, title, body, author_id, state, created_at) VALUES (?1, ?2, ?3, 'pull', 'red', '', ?4, 'open', ?5)`) | |
| 368 | .run(issue, repo.id, 900 + n, mason, `2026-01-0${5 - n}T00:00:00.000Z`); | |
| 369 | app.db.query(`INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, head_repo_id) VALUES (?1, 'main', ?2, '', 'h', ?3)`).run(issue, `red/${n}`, repo.id); | |
| 370 | // A failed check with no finish time: red, but not yet a stale red the sweep would own. | |
| 371 | app.db.query(`INSERT INTO run (id, repo_id, kind, issue_id, commit_oid, state, reason) VALUES (?1, ?2, 'check', ?3, 'h', 'failed', '')`).run(`red-check-${n}`, repo.id, issue); | |
| 372 | } | |
| 373 | const before = app.db.query<{ n: number }, []>("SELECT COUNT(*) AS n FROM issue WHERE title LIKE 'Throughput:%'").get()!.n; | |
| 374 | expect(tickKeeper(app, new Date(t), () => {})).toEqual({ cause: "red_checks", acted: null }); | |
| 375 | expect(app.db.query<{ n: number }, []>("SELECT COUNT(*) AS n FROM issue WHERE title LIKE 'Throughput:%'").get()!.n).toBe(before); | |
| 376 | expect(listAttempts(app.db).some((a) => a.cause === "red_checks")).toBe(false); | |
| 377 | const read = readKeeper(app.db, true); | |
| 378 | expect(read.name).toBe("red_checks"); | |
| 379 | expect(read.cause).toContain("Oldest first: alice/engine#904, alice/engine#903, alice/engine#902, alice/engine#901, alice/engine#900."); | |
| 380 | // Anyone but a site admin reads it with no repository named. | |
| 381 | expect(readKeeper(app.db, false).cause).toBe("Open crew pulls have a red check."); | |
| 382 | }); |
test/flow-pile-oldest.test.ts +21 −14
| @@ -1,4 +1,7 @@ | ||
| 1 | /** The filed "waiting" issue names the oldest waiting pulls, not the red ones. */ | |
| 1 | /** | |
| 2 | * The filed "waiting" issue names the oldest waiting pulls, not the red ones; red ones are said on | |
| 3 | * the panel. | |
| 4 | */ | |
| 2 | 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; |
| 3 | 6 | import { mkdtempSync, rmSync } from "node:fs"; |
| 4 | 7 | import { tmpdir } from "node:os"; |
| @@ -9,7 +12,8 @@ import { createRepo } from "../src/core/repos.ts"; | ||
| 9 | 12 | import { createUser } from "../src/core/users.ts"; |
| 10 | 13 | import { id } from "../src/kernel/id.ts"; |
| 11 | 14 | import { fileOnce } from "../src/flow/keeper.ts"; |
| 12 | import { oldestWaitingOn } from "../src/flow/pile.ts"; | |
| 15 | import { oldestWaitingOn, redPulls } from "../src/flow/pile.ts"; | |
| 16 | import { pickCause, readKeeperFacts } from "../src/flow/keeper_cause.ts"; | |
| 13 | 17 | |
| 14 | 18 | let root: string; |
| 15 | 19 | let app: App; |
| @@ -130,19 +134,22 @@ test("the filed empty_pillar issue says what holds the ready issues", () => { | ||
| 130 | 134 | } |
| 131 | 135 | }); |
| 132 | 136 | |
| 133 | test("the filed red_checks issue names the red pulls, oldest first", () => { | |
| 134 | const was = process.env.FORGE_SENTINEL_REPO; | |
| 135 | process.env.FORGE_SENTINEL_REPO = "trevato/open"; | |
| 136 | try { | |
| 137 | const rate = { lastHour: 0, recent: 0.5, best: 3, ranShare: 1 }; | |
| 138 | fileOnce(app, { cause: "red_checks", says: "2 open crew pulls have a red check." }, rate, Date.now()); | |
| 139 | const b = app.db.query<{ body: string }, []>("SELECT body FROM issue WHERE title LIKE 'Throughput:%' ORDER BY created_at DESC, rowid DESC LIMIT 1").get()!.body; | |
| 140 | expect(b).toContain("Red, oldest first, start here:\n- trevato/open#2"); | |
| 141 | expect(b).not.toContain("Oldest waiting"); | |
| 142 | } finally { | |
| 143 | if (was === undefined) delete process.env.FORGE_SENTINEL_REPO; | |
| 144 | else process.env.FORGE_SENTINEL_REPO = was; | |
| 137 | test("red_checks is a say move, not a file, and its sentence names the red pulls oldest first (#16117)", () => { | |
| 138 | const facts = readKeeperFacts(app, new Date()); | |
| 139 | expect(facts.red).toBe(1); | |
| 140 | expect(facts.redRefs).toEqual([]); | |
| 141 | // Four more red pulls make five: the sentence names them, oldest first. | |
| 142 | for (let n = 0; n < 4; n++) { | |
| 143 | const issue = pull(20 + n, `2026-10-2${n}T00:00:00.000Z`); | |
| 144 | app.db.query(`INSERT INTO run (id, repo_id, kind, issue_id, commit_oid, state, reason) VALUES (?1, ?2, 'check', ?3, 'h', 'failed', '')`).run(`0red${n}`, repoId, issue); | |
| 145 | 145 | } |
| 146 | expect(redPulls(app.db, 10, false)).toEqual(["trevato/open#20", "trevato/open#21", "trevato/open#22", "trevato/open#23", "trevato/open#2"]); | |
| 147 | const read = readKeeperFacts(app, new Date()); | |
| 148 | expect(read.redRefs).toEqual(["trevato/open#20", "trevato/open#21", "trevato/open#22", "trevato/open#23", "trevato/open#2"]); | |
| 149 | const found = pickCause({ ...read, repos: [{ repoId, slug: "trevato/open", startable: 0, inFlight: 1, running: 0, slots: 1, atCeiling: false, noHeadroom: false, resetsAt: null }] }); | |
| 150 | expect(found?.cause).toBe("red_checks"); | |
| 151 | expect(found?.move).toBe("say"); | |
| 152 | expect(found?.says).toContain("Oldest first: trevato/open#20, trevato/open#21, trevato/open#22, trevato/open#23, trevato/open#2."); | |
| 146 | 153 | }); |
| 147 | 154 | |
| 148 | 155 | test("the filed stale_pile issue counts pulls waiting on the merge and does not list them", () => { |
new above
offline