Public: anyone can read this; the crew can change it.
Observability 3b: the /boards index is live by streaming, like a board #16848
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/3715-observability-3b-the-boards-index-is-liv → main 0 commits fork 2 threads · 2 unresolved
18 files
changed +378
−25
- docs/CREW.md
- docs/design/attention-budget.json
- docs/features/boards-index-live.md
- src/boards/store.ts
- src/flow/numbers.ts
- src/http/marks/boards.json
- src/http/server.ts
- src/web/boards-index-live.ts
- src/web/pages/boards-index-stream.ts
- src/web/pages/boards-view.ts
- src/web/pages/flow-panel.ts
- test/boards-index-stream.test.ts
- test/design-audit.test.ts
- test/flow-throughput.test.ts
- test/job-slices.test.ts
- test/no-polling.test.ts
- test/pages-budget.test.ts
- test/server-timing-sweep.test.ts
docs/CREW.md +2
| @@ -383,6 +383,8 @@ Where the whole forge waits is the owner's, on `/boards` (the old `/flow` redire | ||
| 383 | 383 | The terminal also has an Access command (`:` → Access), a site admin's: it reads the same last-day non-browser requests as Settings → Access and the `access` MCP tool, newest first, and filters them with `s` (since), `u` (user agent) and `p` (path), `c` to clear. |
| 384 | 384 | |
| 385 | 385 | `/system` is the machine, for the owner (#1789), laid out like btop (#2721): a meter and a 30-reading block-character history per core, memory and swap meters, load, hwmon temperatures, disk use per mount, disk and network rates (`/proc/diskstats`, `/proc/net/dev`), and a table of every process grouped forge / check (`check:<run>`) / app (`app:<slug>/<env>`) / host with CPU, memory and age, sortable by CPU (`c`) or memory (`m`) or the buttons (shown only with a script; without one the order is by CPU). It reads `/proc` and `/sys` and updates in place over one event stream, `/system/stream` (`?pause` holds it still; no reload, no polling); the 2 s push timer runs only while someone is subscribed, so it costs nothing unwatched. Its history is the `machine` board source. A test file running in more than one check at once is counted at the top of `/system` and the `/boards` flow panel, with the checks. Command lines are never kept — only `*.test.ts` arguments. |
| 386 | ||
| 387 | The `/boards` index follows its flow panel over one event stream, `/boards/stream` (#3715), as data and not markup: a flat map of `data-n` key → text (`landed.hour`, `stage.review.waiting`, `queue.<repo>.queued`, `verdict`; `src/flow/numbers.ts`). The first frame is every key; after that a frame holds only the keys that changed, read 100 ms after the forge's event bus says anything moved. Idle, nothing is sent and nothing is requested; the page shows `live · updated Ns ago` on its own clock, and `/boards?pause` opens no stream. No dependency was added. Left out: the panel's time-driven text (oldest wait, the sparklines, the lists under `?out=`) changes on reload, not by stream; a repository that appears in the merge queue after the page loaded shows on reload. | |
| 386 | 388 | In the terminal, `:` → System shows the same view (the owner's only): per-core CPU with a block-character history, memory, swap, disk and network rates, and each group's top two processes (no sort; the dialog is read-only), below them three sparklines (CPU, memory, load) of the node over the last 6 hours, each with its latest value and peak, read through `historyOver` like the MCP `telemetry_history` tool; `h` cycles the window 1 h / 6 h / 24 h / 72 h, a window with nothing recorded says `no readings yet`, and anyone that tool refuses sees no line. `:` → Telemetry lists the agents and flips `telemetry:read` for the one you press Enter on. |
| 387 | 389 | An agent the owner grants `telemetry:read` (Settings → Telemetry, one switch per agent, revoked the same way) reads the same through `GET /api/v1/telemetry/{system,flow,sources,history}` and the MCP `flow` and `system` tools; private repositories' checks and apps are renamed `check:private-N` and lose their processes and test files, and `flow` (like `system`, an admin agent account needs the grant too: only a person who is an admin reads without it) names only public repositories' conflicted pulls, every read is listed on that page, and an agent without the grant is refused. `/contribute`, `GET /api/v1/contribute` and the MCP `contribute` tool are open to anyone: what the forge is, the bottleneck now, open issues labelled “help wanted” in public repositories, and how to propose (fork, pull, the same gate). The grant is a table, not a token scope, so no token has to be re-issued. |
| 388 | 390 |
docs/design/attention-budget.json +5 −5
| @@ -216,16 +216,16 @@ | ||
| 216 | 216 | }, |
| 217 | 217 | "boards": { |
| 218 | 218 | "390": { |
| 219 | "words": 342, | |
| 220 | "blocks": 98, | |
| 219 | "words": 345, | |
| 220 | "blocks": 99, | |
| 221 | 221 | "colours": 2 |
| 222 | 222 | }, |
| 223 | 223 | "1280": { |
| 224 | "words": 342, | |
| 225 | "blocks": 98, | |
| 224 | "words": 345, | |
| 225 | "blocks": 99, | |
| 226 | 226 | "colours": 2 |
| 227 | 227 | }, |
| 228 | "note": "Raised by 6 words and 3 blocks for the slots above the pipeline, at their least: a line each for checks and the crew (\"Checks 0 of 1 slots busy\", nothing more while nothing waits) and the Change capacity button that replaced the header's Capacity link; no legend (#16830)." | |
| 228 | "note": "Raised by 6 words and 3 blocks for the slots above the pipeline, at their least: a line each for checks and the crew (\"Checks 0 of 1 slots busy\", nothing more while nothing waits) and the Change capacity button that replaced the header's Capacity link; no legend (#16830). Plus 3 words and 1 block for the live line, \"live · Pause\", the one mechanism that replaced the page's old refresh (#3715)." | |
| 229 | 229 | }, |
| 230 | 230 | "forges": { |
| 231 | 231 | "390": { |
docs/features/boards-index-live.md added +14
| @@ -0,0 +1,14 @@ | ||
| 1 | --- | |
| 2 | topic: Tell the crew | |
| 3 | row: The boards index moves its flow numbers as events arrive | |
| 4 | --- | |
| 5 | # The boards index moves its flow numbers as events arrive (#3715) | |
| 6 | ||
| 7 | Open `/boards` as an admin: the flow panel reads `live · updated Ns ago`, and when a run, pull or check event arrives the numbers that moved change in place. `/boards?pause` holds it still. Without JavaScript the page stays as it was served. | |
| 8 | ||
| 9 | - **What goes down**: `GET /boards/stream` sends one full frame on connect, then only the keys that changed, a burst read once. While nothing moves nothing is sent. | |
| 10 | - **Who**: a person who is an admin. An agent or anyone else gets the not-found page. | |
| 11 | - **In the terminal**: there is no live side. The Boards screen in `src/tui/screens/boards.ts` lists boards and does not show the flow panel's numbers. | |
| 12 | - **One mechanism**: the index no longer refetches its HTML on events (`data-live`); the stream replaces it, so the oldest wait, sparklines and `?out=` lists change on reload. `/flow` keeps the refetch. | |
| 13 | ||
| 14 | The stream is `src/web/pages/boards-index-stream.ts`. |
src/boards/store.ts +1 −1
| @@ -50,7 +50,7 @@ const span = (v: unknown, max: number): v is number => | ||
| 50 | 50 | typeof v === "number" && Number.isInteger(v) && v >= 1 && v <= max; |
| 51 | 51 | |
| 52 | 52 | /** Names that belong to a page or an API door of their own, never a board's. */ |
| 53 | const TAKEN = new Set(["data", "sources", "query", "pins"]); | |
| 53 | const TAKEN = new Set(["data", "sources", "query", "pins", "stream"]); | |
| 54 | 54 | |
| 55 | 55 | /** A slug is a file name: lowercase, short, and never one of `TAKEN`. */ |
| 56 | 56 | export const isSlug = (s: unknown): s is string => |
src/flow/numbers.ts added +50
| @@ -0,0 +1,50 @@ | ||
| 1 | /** | |
| 2 | * The flow panel's numbers as plain data: a flat map from a key | |
| 3 | * (`landed.hour`, `stage.review.waiting`, `queue.alice/shop.queued`) to the | |
| 4 | * text the panel shows there. The page draws each at an element carrying that | |
| 5 | * key in `data-k`; the stream (`boards-index-stream.ts`) sends only the keys | |
| 6 | * that changed, and the client sets those elements' text. Plain strings in, | |
| 7 | * `textContent` out: nothing in it is markup. | |
| 8 | */ | |
| 9 | ||
| 10 | import type { Throughput } from "./throughput.ts"; | |
| 11 | import { span, verdict, type PipelineStage } from "./pipeline.ts"; | |
| 12 | import { count } from "../web/figure.ts"; | |
| 13 | import type { QueueRow } from "./queue.ts"; | |
| 14 | ||
| 15 | export type Numbers = Record<string, string>; | |
| 16 | ||
| 17 | /** Every number the panel shows, keyed. */ | |
| 18 | export function flowNumbers( | |
| 19 | stages: readonly PipelineStage[], | |
| 20 | flow: Throughput, | |
| 21 | queue: readonly QueueRow[], | |
| 22 | now: number, | |
| 23 | ): Numbers { | |
| 24 | const n: Numbers = { verdict: verdict(stages, now) }; | |
| 25 | const out = new Map(flow.stages.map((t) => [t.key, t])); | |
| 26 | const landed = out.get("approved"); | |
| 27 | n["landed.hour"] = count(landed?.hours[0] ?? 0); | |
| 28 | n["landed.day"] = count(landed?.items.length ?? 0); | |
| 29 | n.median = flow.medianAskToLiveMs === null ? "—" : span(flow.medianAskToLiveMs); | |
| 30 | for (const s of stages) { | |
| 31 | const t = out.get(s.key); | |
| 32 | n[`stage.${s.key}.waiting`] = count(s.waiting); | |
| 33 | n[`stage.${s.key}.active`] = s.key === "live" ? "—" : count(s.active); | |
| 34 | n[`stage.${s.key}.hour`] = count(t?.hours[0] ?? 0); | |
| 35 | n[`stage.${s.key}.day`] = count(t?.items.length ?? 0); | |
| 36 | } | |
| 37 | for (const q of queue) { | |
| 38 | n[`queue.${q.repo}.queued`] = String(q.queued); | |
| 39 | n[`queue.${q.repo}.gating`] = String(q.gating); | |
| 40 | n[`queue.${q.repo}.landed`] = String(q.landedHour); | |
| 41 | } | |
| 42 | return n; | |
| 43 | } | |
| 44 | ||
| 45 | /** The keys of `next` whose text differs from `before`'s. */ | |
| 46 | export function changed(before: Numbers, next: Numbers): Numbers { | |
| 47 | const delta: Numbers = {}; | |
| 48 | for (const [k, v] of Object.entries(next)) if (before[k] !== v) delta[k] = v; | |
| 49 | return delta; | |
| 50 | } |
src/http/marks/boards.json +1
src/http/server.ts +2
| @@ -75,6 +75,7 @@ import { pinnedRoutes } from "./pinned_routes.ts"; | ||
| 75 | 75 | import { infraRoutes } from "./infra_routes.ts"; |
| 76 | 76 | import { boardsAsk, boardsPage } from "../web/pages/boards.ts"; |
| 77 | 77 | import { boardNew, boardPin, boardPost, pinPost } from "../web/pages/boards-edit.ts"; |
| 78 | import { boardsIndexStream } from "../web/pages/boards-index-stream.ts"; | |
| 78 | 79 | import { boardsHoldPost } from "../web/pages/boards-holds.ts"; |
| 79 | 80 | import { nowPage } from "../web/pages/now.ts"; |
| 80 | 81 | import { myReposPage } from "../web/pages/my-repos.ts"; |
| @@ -1296,6 +1297,7 @@ export function buildRouter(): Router<Handler> { | ||
| 1296 | 1297 | router.add("POST", "/boards/holds", boardsHoldPost); |
| 1297 | 1298 | router.add("POST", "/boards/pin", boardPin); |
| 1298 | 1299 | for (const op of ["pin-panel", "unpin-panel", "move-pin"]) router.add("POST", `/boards/${op}`, pinPost); |
| 1300 | router.add("GET", "/boards/stream", boardsIndexStream); | |
| 1299 | 1301 | router.add("GET", "/boards/:slug", boardShow); |
| 1300 | 1302 | router.add("GET", "/boards/:slug/stream", boardStream); |
| 1301 | 1303 | router.add("POST", "/boards/:slug/:op", boardPost); |
src/web/boards-index-live.ts added +32
| @@ -0,0 +1,32 @@ | ||
| 1 | /** | |
| 2 | * The /boards index's client: one EventSource, each frame a map of | |
| 3 | * `data-k` key → text, set as text on the elements that carry the key. No | |
| 4 | * markup crosses the wire. "live · updated Ns ago" counts on the page's own | |
| 5 | * clock (no request); `?pause` opens nothing and says so. EventSource | |
| 6 | * reconnects by itself after a roll, and its first frame is the full map. | |
| 7 | */ | |
| 8 | export const boardsIndexLiveJs = /* js */ ` | |
| 9 | (function () { | |
| 10 | var status = document.getElementById('flow-live-state'); | |
| 11 | if (typeof EventSource === 'undefined' || /[?&]pause\\b/.test(location.search)) return; | |
| 12 | var at = null, shown = ''; | |
| 13 | function say() { | |
| 14 | if (!status) return; | |
| 15 | var s = at === null ? 'live' : 'live \\u00b7 updated ' + Math.max(0, Math.floor((Date.now() - at) / 1000)) + 's ago'; | |
| 16 | if (s !== shown) { shown = s; status.textContent = s; } | |
| 17 | } | |
| 18 | var es = new EventSource('/boards/stream'); | |
| 19 | es.addEventListener('flow', function (e) { | |
| 20 | var data; | |
| 21 | try { data = JSON.parse(e.data); } catch (_) { return; } | |
| 22 | if (!data || typeof data !== 'object') return; | |
| 23 | Array.prototype.forEach.call(document.querySelectorAll('[data-k]'), function (el) { | |
| 24 | var k = el.getAttribute('data-k'); | |
| 25 | if (Object.prototype.hasOwnProperty.call(data, k) && typeof data[k] === 'string' && el.textContent !== data[k]) el.textContent = data[k]; | |
| 26 | }); | |
| 27 | at = Date.now(); | |
| 28 | say(); | |
| 29 | }); | |
| 30 | setInterval(say, 1000); | |
| 31 | })(); | |
| 32 | `; |
src/web/pages/boards-index-stream.ts added +62
| @@ -0,0 +1,62 @@ | ||
| 1 | /** | |
| 2 | * GET /boards/stream: the index's flow numbers as data. One full frame on | |
| 3 | * connect, then a frame holding only the keys that changed, sent when the | |
| 4 | * forge's event bus says something moved (a burst is read once). While | |
| 5 | * nothing changes nothing is sent, and the server keeps no timer of its own | |
| 6 | * beyond the stream's heartbeat. Same door as the page: a person who is an | |
| 7 | * admin; anyone else gets the not-found page. | |
| 8 | */ | |
| 9 | import { queuesFor } from "../../system/telemetry.ts"; | |
| 10 | import { readPipeline } from "../../flow/pipeline.ts"; | |
| 11 | import { readThroughput } from "../../flow/throughput.ts"; | |
| 12 | import { changed, flowNumbers, type Numbers } from "../../flow/numbers.ts"; | |
| 13 | import type { App } from "../../app.ts"; | |
| 14 | import type { Ctx } from "../../http/context.ts"; | |
| 15 | import { during } from "../../perf/jobs.ts"; | |
| 16 | import { eventStream } from "../../http/sse.ts"; | |
| 17 | import { notFoundPage } from "../chrome.ts"; | |
| 18 | ||
| 19 | /** A burst of events is read once, this long after the first. */ | |
| 20 | export const SETTLE_MS = 100; | |
| 21 | ||
| 22 | /** The panel's numbers now. */ | |
| 23 | export function readNumbers(app: App, now = Date.now()): Numbers { | |
| 24 | const stages = readPipeline(app.db, new Date(now)); | |
| 25 | const flow = readThroughput(app.db, stages.map((s) => s.key), new Date(now)); | |
| 26 | return flowNumbers(stages, flow, queuesFor(app, { kind: "owner" }, new Date(now)), now); | |
| 27 | } | |
| 28 | ||
| 29 | export function boardsIndexStream(ctx: Ctx): Response { | |
| 30 | const u = ctx.auth.user; | |
| 31 | if (u?.isAdmin !== true || u.kind === "agent") return notFoundPage(ctx); | |
| 32 | const { app } = ctx; | |
| 33 | return eventStream(app, ctx.request, (emit, _close, ready) => { | |
| 34 | let sent = readNumbers(app); | |
| 35 | emit("flow", sent); | |
| 36 | let timer: ReturnType<typeof setTimeout> | undefined; | |
| 37 | const off = app.bus.subscribe(() => { | |
| 38 | if (timer !== undefined) return; | |
| 39 | timer = setTimeout( | |
| 40 | () => | |
| 41 | during( | |
| 42 | "boards-index-stream", | |
| 43 | () => { | |
| 44 | timer = undefined; | |
| 45 | if (!ready()) return; | |
| 46 | const next = readNumbers(app); | |
| 47 | const delta = changed(sent, next); | |
| 48 | sent = next; | |
| 49 | if (Object.keys(delta).length > 0) emit("flow", delta); | |
| 50 | }, | |
| 51 | undefined, | |
| 52 | app, | |
| 53 | ), | |
| 54 | SETTLE_MS, | |
| 55 | ); | |
| 56 | }); | |
| 57 | return () => { | |
| 58 | off(); | |
| 59 | if (timer !== undefined) clearTimeout(timer); | |
| 60 | }; | |
| 61 | }); | |
| 62 | } |
src/web/pages/boards-view.ts +8 −2
| @@ -25,6 +25,7 @@ import { readView, viewed, viewHref, type View } from "../../boards/view_bar.ts" | ||
| 25 | 25 | import { emptyList } from "../empty_words.ts"; |
| 26 | 26 | import { fold, reading, readingFailed, readingJs } from "../figure.ts"; |
| 27 | 27 | import { formatValue } from "../../boards/chart.ts"; |
| 28 | import { boardsIndexLiveJs } from "../boards-index-live.ts"; | |
| 28 | 29 | import { flowPanel, outAsked } from "./flow-panel.ts"; |
| 29 | 30 | import { boardsHoldsCard } from "./boards-holds.ts"; |
| 30 | 31 | import { alarmLines } from "../studio/alarm_lines.ts"; |
| @@ -106,6 +107,11 @@ export function warmBoards(app: App): void { | ||
| 106 | 107 | } |
| 107 | 108 | |
| 108 | 109 | // GET /boards |
| 110 | /** Whether the index is following its stream, and the one link that flips it. */ | |
| 111 | const liveLine = (paused: boolean): Html => | |
| 112 | html`<p class="muted"><span id="flow-live-line" role="status"><span id="flow-live-state">${paused ? "paused" : "live"}</span> · | |
| 113 | ${paused ? html`<a href="/boards">Resume</a>` : html`<a href="/boards?pause">Pause</a>`}</span></p>`; | |
| 114 | ||
| 109 | 115 | export async function boardsList(ctx: Ctx): Promise<Response> { |
| 110 | 116 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 111 | 117 | const user = ctx.auth.user; |
| @@ -154,7 +160,7 @@ export async function boardsList(ctx: Ctx): Promise<Response> { | ||
| 154 | 160 | </section>`; |
| 155 | 161 | const drift = driftSection(picture.drifting ?? []); |
| 156 | 162 | const flow = timePhase(ctx.request, "flow", () => |
| 157 | flowPanel(ctx.app, { kind: "owner" }, ctx.url, "/boards", { picture, now: alarmLines(picture.alarms), between: boards, first: drift, last: boardsHoldsCard(ctx.app.db, user, true) })); | |
| 163 | flowPanel(ctx.app, { kind: "owner" }, ctx.url, "/boards", { picture, refetch: false, now: html`${liveLine(ctx.url.searchParams.has("pause"))}${alarmLines(picture.alarms)}`, between: boards, first: drift, last: boardsHoldsCard(ctx.app.db, user, true) })); | |
| 158 | 164 | const rendering = performance.now(); |
| 159 | 165 | const response = page({ |
| 160 | 166 | ctx, |
| @@ -167,7 +173,7 @@ export async function boardsList(ctx: Ctx): Promise<Response> { | ||
| 167 | 173 | </header> |
| 168 | 174 | ${flow} |
| 169 | 175 | </div>`, |
| 170 | scriptJs: liveRegionsJs, | |
| 176 | scriptJs: `${liveRegionsJs}\n${boardsIndexLiveJs}`, | |
| 171 | 177 | }); |
| 172 | 178 | notePhase(ctx.request, "render", performance.now() - rendering); |
| 173 | 179 | return response; |
src/web/pages/flow-panel.ts +12 −12
| @@ -110,16 +110,16 @@ function outCells(base: string, t: StageFlow): Html { | ||
| 110 | 110 | const { day, passed } = t; |
| 111 | 111 | const what = `${OUTFLOW[t.key].label}${t.key === "checking" && day > 0 ? `: ${passed} passed, ${day - passed} failed` : ""}`; |
| 112 | 112 | return html`<td class="num" data-label="Out, 1 h" data-out="${OUTFLOW[t.key].out}"> |
| 113 | <a href="${outHref(base, t.key, 0)}" data-hour="0" title="${what}, in the last hour">${count(t.hours[0] ?? 0)}</a> | |
| 113 | <a href="${outHref(base, t.key, 0)}" data-hour="0" data-k="stage.${t.key}.hour" title="${what}, in the last hour">${count(t.hours[0] ?? 0)}</a> | |
| 114 | 114 | </td> |
| 115 | 115 | <td class="num" data-label="Out, 24 h"> |
| 116 | <a href="${outHref(base, t.key, null)}" data-day="${String(day)}" title="${what}, in the last 24 hours">${count(day)}</a> | |
| 116 | <a href="${outHref(base, t.key, null)}" data-day="${String(day)}" data-k="stage.${t.key}.day" title="${what}, in the last 24 hours">${count(day)}</a> | |
| 117 | 117 | </td> |
| 118 | 118 | <td class="pl-trend" title="${what}, each hour of the last 24">${sparkline(t)}</td>`; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** The panel for `reader`; `base` is the page it sits on, where its counts link. `between` is drawn under the pipeline, above the detail. */ |
| 122 | export function flowPanel(app: App, reader: Reader, url: URL, base: string, slots: { picture?: PanelPicture; now?: Html | null; between?: Html | null; first?: Html | null; last?: Html | null } = {}): Html { | |
| 122 | export function flowPanel(app: App, reader: Reader, url: URL, base: string, slots: { picture?: PanelPicture; now?: Html | null; between?: Html | null; first?: Html | null; last?: Html | null; refetch?: boolean } = {}): Html { | |
| 123 | 123 | const now = Date.now(); |
| 124 | 124 | const stages = readPipeline(app.db, new Date(now)); |
| 125 | 125 | const worst = bottleneck(stages); |
| @@ -158,15 +158,15 @@ export function flowPanel(app: App, reader: Reader, url: URL, base: string, slot | ||
| 158 | 158 | const landedDay = landed?.day ?? 0; |
| 159 | 159 | const opened = openers.reduce((n, o) => n + o.opened, 0); |
| 160 | 160 | const strip = figures([ |
| 161 | figure("Landed, last hour", html`<span data-landed-hour>${count(landed?.hours[0] ?? 0)}</span>`, html`<span data-landed-day>${count(landedDay)}</span> ${landedDay === 1 ? "change" : "changes"} landed on main in 24 hours`, outHref(base, "approved", null), landed === undefined ? null : homeSpark(landed.hours)), | |
| 162 | figure("Asked to live", html`<span data-median>${flow.medianAskToLiveMs === null ? "—" : span(flow.medianAskToLiveMs)}</span>`, flow.medianAskToLiveMs === null ? "nothing asked for went live in 24 hours" : "median from an ask to it serving, last 24 hours", outHref(base, "live", null)), | |
| 161 | figure("Landed, last hour", html`<span data-landed-hour data-k="landed.hour">${count(landed?.hours[0] ?? 0)}</span>`, html`<span data-landed-day data-k="landed.day">${count(landedDay)}</span> ${landedDay === 1 ? "change" : "changes"} landed on main in 24 hours`, outHref(base, "approved", null), landed === undefined ? null : homeSpark(landed.hours)), | |
| 162 | figure("Asked to live", html`<span data-median data-k="median">${flow.medianAskToLiveMs === null ? "—" : span(flow.medianAskToLiveMs)}</span>`, flow.medianAskToLiveMs === null ? "nothing asked for went live in 24 hours" : "median from an ask to it serving, last 24 hours", outHref(base, "live", null)), | |
| 163 | 163 | figure("Opened to landed", lead.medianHours === null ? "—" : html`<span data-median-hours>${span(lead.medianHours * 3_600_000)}</span>`, lead.medianHours === null ? "nothing landed in 24 hours" : html`median for a pull; the slowest took <span data-max-hours>${span((lead.maxHours ?? 0) * 3_600_000)}</span>`, outHref(base, "approved", null)), |
| 164 | 164 | figure("Waiting to start", count(ready?.waiting ?? 0), ready === undefined || ready.waiting === 0 ? "no ready issue waits for a builder" : `ready ${ready.waiting === 1 ? "issue" : "issues"}; the oldest has waited ${waited(ready, now) ?? "no time"}`, "#held", null, worst?.key === "ready" ? "attn" : null), |
| 165 | 165 | figure("Checks passing", checked === 0 ? "—" : `${Math.round((passed / checked) * 100)}%`, checked === 0 ? "no check finished in 24 hours" : `${count(passed)} of ${count(checked)} checks passed in 24 hours`, outHref(base, "checking", null), null, checked > 0 && passed / checked < 0.5 ? "attn" : null), |
| 166 | 166 | ], "The last 24 hours"); |
| 167 | return html`<div class="bd-live" id="flow-live" data-live="${FLOW_LIVE}"> | |
| 167 | return html`<div class="bd-live" id="flow-live" ${slots.refetch === false ? null : html`data-live="${FLOW_LIVE}"`}> | |
| 168 | 168 | <section class="bd-now" id="flow-summary" aria-label="How the pipeline stands"> |
| 169 | <p class="bd-lead" id="bottleneck" data-stage="${worst?.key ?? ""}"><strong>${verdict(stages, now)}</strong></p> | |
| 169 | <p class="bd-lead" id="bottleneck" data-stage="${worst?.key ?? ""}"><strong data-k="verdict">${verdict(stages, now)}</strong></p> | |
| 170 | 170 | ${line === null ? "" : html`<p id="line-busy">${line}</p>`} |
| 171 | 171 | ${slots.now ?? null} |
| 172 | 172 | ${keeperRow(app.db, owner)} |
| @@ -223,8 +223,8 @@ export function flowPanel(app: App, reader: Reader, url: URL, base: string, slot | ||
| 223 | 223 | ${s === worst ? badge("bottleneck", { tone: "danger" }) : null} |
| 224 | 224 | </th> |
| 225 | 225 | <td class="pl-cap" data-label="Capacity" ${s.capacity === null ? html`data-zero` : null}>${s.capacity ?? "—"}</td> |
| 226 | <td class="num" data-label="Waiting" ${s.waiting === 0 ? html`data-zero` : null}>${count(s.waiting)}</td> | |
| 227 | <td class="num" data-label="Active" ${s.key === "live" || s.active === 0 ? html`data-zero` : null}>${s.key === "live" ? "—" : count(s.active)}</td> | |
| 226 | <td class="num" data-label="Waiting" data-k="stage.${s.key}.waiting" ${s.waiting === 0 ? html`data-zero` : null}>${count(s.waiting)}</td> | |
| 227 | <td class="num" data-label="Active" data-k="stage.${s.key}.active" ${s.key === "live" || s.active === 0 ? html`data-zero` : null}>${s.key === "live" ? "—" : count(s.active)}</td> | |
| 228 | 228 | <td class="num" data-label="Oldest" ${s.oldestWaiting === null ? html`data-zero` : null}>${waited(s, now) ?? "—"}</td> |
| 229 | 229 | ${outCells(base, out.get(s.key)!)} |
| 230 | 230 | </tr>`, |
| @@ -350,10 +350,10 @@ function queueCard(rows: readonly QueueRow[]): Html { | ||
| 350 | 350 | (r) => |
| 351 | 351 | html`<tr data-queue="${r.repo}"> |
| 352 | 352 | <th scope="row"><a href="/${r.repo}/pulls">${r.repo}</a></th> |
| 353 | <td class="num" data-queued>${String(r.queued)}</td> | |
| 354 | <td class="num" data-gating>${String(r.gating)}</td> | |
| 353 | <td class="num" data-k="queue.${r.repo}.queued" data-queued>${String(r.queued)}</td> | |
| 354 | <td class="num" data-k="queue.${r.repo}.gating" data-gating>${String(r.gating)}</td> | |
| 355 | 355 | <td class="num" data-gates>${String(r.gates)}</td> |
| 356 | <td class="num" data-landed>${String(r.landedHour)}</td> | |
| 356 | <td class="num" data-k="queue.${r.repo}.landed" data-landed>${String(r.landedHour)}</td> | |
| 357 | 357 | <td class="num" data-approved-to-landed>${r.approvedToLanded === null ? "—" : `${r.approvedToLanded} min`}</td> |
| 358 | 358 | <td class="num" data-red-batches>${redBatchWords(r)}</td> |
| 359 | 359 | </tr>`, |
test/boards-index-stream.test.ts added +179
| @@ -0,0 +1,179 @@ | ||
| 1 | /** | |
| 2 | * The /boards index is live over one stream (#3715): the flow panel's | |
| 3 | * numbers arrive as data, a change is sent as only the keys that changed, | |
| 4 | * and nothing is sent while nothing does. | |
| 5 | */ | |
| 6 | import { signInCookie } from "./helpers/studio-signin.ts"; | |
| 7 | import { boardsIndexLiveJs } from "../src/web/boards-index-live.ts"; | |
| 8 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 9 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 10 | import { tmpdir } from "node:os"; | |
| 11 | import { join } from "node:path"; | |
| 12 | import { createApp, type App } from "../src/app.ts"; | |
| 13 | import { openIssue } from "../src/actions/issues.ts"; | |
| 14 | import { createRepo } from "../src/actions/repos.ts"; | |
| 15 | import type { Repo } from "../src/core/repos.ts"; | |
| 16 | import { createUser, type User } from "../src/core/users.ts"; | |
| 17 | import { changed } from "../src/flow/numbers.ts"; | |
| 18 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 19 | ||
| 20 | describe("/boards/stream", () => { | |
| 21 | let dataDir: string; | |
| 22 | let app: App; | |
| 23 | let servers: Servers; | |
| 24 | let alice: User; | |
| 25 | let repo: Repo; | |
| 26 | let cookie = ""; | |
| 27 | let bobCookie = ""; | |
| 28 | ||
| 29 | const login = (username: string): Promise<string> => signInCookie(servers.url, username); | |
| 30 | ||
| 31 | beforeAll(async () => { | |
| 32 | dataDir = await mkdtemp(join(tmpdir(), "forge-boards-index-")); | |
| 33 | app = createApp({ dataDir, port: 0 }); | |
| 34 | servers = await serve(app); | |
| 35 | const a = await createUser(app.db, { | |
| 36 | origin: "seed", trusted: true, username: "alice", email: "[email protected]", | |
| 37 | password: "a-good-passphrase", adminIfFirst: true, | |
| 38 | }); | |
| 39 | if (!a.ok) throw new Error(a.error); | |
| 40 | alice = a.value; | |
| 41 | const b = await createUser(app.db, { | |
| 42 | origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-good-passphrase", | |
| 43 | }); | |
| 44 | if (!b.ok) throw new Error(b.error); | |
| 45 | const made = await createRepo(app, alice, { name: "shop" }); | |
| 46 | if (!made.ok) throw new Error(String(made.error)); | |
| 47 | repo = made.value; | |
| 48 | cookie = await login("alice"); | |
| 49 | bobCookie = await login("bob"); | |
| 50 | }); | |
| 51 | ||
| 52 | afterAll(async () => { | |
| 53 | servers.stop(); | |
| 54 | app.close(); | |
| 55 | await rm(dataDir, { recursive: true, force: true }); | |
| 56 | }); | |
| 57 | ||
| 58 | /** Frames as they arrive: a reader that resolves each `flow` data line. */ | |
| 59 | function frames(res: Response) { | |
| 60 | const reader = res.body!.getReader(); | |
| 61 | const decoder = new TextDecoder(); | |
| 62 | let buf = ""; | |
| 63 | let bytes = 0; | |
| 64 | let pending: Promise<Awaited<ReturnType<ReadableStreamDefaultReader<Uint8Array>["read"]>>> | null = null; | |
| 65 | return { | |
| 66 | get bytes() { return bytes; }, | |
| 67 | async next(ms: number): Promise<Record<string, string> | null> { | |
| 68 | const deadline = Date.now() + ms; | |
| 69 | for (;;) { | |
| 70 | const at = buf.indexOf("\n\n"); | |
| 71 | if (at >= 0) { | |
| 72 | const block = buf.slice(0, at); | |
| 73 | buf = buf.slice(at + 2); | |
| 74 | const data = block.split("\n").find((l) => l.startsWith("data: ")); | |
| 75 | if (data !== undefined) return JSON.parse(data.slice(6)); | |
| 76 | continue; | |
| 77 | } | |
| 78 | const left = deadline - Date.now(); | |
| 79 | if (left <= 0) return null; | |
| 80 | // One read stays pending across timeouts, so a chunk is never lost. | |
| 81 | pending ??= reader.read(); | |
| 82 | const got = await Promise.race([ | |
| 83 | pending, | |
| 84 | new Promise<null>((r) => setTimeout(() => r(null), left)), | |
| 85 | ]); | |
| 86 | if (got === null) return null; | |
| 87 | pending = null; | |
| 88 | if (got.done) return null; | |
| 89 | bytes += got.value.length; | |
| 90 | buf += decoder.decode(got.value); | |
| 91 | } | |
| 92 | }, | |
| 93 | cancel: () => reader.cancel(), | |
| 94 | }; | |
| 95 | } | |
| 96 | ||
| 97 | test("the page names the stream, its numbers, and a Pause; ?pause says paused", async () => { | |
| 98 | const body = await (await fetch(`${servers.url}/boards`, { headers: { cookie } })).text(); | |
| 99 | expect(boardsIndexLiveJs).toContain("new EventSource('/boards/stream')"); | |
| 100 | expect(body).toMatch(/<script[^>]+src=/); | |
| 101 | expect(body).toContain('data-k="landed.day"'); | |
| 102 | expect(body).toContain('href="/boards?pause"'); | |
| 103 | expect(boardsIndexLiveJs).not.toContain("setTimeout("); | |
| 104 | const paused = await (await fetch(`${servers.url}/boards?pause`, { headers: { cookie } })).text(); | |
| 105 | expect(paused).toContain(">paused<"); | |
| 106 | expect(paused).toContain('href="/boards">Resume'); | |
| 107 | }); | |
| 108 | ||
| 109 | test("only an admin sees the live line; the index refreshes by the stream alone", async () => { | |
| 110 | const admin = await (await fetch(`${servers.url}/boards`, { headers: { cookie } })).text(); | |
| 111 | expect(admin).toContain('id="flow-live-line"'); | |
| 112 | expect(admin).not.toContain("data-live="); | |
| 113 | expect(admin).toContain("How work is moving through the forge right now, and the charts behind it.</p>"); | |
| 114 | for (const headers of [{}, { cookie: bobCookie }]) { | |
| 115 | const page = await (await fetch(`${servers.url}/boards`, { headers, redirect: "manual" })).text(); | |
| 116 | expect(page).not.toContain("flow-live-line"); | |
| 117 | expect(page).not.toContain("/boards/stream"); | |
| 118 | } | |
| 119 | }); | |
| 120 | ||
| 121 | test("the how-to says there is no live terminal side, and the Boards screen does not follow the stream", async () => { | |
| 122 | const howto = await Bun.file(new URL("../docs/features/boards-index-live.md", import.meta.url)).text(); | |
| 123 | expect(howto).toContain("there is no live side"); | |
| 124 | const screen = await Bun.file(new URL("../src/tui/screens/boards.ts", import.meta.url)).text(); | |
| 125 | expect(screen).not.toContain("boards/stream"); | |
| 126 | }); | |
| 127 | ||
| 128 | test("a stranger and a non-admin are refused", async () => { | |
| 129 | for (const headers of [{}, { cookie: bobCookie }]) { | |
| 130 | const res = await fetch(`${servers.url}/boards/stream`, { headers, redirect: "manual" }); | |
| 131 | expect(res.headers.get("content-type") ?? "").not.toContain("text/event-stream"); | |
| 132 | await res.body?.cancel(); | |
| 133 | } | |
| 134 | }); | |
| 135 | ||
| 136 | test("a pull landing changes the landed count within 2 s, in under 2 KB, and idle sends nothing", async () => { | |
| 137 | const res = await fetch(`${servers.url}/boards/stream`, { headers: { cookie } }); | |
| 138 | expect(res.headers.get("content-type")).toContain("text/event-stream"); | |
| 139 | const f = frames(res); | |
| 140 | const first = await f.next(2000); | |
| 141 | expect(first?.["landed.day"]).toBe("0"); | |
| 142 | expect(first?.["landed.hour"]).toBe("0"); | |
| 143 | ||
| 144 | // Idle: a quiet second sends nothing. | |
| 145 | expect(await f.next(1000)).toBeNull(); | |
| 146 | ||
| 147 | const before = f.bytes; | |
| 148 | const issue = openIssue(app, alice, repo, { title: "Add a cart", body: "" }); | |
| 149 | if (!issue.ok) throw new Error(String(issue.error)); | |
| 150 | app.db.query("UPDATE issue SET kind = 'pull', state = 'closed' WHERE id = ?1").run(issue.value.id); | |
| 151 | app.db | |
| 152 | .query( | |
| 153 | `INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, merged_at) | |
| 154 | VALUES (?1, ?2, 'x', '', '', ?3)`, | |
| 155 | ) | |
| 156 | .run(issue.value.id, repo.defaultBranch, new Date().toISOString()); | |
| 157 | app.bus.append({ kind: "pull.merged", repoId: repo.id }); | |
| 158 | const t0 = Date.now(); | |
| 159 | let delta: Record<string, string> | null = null; | |
| 160 | while (Date.now() - t0 < 2000) { | |
| 161 | delta = await f.next(2000 - (Date.now() - t0)); | |
| 162 | if (delta?.["landed.day"] !== undefined) break; | |
| 163 | } | |
| 164 | expect(delta?.["landed.day"]).toBe("1"); | |
| 165 | expect(delta?.["landed.hour"]).toBe("1"); | |
| 166 | expect(f.bytes - before).toBeLessThan(2048); | |
| 167 | // Only what changed travels. | |
| 168 | expect(delta?.["stage.live.waiting"]).toBeUndefined(); | |
| 169 | ||
| 170 | // An event that changes nothing sends nothing. | |
| 171 | app.bus.append({ kind: "noop.event" }); | |
| 172 | expect(await f.next(600)).toBeNull(); | |
| 173 | await f.cancel(); | |
| 174 | }); | |
| 175 | ||
| 176 | test("changed() is the keys whose text differs", () => { | |
| 177 | expect(changed({ a: "1", b: "2" }, { a: "1", b: "3", c: "4" })).toEqual({ b: "3", c: "4" }); | |
| 178 | }); | |
| 179 | }); |
test/design-audit.test.ts +1 −1
| @@ -17,7 +17,7 @@ const doc = readFileSync("docs/design/audit.md", "utf8"); | ||
| 17 | 17 | |
| 18 | 18 | /** Routes that answer a file, a fragment, a redirect hop or a callback. */ |
| 19 | 19 | const NOT_PAGES = |
| 20 | /^\/(design\/theme\.css|design\/theme\/|assets\/|\.well-known\/|icons\/|og\/|live\/|__forge\/|go\/|new\/issue$|events$|system\/stream$|talk\/stream$|peek$|settings\/teams\/stream$|sw\.js$|offline$|robots\.txt$|favicon\.ico$|apple-touch-icon(-precomposed)?\.png$|sitemap\.xml$|edition$|oembed$|manifest\.webmanifest$|opensearch\.xml$|llms(-full)?\.txt$|openapi\.json$|releases\.json$|templates\.json$|maintenance\.json$|changelog\.atom$|explore\.(atom|json)$|feed\.json$|docs(\/[^/]*)?$|audit\.csv$|settings\/traffic\/scrapes\/export$|settings\/payments\.csv$|fleet\/graph\/live$|fleet\/graph\.csv$|forges\/export\.csv$|settings\/origins\/callback$|broker\/origins\/start$|home\/archived\/|settings\/backups\/live$|api\/v1(\/|$))/; | |
| 20 | /^\/(design\/theme\.css|design\/theme\/|assets\/|\.well-known\/|icons\/|og\/|live\/|__forge\/|go\/|new\/issue$|events$|boards\/stream$|system\/stream$|talk\/stream$|peek$|settings\/teams\/stream$|sw\.js$|offline$|robots\.txt$|favicon\.ico$|apple-touch-icon(-precomposed)?\.png$|sitemap\.xml$|edition$|oembed$|manifest\.webmanifest$|opensearch\.xml$|llms(-full)?\.txt$|openapi\.json$|releases\.json$|templates\.json$|maintenance\.json$|changelog\.atom$|explore\.(atom|json)$|feed\.json$|docs(\/[^/]*)?$|audit\.csv$|settings\/traffic\/scrapes\/export$|settings\/payments\.csv$|fleet\/graph\/live$|fleet\/graph\.csv$|forges\/export\.csv$|settings\/origins\/callback$|broker\/origins\/start$|home\/archived\/|settings\/backups\/live$|api\/v1(\/|$))/; | |
| 21 | 21 | |
| 22 | 22 | const getRoutes = [ |
| 23 | 23 | ...server.matchAll(/router\.add\(\s*"GET",\s*"([^"]+)"/g), |
test/flow-throughput.test.ts +3 −3
| @@ -180,9 +180,9 @@ describe("/flow: actual throughput per stage", () => { | ||
| 180 | 180 | expect(res.status).toBe(200); |
| 181 | 181 | const page = await res.text(); |
| 182 | 182 | // The figures say it: landed in the last hour, in 24 hours, and the median from an ask to live. |
| 183 | expect(page).toContain("<span data-landed-hour>2</span>"); | |
| 184 | expect(page).toContain("<span data-landed-day>6</span> changes landed on main in 24 hours"); | |
| 185 | expect(page).toContain("<span data-median>3h 30m</span>"); | |
| 183 | expect(page).toContain('<span data-landed-hour data-k="landed.hour">2</span>'); | |
| 184 | expect(page).toContain('<span data-landed-day data-k="landed.day">6</span> changes landed on main in 24 hours'); | |
| 185 | expect(page).toContain('<span data-median data-k="median">3h 30m</span>'); | |
| 186 | 186 | expect(throughputSays(readThroughput(app.db, PIPELINE, new Date(NOW)))).toBe( |
| 187 | 187 | "landed 2 in the last hour · 6 in 24 h · median ask→live 3.5 h (24 h)", |
| 188 | 188 | ); |
test/job-slices.test.ts +3
| @@ -69,6 +69,7 @@ import { pullDue } from "../src/apps/pull_schedule.ts"; | ||
| 69 | 69 | import { startMaintain } from "../src/maintain/runner.ts"; |
| 70 | 70 | import { retentionJobs } from "../src/system/retention.ts"; |
| 71 | 71 | import { returnSnoozed } from "../src/actions/gate_snooze.ts"; |
| 72 | import { readNumbers } from "../src/web/pages/boards-index-stream.ts"; | |
| 72 | 73 | |
| 73 | 74 | /** |
| 74 | 75 | * Thousands of issues and pulls, as the issue asks; runs, comments and events thinned so the file |
| @@ -154,6 +155,8 @@ function jobs(): Record<string, () => unknown> { | ||
| 154 | 155 | "memory-sampler": () => memory.tick(), |
| 155 | 156 | keeper: () => tickKeeper(app, new Date(), () => {}), |
| 156 | 157 | "gate-snooze": () => returnSnoozed(app), |
| 158 | // The /boards index stream's settled read: the flow numbers, once per burst of events. | |
| 159 | "boards-index-stream": () => readNumbers(app), | |
| 157 | 160 | "red-pulls": () => reportRedPulls(app), |
| 158 | 161 | // The pictures' keeper (`flow/keep.ts`): one look at what is kept; a due reading is started on |
| 159 | 162 | // a worker, never read here. |
test/no-polling.test.ts +1
| @@ -108,6 +108,7 @@ const ALLOWED: Record<string, { allow: string[]; why: string }> = { | ||
| 108 | 108 | "src/web/pages/offline.ts": { allow: ['http-equiv="refresh"'], why: "the offline page: the forge is unreachable, so there is no /events to hear" }, |
| 109 | 109 | "src/web/pages/waking.ts": { allow: ['http-equiv="refresh"'], why: "the waking page: the forge is asleep, so there is no /events to hear" }, |
| 110 | 110 | "src/web/pages/talk.ts": { allow: ["setInterval"], why: "server side: the stream of one turn watches the run's row, which has no event to hear" }, |
| 111 | "src/web/boards-index-live.ts": { allow: ["setInterval"], why: "the \"updated Ns ago\" clock: it only redraws text and requests nothing" }, | |
| 111 | 112 | "src/web/client.ts": { allow: ["setInterval"], why: "clocks that only redraw text" }, |
| 112 | 113 | "src/web/space_client.ts": { allow: ["setInterval"], why: "the map clock label only redraws text; it fetches and reloads nothing" }, |
| 113 | 114 | "src/web/pages/boards-stream.ts": { allow: ["setInterval"], why: "the board's \"updated Ns ago\" label only redraws text; the stream carries the data" }, |
test/pages-budget.test.ts +1 −1
| @@ -77,7 +77,7 @@ const MAX_UNFIXTURED = 167; // +4: /games/:box, /games/:box/:service, its stream | ||
| 77 | 77 | const NOT_PAGES = new Set([ |
| 78 | 78 | "/events", "/system/stream", "/settings/teams/stream", "/fleet/graph/live", |
| 79 | 79 | "/settings/traffic/scrapes/export", "/settings/backups/live", "/:owner/:name/stream", |
| 80 | "/settings/origins/flows/:id/stream", "/boards/:slug/stream", "/:owner/:name/archive/:file", // a tarball download, not a page | |
| 80 | "/settings/origins/flows/:id/stream", "/boards/:slug/stream", "/boards/stream", "/:owner/:name/archive/:file", // a tarball download, not a page | |
| 81 | 81 | "/api/v1/runner/jobs/:id/git/info/refs", // a runner's git door for one job (#13652), not a page |
| 82 | 82 | ]); |
| 83 | 83 |
test/server-timing-sweep.test.ts +1
| @@ -29,6 +29,7 @@ const UNNAMED: Array<[path: string, issue: string]> = [ | ||
| 29 | 29 | const NOT_PAGES = new Set([ |
| 30 | 30 | "/offline", // the worker's static fallback, kept at install: no session to time |
| 31 | 31 | "/events", |
| 32 | "/boards/stream", | |
| 32 | 33 | "/system/stream", |
| 33 | 34 | "/settings/teams/stream", |
| 34 | 35 | "/fleet/graph/live", |
new above
offline
Both doors: this says the Boards screen in src/tui/screens/boards.ts shows the same numbers, but this pull changes nothing under src/tui/, so the how-to describes a door that was not built here (and it is not live, 'read again on each visit'). Build the terminal side or state the truth and carry a real
No door:line.