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
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/16098-sentinel-queue-agent-was-degraded-41-min → main 0 commits fork 2 threads · 2 unresolved
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 { | ||
| 215 | 215 | ); |
| 216 | 216 | if (cause.startsWith("db-")) |
| 217 | 217 | 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"]); | |
| 218 | 221 | if (cause.startsWith("queue:")) |
| 219 | 222 | return needsDecision(`${sentence} Raise the check slots, or leave them?`, "more slots use more of the machine", ["Raise the check slots", "Leave them"]); |
| 220 | 223 | 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"; | ||
| 33 | 33 | import { migrate } from "../kernel/migrate.ts"; |
| 34 | 34 | import { createLog, recentErrors, redactSecrets, type ErrorLedger } from "../kernel/log.ts"; |
| 35 | 35 | 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"; | |
| 37 | 37 | import { STALE_AFTER_MS } from "../runs/lease.ts"; |
| 38 | 38 | import { isOutageSummary } from "./network.ts"; |
| 39 | 39 | import { |
| @@ -591,7 +591,9 @@ const BREACH_CAUSE = /^(queue:check|stuck:|budget:|red:|shared:)/; | ||
| 591 | 591 | * Causes only a person can settle (#12613): never filed as an issue a builder could be given. |
| 592 | 592 | * Each stays a vitals card in the owner's needs, with its one action (`forgeRecommended`). |
| 593 | 593 | */ |
| 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]; | |
| 595 | 597 | |
| 596 | 598 | /** |
| 597 | 599 | * 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"; | ||
| 105 | 105 | * One cause of the forge being off: the `needs` sentence, a `cause` key that |
| 106 | 106 | * holds for as long as its condition does (`memory`, `disk`, `disk-floor`, `disk-80`, `disk-70`, |
| 107 | 107 | * `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. | |
| 112 | 112 | */ |
| 113 | 113 | export interface Degraded { |
| 114 | 114 | readonly cause: string; |
| @@ -375,6 +375,15 @@ function queueSentence( | ||
| 375 | 375 | return `The ${kind} queue has waited over ${QUEUE_WAIT_MAX_MS / 60_000} minutes: ${queued} queued, ${behind}${more}.`; |
| 376 | 376 | } |
| 377 | 377 | |
| 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 | */ | |
| 385 | export const QUEUE_AGENT_FULL = "queue:agent:full"; | |
| 386 | ||
| 378 | 387 | /** |
| 379 | 388 | * The lane's one sentence, with its cause: how many wait, since when, and |
| 380 | 389 | * what runs. With one slot: "22 checks wait behind one lane; the oldest since |
| @@ -583,20 +592,17 @@ export function vitals(input: VitalsInput): Vitals { | ||
| 583 | 592 | } |
| 584 | 593 | if (oldest === null) continue; |
| 585 | 594 | 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; | |
| 587 | 598 | need( |
| 588 | 599 | "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), | |
| 597 | 602 | new Date(oldest).toISOString(), |
| 598 | 603 | "/settings/capacity", |
| 599 | 604 | ); |
| 605 | } | |
| 600 | 606 | } |
| 601 | 607 | |
| 602 | 608 | 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 | ||
| 78 | 78 | } |
| 79 | 79 | }); |
| 80 | 80 | |
| 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 | ||
| 81 | 91 | test("forge needs: a backup-refs card is the owner's ask and names its action, re-push or delete (#12613)", () => { |
| 82 | 92 | const sentence = "2 branches of scout/forge cannot be backed up: their commits are missing (a, b)."; |
| 83 | 93 | 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"; | ||
| 12 | 12 | import { createRepo } from "../src/actions/repos.ts"; |
| 13 | 13 | import { setCapacity } from "../src/core/capacity.ts"; |
| 14 | 14 | import { clearErrors, createLog } from "../src/kernel/log.ts"; |
| 15 | import { spans } from "../src/kernel/degraded_history.ts"; | |
| 15 | 16 | import { recordDecision } from "../src/core/decisions.ts"; |
| 16 | 17 | import { addComment, createIssue, createLabel, labelsFor, listComments, listIssues } from "../src/core/issues.ts"; |
| 17 | 18 | import { addCrew, createAgentRow } from "../src/core/agents.ts"; |
| @@ -646,6 +647,29 @@ describe("degraded causes", () => { | ||
| 646 | 647 | expect(openIssues().length).toBe(before); |
| 647 | 648 | expect(openIssues().some((i) => i.title.includes("backup-"))).toBe(false); |
| 648 | 649 | }); |
| 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 | }); | |
| 649 | 673 | }); |
| 650 | 674 | |
| 651 | 675 | // ---- budget breaches (#1270) ---- |
test/vitals-held-agent.test.ts +26 −2
| @@ -13,7 +13,8 @@ import { turnValve } from "../src/flow/valve_store.ts"; | ||
| 13 | 13 | import { serve } from "../src/http/server.ts"; |
| 14 | 14 | import { setQuota } from "../src/settings/quotas.ts"; |
| 15 | 15 | 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"; | |
| 17 | 18 | |
| 18 | 19 | let dataDir: string; |
| 19 | 20 | let app: App; |
| @@ -45,7 +46,7 @@ afterAll(async () => { | ||
| 45 | 46 | }); |
| 46 | 47 | |
| 47 | 48 | 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")); | |
| 49 | 50 | |
| 50 | 51 | test("a pass's holds are read while fresh, and forgotten once the dispatcher goes quiet", () => { |
| 51 | 52 | const at = Date.now(); |
| @@ -278,3 +279,26 @@ test("with the real dispatcher and every slot taken, a run an account limit hold | ||
| 278 | 279 | servers.stop(); |
| 279 | 280 | } |
| 280 | 281 | }); |
| 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 | }); |
new above
offline
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.