diff --git a/ui/e2e/group-run.spec.ts b/ui/e2e/group-run.spec.ts index 2c2f8d1a5f..33e0724436 100644 --- a/ui/e2e/group-run.spec.ts +++ b/ui/e2e/group-run.spec.ts @@ -1197,3 +1197,50 @@ test('a group run whose jobs all started on a newer version than its own counts await note.click(); await expect(page.getByText('Not used: removes the group nightly')).toHaveCount(1); }); + +test('a group run names the jobs a failure held back, says on each row what held it, and its +N shows them all; idle ticks stay within budget', async ({ page }) => { + const { fake, run } = server(Array.from({ length: 20 }, (_, i) => `job_${String(i).padStart(2, '0')}`), 150); + const [failed, ...held] = run.members; + for (const k of Object.keys(failed.nodes)) failed.nodes[k] = 'success'; + failed.nodes['model:job_00_10'] = 'failed'; + failed.nodes['model:job_00_11'] = 'failed'; + failed.failed = true; + for (const m of held) { + m.blockedBy = failed.jobKey; + for (const k of Object.keys(m.nodes)) m.nodes[k] = 'skipped'; + } + await page.clock.install(); + await fake.install(page); + await page.goto(`/runs/${run.id}`); + + // The header names two of the 19 jobs held back and counts the rest; the failed job's row says nothing of being held. + const heldBack = page.getByTestId('held-back'); + await expect(heldBack).toHaveText(/held back\s+job_01,\s*job_02\s*\+17/, { timeout: 30_000 }); + const tree = page.getByTestId('run-tree'); + const row = (job: string) => tree.getByRole('treeitem', { name: new RegExp(`^Open ${job}\\b`) }).first(); + await expect(row('job_01')).toContainText('blocked by job_00 · job_00_10 failed (+1)'); + await expect(row('job_00')).not.toContainText('blocked by'); + + // Clock ticks on an ended run with 19 blocked rows do no pass over its 3,000 nodes or its failures. + const settle = await countCalls(page, fake); + await page.clock.pauseAt(Date.now() + 1000); + await page.clock.runFor(4000); + await settle(); + await page.clock.runFor(5000); + const idle = await settle(); + expect(idle, `calls in 5 idle ticks: ${idle}`).toBeLessThan(5 * IDLE_CALLS_PER_TICK); + + // +17 shows the blocked jobs in the tree: the failed job leaves it, the held ones stay. + await heldBack.getByRole('button', { name: '+17' }).click(); + await page.clock.runFor(1000); + await expect(row('job_00')).toHaveCount(0); + await expect(row('job_01')).toBeVisible(); + await page.screenshot({ path: test.info().outputPath('held-back-more.png') }); + + // A held job's panel goes from the failure upstream, through the job's own nodes it skipped, to what that left. + await row('job_01').getByRole('button', { name: 'job_01', exact: true }).click(); + await page.clock.runFor(1000); + const chain = page.getByTestId('job-detail').getByTestId('job-error').getByRole('listitem'); + await expect(chain).toHaveText([/^job_00\s*·\s*job_00_10 failed \(\+1\)\s*$/, /^job_01_0,\s*job_01_1\s*\+148\s*skipped$/, '150 nodes in this job skipped · 0 ran']); + await page.screenshot({ path: test.info().outputPath('held-back-panel.png') }); +}); diff --git a/ui/e2e/real/crash.spec.ts b/ui/e2e/real/crash.spec.ts index 0201e275bd..a24da8fd58 100644 --- a/ui/e2e/real/crash.spec.ts +++ b/ui/e2e/real/crash.spec.ts @@ -54,11 +54,11 @@ test("a stopped worker's unreached nodes read as not run, and the jobs that read const afterRow = page.locator(`.line.node[data-row="n:${crashRunId}:${[...crashNodes.values()].find((n) => n.node_key.endsWith('crash_after'))!.node_key}"]`); await expect(afterRow.locator('.sb-mark')).toHaveAttribute('data-state', 'not_run'); - // The line under the title names the job that stopped and why, and that it held one job back, first. + // The line under the title names the job that stopped and why, and the job it held back, first. const cause = page.getByTestId('root-cause').first(); await expect(cause).toContainText('crash_job'); await expect(cause).toContainText(/crash_wait failed: the worker (exited with code \d+|stopped) without reporting a result/); - await expect(cause).toContainText('held back 1 job'); + await expect(cause.getByTestId('held-back')).toHaveText(/held back\s+after_crash_job\s*$/); await expect(page.getByTestId('run-summary')).toContainText('1 not run'); // A skipped node names the unreached node in the other job, and opens it. diff --git a/ui/e2e/real/root-failures.spec.ts b/ui/e2e/real/root-failures.spec.ts index e98606b702..bb3c6b770f 100644 --- a/ui/e2e/real/root-failures.spec.ts +++ b/ui/e2e/real/root-failures.spec.ts @@ -41,11 +41,34 @@ test("a sensor gets one run_failed for the group run, naming each root failure a ['feeds_job', 'return_feed', ['return_summary_job'], ['return_summary'], 1] ]); - // The page's line under the title reads the same root failures: one job, its two failed nodes, two jobs held back. + // The page's line under the title reads the same root failures: one job, its two failed nodes, and the two jobs it + // held back by name. await page.goto(`${server.uiUrl}/runs/${groupRunId}`); const causes = page.getByTestId('root-cause'); await expect(causes).toHaveCount(1, { timeout: 30_000 }); await expect(causes).toContainText('feeds_job'); await expect(causes).toContainText('refund_feed failed (+1)'); - await expect(causes).toContainText('held back 2 jobs'); + await expect(causes.getByTestId('held-back')).toHaveText(/held back\s+refund_summary_job,\s*return_summary_job/); + + // Each held-back job's row says which job held it back and which of its nodes failed: each waits on its own feed. + const row = (job: string) => page.locator('[data-row]').filter({ has: page.getByRole('button', { name: job, exact: true }) }); + await expect(row('refund_summary_job')).toContainText('blocked by feeds_job · refund_feed failed'); + await expect(row('return_summary_job')).toContainText('blocked by feeds_job · return_feed failed'); + await expect(row('feeds_job')).not.toContainText('blocked by'); + await page.screenshot({ path: test.info().outputPath('blocked-rows.png') }); + + // A held job's panel: the failure that held it, the node of its own that skipped, and what that left of the job. + await row('refund_summary_job').getByRole('button', { name: 'refund_summary_job', exact: true }).click(); + const chain = page.getByTestId('job-detail').getByTestId('job-error').getByRole('listitem'); + await expect(chain).toHaveText([/^feeds_job\s*·\s*refund_feed failed\s*$/, /^refund_summary\s*skipped$/, '1 node in this job skipped · 0 ran']); + await page.screenshot({ path: test.info().outputPath('blocked-panel.png') }); + + // The tree as its own column, too narrow for the sentence, says "blocked" where "N failed" goes, and why on hover. + await page.evaluate(() => localStorage.setItem('sqlbuild.run.treeColumn', '1')); + await page.reload(); + const column = page.getByTestId('tree-column'); + const refund = column.locator('[data-row]').filter({ hasText: 'refund_summary_job' }); + await expect(refund.getByText('blocked', { exact: true })).toHaveAttribute('title', 'blocked by feeds_job · refund_feed failed', { timeout: 30_000 }); + await expect(column.locator('[data-row]').filter({ hasText: 'feeds_job' }).first().getByText('blocked', { exact: true })).toHaveCount(0); + await page.screenshot({ path: test.info().outputPath('blocked-rows-column.png') }); }); diff --git a/ui/e2e/support/fake-control.ts b/ui/e2e/support/fake-control.ts index 0a60efdadb..4c07e932e2 100644 --- a/ui/e2e/support/fake-control.ts +++ b/ui/e2e/support/fake-control.ts @@ -62,6 +62,8 @@ export type FakeMemberRun = { replaced?: boolean; /** The job run has ended failed. */ failed?: boolean; + /** The job run has ended blocked, held back by this job's failed run; the server lists it under that job's root failures. */ + blockedBy?: string; /** Nodes it read that an earlier job built on an older version and that changed since, as the server sends them. */ staleReads?: { node_key: string; built_on_generation: number; changed_in_generation: number; built_by_run_id: string }[]; /** Rows a running node has written so far, as the server reports them, by node key. */ @@ -364,7 +366,8 @@ export class FakeControl { .filter((m) => m.failed && !m.replaced) .flatMap((m) => { const failed = Object.keys(m.nodes).filter((key) => m.nodes[key] === 'failed').sort(); - return (failed.length ? failed : [null]).map((node_key) => ({ job_key: m.jobKey, node_key, blocked_jobs: [], blocked_nodes: [], blocked_node_count: 0 })); + const blocked_jobs = live.members.filter((b) => b.blockedBy === m.jobKey).map((b) => b.jobKey); + return (failed.length ? failed : [null]).map((node_key) => ({ job_key: m.jobKey, node_key, blocked_jobs, blocked_nodes: [], blocked_node_count: 0 })); }) .sort((a, b) => a.job_key.localeCompare(b.job_key) || (a.node_key ?? '').localeCompare(b.node_key ?? '')); // As the server: every node without `since` or from a version it never gave, else each run moved past `since`, whole. @@ -449,8 +452,8 @@ export class FakeControl { return { run_id: run.id, location_id: LOCATIONS.shop, target: 'dev', snapshot_id: SNAPSHOT, snapshot_generation: (member && run.generation) || 1, git_revision: null, git_dirty: false, sqb_version: '0.0.0', image_id: null, job_key: run.jobKey, kind: member ? 'job' : 'group', origin: 'manual', parent_run_id: member ? live.id : null, root_run_id: live.id, trigger_id: null, trigger_name: null, tick_id: null, rerun_of_run_id: (member && run.retry?.of) || null, - requested_by: member && run.retry?.automatic ? 'system:retry' : 'principal:tester', requester_name: member && run.retry?.automatic ? null : 'tester', priority: 0, rewrite_history: false, status: member && run.replaced ? 'cancelled' : queued ? 'queued' : member && run.failed ? 'failed' : 'running', status_reason: null, - queued_at: at, launched_at: queued ? null : at, started_at: queued ? null : at, ended_at: member && run.failed ? at : null, cancel_requested_at: member ? null : (live.cancelRequestedAt ?? null), node_counts_json: counts, + requested_by: member && run.retry?.automatic ? 'system:retry' : 'principal:tester', requester_name: member && run.retry?.automatic ? null : 'tester', priority: 0, rewrite_history: false, status: member && run.replaced ? 'cancelled' : queued ? 'queued' : member && run.failed ? 'failed' : member && run.blockedBy ? 'blocked' : 'running', status_reason: null, + queued_at: at, launched_at: queued ? null : at, started_at: queued ? null : at, ended_at: member && (run.failed || run.blockedBy) ? at : null, cancel_requested_at: member ? null : (live.cancelRequestedAt ?? null), node_counts_json: counts, ignored_audit_failures: 0, last_event_storage_id: member ? run.cursor : 1, narrowing: null, member_attempt: (member && run.retry?.attempt) || null, version_policy: member ? null : (live.versionPolicy ?? 'newest'), skipped_versions: member ? [] : (live.skippedVersions ?? []), stale_reads: (member && run.staleReads) || [] }; diff --git a/ui/src/routes/runs/[id]/job-drawer.svelte b/ui/src/routes/runs/[id]/job-drawer.svelte index fed598e315..4bb1ae59fc 100644 --- a/ui/src/routes/runs/[id]/job-drawer.svelte +++ b/ui/src/routes/runs/[id]/job-drawer.svelte @@ -3,6 +3,7 @@ import type { RunNode } from '$lib/api'; import { formatAgo, formatDuration, formatStamp } from '$lib/format/time'; import { nodeLabel, outcomeCounts, shortRunId } from '$lib/operate/labels'; + import { groupedCount } from '$lib/format/plural'; import { to } from '$lib/paths'; import { app } from '$lib/state/app.svelte'; import { createResource } from '$lib/state/resource.svelte'; @@ -12,6 +13,7 @@ import RunDrawer from './run-drawer.svelte'; import type { RunDetailState } from './state.svelte'; import { countsText, type TreeRow } from './utils/run-tree'; + import { heldBy, rootFailed } from './utils/job-outcomes'; import { attemptFailure, failureLine } from '$lib/run/failure'; // A group run's job in the right-hand panel: how it went in this run (its nodes as a bar, what builds @@ -114,8 +116,30 @@ {#if run?.statusReason && nodes.some((n) => n.status === 'not_run')}

Stopped: {run.statusReason}

{/if} {:else if outcome === 'blocked'} - -

Blocked: {blocker ?? 'an upstream node failed'}

+ + {@const held = heldBy(jobKey, view.detail?.rootFailures ?? [])} + {@const skipped = nodes.filter((n) => n.status === 'skipped')} + {@const ran = job.counts.built + job.counts.running + job.counts.failed} +
    +
  1. + {#if held} + {held.root.jobKey} · + {#if held.root.nodeKey}{:else}{rootFailed(held)}{/if} + {#if held.moreJobs} · and {held.moreJobs} more {held.moreJobs === 1 ? 'job' : 'jobs'}{/if} + {:else} + {blocker ?? 'an upstream node failed'} + {/if} +
  2. + {#if skipped.length} +
  3. + {#each skipped.slice(0, 2) as n, i (n.nodeKey)}{#if i}, {/if}{/each} + {#if skipped.length > 2} +{groupedCount(skipped.length - 2)}{/if} + skipped +
  4. + {/if} +
  5. {groupedCount(job.counts.skipped)} {job.counts.skipped === 1 ? 'node' : 'nodes'} in this job skipped · {groupedCount(ran)} ran
  6. +
{/if} {#if run?.staleReads.length}
@@ -258,7 +282,7 @@ white-space: nowrap; } .error, - .blocked { + .chain { margin: 0 0 10px; font-size: 12.5px; overflow-wrap: anywhere; @@ -281,8 +305,53 @@ font-size: 12px; overflow-wrap: anywhere; } - .blocked { + /* What held a blocked job back, as steps down a thin rule: the failure upstream, the job's own nodes it skipped, + and what that left of the job. */ + .chain { + padding: 0; + list-style: none; color: var(--muted-foreground); + line-height: 18px; + } + .chain li { + position: relative; + padding: 0 0 8px 16px; + } + .chain li:last-child { + padding-bottom: 0; + } + .chain li::before { + position: absolute; + top: 6px; + left: 0; + box-sizing: border-box; + width: 7px; + height: 7px; + border: 1px solid var(--sb-text-faint); + border-radius: 50%; + content: ''; + } + .chain li:not(:last-child)::after { + position: absolute; + top: 15px; + bottom: 1px; + left: 3px; + border-left: 1px solid var(--border); + content: ''; + } + .chain .root::before { + border-color: var(--sb-error); + background: var(--sb-error); + } + .chain .root .failed-node { + color: var(--sb-error); + } + .chain .from, + .chain .here { + color: var(--foreground); + } + .chain .from { + font-family: var(--font-mono); } .faint { color: var(--sb-text-faint); diff --git a/ui/src/routes/runs/[id]/root-causes.svelte b/ui/src/routes/runs/[id]/root-causes.svelte index eaec0d4d7d..179f6c2927 100644 --- a/ui/src/routes/runs/[id]/root-causes.svelte +++ b/ui/src/routes/runs/[id]/root-causes.svelte @@ -5,11 +5,13 @@ import { causeLine, type RootCause } from './utils/job-outcomes'; // A group run's root causes under its title, one line: the job that failed on its own account, what - // failed or why its run stopped, and how many jobs it held back. A job's name opens it in the panel; - // past two causes the rest are a count, which shows the failed jobs in the tree. - let { causes, onopen, onmore }: { causes: RootCause[]; onopen: (runId: string) => void; onmore: () => void } = $props(); + // failed or why its run stopped, and the jobs it held back. A job's name opens it in the panel; past two + // causes the rest are a count, which shows the failed jobs in the tree, and past two held jobs the rest are a + // count, which shows the blocked jobs. + let { causes, onopen, onmore, onblocked }: { causes: RootCause[]; onopen: (runId: string) => void; onmore: () => void; onblocked: () => void } = $props(); const SHOWN = 2; + const HELD_SHOWN = 2; {#if causes.length} @@ -23,7 +25,13 @@ {causeLine(c)} {#if c.run.endedAt}at {formatClock(c.run.endedAt, app.now)}{/if} - {#if c.heldBack}· held back {c.heldBack === 1 ? '1 job' : `${c.heldBack} jobs`}{/if} + {#if c.held.length} + · held back + {#each c.held.slice(0, HELD_SHOWN) as h, j (h.id)}{#if j}, {/if}{/each} + + {#if c.held.length > HELD_SHOWN}{/if} + + {/if} {/each} @@ -63,6 +71,11 @@ font-family: var(--font-mono); font-weight: 500; } + /* A job held back failed nothing of its own: named quietly, beside the cause that held it. */ + .held-job { + color: var(--foreground); + font-weight: 400; + } .job:hover, .more:hover { text-decoration: underline; diff --git a/ui/src/routes/runs/[id]/run-tree.svelte b/ui/src/routes/runs/[id]/run-tree.svelte index 5a7b74025f..d81c5b6f81 100644 --- a/ui/src/routes/runs/[id]/run-tree.svelte +++ b/ui/src/routes/runs/[id]/run-tree.svelte @@ -50,7 +50,8 @@ focus = null, baseVersion = null, publishedAt = () => null, - marks = [] + marks = [], + blockers = new Map() }: { tree: TreeRow[]; /** Node keys the default view shows. */ @@ -80,6 +81,8 @@ publishedAt?: (generation: number | null) => string | null; /** Moments to mark on the timeline, in ms since the epoch: a version published while the run went. */ marks?: { label: string; at: number; title: string }[]; + /** Why each blocked job was held back, by run ID: the job and the node that failed upstream. */ + blockers?: ReadonlyMap; } = $props(); const ROW = 27; @@ -226,7 +229,7 @@ const rows = r.node?.status === 'running' ? rowsText(r.node) : null; const time = r.end === null ? `${length} so far${rows ? ` · ${rows.replace(/ so far$/, '')}` : ''}` : length; const action = r.node?.action ? nodeActionLabel[r.node.action] : null; - const label = r.kind === 'node' ? (action ? `${action} · ${time}` : time) : [r.run && attemptFailure(r.run), preparing(r) && 'preparing', countsOf(r.counts), time].filter(Boolean).join(' · '); + const label = r.kind === 'node' ? (action ? `${action} · ${time}` : time) : [r.run && attemptFailure(r.run), r.kind === 'job' && blockers.get(r.runId), preparing(r) && 'preparing', countsOf(r.counts), time].filter(Boolean).join(' · '); // The words go after the bar where they fit, else before it, else on the side with more room, cut short there. const after = (1 - (e - ui.v0) / span) * trackWidth - 6; const ahead = ((s - ui.v0) / span) * trackWidth - 6; @@ -339,7 +342,7 @@ {#if r.kind === 'job' && r.run?.staleReads.length}{@const s = r.run.staleReads}{/if} {#if version}{@const at = publishedAt(r.run!.snapshotGeneration)}{version}{/if} {/if} - {#if r.kind !== 'node'}{#if r.counts.failed}{r.counts.failed} failed{/if}{groupedCount(r.counts.total)}{/if} + {#if r.kind !== 'node'}{#if mode === 'filter' && r.kind === 'job' && blockers.get(r.runId)}blocked{/if}{#if r.counts.failed}{r.counts.failed} failed{/if}{groupedCount(r.counts.total)}{/if}
{#if mode === 'timeline'}
@@ -349,7 +352,7 @@ {:else if r.kind === 'node' && attention.has(r.node!.nodeKey) && r.worst === 'waiting'} ready · waiting for a free slot {:else if r.kind !== 'node'} - {[r.run && attemptFailure(r.run), r.kind === 'job' && r.worst === 'running' && 'starting', countsOf(r.counts)].filter(Boolean).join(' · ')} + {[r.run && attemptFailure(r.run), r.kind === 'job' && blockers.get(r.runId), r.kind === 'job' && r.worst === 'running' && 'starting', countsOf(r.counts)].filter(Boolean).join(' · ')} {/if}
{/if} @@ -548,6 +551,10 @@ color: var(--sb-error); font-weight: 500; } + .blocked { + color: var(--muted-foreground); + cursor: help; + } .track { position: relative; height: 100%; diff --git a/ui/src/routes/runs/[id]/run-view.svelte b/ui/src/routes/runs/[id]/run-view.svelte index c06f023c91..864273345b 100644 --- a/ui/src/routes/runs/[id]/run-view.svelte +++ b/ui/src/routes/runs/[id]/run-view.svelte @@ -29,7 +29,7 @@ import RunGantt from './run-gantt.svelte'; import RunTree, { treeUi, type TreeUi } from './run-tree.svelte'; import PanelLeftIcon from '@lucide/svelte/icons/panel-left'; - import { memberOutcomes, rootCauses } from './utils/job-outcomes'; + import { blockedBy, memberOutcomes, rootCauses } from './utils/job-outcomes'; import { attentionKeys, keysUnder, runTree, stateOfNode } from './utils/run-tree'; import { useCatalogNodes } from '$lib/state/catalog.svelte'; import RunHeader from './run-header.svelte'; @@ -174,6 +174,15 @@ const outcomes = $derived(memberOutcomes(view.detail?.children ?? [])); /** The jobs that failed on their own account, as the server lists them, for the line under the title as soon as one does. */ const causes = $derived(isGroup ? rootCauses(view.detail?.children ?? [], view.detail?.rootFailures ?? [], view.currentNodes) : []); + /** What held back each blocked job, by the run ID of its latest attempt, for its row. */ + const blockers = $derived.by(() => { + const out = new Map(); + for (const m of view.detail?.children ?? []) { + const why = outcomes.get(m.id) === 'blocked' && m.jobKey ? blockedBy(m.jobKey, view.detail?.rootFailures ?? []) : null; + if (why) out.set(m.id, why); + } + return out; + }); const shownTree = $derived(view.jobFilter ? tree.filter((r) => outcomes.get(r.runId) === view.jobFilter) : tree); /** * Opening a job zooms the timeline to it. The window is taken once, when the job opens, so a @@ -253,7 +262,7 @@ {#if detail} - {#if !isGroup}{:else} openJob(id, true)} onmore={() => (view.jobFilter = 'failed')} />{/if} + {#if !isGroup}{:else} openJob(id, true)} onmore={() => (view.jobFilter = 'failed')} onblocked={() => (view.jobFilter = 'blocked')} />{/if} b.key !== 'failed') : view.banners} /> {#if cantRun.length} @@ -266,7 +275,7 @@
{#if columnMode && viewShown} -
view.tick(row.selector, all)} bind:ui={treeState} selectedKeys={view.selection.keys} {stateFilter} onstate={(s) => (view.treeFilter = s)} onopennode={(key) => view.openDrawer(key)} focus={focusRow} onopenjob={openJob} onreset={() => ((view.jobFilter = null), lineage?.reset())} />
+
view.tick(row.selector, all)} bind:ui={treeState} selectedKeys={view.selection.keys} {stateFilter} onstate={(s) => (view.treeFilter = s)} onopennode={(key) => view.openDrawer(key)} focus={focusRow} onopenjob={openJob} onreset={() => ((view.jobFilter = null), lineage?.reset())} />
{/if}
{#if nodes.length} @@ -301,10 +310,10 @@ {:else if columnMode}
{:else if isGroup && topView === 'timeline'} - (view.treeFilter = s)} onopennode={(key) => view.openDrawer(key)} focus={focusRow} onopenjob={openJob} onreset={() => ((view.jobFilter = null), lineage?.reset())} /> + (view.treeFilter = s)} onopennode={(key) => view.openDrawer(key)} focus={focusRow} onopenjob={openJob} onreset={() => ((view.jobFilter = null), lineage?.reset())} /> {:else if isGroup}
-
view.tick(row.selector, all)} bind:ui={treeState} selectedKeys={view.selection.keys} {stateFilter} onstate={(s) => (view.treeFilter = s)} onopennode={(key) => view.openDrawer(key)} focus={focusRow} onopenjob={openJob} onreset={() => ((view.jobFilter = null), lineage?.reset())} />
+
view.tick(row.selector, all)} bind:ui={treeState} selectedKeys={view.selection.keys} {stateFilter} onstate={(s) => (view.treeFilter = s)} onopennode={(key) => view.openDrawer(key)} focus={focusRow} onopenjob={openJob} onreset={() => ((view.jobFilter = null), lineage?.reset())} />
{:else if topView === 'timeline' || !hasGraph} diff --git a/ui/src/routes/runs/[id]/utils/job-outcomes.test.ts b/ui/src/routes/runs/[id]/utils/job-outcomes.test.ts index 58ec4916ec..5225d2f0eb 100644 --- a/ui/src/routes/runs/[id]/utils/job-outcomes.test.ts +++ b/ui/src/routes/runs/[id]/utils/job-outcomes.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; import type { GroupRootFailure, Run, RunNode } from '$lib/api'; -import { causeLine, memberOutcomes, rootCauses } from './job-outcomes'; +import { blockedBy, causeLine, memberOutcomes, rootCauses } from './job-outcomes'; const member = (id: string, jobKey: string, status: Run['status'], endedAt: string | null = null, statusReason: string | null = null) => ({ id, jobKey, status, endedAt, statusReason, memberAttempt: null, rerunOfRunId: null, parentRunId: 'g' }) as unknown as Run; @@ -51,17 +51,18 @@ describe('member outcomes of a group run', () => { }); describe('root causes of a group run', () => { + // crash_job skipped a node for load_job's failure too, but it failed on its own, so it is a cause, not held back. it("lists the server's root failures by job, most held back first, with what failed and whether its run stopped short", () => { const causes = rootCauses(members, failures, nodes); - expect(causes.map((c) => [c.run.jobKey, c.failedNodes, c.heldBack, c.stopped])).toEqual([ - ['load_job', ['loader:raw'], 2, false], - ['crash_job', [], 1, true], - ['report_job', ['model:rep'], 0, false] + expect(causes.map((c) => [c.run.jobKey, c.failedNodes, c.held.map((h) => h.jobKey), c.stopped])).toEqual([ + ['crash_job', [], ['publish_job'], true], + ['load_job', ['loader:raw'], ['stage_job'], false], + ['report_job', ['model:rep'], [], false] ]); }); it('makes one cause of a job with two failed nodes, counting each job it held back once', () => { const twice = rootCauses(members, [root('load_job', 'loader:a', ['stage_job']), root('load_job', 'loader:raw', ['stage_job', 'crash_job'])], nodes); - expect(twice.map((c) => [c.run.jobKey, c.failedNodes, c.heldBack])).toEqual([['load_job', ['loader:a', 'loader:raw'], 2]]); + expect(twice.map((c) => [c.run.jobKey, c.failedNodes, c.held.map((h) => h.jobKey)])).toEqual([['load_job', ['loader:a', 'loader:raw'], ['stage_job']]]); expect(causeLine(twice[0])).toBe('a failed (+1)'); }); }); @@ -74,8 +75,24 @@ describe('the line a root cause says', () => { }); it('says what failed, why a run stopped short, and where an attempt stopped before any node', () => { const said = rootCauses(members, failures, nodes).map(causeLine); - expect(said).toEqual(['raw failed', 'worker stopped; physical exit or absence confirmed', 'rep failed']); + expect(said).toEqual(['worker stopped; physical exit or absence confirmed', 'raw failed', 'rep failed']); const retry = { ...member('load2', 'load_job', 'failed', null, housekeeping), memberAttempt: 2, failure: { phase: 'worker_start', code: 'PythonNodeDiscoveryError', message: null } } as unknown as Run; - expect(causeLine({ run: retry, failedNodes: [], heldBack: 0, stopped: true })).toBe("attempt 2 couldn't start: PythonNodeDiscoveryError"); + expect(causeLine({ run: retry, failedNodes: [], held: [], stopped: true })).toBe("attempt 2 couldn't start: PythonNodeDiscoveryError"); + }); +}); + +describe('why a blocked job was held back', () => { + it('names the job and the node that failed upstream, from the root failures that list it', () => { + expect(blockedBy('stage_job', failures)).toBe('blocked by load_job · raw failed'); + // A job held back by a job that failed before any node of its own: that job, with no node. + expect(blockedBy('publish_job', failures)).toBe('blocked by crash_job · failed'); + }); + it('counts a second failed node in the same job, and other jobs, rather than listing them', () => { + const two = [root('load_job', 'loader:a', ['stage_job']), root('load_job', 'loader:raw', ['stage_job']), root('crash_job', null, ['stage_job']), root('report_job', 'model:rep', ['stage_job'])]; + expect(blockedBy('stage_job', two)).toBe('blocked by load_job · a failed (+1), and 2 more jobs'); + }); + it('says nothing for a job no root failure names, or a root failure that held back nothing', () => { + expect(blockedBy('ok_job', failures)).toBeNull(); + expect(blockedBy('report_job', failures)).toBeNull(); }); }); diff --git a/ui/src/routes/runs/[id]/utils/job-outcomes.ts b/ui/src/routes/runs/[id]/utils/job-outcomes.ts index 49344dfcf9..5844a798cd 100644 --- a/ui/src/routes/runs/[id]/utils/job-outcomes.ts +++ b/ui/src/routes/runs/[id]/utils/job-outcomes.ts @@ -27,8 +27,8 @@ export function memberOutcomes(members: readonly Run[]): Map { return out; } -/** A job that failed on its own account, its failed nodes, and how many other jobs it held back. */ -export type RootCause = { run: Run; failedNodes: string[]; heldBack: number; stopped: boolean }; +/** A job that failed on its own account, its failed nodes, and the other jobs it held back (their latest attempts). */ +export type RootCause = { run: Run; failedNodes: string[]; held: Run[]; stopped: boolean }; /** * A group run's root causes, from the root failures the server lists, one per job: its latest attempt, its failed @@ -47,9 +47,12 @@ export function rootCauses(members: readonly Run[], failures: readonly GroupRoot return [...byJob] .flatMap(([job, { failedNodes, held }]) => { const run = latest.get(job); - return run ? [{ run, failedNodes, heldBack: held.size, stopped: stopped.has(run.id) }] : []; + // Held means blocked: the server also lists a job that failed or still runs and had a node skipped for this one, + // which is its own cause or not over yet. A held job with no run in the group (none read yet) can't be named. + const blocked = [...held].flatMap((k) => (latest.get(k)?.status === 'blocked' ? [latest.get(k)!] : [])); + return run ? [{ run, failedNodes, held: blocked, stopped: stopped.has(run.id) }] : []; }) - .sort((a, b) => b.heldBack - a.heldBack || (a.run.endedAt ?? '').localeCompare(b.run.endedAt ?? '')); + .sort((a, b) => b.held.length - a.held.length || (a.run.endedAt ?? '').localeCompare(b.run.endedAt ?? '')); } /** @@ -66,3 +69,24 @@ export function causeLine(c: RootCause): string { const failed = first ? `${nodeLabel(first)} failed${rest.length ? ` (+${rest.length})` : ''}` : c.stopped ? null : 'a check failed'; return [failed, why].filter(Boolean).join(': ') || 'failed'; } + +/** The root failure that held a blocked job back, the first the server names, with how many more nodes failed in its job and how many more jobs held this one back; null for a job no root failure names. */ +export function heldBy(jobKey: string, failures: readonly GroupRootFailure[]): { root: GroupRootFailure; moreNodes: number; moreJobs: number } | null { + const by = failures.filter((f) => f.blockedJobs.includes(jobKey)); + if (!by.length) return null; + const [root] = by; + return { root, moreNodes: Math.max(0, by.filter((f) => f.jobKey === root.jobKey && f.nodeKey).length - 1), moreJobs: new Set(by.map((f) => f.jobKey)).size - 1 }; +} + +/** What failed at a root: its node, with a count of the others that failed in its job. */ +export const rootFailed = (h: { root: GroupRootFailure; moreNodes: number }) => (h.root.nodeKey ? `${nodeLabel(h.root.nodeKey)} failed${h.moreNodes ? ` (+${h.moreNodes})` : ''}` : 'failed'); + +/** + * Why a blocked job didn't run, for its row: the job that held it back and what failed there, from the server's root + * failures; a second cause is a count. Null for a job no root failure names, which says only that it was blocked. + */ +export function blockedBy(jobKey: string, failures: readonly GroupRootFailure[]): string | null { + const h = heldBy(jobKey, failures); + if (!h) return null; + return `blocked by ${h.root.jobKey} · ${rootFailed(h)}${h.moreJobs ? `, and ${h.moreJobs} more ${h.moreJobs === 1 ? 'job' : 'jobs'}` : ''}`; +}