Public: anyone can read this; the crew can change it.
The board's one-line verdict says 'needs you: forge …' from forgeVerdict, and lists every incident #2334
scout/forge:scout/2324-the-board-s-one-line-verdict-says-needs → main 4 commits fork 4 threads · 4 unresolved
8 files
changed +104
−36
src/actions/health.ts +3 −9
| @@ -12,7 +12,8 @@ import type { App } from "../app.ts"; | ||
| 12 | 12 | import { appsRuntime } from "../apps/runtime.ts"; |
| 13 | 13 | import { listApps } from "../core/apps.ts"; |
| 14 | 14 | import type { User } from "../core/users.ts"; |
| 15 | import { forgeHealth, rolloutLine, type ForgeHealth } from "../kernel/guard.ts"; | |
| 15 | import { forgeHealth, type ForgeHealth } from "../kernel/guard.ts"; | |
| 16 | import { guardNeeds } from "../kernel/guard_verdict.ts"; | |
| 16 | 17 | import { |
| 17 | 18 | laneLine, |
| 18 | 19 | sinceWords, |
| @@ -70,14 +71,7 @@ export function readHealth( | ||
| 70 | 71 | export function forgeNeeds(app: App, actor: User | undefined): string[] | undefined { |
| 71 | 72 | if (!actor?.isAdmin) return undefined; |
| 72 | 73 | const h = readHealth(app, actor) as Vitals & ForgeHealth; |
| 73 | const rollout = rolloutLine(h); | |
| 74 | return [ | |
| 75 | ...(rollout === null ? [] : [rollout]), | |
| 76 | ...h.incidents | |
| 77 | .filter((i) => i.key !== "stuck" && i.key !== "held") | |
| 78 | .map((i) => `${i.key}: ${i.message}`), | |
| 79 | ...h.degraded.map(needLine), | |
| 80 | ]; | |
| 74 | return [...guardNeeds(h, Date.now()), ...h.degraded.map(needLine)]; | |
| 81 | 75 | } |
| 82 | 76 | |
| 83 | 77 | export { sinceWords }; |
src/kernel/guard.ts −7
| @@ -126,10 +126,3 @@ export function forgeHealth( | ||
| 126 | 126 | checkedAt: guard.checkedAt, |
| 127 | 127 | }; |
| 128 | 128 | } |
| 129 | ||
| 130 | /** The status-line words for a rollout that is not simply fine, else null. */ | |
| 131 | export function rolloutLine(h: ForgeHealth): string | null { | |
| 132 | if (h.rollout.state === "blocked") return `rollout blocked: ${h.rollout.reason}`; | |
| 133 | if (h.rollout.state === "held") return `rollout held: ${h.rollout.reason}`; | |
| 134 | return h.stale ? h.rollout.reason : null; | |
| 135 | } |
src/kernel/guard_verdict.ts +39 −5
| @@ -4,7 +4,7 @@ | ||
| 4 | 4 | * view that was never written (no `checkedAt`) is not stale. |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | import { GUARD_STALE_MS, type Guard } from "./guard.ts"; | |
| 7 | import { GUARD_STALE_MS, type Guard, type Incident } from "./guard.ts"; | |
| 8 | 8 | |
| 9 | 9 | /** Draining longer than this is a release that did not finish. */ |
| 10 | 10 | export const DRAIN_LIMIT_MS = 5 * 60_000; |
| @@ -14,15 +14,49 @@ export interface VerdictView extends Guard { | ||
| 14 | 14 | readonly drainingSince?: number | null; |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | export function forgeVerdict(view: VerdictView, now: number): string | undefined { | |
| 17 | interface Verdict { | |
| 18 | readonly text: string; | |
| 19 | /** The incident the text names; absent for a drain or a stale view. */ | |
| 20 | readonly incident?: Incident; | |
| 21 | } | |
| 22 | ||
| 23 | function verdictOf(view: VerdictView, now: number): Verdict | undefined { | |
| 18 | 24 | const found = view.incidents.find( |
| 19 | 25 | (i) => i.key === "held" || i.key === "stuck" || i.key.startsWith("oom:"), |
| 20 | 26 | ); |
| 21 | if (found) return `${found.key}: ${found.message}`; | |
| 27 | if (found) return { text: `${found.key}: ${found.message}`, incident: found }; | |
| 22 | 28 | const since = view.drainingSince; |
| 23 | 29 | if (typeof since === "number" && now - since > DRAIN_LIMIT_MS) |
| 24 | return `draining for ${Math.floor((now - since) / 60_000)} minutes`; | |
| 30 | return { text: `draining for ${Math.floor((now - since) / 60_000)} minutes` }; | |
| 25 | 31 | if (view.checkedAt !== null && now - Date.parse(view.checkedAt) > GUARD_STALE_MS) |
| 26 | return `the platform's view is stale: its last check was ${view.checkedAt}`; | |
| 32 | return { text: `the platform's view is stale: its last check was ${view.checkedAt}` }; | |
| 27 | 33 | return undefined; |
| 28 | 34 | } |
| 35 | ||
| 36 | export function forgeVerdict(view: VerdictView, now: number): string | undefined { | |
| 37 | return verdictOf(view, now)?.text; | |
| 38 | } | |
| 39 | ||
| 40 | /** | |
| 41 | * The platform's causes for concern, one sentence each, for every door that | |
| 42 | * prints them (the board's strip, the terminal): the verdict's incident, or | |
| 43 | * the verdict itself when it names none, reads "needs you: forge …"; a | |
| 44 | * stuck or held incident that is not the verdict keeps "rollout blocked/held", | |
| 45 | * the rest "key: message". Each fact once. Only the first of held, stuck or | |
| 46 | * oom is the verdict; the others keep their older wording. | |
| 47 | */ | |
| 48 | export function guardNeeds(view: VerdictView, now: number): string[] { | |
| 49 | const verdict = verdictOf(view, now); | |
| 50 | const lines = view.incidents.map((i) => | |
| 51 | i === verdict?.incident | |
| 52 | ? `needs you: forge ${verdict.text}` | |
| 53 | : i.key === "stuck" | |
| 54 | ? `rollout blocked: ${i.message}` | |
| 55 | : i.key === "held" | |
| 56 | ? `rollout held: ${i.message}` | |
| 57 | : `${i.key}: ${i.message}`, | |
| 58 | ); | |
| 59 | if (verdict !== undefined && verdict.incident === undefined) | |
| 60 | lines.push(`needs you: forge ${verdict.text}`); | |
| 61 | return lines; | |
| 62 | } |
src/web/pages/board.ts +4 −7
| @@ -43,7 +43,8 @@ import { | ||
| 43 | 43 | import { readSpend } from "../../actions/spend.ts"; |
| 44 | 44 | import { spendView } from "./spend.ts"; |
| 45 | 45 | import type { HandContext } from "../../crew/handover.ts"; |
| 46 | import { forgeHealth, rolloutLine } from "../../kernel/guard.ts"; | |
| 46 | import { forgeHealth } from "../../kernel/guard.ts"; | |
| 47 | import { guardNeeds } from "../../kernel/guard_verdict.ts"; | |
| 47 | 48 | import { laneLine, type Vitals } from "../../kernel/vitals.ts"; |
| 48 | 49 | import { getIssue, getIssuesByIds, type Issue } from "../../core/issues.ts"; |
| 49 | 50 | import { looksForApps } from "../../core/looks.ts"; |
| @@ -328,10 +329,7 @@ function forgeStrip(ctx: Ctx): Html | null { | ||
| 328 | 329 | if (!ctx.auth.user?.isAdmin) return null; |
| 329 | 330 | const v = forgeVitals(ctx.app); |
| 330 | 331 | const fh = forgeHealth(); |
| 331 | const rollout = rolloutLine(fh); | |
| 332 | const others = fh.incidents.filter( | |
| 333 | (i) => i.key !== "stuck" && i.key !== "held", | |
| 334 | ); | |
| 332 | const needs = guardNeeds(fh, Date.now()); | |
| 335 | 333 | const ok = v.ok && fh.ok; |
| 336 | 334 | const lane = laneLine(v.lane); |
| 337 | 335 | return html`<div |
outdated
Matching on the formatted string couples the board to forgeVerdict's output format. Put the 'needs you' derivation in one shared function used by the board and by src/actions/health.ts, so the terminal says it too. |
||
| @@ -343,8 +341,7 @@ function forgeStrip(ctx: Ctx): Html | null { | ||
| 343 | 341 | role="status" |
| 344 | 342 | > |
| 345 | 343 | ${sentinelSpan(ctx.app)} |
| 346 | ${rollout === null ? "" : html`<span class="board-forge-need">${rollout}</span>`} | |
| 347 | ${others.map((i) => html`<span class="board-forge-need">${i.key}: ${i.message}</span>`)} | |
| 344 | ${needs.map((n) => html`<span class="board-forge-need">${n}</span>`)} | |
| 348 | 345 | ${lane === null ? "" : html`<span class="board-forge-lane">Lane: ${lane}</span>`} |
| 349 | 346 | ${ |
| 350 | 347 | ok |
test/board.test.ts +38 −1
| @@ -12,6 +12,7 @@ import { tmpdir } from "node:os"; | ||
| 12 | 12 | import { join } from "node:path"; |
| 13 | 13 | import { createApp, type App } from "../src/app.ts"; |
| 14 | 14 | import { changeCapacity } from "../src/actions/capacity.ts"; |
| 15 | import { forgeNeeds } from "../src/actions/health.ts"; | |
| 15 | 16 | import { enableApp } from "../src/actions/apps.ts"; |
| 16 | 17 | import { addToCrew, createAgent } from "../src/actions/crew.ts"; |
| 17 | 18 | import { openIssue } from "../src/actions/issues.ts"; |
| @@ -513,7 +514,7 @@ describe("the board's forge strip", () => { | ||
| 513 | 514 | ); |
| 514 | 515 | writeFileSync(join(guard, "checkedAt"), new Date().toISOString()); |
| 515 | 516 | const blocked = await board("root"); |
| 516 | expect(blocked).toContain("rollout blocked: quota refused <i>8Gi</i>"); | |
| 517 | expect(blocked).toContain("needs you: forge stuck: quota refused <i>8Gi</i>"); | |
| 517 | 518 | expect(blocked).not.toContain("<i>8Gi</i>"); |
| 518 | 519 | // One line, and the board beneath it still renders. |
| 519 | 520 | expect(blocked.match(/class="board-forge-need"/g)?.length).toBe(1); |
| @@ -525,6 +526,42 @@ describe("the board's forge strip", () => { | ||
| 525 | 526 | } |
| 526 | 527 | }); |
| 527 | 528 | |
| 529 | test("a held incident adds 'needs you: forge …'; an empty view leaves All fine", async () => { | |
| 530 | const guard = mkdtempSync(join(tmpdir(), "forge-board-guard-")); | |
| 531 | process.env["FORGE_GUARD_DIR"] = guard; | |
| 532 | try { | |
| 533 | writeFileSync(join(guard, "status.json"), JSON.stringify({ incidents: {} })); | |
| 534 | writeFileSync(join(guard, "checkedAt"), new Date().toISOString()); | |
| 535 | const calm = await board("root"); | |
| 536 | expect(calm).toContain("All fine"); | |
| 537 | expect(calm).not.toContain("needs you: forge"); | |
| 538 | writeFileSync(join(guard, "status.json"), JSON.stringify({ incidents: { held: "preflight <b>refused</b>", down: "paged already" } })); | |
| 539 | const held = await board("root"); | |
| 540 | expect(held).toContain("needs you: forge held: preflight <b>refused</b>"); | |
| 541 | expect(held).toContain("down: paged already"); | |
| 542 | expect(held.split("held: preflight").length - 1).toBe(1); | |
| 543 | expect(held.match(/class="board-forge-need"/g)?.length).toBe(2); | |
| 544 | expect(held).not.toContain("board-forge-verdict"); | |
| 545 | // The terminal says the same lines as the board. | |
| 546 | const terminal = forgeNeeds(app, getUserByName(app.db, "root")!)!; | |
| 547 | expect(terminal).toContain("needs you: forge held: preflight <b>refused</b>"); | |
| 548 | expect(terminal).toContain("down: paged already"); | |
| 549 | for (const line of terminal) expect(held).toContain(line.replace("<b>", "<b>").replace("</b>", "</b>")); | |
| 550 | // A held and an oom incident: the first is the verdict, the oom says itself once. | |
| 551 | writeFileSync(join(guard, "status.json"), JSON.stringify({ incidents: { "oom:x": "killed", stuck: "no quota" } })); | |
| 552 | const both = await board("root"); | |
| 553 | expect(both.split("oom:x: killed").length - 1).toBe(1); | |
| 554 | expect(both.split("no quota").length - 1).toBe(1); | |
| 555 | expect(both).toContain("needs you: forge oom:x: killed"); | |
| 556 | expect(both).toContain("rollout blocked: no quota"); | |
| 557 | expect(held).not.toContain("All fine"); | |
| 558 | expect(await board("bob")).not.toContain("needs you: forge"); | |
| 559 | } finally { | |
| 560 | delete process.env["FORGE_GUARD_DIR"]; | |
| 561 | rmSync(guard, { recursive: true, force: true }); | |
| 562 | } | |
| 563 | }); | |
| 564 | ||
| 528 | 565 | test("the sentinel's line is the admin's alone, and absent before the first hunt", async () => { |
| 529 | 566 | expect(await board("root")).not.toContain("sentinel"); |
| 530 | 567 |
test/guard-verdict.test.ts +18
| @@ -31,3 +31,21 @@ test("an empty view and a never-written view give undefined", () => { | ||
| 31 | 31 | expect(forgeVerdict(view({}), NOW)).toBeUndefined(); |
| 32 | 32 | expect(forgeVerdict(view({}, null), NOW)).toBeUndefined(); |
| 33 | 33 | }); |
| 34 | ||
| 35 | test("guardNeeds says each incident once; the verdict's reads 'needs you: forge'", async () => { | |
| 36 | const { guardNeeds } = await import("../src/kernel/guard_verdict.ts"); | |
| 37 | expect(guardNeeds(view({}), NOW)).toEqual([]); | |
| 38 | expect(guardNeeds(view({ down: "paged", held: "preflight", "oom:x": "killed" }), NOW)).toEqual([ | |
| 39 | "down: paged", | |
| 40 | "needs you: forge held: preflight", | |
| 41 | "oom:x: killed", | |
| 42 | ]); | |
| 43 | expect(guardNeeds(view({ "oom:x": "killed", stuck: "no quota" }), NOW)).toEqual([ | |
| 44 | "needs you: forge oom:x: killed", | |
| 45 | "rollout blocked: no quota", | |
| 46 | ]); | |
| 47 | expect(guardNeeds(view({ down: "paged" }, "2026-10-02T11:00:00Z"), NOW)).toEqual([ | |
| 48 | "down: paged", | |
| 49 | "needs you: forge the platform's view is stale: its last check was 2026-10-02T11:00:00Z", | |
| 50 | ]); | |
| 51 | }); |
test/guard.test.ts −5
| @@ -12,7 +12,6 @@ import { | ||
| 12 | 12 | forgeHealth, |
| 13 | 13 | parseGuard, |
| 14 | 14 | readGuard, |
| 15 | rolloutLine, | |
| 16 | 15 | } from "../src/kernel/guard.ts"; |
| 17 | 16 | |
| 18 | 17 | const NOW = Date.parse("2026-10-02T12:00:00Z"); |
| @@ -28,7 +27,6 @@ test("no ConfigMap, or an empty one, reports ok", () => { | ||
| 28 | 27 | const empty = forgeHealth(parseGuard(status({}), fresh), NOW); |
| 29 | 28 | expect(empty.ok).toBe(true); |
| 30 | 29 | expect(empty.incidents).toEqual([]); |
| 31 | expect(rolloutLine(empty)).toBeNull(); | |
| 32 | 30 | }); |
| 33 | 31 | |
| 34 | 32 | test("a stuck incident blocks the rollout with its reason", () => { |
| @@ -36,7 +34,6 @@ test("a stuck incident blocks the rollout with its reason", () => { | ||
| 36 | 34 | const h = forgeHealth(parseGuard(status({ stuck: reason }), fresh), NOW); |
| 37 | 35 | expect(h.rollout).toEqual({ state: "blocked", reason }); |
| 38 | 36 | expect(h.ok).toBe(false); |
| 39 | expect(rolloutLine(h)).toBe(`rollout blocked: ${reason}`); | |
| 40 | 37 | }); |
| 41 | 38 | |
| 42 | 39 | test("a held incident holds the rollout", () => { |
| @@ -45,7 +42,6 @@ test("a held incident holds the rollout", () => { | ||
| 45 | 42 | NOW, |
| 46 | 43 | ); |
| 47 | 44 | expect(h.rollout).toEqual({ state: "held", reason: "preflight: no room on node" }); |
| 48 | expect(rolloutLine(h)).toBe("rollout held: preflight: no room on node"); | |
| 49 | 45 | }); |
| 50 | 46 | |
| 51 | 47 | test("a stale view says so instead of all fine", () => { |
| @@ -53,7 +49,6 @@ test("a stale view says so instead of all fine", () => { | ||
| 53 | 49 | expect(h.stale).toBe(true); |
| 54 | 50 | expect(h.ok).toBe(false); |
| 55 | 51 | expect(h.rollout.reason).toContain("stale"); |
| 56 | expect(rolloutLine(h)).toContain("stale"); | |
| 57 | 52 | }); |
| 58 | 53 | |
| 59 | 54 | test("malformed input reads as nothing, and odd keys are dropped", () => { |
test/tui-screens.test.ts +2 −2
| @@ -789,7 +789,7 @@ describe("the forge's health in the terminal", () => { | ||
| 789 | 789 | |
| 790 | 790 | const admin = boot(forge, as(a.value)); |
| 791 | 791 | await admin.settle(); |
| 792 | expect(admin.text()).toContain("rollout blocked: quota refused"); | |
| 792 | expect(admin.text()).toContain("needs you: forge stuck: quota refused"); | |
| 793 | 793 | expect(admin.text()).not.toContain("All fine"); |
| 794 | 794 | expect(admin.text()).not.toContain("Lane:"); |
| 795 | 795 | admin.stop(); |
| @@ -804,7 +804,7 @@ describe("the forge's health in the terminal", () => { | ||
| 804 | 804 | |
| 805 | 805 | const other = boot(forge, as(b.value)); |
| 806 | 806 | await other.settle(); |
| 807 | expect(other.text()).not.toContain("rollout blocked"); | |
| 807 | expect(other.text()).not.toContain("needs you: forge"); | |
| 808 | 808 | expect(other.text()).not.toContain("Lane:"); |
| 809 | 809 | expect(other.text()).not.toContain("All fine"); |
| 810 | 810 | other.stop(); |
new above
offline
The verdict repeats what
rolloutandothersalready print forheldandoom:*. Pass the verdict into the filter, or build one list, so no incident shows twice.