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

Sentinel: queue:agent was degraded 41 minutes today: The agent queue has waited over 30 minutes: 10 queued, 6 of 6 slots running. #16119

Merged opened this

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

Merged

mason/forge:mason/16098-sentinel-queue-agent-was-degraded-41-min → main 0 commits fork 2 threads · 2 unresolved

  • Merged. mason/16098-sentinel-queue-agent-was-degraded-41-min was merged into main as 276bd01.

Review

Sign in to review this change.
7 files changed +121 −17
docs/features/agent-queue-full.md added +35
@@ -0,0 +1,35 @@
1 ---
2 topic: When something is wrong
3 row: A full agent queue asks to raise Speed and files no issue
4 ---
5 # A full agent queue asks to raise Speed and files no issue (#16098)
6
7 Vitals raise a long agent queue when a run has waited over 30 minutes for a
8 slot. What happens next depends on why it waited. Vitals decide that from the
9 counts, never from the card's words (`src/kernel/vitals.ts`):
10
11 - **Every slot busy:** the cause is `queue:agent:full`. The queue is waiting
12 for capacity, and only a person adds capacity. The owner's needs (Home, the
13 terminal's needs screen, the MCP `forge` tool) show one card, for example
14 "The agent queue has waited over 30 minutes: 10 queued, 6 of 6 slots running.
15 Raise Speed, or leave it?" *Raise Speed* means raising **Speed**
16 (`crew.concurrency`) on `/settings/capacity` or on the terminal's Capacity
17 screen. More crew runs at once use more of the machine and spend the week's
18 budget sooner, so the forge never raises it by itself.
19 - **A slot free:** the cause stays `queue:agent`. A queue that waits while a
20 slot is free is a dispatcher defect. The card is the same, and the sentinel
21 still files its minutes as a builder's issue (`degradedCauses` in
22 `src/crew/sentinel.ts`).
23
24 **The sentinel rule.** `queue:agent:full` is in `PERSON_ONLY`, so the sentinel
25 never files it. A builder cannot raise Speed, and an issue would only ask a
26 builder for a setting the owner holds. The minutes are not lost. Each full
27 stretch is its own row in `degraded_span`, and the maintenance findings list
28 it (`src/maintenance/findings.ts`: `/maintenance`, the terminal's maintenance
29 screen and its JSON) with its latest reading and how many days it held.
30
31 **Why a full queue is not a pipeline defect.** Landed-per-hour is capped by
32 how many crew runs are allowed at once. With every slot busy, the pipeline
33 runs at that cap, so no code change makes it go faster: raising the cap is
34 the only lever, and it costs budget. A queue that waits with a slot free is
35 what holds the pipeline back, and that is still filed.
src/actions/needs.ts +3
@@ -215,6 +215,9 @@ export function forgeRecommended(cause: string, sentence: string): Recommended {
215215 );
216216 if (cause.startsWith("db-"))
217217 return needsDecision(`${sentence} Make room, or leave it?`, "the database's size has no safe default: clearing it loses data, leaving it keeps growing", ["Make room", "Leave it"]);
218 // The agent queue's slots are Speed (crew.concurrency), not the check slots (#16098).
219 if (cause.startsWith("queue:agent"))
220 return needsDecision(`${sentence} Raise Speed, or leave it?`, "more crew runs at once use more of the machine and the week's budget sooner", ["Raise Speed", "Leave it"]);
218221 if (cause.startsWith("queue:"))
219222 return needsDecision(`${sentence} Raise the check slots, or leave them?`, "more slots use more of the machine", ["Raise the check slots", "Leave them"]);
220223 return needsDecision(`${sentence} Look into it?`, "the forge's own health is the owner's to act on", ["Open it", "Leave it"]);
src/crew/sentinel.ts +4 −2
@@ -33,7 +33,7 @@ import { getUserByName, type User } from "../core/users.ts";
3333 import { migrate } from "../kernel/migrate.ts";
3434 import { createLog, recentErrors, redactSecrets, type ErrorLedger } from "../kernel/log.ts";
3535 import { spans } from "../kernel/degraded_history.ts";
36 import { QUEUE_WAIT_MAX_MS } from "../kernel/vitals.ts";
36 import { QUEUE_AGENT_FULL, QUEUE_WAIT_MAX_MS } from "../kernel/vitals.ts";
3737 import { STALE_AFTER_MS } from "../runs/lease.ts";
3838 import { isOutageSummary } from "./network.ts";
3939 import {
@@ -591,7 +591,9 @@ const BREACH_CAUSE = /^(queue:check|stuck:|budget:|red:|shared:)/;
591591 * Causes only a person can settle (#12613): never filed as an issue a builder could be given.
592592 * Each stays a vitals card in the owner's needs, with its one action (`forgeRecommended`).
593593 */
594 export const PERSON_ONLY: readonly string[] = ["backup-refs:", "backup-repo:"];
594 // An agent queue waiting with every slot busy waits for Speed, the owner's capacity and budget
595 // call (#16098): its spans stay on the findings board; minutes with a slot free are still filed.
596 export const PERSON_ONLY: readonly string[] = ["backup-refs:", "backup-repo:", QUEUE_AGENT_FULL];
595597
596598 /**
597599 * A red main in another repository is its owner's to fix, not the forge's
src/kernel/vitals.ts +19 −13
@@ -105,10 +105,10 @@ export type NeedKind = "broken" | "todo";
105105 * One cause of the forge being off: the `needs` sentence, a `cause` key that
106106 * holds for as long as its condition does (`memory`, `disk`, `disk-floor`, `disk-80`, `disk-70`,
107107 * `db-size`, `db-growth`, `forges-memory`, `errors`, `internal`,
108 * `queue:<kind>`, `release`, `stuck:<runId>`, `red:<repoId>`, `shared:<repoId>:<test>`), when it
109 * began by the forge's own evidence (the oldest evidence the forge holds, else the first time this
110 * process saw it, held until the cause clears; `at` is never the answer to a repeat call), and
111 * where to look.
108 * `queue:<kind>`, `queue:agent:full`, `release`, `stuck:<runId>`, `red:<repoId>`,
109 * `shared:<repoId>:<test>`), when it began by the forge's own evidence (the oldest evidence the
110 * forge holds, else the first time this process saw it, held until the cause clears; `at` is never
111 * the answer to a repeat call), and where to look.
112112 */
113113 export interface Degraded {
114114 readonly cause: string;
@@ -375,6 +375,15 @@ function queueSentence(
375375 return `The ${kind} queue has waited over ${QUEUE_WAIT_MAX_MS / 60_000} minutes: ${queued} queued, ${behind}${more}.`;
376376 }
377377
378 /**
379 * The cause of a long agent queue when every slot is busy: it waits for capacity, which only a
380 * person adds (Speed, /settings/capacity), so it is its own cause, set from the counts and not
381 * read back from the sentence (#16098). A queue waiting with a slot free stays `queue:agent`.
382 * Each stretch is its own `degraded_span`, so the full minutes stay on the record (the findings
383 * board, /api/v1/forge/findings) even though the sentinel files no issue for them.
384 */
outdated

Parsing the human sentence with a regex couples the sentinel to the wording of queueSentence. Return a structured flag (full: boolean) from the vitals or the span instead, and drop this parse.

385 export const QUEUE_AGENT_FULL = "queue:agent:full";
386
378387 /**
379388 * The lane's one sentence, with its cause: how many wait, since when, and
380389 * what runs. With one slot: "22 checks wait behind one lane; the oldest since
@@ -583,20 +592,17 @@ export function vitals(input: VitalsInput): Vitals {
583592 }
584593 if (oldest === null) continue;
585594 const waited = now - new Date(oldest).getTime();
586 if (waited > QUEUE_WAIT_MAX_MS)
595 if (waited > QUEUE_WAIT_MAX_MS) {
596 const busy = holders(running.filter((r) => r.run.kind === row.kind).map((r) => r.run.issueId), row.kind === "agent");
597 const slots = row.kind === "agent" ? Number(capacityValue(input.db, "crew.concurrency")) : null;
587598 need(
588599 "todo",
589 `queue:${row.kind}`,
590 queueSentence(
591 row.kind,
592 waiting,
593 holders(running.filter((r) => r.run.kind === row.kind).map((r) => r.run.issueId), row.kind === "agent"),
594 row.kind === "agent" ? Number(capacityValue(input.db, "crew.concurrency")) : null,
595 byCause,
596 ),
600 slots !== null && busy >= slots ? QUEUE_AGENT_FULL : `queue:${row.kind}`,
601 queueSentence(row.kind, waiting, busy, slots, byCause),
597602 new Date(oldest).toISOString(),
598603 "/settings/capacity",
599604 );
605 }
600606 }
601607
602608 const stuck: Vitals["stuck"] = [];
test/forge-needs-defaults.test.ts +10
@@ -78,6 +78,16 @@ test("forge needs: the restore drill is a default; a database, a queue and a sta
7878 }
7979 });
8080
81 test("forge needs: a full agent queue's card asks to raise Speed, not the check slots (#16098)", () => {
82 const sentence = "The agent queue has waited over 30 minutes: 10 queued, 6 of 6 slots running.";
83 for (const cause of ["queue:agent", "queue:agent:full"]) {
84 const r = forgeRecommended(cause, sentence);
85 expect(r.ask).toBe(`${sentence} Raise Speed, or leave it?`);
86 expect(r.options).toEqual(["Raise Speed", "Leave it"]);
87 }
88 expect(forgeRecommended("queue:check", sentence).options).toEqual(["Raise the check slots", "Leave them"]);
89 });
90
8191 test("forge needs: a backup-refs card is the owner's ask and names its action, re-push or delete (#12613)", () => {
8292 const sentence = "2 branches of scout/forge cannot be backed up: their commits are missing (a, b).";
8393 const r = forgeRecommended("backup-refs:scout/forge", sentence);
test/sentinel.test.ts +24
@@ -12,6 +12,7 @@ import { createApp, type App } from "../src/app.ts";
1212 import { createRepo } from "../src/actions/repos.ts";
1313 import { setCapacity } from "../src/core/capacity.ts";
1414 import { clearErrors, createLog } from "../src/kernel/log.ts";
15 import { spans } from "../src/kernel/degraded_history.ts";
1516 import { recordDecision } from "../src/core/decisions.ts";
1617 import { addComment, createIssue, createLabel, labelsFor, listComments, listIssues } from "../src/core/issues.ts";
1718 import { addCrew, createAgentRow } from "../src/core/agents.ts";
@@ -646,6 +647,29 @@ describe("degraded causes", () => {
646647 expect(openIssues().length).toBe(before);
647648 expect(openIssues().some((i) => i.title.includes("backup-"))).toBe(false);
648649 });
650
651 test("a queue that waited with every slot busy is the owner's capacity call, not a builder's issue (#16098)", () => {
652 const day = D_NIGHT + 21 * D_DAY;
653 const span = (cause: string, sentence: string, openedAt: number, minutes: number) =>
654 dapp.db
655 .query("INSERT INTO degraded_span (cause, sentence, href, opened_at, closed_at) VALUES (?1, ?2, '/settings/capacity', ?3, ?4)")
656 .run(cause, sentence, openedAt, openedAt + minutes * D_MIN);
657 // The cause is the fact, not the words: a reworded sentence changes nothing.
658 span("queue:agent:full", "Any words at all.", day - 5 * 3_600_000, 41);
659 span("queue:agent:full", "The agent queue has waited over 30 minutes: 10 queued, 2 of 6 slots running.", day - 3 * 3_600_000, 20);
660 expect(degradedCauses(dapp.db, day, drepo.id)).toEqual([]);
661 const before = openIssues().length;
662 expect(hunt(dapp, "alice/forge", day).filed).toBe(0);
663 expect(openIssues().length).toBe(before);
664 // The full minutes stay on the record the findings board reads.
665 expect(spans(dapp.db, day - D_DAY, day).filter((s) => s.cause === "queue:agent:full").length).toBe(2);
666 // Waiting with a slot free is a dispatcher defect: those minutes alone are filed.
667 span("queue:agent", "The agent queue has waited over 30 minutes: 10 queued, 6 of 6 slots running.", day - 2 * 3_600_000, 25);
668 const found = degradedCauses(dapp.db, day, drepo.id);
669 expect(found.map((f) => f.key)).toEqual(["degraded:queue-agent"]);
670 expect(found[0]!.title).toStartWith("queue:agent was degraded 25 minutes today: ");
671 dapp.db.query("DELETE FROM degraded_span WHERE cause LIKE 'queue:agent%'").run();
672 });
649673 });
650674
651675 // ---- budget breaches (#1270) ----
test/vitals-held-agent.test.ts +26 −2
@@ -13,7 +13,8 @@ import { turnValve } from "../src/flow/valve_store.ts";
1313 import { serve } from "../src/http/server.ts";
1414 import { setQuota } from "../src/settings/quotas.ts";
1515 import { HELD_FRESH_MS, heldRuns, noteHeld } from "../src/runs/held.ts";
16 import { QUEUE_WAIT_MAX_MS, vitals } from "../src/kernel/vitals.ts";
16 import { QUEUE_AGENT_FULL, QUEUE_WAIT_MAX_MS, vitals } from "../src/kernel/vitals.ts";
17 import { setCapacity } from "../src/core/capacity.ts";
1718
1819 let dataDir: string;
1920 let app: App;
@@ -45,7 +46,7 @@ afterAll(async () => {
4546 });
4647
4748 const agentQueue = (now: number) =>
48 vitals({ db: app.db, signals: app.signals, dataDir, disk: roomy, now }).degraded.find((d) => d.cause === "queue:agent");
49 vitals({ db: app.db, signals: app.signals, dataDir, disk: roomy, now }).degraded.find((d) => d.cause.startsWith("queue:agent"));
4950
5051 test("a pass's holds are read while fresh, and forgotten once the dispatcher goes quiet", () => {
5152 const at = Date.now();
@@ -278,3 +279,26 @@ test("with the real dispatcher and every slot taken, a run an account limit hold
278279 servers.stop();
279280 }
280281 });
282
283 test("vitals names a full agent queue by its cause, from the counts: every slot busy, or one free (#16098)", () => {
284 app.db.query("DELETE FROM run").run();
285 setCapacity(app.db, "crew.concurrency", "1", ownerId);
286 try {
287 createRun(app.db, { repoId, kind: "agent" });
288 const later = Date.now() + 2 * QUEUE_WAIT_MAX_MS;
289 noteHeld(app.db, new Map(), later);
290 const causes = () =>
291 vitals({ db: app.db, signals: app.signals, dataDir, disk: roomy, now: later })
292 .degraded.map((d) => d.cause)
293 .filter((c) => c.startsWith("queue:agent"));
294 expect(causes()).toEqual(["queue:agent"]);
295 const busy = createRun(app.db, { repoId, kind: "agent" });
296 app.db
297 .query("UPDATE run SET state = 'running', started_at = ?1, heartbeat_at = ?1 WHERE id = ?2")
298 .run(new Date(later).toISOString(), busy.id);
299 expect(causes()).toEqual([QUEUE_AGENT_FULL]);
300 } finally {
301 setCapacity(app.db, "crew.concurrency", null, ownerId);
302 app.db.query("DELETE FROM run").run();
303 }
304 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs