Public: anyone can read this; the crew can change it.
Sentinel: queue:check is past its budget: 13 checks wait for 8 slots, 7 busy; the oldest since 06:21; the longest running is #16844 at 46 min (limit 60). #17005
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/16995-sentinel-queue-check-is-past-its-budget → main 0 commits fork 2 threads · 2 unresolved
5 files
changed +98
−6
src/checks/busy_slots.ts added +23
| @@ -0,0 +1,23 @@ | ||
| 1 | /** | |
| 2 | * The check slots busy, counted as the lane counts them (`checks/scheduler.ts`): | |
| 3 | * a check run holds one unless it is the verification lane's, which holds | |
| 4 | * none, and a merge-queue gate in flight holds one and writes no run (#6376). | |
| 5 | * Vitals reads the lane through this one door, so a full lane never reads as | |
| 6 | * one with a slot free (#16995). | |
| 7 | */ | |
| 8 | ||
| 9 | import type { Database } from "bun:sqlite"; | |
| 10 | import { openGates } from "./gate_record.ts"; | |
| 11 | import { GATE_DEADLINE_MS } from "./queue.ts"; | |
| 12 | import { inVerifyLane } from "./verify.ts"; | |
| 13 | ||
| 14 | /** Whether a check run of this `env` holds a lane slot. */ | |
| 15 | export const holdsSlot = (env: string): boolean => !inVerifyLane(env); | |
| 16 | ||
| 17 | /** | |
| 18 | * The merge-queue gates holding a slot at `now`, in any process on this | |
| 19 | * database; a row a crash left open stops counting at the queue's deadline. | |
| 20 | */ | |
| 21 | export function gatesHolding(db: Database, now: number): { pull: number | null; since: string }[] { | |
| 22 | return openGates(db, new Date(now - GATE_DEADLINE_MS)); | |
| 23 | } |
src/checks/gate_record.ts +16
| @@ -54,3 +54,19 @@ export function gateHolding(db: Database, prefix: string, since: Date): boolean | ||
| 54 | 54 | .get(prefix.length, prefix, since.toISOString()) !== null |
| 55 | 55 | ); |
| 56 | 56 | } |
| 57 | ||
| 58 | /** | |
| 59 | * The gates holding a check slot now, in any process on this database: open, | |
| 60 | * and started after `since` (a row a crash left open stops counting there). | |
| 61 | * The lane counts each as a busy slot (`checks/scheduler.ts`, #6376), so | |
| 62 | * vitals counts them too, or a full lane reads as one with a slot free (#16995). | |
| 63 | */ | |
| 64 | export function openGates(db: Database, since: Date): { pull: number | null; since: string }[] { | |
| 65 | return db | |
| 66 | .query<{ pull: number | null; since: string }, [string]>( | |
| 67 | `SELECT issue.number AS pull, check_gate.started_at AS since FROM check_gate | |
| 68 | LEFT JOIN issue ON issue.id = check_gate.issue_id | |
| 69 | WHERE check_gate.finished_at IS NULL AND check_gate.started_at > ?1`, | |
| 70 | ) | |
| 71 | .all(since.toISOString()); | |
| 72 | } |
src/kernel/vitals.ts +12 −5
| @@ -54,6 +54,7 @@ import { domainDrillNeeds } from "./domain_drill.ts"; | ||
| 54 | 54 | import { watchNeeds } from "../cloud/watch.ts"; |
| 55 | 55 | import { freeChecks, heldChecks, redHref, redSentence } from "../checks/red_main.ts"; |
| 56 | 56 | import { diskRedSentence, diskReds } from "../checks/disk_red.ts"; |
| 57 | import { gatesHolding, holdsSlot } from "../checks/busy_slots.ts"; | |
| 57 | 58 | import { flakeList, type FlakeRow } from "../checks/flake.ts"; |
| 58 | 59 | import { flakeHref, sharedCause, sharedSentence, sharedTests } from "../checks/shared_red.ts"; |
| 59 | 60 | |
| @@ -391,8 +392,10 @@ export const QUEUE_AGENT_FULL = "queue:agent:full"; | ||
| 391 | 392 | * lane starts the longest-waiting check first once it has waited |
| 392 | 393 | * `STARVATION_MS`, so a lane full of running checks is waiting for slots, which |
| 393 | 394 | * only a person adds (`checks.concurrency`, /settings/capacity). Set from the |
| 394 | * counts, as `QUEUE_AGENT_FULL` is. A lane waiting with a slot free stays | |
| 395 | * `queue:check`: that is a scheduler defect, and the sentinel files it. | |
| 395 | * counts, as `QUEUE_AGENT_FULL` is, and counted as the lane counts: a | |
| 396 | * merge-queue gate holds a slot, the verification lane none (#16995). A | |
| 397 | * lane waiting with a slot free stays `queue:check`: that is a scheduler | |
| 398 | * defect, and the sentinel files it. | |
| 396 | 399 | */ |
| 397 | 400 | export const QUEUE_CHECK_FULL = "queue:check:full"; |
| 398 | 401 | |
| @@ -558,8 +561,9 @@ export function vitals(input: VitalsInput): Vitals { | ||
| 558 | 561 | |
| 559 | 562 | const running = listRunning(input.db); |
| 560 | 563 | const lane = readLane(input.db, running, now); |
| 564 | // The check runs holding a slot as the lane counts them (`checks/busy_slots.ts`, #16995). | |
| 561 | 565 | const checkRuns: LaneRun[] = running |
| 562 | .filter((r) => r.run.kind === "check" && !leaseLapsed(r.run, STALE_AFTER_MS, now)) | |
| 566 | .filter((r) => r.run.kind === "check" && holdsSlot(r.run.env) && !leaseLapsed(r.run, STALE_AFTER_MS, now)) | |
| 563 | 567 | .map((r) => ({ pull: r.issue, since: r.run.startedAt ?? r.run.createdAt })); |
| 564 | 568 | const queue: Record<string, number> = {}; |
| 565 | 569 | const reds = heldChecks(input.db); |
| @@ -572,10 +576,13 @@ export function vitals(input: VitalsInput): Vitals { | ||
| 572 | 576 | // Age and "since" come from the free checks alone. |
| 573 | 577 | if (free.oldest !== null && now - new Date(free.oldest).getTime() > BUDGETS.laneWait) { |
| 574 | 578 | const slots = Number(capacityValue(input.db, "checks.concurrency")); |
| 579 | // Gates in flight hold slots too; read only when the lane is past its | |
| 580 | // budget, so a calm build pays no read for them. | |
| 581 | const busy: LaneRun[] = [...checkRuns, ...gatesHolding(input.db, now)]; | |
| 575 | 582 | need( |
| 576 | 583 | "todo", |
| 577 | checkRuns.length >= Math.max(1, slots) ? QUEUE_CHECK_FULL : "queue:check", | |
| 578 | laneSentence(free.n, free.oldest, checkRuns, slots, now, Math.min(held, row.queued), free.byAccount), | |
| 584 | busy.length >= Math.max(1, slots) ? QUEUE_CHECK_FULL : "queue:check", | |
| 585 | laneSentence(free.n, free.oldest, busy, slots, now, Math.min(held, row.queued), free.byAccount), | |
| 579 | 586 | new Date(free.oldest).toISOString(), |
| 580 | 587 | "/settings/capacity", |
| 581 | 588 | ); |
test/kernel-boundary.test.ts +1
| @@ -50,6 +50,7 @@ const CROSSINGS: Readonly<Record<string, string>> = { | ||
| 50 | 50 | "vitals.ts -> ../checks/red_main.ts": "the standing says when main is red", |
| 51 | 51 | "vitals.ts -> ../checks/disk_red.ts": "the standing names checks red for lack of disk", |
| 52 | 52 | "vitals.ts -> ../checks/flake.ts": "the standing lists flaky tests", |
| 53 | "vitals.ts -> ../checks/busy_slots.ts": "the standing counts check slots busy as the lane does", | |
| 53 | 54 | "vitals.ts -> ../checks/shared_red.ts": "the standing names a cause shared by red checks", |
| 54 | 55 | }; |
| 55 | 56 |
test/vitals.test.ts +46 −1
| @@ -9,6 +9,9 @@ import { tmpdir } from "node:os"; | ||
| 9 | 9 | import { join } from "node:path"; |
| 10 | 10 | import { createApp, type App } from "../src/app.ts"; |
| 11 | 11 | import { createRun } from "../src/core/runs.ts"; |
| 12 | import { setCapacity } from "../src/core/capacity.ts"; | |
| 13 | import { beginGate, endGate } from "../src/checks/gate_record.ts"; | |
| 14 | import { VERIFY_ENV } from "../src/checks/verify.ts"; | |
| 12 | 15 | import { createToken } from "../src/core/tokens.ts"; |
| 13 | 16 | import { createUser } from "../src/core/users.ts"; |
| 14 | 17 | import { vitals } from "../src/kernel/vitals.ts"; |
| @@ -187,7 +190,8 @@ test("the number of queries does not grow with runs", () => { | ||
| 187 | 190 | // hourly cloud watch's readings, one row an account (#16329). And, once per distinct owner of a |
| 188 | 191 | // queued check, the concurrent-checks limit the scheduler asks (#5130): its stored value, then |
| 189 | 192 | // whether the owner is a newcomer; two for this fixture's one owner, however many checks. |
| 190 | // And the one read that names a runner that stopped answering. | |
| 193 | // And the one read that names a runner that stopped answering. The merge-queue gates holding | |
| 194 | // a check slot are read only when the lane is past its budget (#16995), so not here. | |
| 191 | 195 | expect(before).toBe(16); |
| 192 | 196 | }); |
| 193 | 197 | |
| @@ -491,6 +495,47 @@ test("a lane older than its budget is degraded with its cause; a silent run is s | ||
| 491 | 495 | app.db.query("DELETE FROM run").run(); |
| 492 | 496 | }); |
| 493 | 497 | |
| 498 | test("a merge-queue gate holds a check slot and the verification lane none, as the lane counts them (#16995)", () => { | |
| 499 | app.db.query("DELETE FROM run").run(); | |
| 500 | app.db.query("DELETE FROM check_gate").run(); | |
| 501 | const admin = app.db.query<{ id: string }, []>("SELECT id FROM user LIMIT 1").get()!.id; | |
| 502 | setCapacity(app.db, "checks.concurrency", "2", admin); | |
| 503 | try { | |
| 504 | const now = Date.now(); | |
| 505 | const iso = (ms: number) => new Date(ms).toISOString(); | |
| 506 | const running = (env?: string) => { | |
| 507 | const r = createRun(app.db, { repoId, kind: "check", ...(env === undefined ? {} : { env }) }); | |
| 508 | app.db | |
| 509 | .query("UPDATE run SET state='running', started_at=?2, heartbeat_at=?3 WHERE id=?1") | |
| 510 | .run(r.id, iso(now - 20 * 60_000), iso(now)); | |
| 511 | }; | |
| 512 | running(); | |
| 513 | running(VERIFY_ENV); | |
| 514 | const queued = createRun(app.db, { repoId, kind: "check" }); | |
| 515 | app.db.query("UPDATE run SET created_at=?2 WHERE id=?1").run(queued.id, iso(now - 13 * 60_000)); | |
| 516 | const lane = () => | |
| 517 | vitals({ db: app.db, signals: app.signals, dataDir, disk: roomy, now }).degraded.find((d) => | |
| 518 | d.cause.startsWith("queue:check"), | |
| 519 | ); | |
| 520 | // One check runs and the verification lane holds no slot: a slot is free, a scheduler defect. | |
| 521 | expect(lane()?.cause).toBe("queue:check"); | |
| 522 | expect(lane()?.sentence).toContain("1 check waits for 2 slots, 1 busy"); | |
| 523 | // A gate takes the other slot: the lane is full, waiting for capacity. | |
| 524 | const gate = beginGate(app.db, repoId, undefined, "a".repeat(40), new Date(now - 5 * 60_000)); | |
| 525 | expect(lane()?.cause).toBe("queue:check:full"); | |
| 526 | expect(lane()?.sentence).toContain("1 check waits for 2 slots, all busy"); | |
| 527 | // A gate open past its deadline is a crash's leftover, and holds nothing. | |
| 528 | app.db.query("UPDATE check_gate SET started_at=?2 WHERE id=?1").run(gate, iso(now - 16 * 60_000)); | |
| 529 | expect(lane()?.cause).toBe("queue:check"); | |
| 530 | endGate(app.db, gate); | |
| 531 | expect(lane()?.cause).toBe("queue:check"); | |
| 532 | } finally { | |
| 533 | setCapacity(app.db, "checks.concurrency", "", admin); | |
| 534 | app.db.query("DELETE FROM run").run(); | |
| 535 | app.db.query("DELETE FROM check_gate").run(); | |
| 536 | } | |
| 537 | }); | |
| 538 | ||
| 494 | 539 | test("only the disk need sees the disk: a 5% reading raises it, and nothing else does", () => { |
| 495 | 540 | const low = () => ({ freeBytes: 5, totalBytes: 100 }); |
| 496 | 541 | const v = vitals({ db: app.db, signals: app.signals, dataDir, disk: low }); |
new above
offline
Rewrap this comment; the line runs well past the others.
bun scripts/gate.ts --fixdoes it.