From c3b655c65173a242e70ac462f3e63678541bba1e Mon Sep 17 00:00:00 2001 From: Kevin Longe <273747162+kvlonge@users.noreply.github.com> Date: Sat, 14 Nov 2026 00:14:00 +0000 Subject: [PATCH 1/2] feat(ui): build what changed from Overview and Lineage, and show held-back nodes in the plan --- ui/src/lib/api/http-runs.ts | 3 +- ui/src/lib/api/mock/build-fixtures.ts | 12 ++++ ui/src/lib/api/mock/fixtures.ts | 2 +- ui/src/lib/api/mock/mock-client.ts | 6 +- ui/src/lib/api/mock/operate-store.ts | 56 ++++++++++++++++-- ui/src/lib/api/types/operate.ts | 14 +++++ ui/src/lib/run/command.ts | 7 ++- ui/src/lib/run/plan-report.svelte | 14 ++++- ui/src/lib/run/plan-text.test.ts | 64 ++++++++++++++++++++- ui/src/lib/run/plan-text.ts | 83 ++++++++++++++++++++++----- ui/src/routes/+page.svelte | 9 ++- ui/src/routes/lineage/+page.svelte | 13 ++++- ui/src/routes/plan/+page.svelte | 10 +++- 13 files changed, 259 insertions(+), 34 deletions(-) diff --git a/ui/src/lib/api/http-runs.ts b/ui/src/lib/api/http-runs.ts index d5f6d4a9e8..a8e287b1d8 100644 --- a/ui/src/lib/api/http-runs.ts +++ b/ui/src/lib/api/http-runs.ts @@ -35,7 +35,8 @@ export function planResultOf(outcome: Wire['LocationWorkOutcome']): PlanResult { column_migrations: list(document.column_migrations), table_type_conversions: list(document.table_type_conversions), retention: list(document.retention), - synced_copy: document.synced_copy ?? null + synced_copy: document.synced_copy ?? null, + changed: document.changed ?? null }, error: null }; diff --git a/ui/src/lib/api/mock/build-fixtures.ts b/ui/src/lib/api/mock/build-fixtures.ts index ea290431ca..b6635e88e5 100644 --- a/ui/src/lib/api/mock/build-fixtures.ts +++ b/ui/src/lib/api/mock/build-fixtures.ts @@ -358,6 +358,18 @@ const node = (key: string, op: NodeChange['op'], detail: string, extra: Partial< }); export const DEPLOYS: DeploySpec[] = [ + { + generation: 43, + gitRevision: 'c41e9b2', + gitDirty: false, + gitAuthor: ALEX.displayName, + minutesAgo: 6, + publishedBy: CI_ACCOUNT, + nodes: [node('fact_orders', 'changed', 'SQL changed: refunded payments now net out of order revenue', { columns: [{ name: 'net_revenue', op: 'changed', detail: 'expression changed' }] })], + orchestration: [], + roles: [], + environment: null + }, { generation: 42, gitRevision: '7d2e41a', diff --git a/ui/src/lib/api/mock/fixtures.ts b/ui/src/lib/api/mock/fixtures.ts index b56bb33124..0d21ca59a8 100644 --- a/ui/src/lib/api/mock/fixtures.ts +++ b/ui/src/lib/api/mock/fixtures.ts @@ -49,7 +49,7 @@ export function createFixtures(now: number) { health: 'healthy', lastSeenAt: ago(0.2), target: { name: 'prod', adapter: 'snowflake', connectionSummary: 'WAFFLE_SHOP on example-account' }, - snapshot: snapshot(42, '7d2e41a', 190, 'Alex Rivera'), + snapshot: snapshot(43, 'c41e9b2', 6, 'Alex Rivera'), warehouseSync: idleSync(4) }, { diff --git a/ui/src/lib/api/mock/mock-client.ts b/ui/src/lib/api/mock/mock-client.ts index 97c330805e..cde76b46c7 100644 --- a/ui/src/lib/api/mock/mock-client.ts +++ b/ui/src/lib/api/mock/mock-client.ts @@ -275,7 +275,11 @@ export class MockApiClient implements ApiClient { async planBuild(scope: Scope, command: string[]): Promise { this.#location(scope); - return this.#operate.planBuild(scope, command); + // `--changed` starts from the nodes whose own definition changed, as the catalog marks them. + const changed = command.some((t) => t === '--changed' || t.startsWith('--changed=')) + ? new Map((await this.#build.listCatalogNodes(scope)).filter((n) => n.stale?.some((r) => r.reason === 'changed')).map((n) => [n.key, 'definition changed'])) + : null; + return this.#operate.planBuild(scope, command, changed); } async listJobs(scope: Scope): Promise { diff --git a/ui/src/lib/api/mock/operate-store.ts b/ui/src/lib/api/mock/operate-store.ts index ec6a9e1ec3..b2eb72be5c 100644 --- a/ui/src/lib/api/mock/operate-store.ts +++ b/ui/src/lib/api/mock/operate-store.ts @@ -10,6 +10,7 @@ import type { Acknowledgement, AdhocPermission, AdhocRunCheck, + PlanChanged, PlanResult, AdhocRunRequest, BuiltInRole, @@ -65,7 +66,7 @@ import { type TriggerDef } from './operate'; import { SCHEDULER } from './principals'; -import { ancestors, resolveSelection, SNAPSHOT_NODES, snapshotNode, sortTopologically, edgesWithin, writeSetOf } from './operate-graph'; +import { ancestors, isWritable, resolveSelection, SNAPSHOT_NODES, snapshotNode, sortTopologically, edgesWithin, writeSetOf } from './operate-graph'; import { commandOf, computeNodes, @@ -529,13 +530,14 @@ export class MockOperate { return this.#ctx.reply(this.#view(rec, scope)); } - /** Every selected model is planned as unchanged unless the command asks for a full refresh. */ - async planBuild(scope: Scope, command: string[]): Promise { + /** Every selected model is planned as unchanged unless the command asks for a full refresh; `changed` names the models `--changed` starts from. */ + async planBuild(scope: Scope, command: string[], changed: Map | null = null): Promise { const check = this.#check(scope, { command, priority: 0 }); await new Promise((resolve) => setTimeout(resolve, 1200)); if (check.error) return this.#ctx.reply({ plan: null, error: check.error }); if (check.verb !== 'build') return this.#ctx.reply({ plan: null, error: `sqb plan previews builds; sqb ${check.verb} cannot be planned` }); const reason = command.includes('--full-refresh') ? 'full_refresh' : 'no_change'; + const decision = changed ? changedDecision(check.selection, changed) : null; const modelKinds = new Set(['view', 'table', 'incremental']); const models = check.selection.filter((key) => modelKinds.has(snapshotNode(key)?.kind ?? '')).map((key) => { const incremental = snapshotNode(key)?.kind === 'incremental'; @@ -543,7 +545,7 @@ export class MockOperate { name: key, materialization_type: incremental ? 'incremental' : 'table', action: incremental ? 'incremental_append' : 'create_table', - reason: incremental && reason === 'no_change' ? 'normal_incremental' : reason, + reason: changed?.get(key) === 'definition changed' && reason === 'no_change' ? 'query_changed' : incremental && reason === 'no_change' ? 'normal_incremental' : reason, backfill: { action: reason === 'full_refresh' ? 'full' : 'forward', duration: null }, qualified_name: `main.${key}`, ...(incremental ? { incremental_strategy: 'append', cursor_column: 'updated_at', cursor_type: 'timestamp' } : {}) @@ -557,7 +559,7 @@ export class MockOperate { unknown_until_run: ['source freshness', 'retention', 'column rename support', 'sources outside mirrored schemas'] }; return this.#ctx.reply({ - plan: { selected_count: check.selection.length, models, seeds: [], source_loads: [], functions: [], python_nodes: [], warnings: [], migrations: [], column_migrations: [], table_type_conversions: [], retention: [], synced_copy }, + plan: { selected_count: check.selection.length, models, seeds: [], source_loads: [], functions: [], python_nodes: [], warnings: [], migrations: [], column_migrations: [], table_type_conversions: [], retention: [], synced_copy, changed: decision }, error: null }); } @@ -1217,3 +1219,47 @@ export class MockOperate { }; } } + +/** A node as `sqb plan --changed` names it, such as `model:orders`. */ +function changedKey(key: string): string { + const kind = snapshotNode(key)?.kind ?? 'table'; + return `${['view', 'table', 'incremental'].includes(kind) ? 'model' : kind}:${key}`; +} + +/** + * The location's `--changed` decision for the mock project, with its default reach: a change runs what reads + * it, except nodes a triggered job without the change refreshes on its own, and what reads those. + */ +function changedDecision(selection: string[], changed: Map): PlanChanged { + const selected = new Set(selection.filter(isWritable)); + // A node belongs to jobs, not groups; a job counts as triggered when it or a group it is in has a trigger. + const triggered = new Set(TRIGGER_DEFS.flatMap((t) => (t.jobKey ? [t.jobKey] : []))); + const jobs = JOB_DEFS.filter((j) => j.kind === 'job' && (triggered.has(j.key) || JOB_DEFS.some((g) => g.kind === 'group' && triggered.has(g.key) && g.members.includes(j.key)))).map((j) => ({ + key: j.key, + nodes: new Set(jobNodes(j.key)) + })); + /** Each running node's changed root. */ + const root = new Map([...changed.keys()].filter((k) => selected.has(k)).map((k) => [k, k])); + const held = new Set(); + const decision: PlanChanged = { counts: ['definition'], reach: 'job', runs: [...root.keys()].map((k) => ({ node: changedKey(k), reason: changed.get(k)!, downstream_of: null })), held_back: [], unchanged: [] }; + for (const node of SNAPSHOT_NODES) { + if (!selected.has(node.key) || root.has(node.key)) continue; + const heldUpstream = node.upstream.find((u) => held.has(u)); + const runningUpstream = node.upstream.find((u) => root.has(u)); + if (heldUpstream) { + held.add(node.key); + decision.held_back.push({ node: changedKey(node.key), reads: changedKey(heldUpstream) }); + } else if (runningUpstream) { + const origin = root.get(runningUpstream)!; + const owners = jobs.filter((j) => j.nodes.has(node.key)); + if (owners.length && !owners.some((j) => j.nodes.has(origin))) { + held.add(node.key); + decision.held_back.push({ node: changedKey(node.key), refreshed_by: owners.map((j) => j.key) }); + } else { + root.set(node.key, origin); + decision.runs.push({ node: changedKey(node.key), reason: `upstream model ${origin} runs`, downstream_of: changedKey(origin) }); + } + } else decision.unchanged.push(changedKey(node.key)); + } + return decision; +} diff --git a/ui/src/lib/api/types/operate.ts b/ui/src/lib/api/types/operate.ts index 018089737f..91fbf07639 100644 --- a/ui/src/lib/api/types/operate.ts +++ b/ui/src/lib/api/types/operate.ts @@ -530,6 +530,20 @@ export type PlanDocument = { retention: { model: string; action?: string }[]; /** What a location's preview planned from instead of the warehouse; `null` for a live plan. */ synced_copy: PlanSyncedCopy | null; + /** What `--changed` runs, holds back and skips; `null` without `--changed`. */ + changed: PlanChanged | null; +}; + +/** `sqb plan --changed`'s decision. Nodes are keys such as `model:orders`. */ +export type PlanChanged = { + counts: ('definition' | 'source_data')[]; + reach: 'job' | 'all'; + /** Each node that runs, with why; `downstream_of` names the changed upstream it runs for. */ + runs: { node: string; reason: string; downstream_of: string | null }[]; + /** Nodes left for a job's own run (`refreshed_by`), or that read such a node (`reads`). */ + held_back: ({ node: string; refreshed_by: string[] } | { node: string; reads: string })[]; + /** Selected nodes that run only when something they read changed; nothing did. */ + unchanged: string[]; }; /** The server's synced copy of warehouse metadata a location's plan preview planned from. */ diff --git a/ui/src/lib/run/command.ts b/ui/src/lib/run/command.ts index b347628ff8..da87250d3c 100644 --- a/ui/src/lib/run/command.ts +++ b/ui/src/lib/run/command.ts @@ -97,11 +97,14 @@ export function tokenAt(text: string, caret: number): TokenContext { } /** The plan page for a command, opened by every Run button before anything runs; with `job`, a run of that job narrowed by the command. */ -export function planHref(selection: string[] = [], verb: LaunchVerb = 'build', narrowing: { job?: string; exclude?: string[] } = {}): string { - const command = buildCommand({ verb, select: selection.map(selectorOf), exclude: (narrowing.exclude ?? []).map(selectorOf), flags: {} }); +export function planHref(selection: string[] = [], verb: LaunchVerb = 'build', narrowing: { job?: string; exclude?: string[]; flags?: CommandParts['flags'] } = {}): string { + const command = buildCommand({ verb, select: selection.map(selectorOf), exclude: (narrowing.exclude ?? []).map(selectorOf), flags: narrowing.flags ?? {} }); return `/plan?cmd=${encodeURIComponent(command)}${narrowing.job ? `&job=${encodeURIComponent(narrowing.job)}` : ''}`; } +/** The plan of `sqb build --changed`: what changed, what runs downstream of it, and what waits for its job. */ +export const CHANGED_PLAN_HREF = planHref([], 'build', { flags: { '--changed': true } }); + /** The review page for rerunning runs, opened before anything reruns; `nodes` only for one run's selected nodes. */ export function rerunHref(runIds: string[], mode: RerunMode, nodes: string[] = []): string { const query = new URLSearchParams([...runIds.map((id) => ['run', id]), ['mode', mode], ...nodes.map((n) => ['node', n])]); diff --git a/ui/src/lib/run/plan-report.svelte b/ui/src/lib/run/plan-report.svelte index 23d93fa2bf..49675335b5 100644 --- a/ui/src/lib/run/plan-report.svelte +++ b/ui/src/lib/run/plan-report.svelte @@ -5,11 +5,12 @@ import type { PlanDocument } from '$lib/api'; import { formatAgo } from '$lib/format/time'; import { app } from '$lib/state/app.svelte'; - import { planSections, type PlanEntry } from './plan-text'; + import { changedPolicyLine, changedSections, planSections, type PlanEntry } from './plan-text'; - let { plan }: { plan: PlanDocument } = $props(); + /** `refresh` words what refreshes the nodes a `--changed` plan holds back for a job. */ + let { plan, refresh = (job: string) => `job ${job}` }: { plan: PlanDocument; refresh?: (job: string) => string } = $props(); - const sections = $derived(planSections(plan)); + const sections = $derived([...planSections(plan), ...(plan.changed ? changedSections(plan.changed, refresh) : [])]); /** Rows a section shows before "Show all", as the CLI truncates long sections. */ const limit = 50; let expanded = $state>({}); @@ -34,6 +35,7 @@ {/if} {/if} + {#if plan.changed}

{changedPolicyLine(plan.changed)}

{/if} {#each sections as s (s.title)} {@const shown = expanded[s.title] ? s.entries : s.entries.slice(0, limit)}
@@ -88,6 +90,12 @@ gap: 18px; font-size: 12.5px; } + .policy { + margin: 0; + color: var(--muted-foreground); + font-family: var(--font-mono); + font-size: 12px; + } h4 { display: flex; align-items: center; diff --git a/ui/src/lib/run/plan-text.test.ts b/ui/src/lib/run/plan-text.test.ts index 5198692770..0e4316bb38 100644 --- a/ui/src/lib/run/plan-text.test.ts +++ b/ui/src/lib/run/plan-text.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; import type { PlanDocument, PlanModel } from '$lib/api'; -import { actionText, planSections, planSentence } from './plan-text'; +import { actionText, changedPolicyLine, changedSections, jobRefreshText, planSections, planSentence } from './plan-text'; const model = (name: string, over: Partial = {}): PlanModel => ({ name, @@ -23,6 +23,7 @@ const plan = (models: PlanModel[], over: Partial = {}): PlanDocume table_type_conversions: [], retention: [], synced_copy: null, + changed: null, ...over }); @@ -98,4 +99,65 @@ describe('plan sentence', () => { const functions = [{ name: 'margin', language: 'sql', reason: 'definition_changed' }, { name: 'tax', language: 'sql', reason: 'no_change' }]; expect(planSentence(plan([], { functions }))).toBe('No models build. 1 changed function is recreated.'); }); + + // The reach fixture's `sqb plan --changed --json` after stg_orders is redefined: finance_daily holds two models back. + const reach = plan( + [ + model('stg_customers'), + model('stg_orders', { reason: 'query_changed' }), + model('customer_orders'), + model('int_orders'), + model('fct_revenue'), + model('orders_export'), + model('rpt_pnl'), + model('summary') + ], + { + changed: { + counts: ['definition'], + reach: 'job', + runs: [ + { node: 'model:customer_orders', reason: 'upstream model stg_orders runs', downstream_of: 'model:stg_orders' }, + { node: 'model:int_orders', reason: 'upstream model stg_orders runs', downstream_of: 'model:stg_orders' }, + { node: 'model:orders_export', reason: 'upstream model stg_orders runs', downstream_of: 'model:stg_orders' }, + { node: 'model:stg_orders', reason: 'planner change (query_changed)', downstream_of: null } + ], + held_back: [ + { node: 'model:fct_revenue', refreshed_by: ['finance_daily'] }, + { node: 'model:rpt_pnl', refreshed_by: ['finance_daily'] }, + { node: 'model:summary', reads: 'model:fct_revenue' } + ], + unchanged: ['model:stg_customers'] + } + } + ); + + it('under --changed lists only what runs, then what waits for its job and what is skipped, as sqb plan does', () => { + const sections = [...planSections(reach), ...changedSections(reach.changed!, (job) => `job ${job}`)]; + expect(sections.map((s) => [s.title, s.entries.map((e) => `${e.name}: ${e.value}${e.detail.length ? ` (${e.detail.join(', ')})` : ''}`)])).toEqual([ + ['Query changed', ['stg_orders: continue forward']], + ['Models', ['customer_orders: table (reads stg_orders)', 'int_orders: table (reads stg_orders)', 'orders_export: table (reads stg_orders)']], + ['Held back', ['fct_revenue: job finance_daily', 'rpt_pnl: job finance_daily', 'summary: reads fct_revenue, which is held back']], + ['Unchanged', ['stg_customers: skipped by --changed']] + ]); + expect(changedPolicyLine(reach.changed!)).toBe('Counting: definition (source data not counted) · reach: job'); + expect(changedPolicyLine({ ...reach.changed!, counts: ['definition', 'source_data'], reach: 'all' })).toBe('Counting: definition, source data · reach: all'); + expect(planSentence(reach)).toBe( + '4 models build: stg_orders changed since its last build and the other 3 models read a changed model. 3 models wait for their job\'s own run. 1 unchanged node is skipped by --changed.' + ); + }); + + it("says what refreshes a held-back node: its own or its group's next run, or that every trigger is paused", () => { + const now = Date.parse('2026-01-01T00:00:00Z'); + const jobs = [ + { key: 'finance_daily', kind: 'job' as const, members: null }, + { key: 'nightly', kind: 'group' as const, members: ['finance_daily', 'crm'] } + ]; + const trigger = (jobKey: string, state: 'running' | 'paused', nextDueAt: string | null) => ({ jobKey, state, nextDueAt }); + expect(jobRefreshText('finance_daily', jobs, [trigger('finance_daily', 'running', '2026-01-01T05:00:00Z'), trigger('nightly', 'running', '2026-01-01T02:00:00Z')], now)).toBe('job finance_daily · next run in 2h'); + expect(jobRefreshText('finance_daily', jobs, [trigger('finance_daily', 'paused', '2026-01-01T05:00:00Z'), trigger('nightly', 'paused', null)], now)).toBe('job finance_daily is paused'); + expect(jobRefreshText('finance_daily', jobs, [trigger('finance_daily', 'paused', '2026-01-01T05:00:00Z'), trigger('finance_daily', 'running', null)], now)).toBe('job finance_daily · when its sensor fires'); + expect(jobRefreshText('crm', jobs, [trigger('finance_daily', 'running', '2026-01-01T05:00:00Z')], now)).toBe('job crm'); + }); }); + diff --git a/ui/src/lib/run/plan-text.ts b/ui/src/lib/run/plan-text.ts index f999908708..c8c830b239 100644 --- a/ui/src/lib/run/plan-text.ts +++ b/ui/src/lib/run/plan-text.ts @@ -2,7 +2,8 @@ // terminal read the same: work that runs first, one section per change reason with each model's detail, // then the routine models, functions, seeds and warnings. -import type { PlanDocument, PlanModel } from '$lib/api'; +import type { Job, PlanChanged, PlanDocument, PlanModel, Trigger } from '$lib/api'; +import { formatIn } from '$lib/format/time'; export type PlanEntry = { name: string; @@ -29,6 +30,22 @@ const REASON_GROUPS: [string, string][] = [ ]; const ROUTINE = new Set(['no_change', 'normal_incremental']); +/** A node key such as `model:orders` by the name `sqb plan` prints. */ +const keyName = (key: string) => key.slice(key.indexOf(':') + 1); + +/** The models the run builds: none the planner skips, and under `--changed` only those it runs. */ +export function builtModels(plan: PlanDocument): PlanModel[] { + return plan.models.filter((m) => m.action !== 'skip' && runsUnderChanged(plan, `model:${m.name}`)); +} + +/** Without `--changed` every planned node runs; with it, only those its decision runs. */ +function runsUnderChanged(plan: PlanDocument, key: string): boolean { + return !plan.changed || plan.changed.runs.some((r) => r.node === key); +} + +/** The seeds the run loads or reports on: under `--changed`, only those it runs. */ +const builtSeeds = (plan: PlanDocument) => plan.seeds.filter((s) => runsUnderChanged(plan, `seed:${s.name}`)); + /** The model's materialization as the CLI labels it, such as `view` or `delete_insert (timestamp)`. */ export function materializationLabel(m: PlanModel): string { if (m.materialization_type !== 'incremental') return m.materialization_type; @@ -92,13 +109,13 @@ function changedEntry(m: PlanModel, reason: string, windowStart?: string): PlanE /** Whether the plan reads as one full refresh: every model being built is one, as in the CLI. */ export function isFullRefresh(plan: PlanDocument): boolean { - const active = plan.models.filter((m) => m.action !== 'skip'); + const active = builtModels(plan); return active.length > 0 && active.every((m) => m.reason === 'full_refresh'); } /** The plan's sections in the order `sqb plan` prints them. Skipped models are left out, as there. */ export function planSections(plan: PlanDocument): PlanSection[] { - const active = plan.models.filter((m) => m.action !== 'skip'); + const active = builtModels(plan); const sections: PlanSection[] = []; const add = (title: string, entries: PlanEntry[], changed = false) => { if (entries.length) sections.push({ title, entries, changed }); @@ -123,11 +140,13 @@ export function planSections(plan: PlanDocument): PlanSection[] { } else { const starts = plan.synced_copy?.cursor_window_starts ?? {}; for (const [reason, title] of REASON_GROUPS) add(title, active.filter((m) => m.reason === reason).map((m) => changedEntry(m, reason, starts[m.name])), true); - add('Models', active.filter((m) => ROUTINE.has(m.reason)).map((m) => ({ name: m.name, value: materializationLabel(m), detail: cursorLines(m, true, starts[m.name]) }))); + // Under --changed a routine model runs because a model it reads changed. + const upstream = new Map((plan.changed?.runs ?? []).flatMap((r) => (r.downstream_of ? [[keyName(r.node), keyName(r.downstream_of)]] : []))); + add('Models', active.filter((m) => ROUTINE.has(m.reason)).map((m) => ({ name: m.name, value: materializationLabel(m), detail: [...cursorLines(m, true, starts[m.name]), ...(upstream.has(m.name) ? [`reads ${upstream.get(m.name)}`] : [])] }))); } add('Functions', plan.functions.filter((f) => !f.reason || f.reason === 'no_change').map(functionEntry)); const seedLabel: Record = { first_run: 'first_run', config_changed: 'seed_changed', no_change: 'current' }; - add('Seeds', plan.seeds.map((s) => ({ name: s.name, value: seedLabel[s.reason] ?? '', detail: [] }))); + add('Seeds', builtSeeds(plan).map((s) => ({ name: s.name, value: seedLabel[s.reason] ?? '', detail: [] }))); add('Python', plan.python_nodes.map((p) => ({ name: p.name, value: `${p.kind} · ${p.identity_status}`, detail: [] }))); return sections; } @@ -142,10 +161,12 @@ const few = (models: PlanModel[], noun: string) => (models.length <= 2 ? models. * first time, which take new rows and that the rest are recreated as usual, then what else happens. */ export function planSentence(plan: PlanDocument): string { - const active = plan.models.filter((m) => m.action !== 'skip'); + const active = builtModels(plan); // The planner skips only disabled models; seeds it reports as current don't load. - const skipped = plan.models.length - active.length; - const seeds = plan.seeds.filter((s) => s.reason !== 'no_change').length; + const skipped = plan.models.filter((m) => m.action === 'skip').length; + const held = plan.changed?.held_back.length ?? 0; + const unchanged = plan.changed?.unchanged.length ?? 0; + const seeds = builtSeeds(plan).filter((s) => s.reason !== 'no_change').length; const functions = plan.functions.filter((f) => f.reason && f.reason !== 'no_change').length; const runs = [ plan.source_loads.length && count(plan.source_loads.length, 'source loads first', 'sources load first'), @@ -153,25 +174,61 @@ export function planSentence(plan: PlanDocument): string { functions && count(functions, 'changed function is recreated', 'changed functions are recreated'), plan.python_nodes.length && count(plan.python_nodes.length, 'Python node runs', 'Python nodes run') ].filter((p): p is string => !!p); - const after = [...runs, ...(skipped ? [count(skipped, 'disabled model is skipped', 'disabled models are skipped')] : [])].map((p) => ` ${p}.`).join(''); + const after = [ + ...runs, + ...(skipped ? [count(skipped, 'disabled model is skipped', 'disabled models are skipped')] : []), + ...(held ? [`${count(held, 'model waits', 'models wait')} for ${held === 1 ? 'its' : 'their'} job's own run`] : []), + ...(unchanged ? [`${count(unchanged, 'unchanged node is', 'unchanged nodes are')} skipped by --changed`] : []) + ] + .map((p) => ` ${p}.`) + .join(''); if (!active.length) return `${runs.length ? 'No models build.' : 'Nothing to build.'}${after}`; const builds = count(active.length, 'model builds', 'models build'); if (isFullRefresh(plan)) return `${builds} from scratch, replacing what was built.${after}`; const changed = active.filter((m) => !ROUTINE.has(m.reason) && m.reason !== 'first_run'); const fresh = active.filter((m) => m.reason === 'first_run'); - const rows = active.filter((m) => m.reason === 'normal_incremental'); - const usual = active.filter((m) => m.reason === 'no_change'); + // Under --changed every routine model runs because it reads a changed one, so none is counted as just taking new rows. + const rows = plan.changed ? [] : active.filter((m) => m.reason === 'normal_incremental'); + const usual = active.filter((m) => (plan.changed ? ROUTINE.has(m.reason) : m.reason === 'no_change')); const parts = [ changed.length && `${few(changed, 'model')} changed since ${changed.length === 1 ? 'its' : 'their'} last build`, fresh.length && `${few(fresh, 'model')} ${fresh.length === 1 ? 'builds' : 'build'} for the first time`, rows.length && `${count(rows.length, 'incremental model takes', 'incremental models take')} new rows` ].filter((p): p is string => !!p); - if (usual.length) parts.push(parts.length ? `the other ${usual.length} ${usual.length === 1 ? 'is' : 'are'} recreated as usual` : `none changed since ${usual.length === 1 ? 'its' : 'their'} last build`); + if (usual.length && plan.changed) parts.push(`${parts.length ? 'the other ' : ''}${count(usual.length, 'model reads', 'models read')} a changed model`); + else if (usual.length) parts.push(parts.length ? `the other ${usual.length} ${usual.length === 1 ? 'is' : 'are'} recreated as usual` : `none changed since ${usual.length === 1 ? 'its' : 'their'} last build`); const detail = parts.length > 1 ? `${parts.slice(0, -1).join(', ')} and ${parts.at(-1)}` : parts[0]; return `${builds}: ${detail}.${after}`; } /** The models a plan changes, as catalog keys, for drawing just the part of a large selection that matters. */ export function changedModelKeys(plan: PlanDocument): string[] { - return plan.models.filter((m) => m.action !== 'skip' && !ROUTINE.has(m.reason)).map((m) => `model:${m.name}`); + return builtModels(plan).filter((m) => !ROUTINE.has(m.reason)).map((m) => `model:${m.name}`); +} + +/** The line `sqb plan --changed` opens with: what counts as a change and how far a change reaches. */ +export function changedPolicyLine(changed: PlanChanged): string { + const label = { definition: 'definition', source_data: 'source data' } as const; + const uncounted = (['definition', 'source_data'] as const).filter((kind) => !changed.counts.includes(kind)).map((kind) => ` (${label[kind]} not counted)`); + return `Counting: ${changed.counts.map((kind) => label[kind]).join(', ')}${uncounted.join('')} · reach: ${changed.reach}`; +} + +/** The Held back and Unchanged sections of a `--changed` plan; `refresh` words what refreshes a job's nodes. */ +export function changedSections(changed: PlanChanged, refresh: (job: string) => string): PlanSection[] { + const sections: PlanSection[] = []; + const held = changed.held_back.map((h) => ({ name: keyName(h.node), value: 'refreshed_by' in h ? h.refreshed_by.map(refresh).join(' · ') : `reads ${keyName(h.reads)}, which is held back`, detail: [] })); + if (held.length) sections.push({ title: 'Held back', entries: held, changed: false }); + if (changed.unchanged.length) sections.push({ title: 'Unchanged', entries: changed.unchanged.map((key) => ({ name: keyName(key), value: 'skipped by --changed', detail: [] })), changed: false }); + return sections; +} + +/** What refreshes a node held back for `job`: the next run of a schedule on it or a group it is in, or that they are paused. */ +export function jobRefreshText(job: string, jobs: Pick[], triggers: Pick[], now: number): string { + const owners = new Set([job, ...jobs.filter((j) => j.kind === 'group' && j.members?.includes(job)).map((j) => j.key)]); + const mine = triggers.filter((t) => t.jobKey !== null && owners.has(t.jobKey)); + const live = mine.filter((t) => t.state === 'running'); + if (mine.length && !live.length) return `job ${job} is paused`; + const next = live.flatMap((t) => (t.nextDueAt ? [t.nextDueAt] : [])).sort()[0]; + if (next) return `job ${job} · next run ${formatIn(next, now)}`; + return live.length ? `job ${job} · when its sensor fires` : `job ${job}`; } diff --git a/ui/src/routes/+page.svelte b/ui/src/routes/+page.svelte index 32124d2847..ccded3bf6a 100644 --- a/ui/src/routes/+page.svelte +++ b/ui/src/routes/+page.svelte @@ -13,7 +13,7 @@ import Button from '$lib/components/ui/button/button.svelte'; import GatedButton from '$lib/components/operate/gated-button.svelte'; import RunTimeline from '$lib/components/timeline/run-timeline.svelte'; - import { planHref } from '$lib/run/command'; + import { CHANGED_PLAN_HREF, planHref } from '$lib/run/command'; import { app } from '$lib/state/app.svelte'; import { createResource } from '$lib/state/resource.svelte'; import { formatAgo } from '$lib/format/time'; @@ -137,7 +137,12 @@ {view.since} {#if item.kind === 'stale_models'} - goto(to(planHref(staleSelection)))}>Rebuild {staleSelection.length} + + {#if item.changed.length} + goto(to(CHANGED_PLAN_HREF))}>Build changed + {:else} + goto(to(planHref(staleSelection)))}>Rebuild {staleSelection.length} + {/if} {/if} {#if 'acknowledged' in item && canAcknowledge} - {#if app.client.supports('launchAdhocRun')} goto(to(planHref(runSelection)))}>▷ Execute{runSelection.length ? ` ${runSelection.length}` : ''}{/if} + {#if app.client.supports('launchAdhocRun')} + {#if changedCount} goto(to(CHANGED_PLAN_HREF))}>Build {changedCount} changed{/if} + goto(to(planHref(runSelection)))}>▷ Execute{runSelection.length ? ` ${runSelection.length}` : ''} + {/if} @@ -1012,6 +1017,10 @@ background: var(--sb-hover); color: var(--foreground); } + .changed-count { + color: var(--sb-stale); + font-weight: 500; + } .status-summary { display: flex; align-items: center; diff --git a/ui/src/routes/plan/+page.svelte b/ui/src/routes/plan/+page.svelte index 7702efb5bc..742340d61a 100644 --- a/ui/src/routes/plan/+page.svelte +++ b/ui/src/routes/plan/+page.svelte @@ -20,13 +20,17 @@ import PlanReport from '$lib/run/plan-report.svelte'; import StatusLabel from '$lib/components/list/status-label.svelte'; import { checkOutcomeLabel, checkOutcomeTone } from '$lib/status'; - import { changedModelKeys, planSentence } from '$lib/run/plan-text'; + import { builtModels, changedModelKeys, jobRefreshText, planSentence } from '$lib/run/plan-text'; import { app } from '$lib/state/app.svelte'; import { createResource } from '$lib/state/resource.svelte'; const snapshotNodes = createResource((client, scope) => client.listSnapshotNodes(scope), ['snapshot']); const catalog = createResource((client, scope) => client.listCatalogNodes(scope), ['snapshot', 'runs', 'node_status']); const checkList = createResource((client, scope) => client.listChecks(scope), ['checks']); + // A `--changed` plan names the job whose own run refreshes what it holds back, with that job's schedule. + const jobList = createResource((client, scope) => client.listJobs(scope), ['jobs']); + const triggerList = createResource((client, scope) => client.listTriggers(scope), ['triggers']); + const refresh = (job: string) => jobRefreshText(job, jobList.data ?? [], triggerList.data ?? [], app.now); let cmd = $state(page.url.searchParams.get('cmd') ?? 'sqb build'); let cmdEl = $state(); @@ -145,7 +149,7 @@ /** The recorded checks on the models and seeds the plan builds, which run after them. */ const planChecks = $derived.by(() => { if (!plan) return []; - const built = new Set([...plan.models.filter((m) => m.action !== 'skip').map((m) => m.name), ...plan.seeds.map((s) => s.name)]); + const built = new Set([...builtModels(plan).map((m) => m.name), ...plan.seeds.map((s) => s.name)]); return (checkList.data ?? []).filter((c) => (c.attachment === 'model' || c.attachment === 'seed') && !!c.node && built.has(c.node.slice(c.node.indexOf(':') + 1))); }); /** The tab shown: a replan with no checks leaves the Checks tab for the plan. */ @@ -353,7 +357,7 @@ {:else if shown?.verb === 'build' && plan} - + {:else if shown?.verb && shown.verb !== 'build'} From 28e497a45a49377384f9b39c1042e682721b0737 Mon Sep 17 00:00:00 2001 From: Kevin Longe <273747162+kvlonge@users.noreply.github.com> Date: Sat, 14 Nov 2026 00:23:19 +0000 Subject: [PATCH 2/2] fix(ui): word --changed runs by their own reason and refresh held-back nodes by the named job only --- ui/src/lib/api/mock/operate-store.ts | 35 ++++++++++++++----------- ui/src/lib/run/plan-text.test.ts | 39 ++++++++++++++++++++-------- ui/src/lib/run/plan-text.ts | 34 ++++++++++++++---------- ui/src/routes/+page.svelte | 5 ++-- ui/src/routes/lineage/+page.svelte | 4 +-- ui/src/routes/plan/+page.svelte | 7 +++-- 6 files changed, 76 insertions(+), 48 deletions(-) diff --git a/ui/src/lib/api/mock/operate-store.ts b/ui/src/lib/api/mock/operate-store.ts index b2eb72be5c..8f2a7fc1c8 100644 --- a/ui/src/lib/api/mock/operate-store.ts +++ b/ui/src/lib/api/mock/operate-store.ts @@ -1231,7 +1231,8 @@ function changedKey(key: string): string { * it, except nodes a triggered job without the change refreshes on its own, and what reads those. */ function changedDecision(selection: string[], changed: Map): PlanChanged { - const selected = new Set(selection.filter(isWritable)); + // The decision covers only models and seeds, as the CLI's does. + const selected = new Set(selection.filter((k) => isWritable(k) && ['view', 'table', 'incremental', 'seed'].includes(snapshotNode(k)?.kind ?? ''))); // A node belongs to jobs, not groups; a job counts as triggered when it or a group it is in has a trigger. const triggered = new Set(TRIGGER_DEFS.flatMap((t) => (t.jobKey ? [t.jobKey] : []))); const jobs = JOB_DEFS.filter((j) => j.kind === 'job' && (triggered.has(j.key) || JOB_DEFS.some((g) => g.kind === 'group' && triggered.has(g.key) && g.members.includes(j.key)))).map((j) => ({ @@ -1240,26 +1241,30 @@ function changedDecision(selection: string[], changed: Map): Pla })); /** Each running node's changed root. */ const root = new Map([...changed.keys()].filter((k) => selected.has(k)).map((k) => [k, k])); - const held = new Set(); + /** Each held-back node's changed root, which a node reading it is held from too. */ + const held = new Map(); const decision: PlanChanged = { counts: ['definition'], reach: 'job', runs: [...root.keys()].map((k) => ({ node: changedKey(k), reason: changed.get(k)!, downstream_of: null })), held_back: [], unchanged: [] }; for (const node of SNAPSHOT_NODES) { if (!selected.has(node.key) || root.has(node.key)) continue; const heldUpstream = node.upstream.find((u) => held.has(u)); const runningUpstream = node.upstream.find((u) => root.has(u)); - if (heldUpstream) { - held.add(node.key); + const origin = heldUpstream ? held.get(heldUpstream) : runningUpstream ? root.get(runningUpstream) : undefined; + if (!origin) { + decision.unchanged.push(changedKey(node.key)); + continue; + } + // As in the CLI, a triggered job without the change refreshes the node itself before it counts as reading a held node. + const owners = jobs.filter((j) => j.nodes.has(node.key)); + if (owners.length && !owners.some((j) => j.nodes.has(origin))) { + held.set(node.key, origin); + decision.held_back.push({ node: changedKey(node.key), refreshed_by: owners.map((j) => j.key) }); + } else if (heldUpstream) { + held.set(node.key, origin); decision.held_back.push({ node: changedKey(node.key), reads: changedKey(heldUpstream) }); - } else if (runningUpstream) { - const origin = root.get(runningUpstream)!; - const owners = jobs.filter((j) => j.nodes.has(node.key)); - if (owners.length && !owners.some((j) => j.nodes.has(origin))) { - held.add(node.key); - decision.held_back.push({ node: changedKey(node.key), refreshed_by: owners.map((j) => j.key) }); - } else { - root.set(node.key, origin); - decision.runs.push({ node: changedKey(node.key), reason: `upstream model ${origin} runs`, downstream_of: changedKey(origin) }); - } - } else decision.unchanged.push(changedKey(node.key)); + } else { + root.set(node.key, origin); + decision.runs.push({ node: changedKey(node.key), reason: `upstream model ${origin} runs`, downstream_of: changedKey(origin) }); + } } return decision; } diff --git a/ui/src/lib/run/plan-text.test.ts b/ui/src/lib/run/plan-text.test.ts index 0e4316bb38..dd7b3fd013 100644 --- a/ui/src/lib/run/plan-text.test.ts +++ b/ui/src/lib/run/plan-text.test.ts @@ -143,21 +143,38 @@ describe('plan sentence', () => { expect(changedPolicyLine(reach.changed!)).toBe('Counting: definition (source data not counted) · reach: job'); expect(changedPolicyLine({ ...reach.changed!, counts: ['definition', 'source_data'], reach: 'all' })).toBe('Counting: definition, source data · reach: all'); expect(planSentence(reach)).toBe( - '4 models build: stg_orders changed since its last build and the other 3 models read a changed model. 3 models wait for their job\'s own run. 1 unchanged node is skipped by --changed.' + '4 models build: stg_orders changed since its last build and the other 3 models read a change upstream. 3 models wait for their job\'s own run. 1 unchanged node is skipped by --changed.' ); }); - it("says what refreshes a held-back node: its own or its group's next run, or that every trigger is paused", () => { + it('names the models that run under --changed for their own reason, not as reading a change', () => { + const first = plan([model('orders'), model('order_count', { action: 'incremental_append', reason: 'normal_incremental' })], { + changed: { + counts: ['definition'], + reach: 'job', + runs: [ + { node: 'model:order_count', reason: 'no completed record', downstream_of: null }, + { node: 'model:orders', reason: 'no completed record', downstream_of: null } + ], + held_back: [], + unchanged: [] + } + }); + expect(planSentence(first)).toBe('2 models build: orders and order_count run for their own reason.'); + expect(planSections(first).find((s) => s.title === 'Models')?.entries.map((e) => e.detail.at(-1))).toEqual(['no completed record', 'no completed record']); + }); + + it("says what refreshes a held-back node: the named job's next run, its sensor, or that it is paused", () => { const now = Date.parse('2026-01-01T00:00:00Z'); - const jobs = [ - { key: 'finance_daily', kind: 'job' as const, members: null }, - { key: 'nightly', kind: 'group' as const, members: ['finance_daily', 'crm'] } - ]; - const trigger = (jobKey: string, state: 'running' | 'paused', nextDueAt: string | null) => ({ jobKey, state, nextDueAt }); - expect(jobRefreshText('finance_daily', jobs, [trigger('finance_daily', 'running', '2026-01-01T05:00:00Z'), trigger('nightly', 'running', '2026-01-01T02:00:00Z')], now)).toBe('job finance_daily · next run in 2h'); - expect(jobRefreshText('finance_daily', jobs, [trigger('finance_daily', 'paused', '2026-01-01T05:00:00Z'), trigger('nightly', 'paused', null)], now)).toBe('job finance_daily is paused'); - expect(jobRefreshText('finance_daily', jobs, [trigger('finance_daily', 'paused', '2026-01-01T05:00:00Z'), trigger('finance_daily', 'running', null)], now)).toBe('job finance_daily · when its sensor fires'); - expect(jobRefreshText('crm', jobs, [trigger('finance_daily', 'running', '2026-01-01T05:00:00Z')], now)).toBe('job crm'); + type Kind = 'schedule' | 'sensor'; + const trigger = (jobKey: string, state: 'running' | 'paused', nextDueAt: string | null, type: Kind = 'schedule') => ({ jobKey, type, state, nextDueAt }); + // A group's schedule says nothing about a job whose own trigger is paused; the plan names the group itself when it matters. + expect(jobRefreshText('finance_daily', [trigger('finance_daily', 'paused', '2026-01-01T05:00:00Z'), trigger('nightly', 'running', '2026-01-01T02:00:00Z')], now)).toBe('job finance_daily is paused'); + expect(jobRefreshText('nightly', [trigger('nightly', 'running', '2026-01-01T02:00:00Z'), trigger('nightly', 'running', '2026-01-01T05:00:00Z')], now)).toBe('job nightly · next run in 2h'); + expect(jobRefreshText('finance_daily', [trigger('finance_daily', 'paused', null), trigger('finance_daily', 'running', null, 'sensor')], now)).toBe('job finance_daily · when its sensor fires'); + // A running schedule with no next run, such as a finished calendar, is not a sensor. + expect(jobRefreshText('finance_daily', [trigger('finance_daily', 'running', null)], now)).toBe('job finance_daily'); + expect(jobRefreshText('crm', [trigger('finance_daily', 'running', '2026-01-01T05:00:00Z')], now)).toBe('job crm'); }); }); diff --git a/ui/src/lib/run/plan-text.ts b/ui/src/lib/run/plan-text.ts index c8c830b239..de2320a87d 100644 --- a/ui/src/lib/run/plan-text.ts +++ b/ui/src/lib/run/plan-text.ts @@ -2,7 +2,7 @@ // terminal read the same: work that runs first, one section per change reason with each model's detail, // then the routine models, functions, seeds and warnings. -import type { Job, PlanChanged, PlanDocument, PlanModel, Trigger } from '$lib/api'; +import type { PlanChanged, PlanDocument, PlanModel, Trigger } from '$lib/api'; import { formatIn } from '$lib/format/time'; export type PlanEntry = { @@ -44,7 +44,7 @@ function runsUnderChanged(plan: PlanDocument, key: string): boolean { } /** The seeds the run loads or reports on: under `--changed`, only those it runs. */ -const builtSeeds = (plan: PlanDocument) => plan.seeds.filter((s) => runsUnderChanged(plan, `seed:${s.name}`)); +export const builtSeeds = (plan: PlanDocument) => plan.seeds.filter((s) => runsUnderChanged(plan, `seed:${s.name}`)); /** The model's materialization as the CLI labels it, such as `view` or `delete_insert (timestamp)`. */ export function materializationLabel(m: PlanModel): string { @@ -140,9 +140,12 @@ export function planSections(plan: PlanDocument): PlanSection[] { } else { const starts = plan.synced_copy?.cursor_window_starts ?? {}; for (const [reason, title] of REASON_GROUPS) add(title, active.filter((m) => m.reason === reason).map((m) => changedEntry(m, reason, starts[m.name])), true); - // Under --changed a routine model runs because a model it reads changed. - const upstream = new Map((plan.changed?.runs ?? []).flatMap((r) => (r.downstream_of ? [[keyName(r.node), keyName(r.downstream_of)]] : []))); - add('Models', active.filter((m) => ROUTINE.has(m.reason)).map((m) => ({ name: m.name, value: materializationLabel(m), detail: [...cursorLines(m, true, starts[m.name]), ...(upstream.has(m.name) ? [`reads ${upstream.get(m.name)}`] : [])] }))); + // Under --changed a routine model runs because something it reads changed, or for its own reason, such as no completed record. + const why = changedRuns(plan); + add('Models', active.filter((m) => ROUTINE.has(m.reason)).map((m) => { + const run = why.get(m.name); + return { name: m.name, value: materializationLabel(m), detail: [...cursorLines(m, true, starts[m.name]), ...(run ? [run.downstream_of ? `reads ${keyName(run.downstream_of)}` : run.reason] : [])] }; + })); } add('Functions', plan.functions.filter((f) => !f.reason || f.reason === 'no_change').map(functionEntry)); const seedLabel: Record = { first_run: 'first_run', config_changed: 'seed_changed', no_change: 'current' }; @@ -151,6 +154,9 @@ export function planSections(plan: PlanDocument): PlanSection[] { return sections; } +/** The `--changed` run of each model, by name. */ +const changedRuns = (plan: PlanDocument) => new Map((plan.changed?.runs ?? []).map((r) => [keyName(r.node), r])); + const count = (n: number, one: string, many = `${one}s`) => `${n} ${n === 1 ? one : many}`; /** Names a few models, or counts them when there are more than two. */ @@ -187,15 +193,18 @@ export function planSentence(plan: PlanDocument): string { if (isFullRefresh(plan)) return `${builds} from scratch, replacing what was built.${after}`; const changed = active.filter((m) => !ROUTINE.has(m.reason) && m.reason !== 'first_run'); const fresh = active.filter((m) => m.reason === 'first_run'); - // Under --changed every routine model runs because it reads a changed one, so none is counted as just taking new rows. + // Under --changed a routine model runs because something upstream changed or for its own reason, never just to take new rows. + const why = changedRuns(plan); + const own = plan.changed ? active.filter((m) => ROUTINE.has(m.reason) && !why.get(m.name)?.downstream_of) : []; const rows = plan.changed ? [] : active.filter((m) => m.reason === 'normal_incremental'); - const usual = active.filter((m) => (plan.changed ? ROUTINE.has(m.reason) : m.reason === 'no_change')); + const usual = active.filter((m) => (plan.changed ? ROUTINE.has(m.reason) && !!why.get(m.name)?.downstream_of : m.reason === 'no_change')); const parts = [ changed.length && `${few(changed, 'model')} changed since ${changed.length === 1 ? 'its' : 'their'} last build`, fresh.length && `${few(fresh, 'model')} ${fresh.length === 1 ? 'builds' : 'build'} for the first time`, + own.length && `${few(own, 'model')} ${own.length === 1 ? 'runs for its' : 'run for their'} own reason`, rows.length && `${count(rows.length, 'incremental model takes', 'incremental models take')} new rows` ].filter((p): p is string => !!p); - if (usual.length && plan.changed) parts.push(`${parts.length ? 'the other ' : ''}${count(usual.length, 'model reads', 'models read')} a changed model`); + if (usual.length && plan.changed) parts.push(`${parts.length ? 'the other ' : ''}${count(usual.length, 'model reads', 'models read')} a change upstream`); else if (usual.length) parts.push(parts.length ? `the other ${usual.length} ${usual.length === 1 ? 'is' : 'are'} recreated as usual` : `none changed since ${usual.length === 1 ? 'its' : 'their'} last build`); const detail = parts.length > 1 ? `${parts.slice(0, -1).join(', ')} and ${parts.at(-1)}` : parts[0]; return `${builds}: ${detail}.${after}`; @@ -222,13 +231,12 @@ export function changedSections(changed: PlanChanged, refresh: (job: string) => return sections; } -/** What refreshes a node held back for `job`: the next run of a schedule on it or a group it is in, or that they are paused. */ -export function jobRefreshText(job: string, jobs: Pick[], triggers: Pick[], now: number): string { - const owners = new Set([job, ...jobs.filter((j) => j.kind === 'group' && j.members?.includes(job)).map((j) => j.key)]); - const mine = triggers.filter((t) => t.jobKey !== null && owners.has(t.jobKey)); +/** What refreshes a node held back for `job` (a job or group the plan names): its next scheduled run, its sensor, or that it is paused. */ +export function jobRefreshText(job: string, triggers: Pick[], now: number): string { + const mine = triggers.filter((t) => t.jobKey === job); const live = mine.filter((t) => t.state === 'running'); if (mine.length && !live.length) return `job ${job} is paused`; const next = live.flatMap((t) => (t.nextDueAt ? [t.nextDueAt] : [])).sort()[0]; if (next) return `job ${job} · next run ${formatIn(next, now)}`; - return live.length ? `job ${job} · when its sensor fires` : `job ${job}`; + return live.some((t) => t.type === 'sensor') ? `job ${job} · when its sensor fires` : `job ${job}`; } diff --git a/ui/src/routes/+page.svelte b/ui/src/routes/+page.svelte index ccded3bf6a..691de1fa92 100644 --- a/ui/src/routes/+page.svelte +++ b/ui/src/routes/+page.svelte @@ -137,12 +137,11 @@ {view.since} {#if item.kind === 'stale_models'} - + {#if item.changed.length} goto(to(CHANGED_PLAN_HREF))}>Build changed - {:else} - goto(to(planHref(staleSelection)))}>Rebuild {staleSelection.length} {/if} + goto(to(planHref(staleSelection)))}>Rebuild {staleSelection.length} {/if} {#if 'acknowledged' in item && canAcknowledge}