Public: anyone can read this; the crew can change it.

The slot bars stay put: quarter hours on the clock at their peak, and red only for a failure #17237

opened this

Conflicts with main in 1 file

src/web/flow_slots.ts

check-bars → main 1 commit

Review

Sign in to review this change.
5 files changed +104 −30
docs/design/areas/boards.md +1 −1
@@ -28,7 +28,7 @@ The card under the Pipeline table (`id="verified"`) adds no class: it is a `card
2828 - `.bd-now`, `.bd-lead` — the bottleneck sentence at 16px and, under it in the muted colour, only the lines that hold right now (conflicted pulls, a held rebase lane, idle pulls).
2929 - `.bd-block`, `.bd-head`, `.bd-sub` — a block of the page: its `<h2>`, one sentence of what it shows, and its quiet links.
3030 - `.fl-stages`, `.fl-stage` — /flow's answer under its one sentence: each stage that has anything waiting or worked, one line (`stageSays`: what waits, what is active, what limits it, the oldest wait), the bottleneck in the danger colour. Everything else on /flow folds under one line, and no list shows more than ten rows: the last line, "and N more", links to /flow?all=<list id>, that list whole with its fold open. The same rows carry the merge queue against its targets (#17006), the first fold: one `.fl-stage` per target (`data-target`, `data-met`), and a missed one is marked as the bottleneck is.
31 - `.sl-block`, `.sl`, `.sl-head` (the name, the busy count and, in `.sl-say`, what waits), `.sl-used`, `.sl-chart`, `.sl-busy`, `.sl-full`, `.sl-wait`, `.sl-line`, `.sl-foot` — the slots above the pipeline (`src/web/flow_slots.ts`): for checks and the crew, "4 of 4 slots busy" in the danger colour with a full badge when every slot is busy and something waits, what waits and its oldest and median wait, the crew's pace when it allows fewer, and the 24 hours as bars with the setting dashed across them (solid red where a bar reaches it, muted below, waiting lighter on top). Change capacity is a button under them.
31 - `.sl-block`, `.sl`, `.sl-head` (the name, the busy count and, in `.sl-say`, what waits), `.sl-used`, `.sl-chart`, `.sl-busy`, `.sl-full`, `.sl-wait`, `.sl-line`, `.sl-key`, `.sl-swatch`, `.sl-foot` — the slots above the pipeline (`src/web/flow_slots.ts`): for checks and the crew, "4 of 4 slots busy" in the attention colour with a full badge when every slot is busy and something waits, what waits and its oldest and median wait, the crew's pace when it allows fewer, and the 24 hours as bars with the setting dashed across them. Each bar is a quarter hour on the clock at its peak, so a bar changes only when its runs do. It is solid in the attention colour where every slot was busy (never red: red is a failed run), muted below, with waiting lighter on top. Each bar's title names its quarter and counts, and a `.sl-key` line under the chart gives the colours as `.sl-swatch` squares and says where the 24 hours end. Change capacity is a button under them.
3232 - `.pl`, `.pl-cap`, `.pl-trend`, `.pl-spark` — the pipeline: §5's `.table` with every number right-aligned and tabular, a zero in the faint colour, the day's 24 hours as bars. On a phone each stage is a card: its name, then its five numbers in one row with their names over them.
3333 - `.bd-boards` — the boards as tiles: two across on a phone, four from 720px. Each tile is a `data-nav` row for `j`/`k`.
3434 - `.folds`, `.fold`, `.fold-title`, `.fold-state`, `.fold-body` — `fold()`: a `disclosure` whose summary is the section's name and one sentence of how it stands now ("nothing queued; 26 landed in the last hour"); the detail is inside. Hairlines between, no card.
src/flow/slots.ts +40 −12
@@ -23,12 +23,19 @@ import { forgeRepo } from "../core/forge_repo.ts";
2323 import { repoPace } from "../crew/autonomy_pace.ts";
2424 import { median } from "./estimate_score.ts";
2525
26 /** The instants the 24 hours are read at: one each quarter hour, oldest first. */
26 /**
27 * The 24 hours as quarter hours on the clock (:00, :15, :30, :45), oldest first, the last one the
28 * quarter now under way. Each is what that quarter held at its peak, so a bar changes only when its
29 * own runs do, never because the reading moved by a minute.
30 */
2731 export const SLOT_POINTS = 96;
2832 const STEP_MS = 15 * 60_000;
2933 const HOUR_MS = 3_600_000;
3034
3135 export interface SlotPoint {
36 /** When the quarter hour starts, in ms. */
37 readonly at: number;
38 /** The most that ran at once in it, and the most that waited at once. */
3239 readonly running: number;
3340 readonly queued: number;
3441 }
@@ -181,23 +188,44 @@ function rows(db: Database, since: string): Row[] {
181188 .all(since);
182189 }
183190
191 /**
192 * Each quarter hour's peaks, in one sweep: every start and end is an event at its instant (an end
193 * before a start at the same instant), and a quarter's peak is the most counted at once inside it,
194 * from what was already running as it began. Quarters are the clock's, the last one ending `now`.
195 */
196 function quarterPeaks(spans: readonly { asked: number; started: number; ended: number }[], now: number): SlotPoint[] {
197 const first = Math.floor(now / STEP_MS) * STEP_MS - (SLOT_POINTS - 1) * STEP_MS;
198 const peaks = (pairs: [number, number][]): number[] => {
199 const events: [number, number][] = [];
200 for (const [from, to] of pairs) if (from < to && to > first && from <= now) events.push([from, 1], [to, -1]);
201 events.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
202 const out = new Array<number>(SLOT_POINTS).fill(0);
203 let n = 0;
204 let e = 0;
205 for (; e < events.length && events[e]![0] <= first; e++) n += events[e]![1];
206 for (let q = 0; q < SLOT_POINTS; q++) {
207 const end = first + (q + 1) * STEP_MS;
208 let peak = n;
209 for (; e < events.length && events[e]![0] < end; e++) {
210 n += events[e]![1];
211 if (n > peak) peak = n;
212 }
213 out[q] = peak;
214 }
215 return out;
216 };
217 const running = peaks(spans.map((s) => [s.started, s.ended]));
218 const queued = peaks(spans.map((s) => [s.asked, Math.min(s.started, s.ended)]));
219 return running.map((r, q) => ({ at: first + q * STEP_MS, running: r, queued: queued[q]! }));
220 }
221
184222 /** The line for one kind of run, read from its rows at `now`. Pure: rows in, figures out. */
185223 export function slotLine(kind: SlotLine["kind"], slots: number, runs: readonly Row[], now: number): SlotLine {
186224 const t = (iso: string | null): number => (iso === null ? Infinity : Date.parse(iso));
187225 // Each run's instants parsed once, not once per point: 96 points over a day's runs was a million
188226 // parses on every cold home at production's size (#17043).
189227 const spans = runs.map((r) => ({ asked: t(r.created_at), started: t(r.started_at), ended: t(r.finished_at) }));
190 const points: SlotPoint[] = [];
191 for (let i = SLOT_POINTS - 1; i >= 0; i--) {
192 const at = now - i * STEP_MS;
193 let running = 0;
194 let queued = 0;
195 for (const { asked, started, ended } of spans) {
196 if (started <= at && at < ended) running++;
197 else if (asked <= at && at < Math.min(started, ended)) queued++;
198 }
199 points.push({ running, queued });
200 }
228 const points = quarterPeaks(spans, now);
201229 const waitingNow = runs.filter((r) => r.state === "queued");
202230 const waits = runs
203231 .filter((r) => r.started_at !== null && now - t(r.started_at) <= HOUR_MS && now >= t(r.started_at))
src/web/flow_slots.ts +18 −9
@@ -1,8 +1,11 @@
11 /**
22 * The slots, drawn (`flow/slots.ts`): for checks and for the crew, one line that says how many of
33 * the slots are busy against how many there are, what waits and for how long, and a 24-hour
4 * picture with the ceiling drawn across it, so a saturated lane reads as full at a glance. Bars
5 * that reach the line are drawn solid, those below it muted; what waited sits lighter on top.
4 * picture with the ceiling drawn across it, so a saturated lane reads as full at a glance. Each bar
5 * is a quarter hour on the clock at its peak: every slot busy is the attention colour, fewer is
6 * muted, and what waited sits lighter on top. Each bar names its quarter and counts, and a legend
7 * says the colours and where the 24 hours end. A bar is never red: red is a failed run, and these
8 * are slots, not results.
69 * "Change capacity" goes to the page that sets the ceiling. Shown on /boards and on /flow.
710 */
811
@@ -14,9 +17,11 @@ import { isFull, offByMore, roomSaysUpTo, SLOT_POINTS, waitEstimate, type SlotLi
1417 const NAME: Readonly<Record<SlotLine["kind"], string>> = { checks: "Checks", crew: "Crew runs" };
1518 const H = 32;
1619
20 const hhmm = (ms: number): string => new Date(ms).toISOString().slice(11, 16);
21
1722 /**
18 * The 24 hours: busy as bars, waiting stacked lighter above, the ceiling as a dashed line. A
19 * picture only.
23 * The 24 hours: busy as bars, waiting stacked lighter above, the ceiling as a dashed line. Each bar
24 * says its quarter hour and what it held, for a pointer and a screen reader.
2025 */
2126 function chart(l: SlotLine): Html {
2227 const W = SLOT_POINTS * 3;
@@ -24,6 +29,7 @@ function chart(l: SlotLine): Html {
2429 const y = (n: number): number => H - Math.round((n / top) * (H - 2));
2530 const bars = l.points.map((p, i) => {
2631 const x = i * 3;
32 const said = `${hhmm(p.at)}–${hhmm(p.at + 15 * 60_000)} UTC: up to ${String(p.running)} of ${String(l.slots)} busy${p.queued === 0 ? "" : `, up to ${String(p.queued)} waiting`}`;
2733 const run =
2834 p.running === 0
2935 ? null
@@ -33,7 +39,7 @@ function chart(l: SlotLine): Html {
3339 y="${String(y(p.running))}"
3440 width="2"
3541 height="${String(H - y(p.running))}"
36 />`;
42 ><title>${said}</title></rect>`;
3743 const wait =
3844 p.queued === 0
3945 ? null
@@ -43,14 +49,17 @@ function chart(l: SlotLine): Html {
4349 y="${String(y(p.running + p.queued))}"
4450 width="2"
4551 height="${String(y(p.running) - y(p.running + p.queued))}"
46 />`;
52 >${run === null ? html`<title>${said}</title>` : null}</rect>`;
4753 return html`${run}${wait}`;
4854 });
4955 const at = y(l.slots);
50 return html`<svg class="sl-chart" viewBox="0 0 ${String(W)} ${String(H)}" preserveAspectRatio="none" aria-hidden="true" focusable="false">
56 const last = l.points.at(-1);
57 const end = last === undefined ? "" : hhmm(last.at + 15 * 60_000);
58 return html`<svg class="sl-chart" viewBox="0 0 ${String(W)} ${String(H)}" preserveAspectRatio="none" role="img" aria-label="${NAME[l.kind]}: the 24 hours to ${end} UTC by quarter hour, each at its peak" focusable="false">
5159 ${bars}
5260 <line class="sl-line" x1="0" x2="${String(W)}" y1="${String(at)}" y2="${String(at)}" />
53 </svg>`;
61 </svg>
62 <p class="sl-key small"><span class="sl-swatch" data-swatch="full"></span> every slot busy · <span class="sl-swatch" data-swatch="busy"></span> fewer · <span class="sl-swatch" data-swatch="wait"></span> waited · dashed: today's setting · quarter hours to ${end} UTC</p>`;
5463 }
5564
5665 /**
@@ -90,7 +99,7 @@ function line(l: SlotLine, now: number, admin = false): Html {
9099 <strong>${NAME[l.kind]}</strong>
91100 <span class="sl-used" data-busy="${String(l.busy)}" data-slots="${String(l.slots)}"
92101 >${String(l.busy)} of ${String(l.slots)} slots busy</span
93 >${full ? html` ${badge("full", { tone: "danger" })}` : null}
102 >${full ? html` ${badge("full", { tone: "attn" })}` : null}
94103 ${says.length === 0 ? null : html`<span class="sl-say small">${says.map((s, i) => html`${i === 0 ? "" : " · "}${s}`)}</span>`}
95104 </p>
96105 ${kept(l)}
src/web/style/components.ts +6 −2
@@ -1188,11 +1188,15 @@ a[data-palette] { display: none; }
11881188 .sl { display: grid; gap: 4px; }
11891189 .sl-head { margin: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 8px; }
11901190 .sl-used { font-variant-numeric: tabular-nums; }
1191 .sl[data-full] .sl-used { color: var(--danger); font-weight: 600; }
1191 .sl[data-full] .sl-used { color: var(--attn); font-weight: 600; }
11921192 .sl-say { color: var(--muted-fg); }
11931193 .sl-chart { display: block; width: 100%; height: 32px; color: var(--muted-fg); }
11941194 .sl-busy { fill: currentColor; fill-opacity: .45; }
1195 .sl-full { fill: var(--danger); }
1195 .sl-full { fill: var(--attn); }
1196 .sl-key { margin: 0; color: var(--muted-fg); }
1197 .sl-swatch { display: inline-block; width: 8px; height: 8px; vertical-align: baseline; background: var(--muted-fg); opacity: .45; }
1198 .sl-swatch[data-swatch="full"] { background: var(--attn); opacity: 1; }
1199 .sl-swatch[data-swatch="wait"] { opacity: .18; }
11961200 .sl-wait { fill: currentColor; fill-opacity: .18; }
11971201 .sl-line { stroke: var(--fg); stroke-width: 1; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; }
11981202 .sl-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0; }
test/flow-slots.test.ts +39 −6
@@ -47,15 +47,48 @@ test("a line counts busy, waiting, the oldest and the median wait of the last ho
4747 expect(l.oldestAt).toBe(ago(30));
4848 // Started in the last hour: waited 10 and 15 minutes.
4949 expect(l.medianWaitMs).toBe(12.5 * 60_000);
50 expect(l.points.at(-1)).toEqual({ running: 2, queued: 2 });
51 // Two hours ago only the old run was running; 3 h 20 m ago it was still waiting to start.
52 expect(l.points[SLOT_POINTS - 1 - 8]).toEqual({ running: 1, queued: 0 });
53 expect(l.points[SLOT_POINTS - 1 - 13]).toEqual({ running: 0, queued: 1 });
50 // Quarter hours on the clock, the last the one under way: NOW is 12:00, so it is 12:00–12:15.
51 expect(l.points.at(-1)).toEqual({ at: NOW, running: 2, queued: 2 });
52 expect(l.points[0]!.at).toBe(NOW - (SLOT_POINTS - 1) * 15 * 60_000);
53 // 10:00–10:15: only the old run ran; 08:30–08:45: it was still waiting to start.
54 expect(l.points[SLOT_POINTS - 1 - 8]).toEqual({ at: NOW - 8 * 15 * 60_000, running: 1, queued: 0 });
55 expect(l.points[SLOT_POINTS - 1 - 14]).toEqual({ at: NOW - 14 * 15 * 60_000, running: 0, queued: 1 });
5456 expect(isFull(l)).toBe(true);
5557 expect(isFull({ ...l, waiting: 0 })).toBe(false);
5658 expect(isFull({ ...l, busy: 1 })).toBe(false);
5759 });
5860
61 test("a bar changes only when its own runs do: read a few minutes apart, every finished quarter is the same, and each is its peak, not an instant", () => {
62 // Busy 8 of 8 from 11:02 to 11:13, one free from 11:13 to 11:14, then 8 again: a reading at an
63 // instant could catch 7; the quarter's peak is 8 however the reading falls.
64 const at = (m: number) => new Date(NOW - 60 * 60_000 + m * 60_000).toISOString();
65 const runs = Array.from({ length: 8 }, (_, i) => ({
66 kind: "check",
67 created_at: at(1),
68 started_at: at(2),
69 finished_at: i === 0 ? at(13) : at(40),
70 state: "ok",
71 }));
72 runs.push({ kind: "check", created_at: at(13), started_at: at(14), finished_at: at(40), state: "ok" });
73 const read = (minutesLater: number) => slotLine("checks", 8, runs, NOW + minutesLater * 60_000).points;
74 const a = read(1);
75 const b = read(9);
76 // The same quarter hours, the same counts: only the quarter still under way may differ.
77 expect(a.slice(0, -1)).toEqual(b.slice(0, -1));
78 const eleven = a.find((p) => p.at === NOW - 60 * 60_000)!;
79 expect(eleven.running).toBe(8);
80 });
81
82 test("drawn, each bar names its quarter hour and counts, the chart says where its 24 hours end, and a legend names the colours", () => {
83 const l: SlotLine = { ...slotLine("checks", 4, [], NOW), points: Array.from({ length: SLOT_POINTS }, (_, i) => ({ at: NOW - (SLOT_POINTS - 1 - i) * 15 * 60_000, running: i % 2 === 0 ? 4 : 2, queued: 1 })) };
84 const out = slotsBlock([l], NOW, false).text.replace(/\s+/g, " ");
85 expect(out).toContain("<title>12:00–12:15 UTC: up to 2 of 4 busy, up to 1 waiting</title>");
86 expect(out).toContain('aria-label="Checks: the 24 hours to 12:15 UTC by quarter hour, each at its peak"');
87 expect(out).toContain("every slot busy");
88 expect(out).toContain("quarter hours to 12:15 UTC");
89 expect(out).not.toContain("danger");
90 });
91
5992 test("a line parses each run's instants a few times, not once per quarter hour: the cost does not grow with the 96 points (#17043)", () => {
6093 const runs = Array.from({ length: 200 }, (_, i) => run(i * 7 + 20, i % 3 === 0 ? null : i * 7 + 10, i % 2 === 0 ? i * 7 : null));
6194 const real = Date.parse;
@@ -70,14 +103,14 @@ test("a line parses each run's instants a few times, not once per quarter hour:
70103 expect(calls).toBeLessThan(runs.length * 12);
71104 });
72105
73 test("drawn, a full lane reads as full: the danger badge, solid bars at the line, the setting dashed across", () => {
106 test("drawn, a full lane reads as full: the full badge, solid bars at the line, the setting dashed across", () => {
74107 const full: SlotLine = {
75108 ...slotLine("checks", 4, [], NOW),
76109 busy: 4,
77110 waiting: 17,
78111 oldestAt: ago(44),
79112 medianWaitMs: 12 * 60_000,
80 points: Array.from({ length: SLOT_POINTS }, () => ({ running: 4, queued: 3 })),
113 points: Array.from({ length: SLOT_POINTS }, (_, i) => ({ at: NOW - (SLOT_POINTS - 1 - i) * 15 * 60_000, running: 4, queued: 3 })),
81114 };
82115 const calm: SlotLine = {
83116 ...slotLine("crew", 6, [], NOW),

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs