From 49fa261d14f6d81a8ca73aeb1e6e6e92587bbcd6 Mon Sep 17 00:00:00 2001 From: Kevin Longe <273747162+kvlonge@users.noreply.github.com> Date: Tue, 17 Nov 2026 19:13:44 +0000 Subject: [PATCH 1/8] fix(ui): keep a page open on a running run up to date MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On a real 93-seed run the run page fell ever further behind and looked frozen. A running run sends a change about once a second, and each one made every page reload whole listings: - the sidebar's counts, including the 500 KiB checks listing, with no coalescing at all; - on the run page, all of the run's events, statements, output and cost. At 6× CPU slowdown, as PERF.md assumes, the run page was 81% busy and /settings 78%, so a slower machine never caught up. - The sidebar's counts reload at most every 10 s while changes stream in, and once more after the last change (`throttled`). - `createResource` takes `every`: the least time between reloads that signals start. - A change signal drops shared in-flight listings, so a reload never gets an answer from a request started before the change. Before, that could leave a run's last state unshown. Measured on the real run with a change each second at 6× CPU: /settings 78% → 5% busy, the run page 81% → 15%. PERF.md gains the budget and the rule. --- ui/PERF.md | 13 +++-- ui/src/lib/api/http-client.ts | 7 ++- ui/src/lib/state/app.svelte.ts | 11 ++++- ui/src/lib/state/resource.svelte.ts | 9 +++- ui/src/lib/state/throttle.test.ts | 73 +++++++++++++++++++++++++++++ ui/src/lib/state/throttle.ts | 49 +++++++++++++++++++ 6 files changed, 155 insertions(+), 7 deletions(-) create mode 100644 ui/src/lib/state/throttle.test.ts create mode 100644 ui/src/lib/state/throttle.ts diff --git a/ui/PERF.md b/ui/PERF.md index 6b793bb4c1..eb077ca57a 100644 --- a/ui/PERF.md +++ b/ui/PERF.md @@ -9,6 +9,8 @@ fail when a page breaks these budgets; keep them passing rather than raising the - Opening a list page, first or repeat visit: settled within 2 s. - Graph pan, wheel zoom, trackpad momentum and pinch: 90% of frames ≤ 50 ms, none over 200 ms. - Typing in a search or selection field: suggestions update without a visible stall. +- A page open while a run goes on (a change about every second): under half the time busy, so it keeps + up; the run page's timeline scrolls at the graph budget above. - The plan page on a real-sized plan: switching section, or Show more, has its rows on screen within 1 s. A large section loads one page of rows when it is opened, never all of them. @@ -27,10 +29,15 @@ fail when a page breaks these budgets; keep them passing rather than raising the worked out once per card, and again only when its font loads, and shown by the class. Edge routes are worked out when the nodes change (a layout, a measure, a drop), never per frame. 4. **No DOM measuring in reactive paths** that run on scroll, pan or zoom. -5. **Fetch once, derive locally.** Per-snapshot data (node lists, selection vocabulary) is cached per +5. **Reload in proportion to what changed.** A running run sends a change about every second. A read + that fetches a whole listing (all checks, all of a run's events) reloads at most every few seconds + (`createResource(..., { every })`, `throttled`), and app-wide badges at most every 10 s; small reads + (a run's node states) reload after each burst. A reload never shares a request started before the + change it answers. +6. **Fetch once, derive locally.** Per-snapshot data (node lists, selection vocabulary) is cached per location and snapshot; debounce server evaluation of typed input (~150 ms). -6. **Measure on realistic data.** Mock and benchmark data must be sized like a real project (thousands +7. **Measure on realistic data.** Mock and benchmark data must be sized like a real project (thousands of nodes, long names, populated state). An optimisation proved only on small or empty data does not count. -7. **Prove a guard can fail.** When adding a performance check, break the thing it protects once and +8. **Prove a guard can fail.** When adding a performance check, break the thing it protects once and confirm the check fails, then revert. diff --git a/ui/src/lib/api/http-client.ts b/ui/src/lib/api/http-client.ts index 423eccd7ee..f6b63bfd6e 100644 --- a/ui/src/lib/api/http-client.ts +++ b/ui/src/lib/api/http-client.ts @@ -1249,7 +1249,12 @@ export function createHttpClient({ baseUrl = '', onUnauthorized, fetch: answer, return data; } - implemented.changes.subscribe(() => kept.clear()); + // A change makes every listing read since then out of date: a reload it asks for reads afresh rather + // than sharing a request that started before it, which could leave a run's last state unshown. + implemented.changes.subscribe(() => { + kept.clear(); + inFlight.clear(); + }); return new Proxy(implemented, { get(target, property, receiver) { if (property in target) return Reflect.get(target, property, receiver); diff --git a/ui/src/lib/state/app.svelte.ts b/ui/src/lib/state/app.svelte.ts index c0d635057d..2388747f74 100644 --- a/ui/src/lib/state/app.svelte.ts +++ b/ui/src/lib/state/app.svelte.ts @@ -1,3 +1,4 @@ +import { throttled } from './throttle'; import { browser } from '$app/environment'; import { logout } from '$lib/api/http-client'; import { MockApiClient } from '$lib/api/mock/mock-client'; @@ -23,6 +24,8 @@ import { const SCOPE_KEY = 'sb-scope'; /** How often the shell rereads live problems and warehouse sync; locations report every 30 seconds. */ const POLL_MS = 30_000; +/** The least time between reloads of the sidebar's counts while changes stream in. */ +const NAV_COUNTS_MS = 10_000; /** * App-wide state: the bootstrap, the selected location, and the @@ -85,7 +88,7 @@ class AppState { if (channelMatches(signal.channel, ['platform_events'])) void this.#loadPlatformEvents(); if (channelMatches(signal.channel, ['warehouse_sync'])) void this.#loadWarehouseSync(); if (channelMatches(signal.channel, ['snapshot'])) void this.#loadSnapshot(); - if (channelMatches(signal.channel, ['runs', 'triggers', 'checks'])) void this.#loadNavCounts(); + if (channelMatches(signal.channel, ['runs', 'triggers', 'checks'])) this.#navCounts.request(); }); try { this.bootstrap = await this.client.bootstrap(); @@ -142,6 +145,12 @@ class AppState { this.locationId = location.id; } + /** + * The sidebar's counts read whole listings (every check's result, every run), so a running run's + * stream of changes reloads them at most every `NAV_COUNTS_MS`, and once more after the last change. + */ + #navCounts = throttled(() => this.#loadNavCounts(), NAV_COUNTS_MS); + #loadScoped() { void this.#loadNavCounts(); void this.#loadWarehouseSync(); diff --git a/ui/src/lib/state/resource.svelte.ts b/ui/src/lib/state/resource.svelte.ts index e79faabe04..365d5322f0 100644 --- a/ui/src/lib/state/resource.svelte.ts +++ b/ui/src/lib/state/resource.svelte.ts @@ -42,7 +42,9 @@ export type Resource = { */ export function createResource( load: (client: ApiClient, scope: Scope) => Promise, - topics: readonly string[] = [] + topics: readonly string[] = [], + /** `every`: the least time between reloads a stream of change signals starts, for a large read. */ + options: { every?: number } = {} ): Resource { let data = $state(undefined); let error = $state(null); @@ -52,9 +54,11 @@ export function createResource( let settled = 0; let reloadAgain = false; let pause: ReturnType | null = null; + let started = -Infinity; function run(scope: Scope) { const request = ++latest; + started = Date.now(); // The page's path and query tell apart reads of different jobs, runs and filters made by the same code. const key = `${app.user?.name ?? ''}|${scope.locationId}|${browser ? window.location.pathname + window.location.search : ''}|${load}`; if (key !== shownKey && remembered.has(key)) data = remembered.get(key) as T; @@ -92,11 +96,12 @@ export function createResource( function signalled() { if (pause) return; + const wait = Math.max(SIGNAL_PAUSE_MS, started + (options.every ?? 0) - Date.now()); pause = setTimeout(() => { pause = null; if (settled === latest) refresh(); else reloadAgain = true; - }, SIGNAL_PAUSE_MS); + }, wait); } function refresh() { diff --git a/ui/src/lib/state/throttle.test.ts b/ui/src/lib/state/throttle.test.ts new file mode 100644 index 0000000000..66d1b29460 --- /dev/null +++ b/ui/src/lib/state/throttle.test.ts @@ -0,0 +1,73 @@ +import { describe, expect, it } from 'vitest'; +import { throttled, type Timers } from './throttle'; + +/** Lets a finished load's handlers run. */ +const settle = () => new Promise((done) => setImmediate(done)); + +/** Timers driven by hand: `advance` moves the clock and fires what is due. */ +function fakeTimers() { + let now = 0; + let queue: { at: number; run: () => void; id: number }[] = []; + let next = 0; + const timers: Timers = { + now: () => now, + set: (run, ms) => (queue.push({ at: now + ms, run, id: ++next }), next), + clear: (id) => (queue = queue.filter((t) => t.id !== id)) + }; + const advance = async (ms: number) => { + const until = now + ms; + for (;;) { + queue.sort((a, b) => a.at - b.at); + const due = queue[0]; + if (!due || due.at > until) break; + queue.shift(); + now = due.at; + due.run(); + await settle(); + } + now = until; + }; + return { timers, advance }; +} + +describe('a throttled reload', () => { + it('starts at most once per interval under a stream of signals, and once more after the last', async () => { + const { timers, advance } = fakeTimers(); + const starts: number[] = []; + const reload = throttled(async () => void starts.push(timers.now()), 10_000, timers); + // A signal every second for 25 seconds. + for (let s = 0; s < 25; s++) { + reload.request(); + await advance(1000); + } + await advance(20_000); + expect(starts).toEqual([0, 10_000, 20_000, 30_000]); + }); + + it('never runs two loads at once; signals during a load ask for one more', async () => { + const { timers, advance } = fakeTimers(); + let running = 0; + let most = 0; + let finish: () => void = () => {}; + const reload = throttled( + () => { + running++; + most = Math.max(most, running); + return new Promise((done) => (finish = () => (running--, done()))); + }, + 0, + timers + ); + reload.request(); + reload.request(); + reload.request(); + expect(running).toBe(1); + finish(); + await settle(); + expect(running).toBe(1); + finish(); + await settle(); + expect(running).toBe(0); + expect(most).toBe(1); + }); +}); diff --git a/ui/src/lib/state/throttle.ts b/ui/src/lib/state/throttle.ts new file mode 100644 index 0000000000..c7787e60b6 --- /dev/null +++ b/ui/src/lib/state/throttle.ts @@ -0,0 +1,49 @@ +// A reload that a stream of change signals can ask for as often as it likes, but that starts at most +// once every `minMs`, never twice at a time, and always once more after the last signal. Pure apart +// from the timers it is given. + +export type Timers = { now: () => number; set: (run: () => void, ms: number) => unknown; clear: (handle: unknown) => void }; +const realTimers: Timers = { now: () => Date.now(), set: (run, ms) => setTimeout(run, ms), clear: (h) => clearTimeout(h as ReturnType) }; + +export type Throttled = { request: () => void; cancel: () => void }; + +/** + * `load` run on `request()`: at once when idle and at least `minMs` after the last start, else once + * later. Requests while a load runs, or while one waits, ask for just one more. + */ +export function throttled(load: () => Promise, minMs: number, timers: Timers = realTimers): Throttled { + let lastStart = -Infinity; + let running = false; + let again = false; + let waiting: unknown = null; + const start = () => { + waiting = null; + running = true; + again = false; + lastStart = timers.now(); + void load() + .catch(() => {}) + .finally(() => { + running = false; + if (again) request(); + }); + }; + function request() { + if (running) { + again = true; + return; + } + if (waiting !== null) return; + const wait = lastStart + minMs - timers.now(); + if (wait <= 0) start(); + else waiting = timers.set(start, wait); + } + return { + request, + cancel() { + if (waiting !== null) timers.clear(waiting); + waiting = null; + again = false; + } + }; +} From 9891c2117c155bf46ba057d8994dfd38b085dd29 Mon Sep 17 00:00:00 2001 From: Kevin Longe <273747162+kvlonge@users.noreply.github.com> Date: Tue, 17 Nov 2026 19:13:47 +0000 Subject: [PATCH 2/8] fix(ui): name the node each run event is about, and show printed output as a terminal would A run's log said `run` in the Node column for every node event. The UI read node identity from `resource_id` as a `["", ""]` pair, but the server sends an opaque hash there, with the node in `resource_kind` and `resource_name`. So no event or statement named its node, and parsing the hash threw for every event. The node key is now `:`, as the run keys its nodes, with the old pair still read. The scheduler's own run_node_started and run_node_finished events carry no node identity, and that needs a server change. Printed output arrives as raw chunks full of spinner redraws and escape codes. It now reads as the terminal left it, lines joined across chunks, so the run's printed plan ("Plan ready 93 selected", the seed list) is legible. Node keys show without their kind prefix (`seed:` is said elsewhere), with the full key on hover. --- ui/src/lib/api/http-runs.test.ts | 30 +++++++++++++++ ui/src/lib/api/http-runs.ts | 52 +++++++++++++++++++++++--- ui/src/lib/operate/labels.ts | 5 +++ ui/src/routes/runs/[id]/log-tab.svelte | 4 +- 4 files changed, 83 insertions(+), 8 deletions(-) diff --git a/ui/src/lib/api/http-runs.test.ts b/ui/src/lib/api/http-runs.test.ts index 25a8559f4e..ebff7d1d83 100644 --- a/ui/src/lib/api/http-runs.test.ts +++ b/ui/src/lib/api/http-runs.test.ts @@ -251,6 +251,17 @@ describe('run Recall reads', () => { ]); }); + it('names the node a seed build event is about, as the run keys its nodes, from the resource kind and name', () => { + // As the server sends them now: an opaque resource ID, with the resource's kind and name. + const seed = { resource_id: '3b7370f99e385665996e8f73523b4fd5', resource_kind: 'seed', resource_name: 'seed__order_type__alpha' }; + const mapped = [event('resource_attempt_started', seed), event('resource_attempt_completed', { ...seed, outcome: 'success' }), event('statement_completed', { ...seed, statement_id: 's9' })].flatMap((e) => toRunEvent(e, 'r1') ?? []); + expect(mapped.map((e) => e.nodeKey)).toEqual(['seed:seed__order_type__alpha', 'seed:seed__order_type__alpha', 'seed:seed__order_type__alpha']); + const [statement] = toRunStatements([{ invocation_id: inv, statement_id: 's9', sql_available: true, ...seed }], 'r1'); + expect(statement.nodeKey).toBe('seed:seed__order_type__alpha'); + // A hash alone names no node; the scheduler's node events carry none yet. + expect(toRunEvent(event('resource_attempt_started', { resource_id: '3b7370f99e385665996e8f73523b4fd5' }), 'r1')?.nodeKey).toBeNull(); + }); + it('orders statements as sent and tells running from finished by the end time', () => { const statement = (id: string, extra: Partial): W['RunStatementRecord'] => ({ invocation_id: inv, statement_id: id, sql_available: true, ...extra }); const statements = toRunStatements( @@ -268,6 +279,25 @@ describe('run Recall reads', () => { ]); }); + it('shows printed output as the terminal left it: spinner redraws and colours gone, lines whole across chunks', () => { + const chunk = (sequence: number, text: string) => ({ invocation_id: inv, sequence, stream: 'stdout', occurred_at: `2026-11-08T06:00:0${sequence}Z`, text }); + const output = toRunOutput({ + lines: [ + chunk(1, 'Location snapshot compiled.\n\x1b[?25l\r\x1b[K⠋ Compiling project...\r\x1b[K⠙ Compil'), + chunk(2, 'ing project...\r\x1b[K\x1b[?25hCompiled project. (18.07s)\n\n\n\x1b[1mPlan ready\x1b[0m 93 selected\n'), + chunk(3, '├── seed__order_type__alpha (current)\n') + ], + errors: [] + } as never); + expect(output.map((l) => [l.at.slice(-3, -1), l.text])).toEqual([ + ['01', 'Location snapshot compiled.'], + ['01', 'Compiled project. (18.07s)'], + ['02', ''], + ['02', 'Plan ready 93 selected'], + ['03', '├── seed__order_type__alpha (current)'] + ]); + }); + it('merges error text into the output as stderr in time order', () => { const output = toRunOutput({ lines: [ diff --git a/ui/src/lib/api/http-runs.ts b/ui/src/lib/api/http-runs.ts index ae9ea7f95e..d0579f1d7f 100644 --- a/ui/src/lib/api/http-runs.ts +++ b/ui/src/lib/api/http-runs.ts @@ -391,10 +391,17 @@ const KNOWN_EVENTS: ReadonlySet = new Set(RECALL_EVENT_TYPES); const SCHEDULER_EVENTS: ReadonlySet = new Set(SCHEDULER_FACTS.map((f) => `run_${f}`)); /** The node key a Recall resource ID names: `[invocation, key]`, or null for run-level rows. */ -function recallNodeKey(resourceId: string | null | undefined): string | null { - if (!resourceId) return null; +/** + * The node a Recall row is about, as a run's nodes are keyed (`seed:countries`): its resource's kind and + * name. Older servers sent no kind and name, and a `["", ""]` resource ID instead; + * any other resource ID is an opaque hash. + */ +export function recallNodeKey(row: { resource_id?: string | null; resource_kind?: string | null; resource_name?: string | null }): string | null { + if (row.resource_kind && row.resource_name) return `${row.resource_kind}:${row.resource_name}`; + const id = row.resource_id; + if (!id?.startsWith('[')) return null; try { - const parsed: unknown = JSON.parse(resourceId); + const parsed: unknown = JSON.parse(id); return Array.isArray(parsed) && typeof parsed[1] === 'string' ? parsed[1] : null; } catch { return null; @@ -434,7 +441,7 @@ export function toRunEvent(wire: Wire['RunEventRecord'], runId: string): RunEven occurredAt: wire.occurred_at, level: levelOf(wire.severity), invocationId: wire.invocation_id, - nodeKey: recallNodeKey(wire.resource_id), + nodeKey: recallNodeKey(wire), statementId: wire.statement_id ?? null, attempt: null, message @@ -448,7 +455,7 @@ export function toRunStatements(wire: Wire['RunStatementRecord'][], runId: strin runId, invocationId: s.invocation_id, sequence: i + 1, - nodeKey: recallNodeKey(s.resource_id) ?? s.resource_name ?? '', + nodeKey: recallNodeKey(s) ?? s.resource_name ?? '', kind: s.statement_kind ?? s.purpose ?? 'statement', status: s.outcome === 'failed' ? 'failed' : s.outcome === 'cancelled' ? 'cancelled' : s.ended_at || s.outcome ? 'completed' : 'running', startedAt: s.started_at ?? '', @@ -462,8 +469,41 @@ export function toRunStatements(wire: Wire['RunStatementRecord'][], runId: strin } /** Captured lines and error text in time order; error text reads as stderr of its invocation. */ +/** ANSI escape sequences: colours, cursor moves and the like. */ +const ANSI = /\x1b\[[0-9;?]*[ -/]*[@-~]|\x1b[@-Z\\-_]/g; + +/** + * Printed output as a terminal would leave it on screen. `sqb` redraws spinner and progress lines with + * a carriage return, across chunks, so each stream's chunks are joined, split into lines, and each line + * keeps only what follows its last carriage return, without escape codes. A line is timed by the chunk + * it started in; runs of blank lines read as one. + */ +export function terminalLines(chunks: { invocationId: string; stream: 'stdout' | 'stderr'; at: string; text: string }[]): RunOutputLine[] { + const out: RunOutputLine[] = []; + for (const stream of Map.groupBy(chunks, (c) => `${c.invocationId}\u0000${c.stream}`).values()) { + let line = ''; + let at = stream[0].at; + const finish = () => { + const shown = line.replace(ANSI, '').split('\r').at(-1)!.trimEnd(); + if (shown || out.at(-1)?.text) out.push({ invocationId: stream[0].invocationId, stream: stream[0].stream, at, text: shown, error: false }); + line = ''; + }; + for (const chunk of stream) { + const parts = chunk.text.split('\n'); + parts.forEach((part, i) => { + if (!line) at = chunk.at; + line += part; + if (i < parts.length - 1) finish(); + }); + } + if (line) finish(); + } + return out; +} + export function toRunOutput(wire: Wire['RunOutput']): RunOutputLine[] { - const lines: RunOutputLine[] = wire.lines.map((l) => ({ invocationId: l.invocation_id, stream: l.stream === 'stderr' ? 'stderr' : 'stdout', at: l.occurred_at, text: l.text, error: false })); + const ordered = [...wire.lines].sort((a, b) => a.occurred_at.localeCompare(b.occurred_at) || (a.sequence ?? 0) - (b.sequence ?? 0)); + const lines = terminalLines(ordered.map((l) => ({ invocationId: l.invocation_id, stream: l.stream === 'stderr' ? 'stderr' : 'stdout', at: l.occurred_at, text: l.text }))); const errors: RunOutputLine[] = wire.errors.map((e) => ({ invocationId: e.invocation_id, stream: 'stderr', at: e.occurred_at ?? '', text: e.message, error: true })); return [...lines, ...errors].sort((a, b) => a.at.localeCompare(b.at)); } diff --git a/ui/src/lib/operate/labels.ts b/ui/src/lib/operate/labels.ts index f6822d2230..03869bb5e4 100644 --- a/ui/src/lib/operate/labels.ts +++ b/ui/src/lib/operate/labels.ts @@ -297,3 +297,8 @@ export function clockTime(iso: string): string { export function narrowingText(narrowing: { select: string[]; exclude: string[] }): string { return [narrowing.select.length ? `--select ${narrowing.select.join(' ')}` : '', narrowing.exclude.length ? `--exclude ${narrowing.exclude.join(' ')}` : ''].filter(Boolean).join(' '); } + +/** A node key as a run shows it: `seed:countries` reads `countries`; the kind shows elsewhere, and the full key on hover. */ +export function nodeLabel(key: string): string { + return key.replace(/^[a-z_]+:(?=.)/, ''); +} diff --git a/ui/src/routes/runs/[id]/log-tab.svelte b/ui/src/routes/runs/[id]/log-tab.svelte index 8f253e95f6..68dd70a8e9 100644 --- a/ui/src/routes/runs/[id]/log-tab.svelte +++ b/ui/src/routes/runs/[id]/log-tab.svelte @@ -10,7 +10,7 @@ import SearchIcon from '@lucide/svelte/icons/search'; import type { RunEventLevel } from '$lib/api'; import { formatStamp } from '$lib/format/time'; - import { clockTime, shortRunId } from '$lib/operate/labels'; + import { clockTime, nodeLabel, shortRunId } from '$lib/operate/labels'; import type { EventCategory } from './types'; import { EVENT_CATEGORIES, type LogEntry } from './utils'; import SegmentedFilter from '$lib/components/list/segmented-filter.svelte'; @@ -111,7 +111,7 @@ {clockTime(e.at)} {#if grouped}{shortRunId(e.runId)}{/if} - {e.nodeKey ?? e.stream ?? 'run'} + {e.nodeKey ? nodeLabel(e.nodeKey) : (e.stream ?? 'run')} {#if e.stream} {@const lines = e.text.split('\n')} From 0a2872ac5fccba7a91d12538e2e29438cca49c18 Mon Sep 17 00:00:00 2001 From: Kevin Longe <273747162+kvlonge@users.noreply.github.com> Date: Tue, 17 Nov 2026 19:14:03 +0000 Subject: [PATCH 3/8] fix(ui): the run page lists nodes once, says what's waiting, and scrolls smoothly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - While a run goes on, nodes that haven't started are "Waiting", in their own group and on the timeline. "Not run" is for finished runs only. - A run of more than 40 nodes lists them once, on the timeline. The panel beside it becomes a summary: each outcome's count, which narrows the timeline to that outcome ("Waiting only · 60 of 93 · Show all"). Only failed and skipped nodes are listed there, each with why. Small runs keep the full lists. - The log, statements, output and cost reload at most every 3 s while a run streams changes; node states still reload after each burst. - "Plan it now" beside Details opens the job's build in the plan page. The run's own plan is in its printed output; the server keeps no plan document for a run. - Timeline scrolling: rows out of view are neither laid out nor painted (`content-visibility`). Bars are placed by their times and one --pps, so zooming changes one value instead of every bar. Running bars' stripes move by transform, without repainting. Measured on a real 93-node run at 6× CPU, scrolling went from p90 83 ms / max 133 ms to p90 33 ms / max 67 ms. Scrolling sideways while zoomed in went from p90 50 ms / max 267 ms to p90 17 ms / max 133 ms. --- ui/e2e/run-page.spec.ts | 13 ++++++ ui/src/routes/runs/[id]/node-panel.svelte | 51 +++++++++++++-------- ui/src/routes/runs/[id]/run-gantt.svelte | 50 ++++++++++++++++---- ui/src/routes/runs/[id]/run-header.svelte | 13 ++++++ ui/src/routes/runs/[id]/run-view.svelte | 8 +++- ui/src/routes/runs/[id]/state.svelte.ts | 39 +++++++++++++--- ui/src/routes/runs/[id]/types.ts | 2 +- ui/src/routes/runs/[id]/utils/nodes.test.ts | 27 +++++++++++ ui/src/routes/runs/[id]/utils/nodes.ts | 19 +++++--- 9 files changed, 179 insertions(+), 43 deletions(-) create mode 100644 ui/e2e/run-page.spec.ts create mode 100644 ui/src/routes/runs/[id]/utils/nodes.test.ts diff --git a/ui/e2e/run-page.spec.ts b/ui/e2e/run-page.spec.ts new file mode 100644 index 0000000000..39d2a39e1c --- /dev/null +++ b/ui/e2e/run-page.spec.ts @@ -0,0 +1,13 @@ +import { expect, test } from '@playwright/test'; + +// The run page while a run goes on: nodes that haven't started are waiting their turn, not left out. +test.use({ viewport: { width: 1600, height: 1000 } }); + +test('a running run’s nodes that haven’t started read as waiting', async ({ page }) => { + await page.goto('/runs/run-9d21?mock'); + const panel = page.getByLabel('Nodes by outcome'); + await expect(panel.locator('.group[data-group="waiting"]')).toContainText('Waiting', { timeout: 20_000 }); + await expect(panel.locator('.group[data-group="not_run"]')).toHaveCount(0); + await expect(page.locator('.gantt .note', { hasText: 'Waiting' }).first()).toBeVisible(); + await expect(page.locator('.gantt .note', { hasText: /Pending|Not run/ })).toHaveCount(0); +}); diff --git a/ui/src/routes/runs/[id]/node-panel.svelte b/ui/src/routes/runs/[id]/node-panel.svelte index 1f465834e3..c44e27ba3c 100644 --- a/ui/src/routes/runs/[id]/node-panel.svelte +++ b/ui/src/routes/runs/[id]/node-panel.svelte @@ -3,22 +3,26 @@ import Button from '$lib/components/ui/button/button.svelte'; import { to } from '$lib/paths'; import type { RunNode } from '$lib/api'; - import { shortRunId } from '$lib/operate/labels'; + import { nodeLabel, shortRunId } from '$lib/operate/labels'; import type { RunDetailState } from './state.svelte'; import type { NodeGroupKey } from './types'; - import { formatSpan, groupNodes, notRunReason } from './utils'; + import { formatSpan, notRunReason } from './utils'; let { view }: { view: RunDetailState } = $props(); - const groups = $derived(groupNodes(view.nodes)); - // Small runs show every node; large ones start with the successes folded away. + /** The most nodes a run may have for this panel to list them all. */ + const LIST_MAX = 40; + + const groups = $derived(view.nodeGroups); + /** + * A small run lists every node here. A large one's timeline already lists them, so here it is a summary: + * each outcome's count, which narrows the timeline to it, with only the failed and skipped nodes listed, + * as each says why. + */ + const summary = $derived(view.nodes.length > LIST_MAX); + const LISTED_IN_SUMMARY: NodeGroupKey[] = ['failed', 'skipped']; let closed = $state>(new Set()); - let folded = false; - $effect(() => { - if (folded || !view.nodes.length) return; - folded = true; - if (view.nodes.length > 40) closed = new Set(['succeeded']); - }); + const open = (key: NodeGroupKey) => (summary ? LISTED_IN_SUMMARY.includes(key) : !closed.has(key)); const took = (n: RunNode) => (n.startedAt && n.endedAt ? formatSpan((Date.parse(n.endedAt) - Date.parse(n.startedAt)) / 1000) : null); function toggle(key: NodeGroupKey) { @@ -38,17 +42,24 @@
{#each groups as g (g.key)}
- - - {#if !closed.has(g.key)} + {#if summary} + + + {:else} + + + {/if} + {#if open(g.key)}
    {#each g.nodes as n (`${n.runId}/${n.nodeKey}`)}
  • @@ -63,8 +74,8 @@ {/if} failed{#if why.runId !== n.runId} in {why.jobKey ?? shortRunId(why.runId)}{/if}
- {:else if notRunReason(n)} -
{notRunReason(n)}
+ {:else if n.status !== 'pending' && notRunReason(n, view.active)} +
{notRunReason(n, view.active)}
{/if} {/each} @@ -104,6 +115,10 @@ font-weight: 500; text-align: left; } + .group.picked { + background: color-mix(in srgb, var(--primary) 12%, var(--background)); + box-shadow: inset 2px 0 0 var(--primary); + } .group i { width: 8px; height: 8px; diff --git a/ui/src/routes/runs/[id]/run-gantt.svelte b/ui/src/routes/runs/[id]/run-gantt.svelte index 54f6122ff8..44e69b7519 100644 --- a/ui/src/routes/runs/[id]/run-gantt.svelte +++ b/ui/src/routes/runs/[id]/run-gantt.svelte @@ -7,7 +7,7 @@ import ChevronRightIcon from '@lucide/svelte/icons/chevron-right'; import { onMount } from 'svelte'; import type { RunNode } from '$lib/api'; - import { nodeStatusTone } from '$lib/operate/labels'; + import { nodeLabel, nodeStatusTone } from '$lib/operate/labels'; import { axisTicks as ticksFor, formatSpan, formatTick, tickStep as stepFor } from './utils'; export type GanttGroup = { runId: string; label: string; tone: string; href: string }; @@ -18,6 +18,7 @@ now, selected = [], groups = [], + active = false, onselect }: { nodes: RunNode[]; @@ -27,6 +28,8 @@ selected?: string[]; /** Child runs of a group, to section the rows. */ groups?: GanttGroup[]; + /** The run is still going, so a node that hasn't started is waiting, not left out. */ + active?: boolean; /** `add` is true for Ctrl-, Cmd- or Shift-click. */ onselect: (nodeKey: string, add: boolean) => void; } = $props(); @@ -52,6 +55,8 @@ const trackW = $derived(trackBaseW * zoom); const pxPerSec = $derived(trackW / (total * 1.08)); const xOf = (sec: number) => sec * pxPerSec; + /** Past this share of the track a bar's duration reads on its left, inside the track. */ + const FLIP_AT = 0.9; const tickStep = $derived(stepFor(total, Math.max(4, Math.floor(trackW / 110)))); const axisTicks = $derived(ticksFor(total, tickStep)); @@ -59,7 +64,7 @@ const ctx = document.createElement('canvas').getContext('2d'); if (!ctx) return 250; ctx.font = '12px "IBM Plex Mono", ui-monospace, monospace'; - const widest = Math.max(0, ...nodes.map((n) => ctx.measureText(n.nodeKey).width)); + const widest = Math.max(0, ...nodes.map((n) => ctx.measureText(nodeLabel(n.nodeKey)).width)); return Math.min(360, Math.max(GUTTER_MIN, Math.ceil(widest) + 60)); } @@ -107,7 +112,7 @@ const across = n.skippedBecauseOf.runId !== n.runId; return `skipped: ${n.skippedBecauseOf.nodeKey} failed${across ? ` in ${n.skippedBecauseOf.jobKey ?? n.skippedBecauseOf.runId}` : ''}`; } - if (n.status === 'pending') return 'Pending'; + if (n.status === 'pending') return active ? 'Waiting' : 'Not run'; if (n.status === 'not_run') return 'Not run'; if (n.status === 'cancelled') return 'Cancelled'; return n.status; @@ -128,7 +133,8 @@
(scrolledX = e.currentTarget.scrollLeft > 1)}> -
+ +
{#each axisTicks as tk (tk)}{/each}
@@ -185,14 +191,14 @@ title={n.nodeKey} > {#if selected.includes(n.nodeKey)}{/if} - {n.nodeKey}{#if n.critical}critical{/if} + {nodeLabel(n.nodeKey)}{#if n.critical}critical{/if} - + {#if s == null || e == null} {skipText(n)} {:else} - - trackW - 56}>{formatSpan(e - s)}{n.status === 'running' ? ' so far' : ''} + + FLIP_AT}>{formatSpan(e - s)}{n.status === 'running' ? ' so far' : ''} {/if} @@ -336,11 +342,15 @@ background: var(--primary); content: ''; } + /* Rows out of view are neither laid out nor painted, so scrolling a long run, or zooming it out, only + draws the rows on screen; each row's sticky name cell would otherwise be its own compositor layer. */ .row { position: relative; display: flex; width: 100%; height: 32px; + content-visibility: auto; + contain-intrinsic-size: auto 32px; align-items: center; border-bottom: 1px solid var(--border-subtle); text-align: left; @@ -421,24 +431,40 @@ } .track { position: relative; + width: var(--track-w); height: 100%; } .bar { position: absolute; top: 50%; + left: calc(var(--s) * var(--pps) * 1px); + width: max(3px, calc((var(--e) - var(--s)) * var(--pps) * 1px)); height: 16px; transform: translateY(-50%); border-radius: 2px; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18); } + /* A running bar's stripes move by transform, which the compositor animates without repainting. */ .bar.live { - background-image: linear-gradient(90deg, transparent 0 60%, rgba(255, 255, 255, 0.28) 60% 80%, transparent 80%) !important; + overflow: hidden; + } + .bar.live::after { + position: absolute; + inset: 0 0 0 -24px; + background-image: linear-gradient(90deg, transparent 0 60%, rgba(255, 255, 255, 0.28) 60% 80%, transparent 80%); background-size: 24px 100%; animation: slide 1.2s linear infinite; + content: ''; + will-change: transform; } @keyframes slide { to { - background-position: 24px 0; + transform: translateX(24px); + } + } + @media (prefers-reduced-motion: reduce) { + .bar.live::after { + animation: none; } } .dur, @@ -450,7 +476,11 @@ font-size: 11.5px; white-space: nowrap; } + .dur { + left: calc(var(--e) * var(--pps) * 1px + 8px); + } .dur.flip { + left: calc(var(--s) * var(--pps) * 1px - 8px); transform: translate(-100%, -50%); } .note { diff --git a/ui/src/routes/runs/[id]/run-header.svelte b/ui/src/routes/runs/[id]/run-header.svelte index 985466d740..aecf964d93 100644 --- a/ui/src/routes/runs/[id]/run-header.svelte +++ b/ui/src/routes/runs/[id]/run-header.svelte @@ -1,4 +1,5 @@