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

Merged opened this

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

Merged

torque/forge:torque/16117-the-throughput-keeper-says-red-pulls-on → main 0 commits fork

  • Merged. torque/16117-the-throughput-keeper-says-red-pulls-on was merged into main as d21893b.

Review

Sign in to review this change.
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
88
99 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.
1010 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.
1212 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`).
1313
1414 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`.
1515
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.
1717
1818 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.
1919
src/flow/keeper.ts +2 −4
@@ -19,7 +19,7 @@ import { KEEPER_CAUSES, pickCause, readKeeperFacts, type KeeperCause, type Keepe
1919 import { measuresCached, type KeeperMeasures } from "./keeper_measures.ts";
2020 import { isLow, landedBetween, readRate, type Rate } from "./keeper_rate.ts";
2121 import { HOLDS, heldNow, heldWords } from "../crew/held.ts";
22 import { oldestWaitingOn, redPulls } from "./pile.ts";
22 import { oldestWaitingOn } from "./pile.ts";
2323 import { during } from "../perf/jobs.ts";
2424
2525 const log = createLog("keeper");
@@ -134,8 +134,6 @@ export function fileOnce(app: App, found: { cause: KeeperCause; says: string },
134134 waiting.length === 0
135135 ? ""
136136 : `${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")}`;
139137 const held = found.cause === "empty_pillar" ? heldNow(app, repo) : undefined;
140138 const heldList = held
141139 ? `\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 },
144142 repoId: repo.id,
145143 authorId: repo.ownerId,
146144 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`,
148146 });
149147 if (!made.ok) return;
150148 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";
1616 import { weekSpent } from "../crew/week_read.ts";
1717 import { heldNow } from "../crew/held.ts";
1818 import { pace } from "../crew/pacing.ts";
19 import { readPile } from "./pile.ts";
19 import { readPile, redPulls } from "./pile.ts";
2020 import { readStaleReds } from "./stale_reds.ts";
2121
2222 export const KEEPER_CAUSES = [
@@ -60,6 +60,10 @@ export interface KeeperFacts {
6060 readonly red: number;
6161 /** Red pulls with no run for 30 min and no person holding them. */
6262 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[];
6367 readonly stale: number;
6468 }
6569
@@ -75,6 +79,8 @@ export interface Found {
7579 export const STALE_PULLS = 20;
7680 export const RED_PULLS = 5;
7781 export const STALE_REDS = 3;
82 /** How many red pulls the `red_checks` sentence names. */
83 export const RED_NAMED = 5;
7884
7985 const hhmm = (iso: string): string => `${iso.slice(11, 16)} UTC`;
8086
@@ -119,7 +125,16 @@ export function pickCause(f: KeeperFacts, skip: ReadonlySet<KeeperCause> = new S
119125 if (found) return found;
120126 }
121127 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 });
123138 if (found) return found;
124139 }
125140 if (first && f.stale >= STALE_PULLS) {
@@ -171,5 +186,8 @@ export function readKeeperFacts(app: App, now: Date): KeeperFacts {
171186 });
172187 }
173188 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 };
175193 }
src/flow/pile.ts +2 −2
@@ -110,8 +110,8 @@ export function oldestWaitingOn(db: Database, limit: number, publicOnly = true):
110110
111111 /**
112112 * 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
115115 * left out unless `publicOnly` is false.
116116 */
117117 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
338338 expect(tui.screen.toText()).toContain("Forge 20");
339339 expect(tui.screen.toText()).toContain("running");
340340 });
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 */
25 import { afterAll, beforeAll, expect, test } from "bun:test";
36 import { mkdtempSync, rmSync } from "node:fs";
47 import { tmpdir } from "node:os";
@@ -9,7 +12,8 @@ import { createRepo } from "../src/core/repos.ts";
912 import { createUser } from "../src/core/users.ts";
1013 import { id } from "../src/kernel/id.ts";
1114 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";
1317
1418 let root: string;
1519 let app: App;
@@ -130,19 +134,22 @@ test("the filed empty_pillar issue says what holds the ready issues", () => {
130134 }
131135 });
132136
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);
145145 }
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.");
146153 });
147154
148155 test("the filed stale_pile issue counts pulls waiting on the merge and does not list them", () => {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs