diff --git a/CHANGELOG.md b/CHANGELOG.md index 314fc850..43d77709 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,10 @@ and listed with their assets on the them with `--exec` now, as written (#597). Until this release, a link helps: `ln -sf /root/.local/bin/devstack /usr/local/bin/devstack` in the distribution as root. +- **A job that still runs is not counted as healthy in the dashboard.** The + overview's "healthy" count, its filter and a job's shortcut card put a + running job (a migration) there; it counts as starting now until it + completed, as the daemon and the hub's summary count it (#591). ## [0.51.0] - 2026-11-19 diff --git a/ui/src/api/mock/index.ts b/ui/src/api/mock/index.ts index 43a9c577..d355b9ce 100644 --- a/ui/src/api/mock/index.ts +++ b/ui/src/api/mock/index.ts @@ -339,7 +339,7 @@ class MockHub { return { id: s.entry.id, state: attention ? 'attention' : s.entry.running ? 'ok' : 'stopped', - ready: services.filter((v) => statusBucket(v.status) === 'healthy').length, + ready: services.filter((v) => statusBucket(v) === 'healthy').length, total: services.length, lanes: s.entry.running ? s.startedLanes.size : 0, }; @@ -1428,7 +1428,9 @@ export class MockTransport implements Transport { const svc = s.view.services.find((x) => x.name === r); const ctr = s.view.infra.flatMap((g) => g.containers).find((c) => c.service === r); const state = svc ? svc.status.state : ctr ? (ctr.state === 'running' ? 'running' : ctr.state) : 'missing'; - if (!ready(state)) return json(409, { error: `${name} requires ${r}, which is not ready (${state})` }); + // A job that still runs is not ready (#591), as the daemon counts it. + const isReady = svc ? statusBucket(svc) === 'healthy' : ready(state); + if (!isReady) return json(409, { error: `${name} requires ${r}, which is not ready (${state})` }); } const run = s.startRun(name, commandPlan(name)); return json(202, { run: run.id }); diff --git a/ui/src/components/ShortcutCard.vue b/ui/src/components/ShortcutCard.vue index 56377933..0614e905 100644 --- a/ui/src/components/ShortcutCard.vue +++ b/ui/src/components/ShortcutCard.vue @@ -14,7 +14,7 @@ const url = computed(() => { const s = props.service; return webUrl(s.link) || webUrl(s.url) || s.port ? serviceUrl(s) : null; }); -const bucket = computed(() => statusBucket(props.service.status)); +const bucket = computed(() => statusBucket(props.service)); const tone: Record, string> = { healthy: 'ok', starting: 'accent', failed: 'danger', idle: 'neutral' }; diff --git a/ui/src/components/Sidebar.vue b/ui/src/components/Sidebar.vue index 27b87038..815817c4 100644 --- a/ui/src/components/Sidebar.vue +++ b/ui/src/components/Sidebar.vue @@ -230,8 +230,8 @@ watch( () => [stack.id, stack.lane, stack.live, stack.services] as const, ([id, lane, live, services]) => { if (id && lane === null && live && services.length) { - mainActive.value[id] = services.some((x) => statusBucket(x.status) !== 'idle'); - mainFails.value[id] = services.some((x) => statusBucket(x.status) === 'failed'); + mainActive.value[id] = services.some((x) => statusBucket(x) !== 'idle'); + mainFails.value[id] = services.some((x) => statusBucket(x) === 'failed'); } }, { immediate: true }, @@ -268,7 +268,7 @@ const servedBy = (s: StackEntry) => (known.value[s.id] ?? []).find((l) => l.owns */ function laneRuns(s: StackEntry, l: LaneView): number { if (s.id !== stack.id || stack.lane !== l.name || !stack.live || !stack.services.length) return l.running; - return stack.services.filter((x) => statusBucket(x.status) !== 'idle').length; + return stack.services.filter((x) => statusBucket(x) !== 'idle').length; } /** How many of a lane's containers run, and of all: the shown lane's from its stream, as `laneRuns` does. */ function laneContainers(s: StackEntry, l: LaneView): [number, number] { @@ -282,7 +282,7 @@ function laneDot(s: StackEntry, l: LaneView): Dot { if (l.moving?.error) return 'err'; // The shown lane's own services, from its stream. // (A lane not started has no stream: the one shown is the main tree's.) - if (started(l) && s.id === stack.id && stack.lane === l.name && stack.live && stack.services.some((x) => statusBucket(x.status) === 'failed')) return 'err'; + if (started(l) && s.id === stack.id && stack.lane === l.name && stack.live && stack.services.some((x) => statusBucket(x) === 'failed')) return 'err'; if (started(l) && (l.node_error || l.notices?.length)) return 'warn'; if (!started(l)) return 'off'; const [cr, c] = laneContainers(s, l); diff --git a/ui/src/lib/status.test.ts b/ui/src/lib/status.test.ts index 3bde33be..7c1cd548 100644 --- a/ui/src/lib/status.test.ts +++ b/ui/src/lib/status.test.ts @@ -21,10 +21,20 @@ describe('statusLook', () => { }); it('buckets for the summary', () => { - expect(statusBucket({ state: 'running' })).toBe('healthy'); - expect(statusBucket({ state: 'unhealthy', reason: '' })).toBe('failed'); - expect(statusBucket({ state: 'exited', exit_code: 0 })).toBe('idle'); - expect(statusBucket({ state: 'exited', exit_code: 1 })).toBe('failed'); + const b = (status: Status, kind = 'service') => statusBucket({ status, kind }); + expect(b({ state: 'running' })).toBe('healthy'); + expect(b({ state: 'unhealthy', reason: '' })).toBe('failed'); + expect(b({ state: 'exited', exit_code: 0 })).toBe('idle'); + expect(b({ state: 'exited', exit_code: 1 })).toBe('failed'); + }); + + it('counts a running job as starting, not healthy (#591)', () => { + const b = (status: Status) => statusBucket({ status, kind: 'job' }); + expect(b({ state: 'running' })).toBe('starting'); + expect(b({ state: 'completed', exit_code: 0 })).toBe('idle'); + expect(b({ state: 'failed', reason: 'exit 1' })).toBe('failed'); + // A long-running kind stays healthy while it runs. + expect(statusBucket({ status: { state: 'running' }, kind: 'devserver' })).toBe('healthy'); }); }); diff --git a/ui/src/lib/status.ts b/ui/src/lib/status.ts index 9cec137c..ba51bb5e 100644 --- a/ui/src/lib/status.ts +++ b/ui/src/lib/status.ts @@ -31,12 +31,18 @@ export function statusLook(s: Status): StatusLook { return { label: cap(state), tone: 'neutral', busy: false, detail: null }; } -/** Healthy/starting/failed buckets for the summary. */ -export function statusBucket(s: Status): 'healthy' | 'starting' | 'failed' | 'idle' { +/** + * Healthy/starting/failed buckets for the summary. Takes the service, not its + * status alone: a job is `running` while it runs, and counts as ready only + * once it completed (#591, as the daemon's #573 and the hub's #575 count). + */ +export function statusBucket(svc: Pick): 'healthy' | 'starting' | 'failed' | 'idle' { + const s = svc.status; switch (s.state) { case 'healthy': - case 'running': return 'healthy'; + case 'running': + return svc.kind === 'job' ? 'starting' : 'healthy'; case 'starting': case 'building': return 'starting'; diff --git a/ui/src/stores/stack.ts b/ui/src/stores/stack.ts index ec13a68d..2c260bd7 100644 --- a/ui/src/stores/stack.ts +++ b/ui/src/stores/stack.ts @@ -294,7 +294,7 @@ export const useStack = defineStore('stack', () => { active: mainActive.value, port_offset: 0, owns_main: !(lanesOf.value === id.value && lanes.value.some((l) => l.owns_main)), - running: services.filter((x) => statusBucket(x.status) !== 'idle').length, + running: services.filter((x) => statusBucket(x) !== 'idle').length, services: services.length, containers_running: containers.filter((c) => c.state === 'running').length, containers: containers.length, @@ -319,7 +319,7 @@ export const useStack = defineStore('stack', () => { const runningLanes = computed(() => (lanesOf.value === id.value ? lanes.value.filter((l) => l.active !== false).map((l) => l.name) : [])); /** The main tree is shown and nothing of it runs, while its daemon stays for the lanes. */ const mainIdle = computed( - () => running.value && lane.value === null && live.value && services.value.length > 0 && services.value.every((s) => statusBucket(s.status) === 'idle'), + () => running.value && lane.value === null && live.value && services.value.length > 0 && services.value.every((s) => statusBucket(s) === 'idle'), ); /** @@ -350,7 +350,7 @@ export const useStack = defineStore('stack', () => { if (!running.value) return false; const mv = mainView.value; if (!mv) return true; - if (mv.services.length) return mv.services.some((x) => statusBucket(x.status) !== 'idle'); + if (mv.services.length) return mv.services.some((x) => statusBucket(x) !== 'idle'); const containers = mv.infra.flatMap((g) => g.containers).filter((c) => c.managed !== false); return !containers.length || containers.some((c) => c.state === 'running'); }); @@ -634,7 +634,7 @@ export const useStack = defineStore('stack', () => { } catch { /* the last view seen */ } - const names = list.filter((x) => statusBucket(x.status) !== 'idle' && (how === 'restart' || x.build_id)).map((x) => x.name); + const names = list.filter((x) => statusBucket(x) !== 'idle' && (how === 'restart' || x.build_id)).map((x) => x.name); if (!names.length) { ui.toast('info', `${what} main`, 'Nothing of it runs.'); return; @@ -877,7 +877,7 @@ export const useStack = defineStore('stack', () => { } }); /** A service that runs, or is on its way to. */ - const ran = (s: ServiceView) => !['idle', 'failed'].includes(statusBucket(s.status)); + const ran = (s: ServiceView) => !['idle', 'failed'].includes(statusBucket(s)); function connect() { if (!id.value) return; diff --git a/ui/src/views/OverviewView.vue b/ui/src/views/OverviewView.vue index 4855a242..dceec134 100644 --- a/ui/src/views/OverviewView.vue +++ b/ui/src/views/OverviewView.vue @@ -71,7 +71,7 @@ function toggle(f: Filter) { filter.value = filter.value === f ? null : f; } function matches(m: Member, f: Filter): boolean { - if (m.kind === 'service') return f === 'pending' ? !!m.service.candidate : statusBucket(m.service.status) === f; + if (m.kind === 'service') return f === 'pending' ? !!m.service.candidate : statusBucket(m.service) === f; if (m.kind === 'container') return f !== 'pending' && !!m.container && containerBucket(m.container) === f; return false; } @@ -116,7 +116,7 @@ const counts = computed(() => { const c = { healthy: 0, starting: 0, failed: 0, idle: 0 }; const v = view.value; if (!v) return c; - for (const s of v.services) c[statusBucket(s.status)]++; + for (const s of v.services) c[statusBucket(s)]++; for (const g of v.infra) for (const x of g.containers) c[containerBucket(x)]++; return c; });