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 #2431

Parked opened this
Closed without merging

scout/forge:scout/2324-the-board-s-one-line-verdict-says-needs → main 4 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
8 files changed +104 −36
src/actions/health.ts +3 −9
@@ -12,7 +12,8 @@ import type { App } from "../app.ts";
1212 import { appsRuntime } from "../apps/runtime.ts";
1313 import { listApps } from "../core/apps.ts";
1414 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";
1617 import {
1718 laneLine,
1819 sinceWords,
@@ -70,14 +71,7 @@ export function readHealth(
7071 export function forgeNeeds(app: App, actor: User | undefined): string[] | undefined {
7172 if (!actor?.isAdmin) return undefined;
7273 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)];
8175 }
8276
8377 export { sinceWords };
src/kernel/guard.ts −7
@@ -126,10 +126,3 @@ export function forgeHealth(
126126 checkedAt: guard.checkedAt,
127127 };
128128 }
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 @@
44 * view that was never written (no `checkedAt`) is not stale.
55 */
66
7 import { GUARD_STALE_MS, type Guard } from "./guard.ts";
7 import { GUARD_STALE_MS, type Guard, type Incident } from "./guard.ts";
88
99 /** Draining longer than this is a release that did not finish. */
1010 export const DRAIN_LIMIT_MS = 5 * 60_000;
@@ -14,15 +14,49 @@ export interface VerdictView extends Guard {
1414 readonly drainingSince?: number | null;
1515 }
1616
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 {
1824 const found = view.incidents.find(
1925 (i) => i.key === "held" || i.key === "stuck" || i.key.startsWith("oom:"),
2026 );
21 if (found) return `${found.key}: ${found.message}`;
27 if (found) return { text: `${found.key}: ${found.message}`, incident: found };
2228 const since = view.drainingSince;
2329 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` };
2531 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}` };
2733 return undefined;
2834 }
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 {
4343 import { readSpend } from "../../actions/spend.ts";
4444 import { spendView } from "./spend.ts";
4545 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";
4748 import { laneLine, type Vitals } from "../../kernel/vitals.ts";
4849 import { getIssue, getIssuesByIds, type Issue } from "../../core/issues.ts";
4950 import { looksForApps } from "../../core/looks.ts";
@@ -328,10 +329,7 @@ function forgeStrip(ctx: Ctx): Html | null {
328329 if (!ctx.auth.user?.isAdmin) return null;
329330 const v = forgeVitals(ctx.app);
330331 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());
335333 const ok = v.ok && fh.ok;
336334 const lane = laneLine(v.lane);
337335 return html`<div
@@ -343,8 +341,7 @@ function forgeStrip(ctx: Ctx): Html | null {
343341 role="status"
344342 >
345343 ${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>`)}
348345 ${lane === null ? "" : html`<span class="board-forge-lane">Lane: ${lane}</span>`}
349346 ${
350347 ok
test/board.test.ts +38 −1
@@ -12,6 +12,7 @@ import { tmpdir } from "node:os";
1212 import { join } from "node:path";
1313 import { createApp, type App } from "../src/app.ts";
1414 import { changeCapacity } from "../src/actions/capacity.ts";
15 import { forgeNeeds } from "../src/actions/health.ts";
1516 import { enableApp } from "../src/actions/apps.ts";
1617 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1718 import { openIssue } from "../src/actions/issues.ts";
@@ -513,7 +514,7 @@ describe("the board's forge strip", () => {
513514 );
514515 writeFileSync(join(guard, "checkedAt"), new Date().toISOString());
515516 const blocked = await board("root");
516 expect(blocked).toContain("rollout blocked: quota refused &lt;i&gt;8Gi&lt;/i&gt;");
517 expect(blocked).toContain("needs you: forge stuck: quota refused &lt;i&gt;8Gi&lt;/i&gt;");
517518 expect(blocked).not.toContain("<i>8Gi</i>");
518519 // One line, and the board beneath it still renders.
519520 expect(blocked.match(/class="board-forge-need"/g)?.length).toBe(1);
@@ -525,6 +526,42 @@ describe("the board's forge strip", () => {
525526 }
526527 });
527528
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 &lt;b&gt;refused&lt;/b&gt;");
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>", "&lt;b&gt;").replace("</b>", "&lt;/b&gt;"));
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
528565 test("the sentinel's line is the admin's alone, and absent before the first hunt", async () => {
529566 expect(await board("root")).not.toContain("sentinel");
530567
test/guard-verdict.test.ts +18
@@ -31,3 +31,21 @@ test("an empty view and a never-written view give undefined", () => {
3131 expect(forgeVerdict(view({}), NOW)).toBeUndefined();
3232 expect(forgeVerdict(view({}, null), NOW)).toBeUndefined();
3333 });
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 {
1212 forgeHealth,
1313 parseGuard,
1414 readGuard,
15 rolloutLine,
1615 } from "../src/kernel/guard.ts";
1716
1817 const NOW = Date.parse("2026-10-02T12:00:00Z");
@@ -28,7 +27,6 @@ test("no ConfigMap, or an empty one, reports ok", () => {
2827 const empty = forgeHealth(parseGuard(status({}), fresh), NOW);
2928 expect(empty.ok).toBe(true);
3029 expect(empty.incidents).toEqual([]);
31 expect(rolloutLine(empty)).toBeNull();
3230 });
3331
3432 test("a stuck incident blocks the rollout with its reason", () => {
@@ -36,7 +34,6 @@ test("a stuck incident blocks the rollout with its reason", () => {
3634 const h = forgeHealth(parseGuard(status({ stuck: reason }), fresh), NOW);
3735 expect(h.rollout).toEqual({ state: "blocked", reason });
3836 expect(h.ok).toBe(false);
39 expect(rolloutLine(h)).toBe(`rollout blocked: ${reason}`);
4037 });
4138
4239 test("a held incident holds the rollout", () => {
@@ -45,7 +42,6 @@ test("a held incident holds the rollout", () => {
4542 NOW,
4643 );
4744 expect(h.rollout).toEqual({ state: "held", reason: "preflight: no room on node" });
48 expect(rolloutLine(h)).toBe("rollout held: preflight: no room on node");
4945 });
5046
5147 test("a stale view says so instead of all fine", () => {
@@ -53,7 +49,6 @@ test("a stale view says so instead of all fine", () => {
5349 expect(h.stale).toBe(true);
5450 expect(h.ok).toBe(false);
5551 expect(h.rollout.reason).toContain("stale");
56 expect(rolloutLine(h)).toContain("stale");
5752 });
5853
5954 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", () => {
789789
790790 const admin = boot(forge, as(a.value));
791791 await admin.settle();
792 expect(admin.text()).toContain("rollout blocked: quota refused");
792 expect(admin.text()).toContain("needs you: forge stuck: quota refused");
793793 expect(admin.text()).not.toContain("All fine");
794794 expect(admin.text()).not.toContain("Lane:");
795795 admin.stop();
@@ -804,7 +804,7 @@ describe("the forge's health in the terminal", () => {
804804
805805 const other = boot(forge, as(b.value));
806806 await other.settle();
807 expect(other.text()).not.toContain("rollout blocked");
807 expect(other.text()).not.toContain("needs you: forge");
808808 expect(other.text()).not.toContain("Lane:");
809809 expect(other.text()).not.toContain("All fine");
810810 other.stop();

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs