diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f5676f3..07a76a5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,18 @@ and listed with their assets on the ## [Unreleased] +### Fixed + +- **A long-running job no longer reads as "starting" for its whole run** + (#611). In a stack's overview a job that runs is in a state of its own + ("running as a job"), counted neither as healthy nor as starting, with + its own filter. On the start page a stack with a running job is + "Running · 1 job" instead of "Starting", and a stack whose main tree is + stopped while a lane runs shows the lanes' services ("Services in + lanes 1/4") instead of 0/4. The hub's summary (`GET /hub/summary`, the + `summary` event) carries `jobs`, `lane_ready` and `lane_total` for it; + a running job no longer makes a stack `starting`. + ## [0.52.0] - 2026-11-21 A shared machine keeps the GPUs its owner wants: the share switch takes a diff --git a/crates/devstack-hub/src/notify/rules.rs b/crates/devstack-hub/src/notify/rules.rs index 94c6bfaf..705c3d98 100644 --- a/crates/devstack-hub/src/notify/rules.rs +++ b/crates/devstack-hub/src/notify/rules.rs @@ -181,8 +181,9 @@ impl Scope { for name in names { let svc = &self.services[name]; match svc.state.as_str() { - // A job runs until it ends (#544): that is its start (#575). - "running" if svc.kind == "job" => g.starting = true, + // A job runs until it ends (#544): not ready (#575), and not + // a start either, which a run of hours would show (#611). + "running" if svc.kind == "job" => g.jobs += 1, "running" | "healthy" => g.ready += 1, "completed" if svc.exit_code == Some(0) => g.ready += 1, "building" | "starting" => g.starting = true, @@ -530,25 +531,27 @@ mod tests { assert_eq!(g.attention[1].level, Level::Error); } - /// #575: a job is `running` while it runs (#544), which is its start, - /// not a service that is ready; a long-running service's `running` is. + /// #575: a job is `running` while it runs (#544), not a service that is + /// ready; a long-running service's `running` is. #611: nor is it a start, + /// which a training of hours would show for its whole run. #[test] - fn a_running_job_counts_as_starting_not_ready() { + fn a_running_job_counts_as_a_job_not_ready_nor_starting() { let mut s = Scope::default(); s.apply(&snapshot(json!([ { "name": "api", "kind": "long-running", "status": { "state": "running" } }, { "name": "migrate", "kind": "job", "status": { "state": "starting" } } ]))); + assert_eq!((s.glance().starting, s.glance().jobs), (true, 0)); // The service event carries no kind: the snapshot's stays. s.apply(&service("migrate", json!({ "state": "running" }))); let g = s.glance(); - assert_eq!((g.ready, g.total, g.starting), (1, 2, true)); + assert_eq!((g.ready, g.total, g.starting, g.jobs), (1, 2, false, 1)); s.apply(&service( "migrate", json!({ "state": "completed", "exit_code": 0 }), )); let g = s.glance(); - assert_eq!((g.ready, g.starting), (2, false)); + assert_eq!((g.ready, g.starting, g.jobs), (2, false, 0)); } #[test] diff --git a/crates/devstack-hub/src/summary.rs b/crates/devstack-hub/src/summary.rs index dec67f71..b5dba133 100644 --- a/crates/devstack-hub/src/summary.rs +++ b/crates/devstack-hub/src/summary.rs @@ -48,6 +48,8 @@ pub(crate) struct Glance { pub total: usize, /// A service builds or starts. pub starting: bool, + /// Jobs running (#611): neither ready nor starting. + pub jobs: usize, pub attention: Vec, } @@ -145,6 +147,12 @@ pub(crate) struct StackSummary { pub total: usize, /// Lanes whose stream the hub follows: started, here or on a node. pub lanes: usize, + /// Jobs running in the main tree and the lanes (#611). + pub jobs: usize, + /// The lanes' services ready, of all, summed (#611): a stack that works + /// in a lane while its main tree is stopped does not look idle. + pub lane_ready: usize, + pub lane_total: usize, pub attention: Vec, } @@ -180,9 +188,15 @@ fn stack( }); } let mut starting = false; + let (mut jobs, mut lane_ready, mut lane_total) = (0, 0, 0); for (lane, g) in streams { if e.running { starting |= g.starting; + jobs += g.jobs; + if lane.is_some() { + lane_ready += g.ready; + lane_total += g.total; + } attention.extend(g.attention.iter().cloned().map(|mut i| { i.lane = lane.clone(); i @@ -206,6 +220,9 @@ fn stack( ready: main.ready, total: main.total, lanes: streams.keys().filter(|l| l.is_some()).count(), + jobs, + lane_ready, + lane_total, attention, } } @@ -274,6 +291,9 @@ pub(crate) struct StackGlance { pub ready: usize, pub total: usize, pub lanes: usize, + pub jobs: usize, + pub lane_ready: usize, + pub lane_total: usize, } /// Every stack's figures in `sum`, for `/hub/events`. @@ -286,6 +306,9 @@ pub(crate) fn glances(sum: &Summary) -> Vec { ready: st.ready, total: st.total, lanes: st.lanes, + jobs: st.jobs, + lane_ready: st.lane_ready, + lane_total: st.lane_total, }) .collect() } @@ -345,6 +368,39 @@ mod tests { assert_eq!(overall(&[s]), "attention"); } + /// #611: a job running for hours in a lane, while the main tree is + /// stopped, is neither a start nor an idle stack. + #[test] + fn a_running_job_is_counted_and_the_lanes_have_their_figures() { + let streams = BTreeMap::from([ + ( + None, + Glance { + total: 4, + ..Default::default() + }, + ), + ( + Some("run-8".to_string()), + Glance { + ready: 1, + total: 4, + jobs: 1, + ..Default::default() + }, + ), + ]); + let s = stack(&entry("ab12", true), None, &streams); + assert_eq!(s.state, "ok"); + assert_eq!( + (s.ready, s.total, s.jobs, s.lane_ready, s.lane_total), + (0, 4, 1, 1, 4) + ); + // A stopped stack's stale streams count nothing. + let s = stack(&entry("ab12", false), None, &streams); + assert_eq!((s.jobs, s.lane_ready, s.lane_total), (0, 0, 0)); + } + #[test] fn a_stopped_stack_shows_its_failed_start_and_nothing_stale() { let mut e = entry("ab12", false); @@ -427,11 +483,15 @@ mod tests { ready: 2, total: 3, lanes: 1, + jobs: 1, + lane_ready: 1, + lane_total: 4, }) .unwrap(); assert_eq!( v, - serde_json::json!({ "id": "ab12", "state": "ok", "ready": 2, "total": 3, "lanes": 1 }) + serde_json::json!({ "id": "ab12", "state": "ok", "ready": 2, "total": 3, "lanes": 1, + "jobs": 1, "lane_ready": 1, "lane_total": 4 }) ); } diff --git a/docs/dashboard-api.md b/docs/dashboard-api.md index f017898c..2cca779c 100644 --- a/docs/dashboard-api.md +++ b/docs/dashboard-api.md @@ -56,10 +56,10 @@ and `Referrer-Policy: no-referrer`. The dashboard has no inline script. | `POST /hub/notify/test` | cookie + Origin | one notification whatever the settings say: `204`, or `503` with why nothing shows. A click opens the dashboard | | `GET /hub/session` | cookie | `200 {"version": "", "link_unavailable": string\|null}`, or `401` (not paired: show "run `devstack ui`"). `link_unavailable` says why this platform has no `devstack://` link (macOS: "not on macOS yet", ADR-0054): the page keeps it and offers `devstack hub start` instead of its "Start hub" link while the hub is down. Older hubs leave it out | | `GET /hub/stacks` | cookie | `[StackEntry]` | -| `GET /hub/summary` | cookie or token | every registered stack at a glance, for the tray ([ADR-0060](adr/0060-the-tray-is-a-client-of-the-hub.md)): `{"state", "version", "stacks": [{id, name, repo, running, state, ready, total, lanes, attention: [{lane, service, text, detail}]}]}`. A stack's `state`: `stopped`, `starting`, `stopping` (a start or stop the hub runs), `ok` or `attention`; the whole `state` is the worst: `attention`, `starting`, `ok` (a stack runs) or `idle`. `ready` of `total`: the main tree's services running, healthy or done. `lanes`: started lanes. `attention`: what notifies (ADR-0045) and is still so, in the main tree and every started lane (`lane` names it): a failed service (not one the user stopped, not one held back by another's failure), a candidate `held` or whose build `failed`, a lane whose start or move on a node failed (`service` `null`); and a failed start from the dashboard (`service` `null`). Each item's `level` ([ADR-0097](adr/0097-the-dashboards-mark-says-what-needs-attention.md)): `warn` for a candidate held, `error` for the rest; older hubs leave it out. Containers are not in it. `version`: the hub's devstack | +| `GET /hub/summary` | cookie or token | every registered stack at a glance, for the tray ([ADR-0060](adr/0060-the-tray-is-a-client-of-the-hub.md)): `{"state", "version", "stacks": [{id, name, repo, running, state, ready, total, lanes, jobs, lane_ready, lane_total, attention: [{lane, service, text, detail}]}]}`. A stack's `state`: `stopped`, `starting`, `stopping` (a start or stop the hub runs), `ok` or `attention`; the whole `state` is the worst: `attention`, `starting`, `ok` (a stack runs) or `idle`. `ready` of `total`: the main tree's services running, healthy or done; a job that still runs is not ready, and does not make the stack `starting` either. `lanes`: started lanes. `jobs`: jobs running, in the main tree and the started lanes. `lane_ready` of `lane_total`: the started lanes' services, summed (the start page shows them while nothing of the main tree is up). Older hubs leave the last three out. `attention`: what notifies (ADR-0045) and is still so, in the main tree and every started lane (`lane` names it): a failed service (not one the user stopped, not one held back by another's failure), a candidate `held` or whose build `failed`, a lane whose start or move on a node failed (`service` `null`); and a failed start from the dashboard (`service` `null`). Each item's `level` ([ADR-0097](adr/0097-the-dashboards-mark-says-what-needs-attention.md)): `warn` for a candidate held, `error` for the rest; older hubs leave it out. Containers are not in it. `version`: the hub's devstack | | `GET /hub/ports` | cookie or token | the ports of every registered stack on this machine and where two stacks meet ([ADR-0082](adr/0082-the-ports-of-a-machine.md)): `{"stacks": [{id, name, running, containers?, ports: [PortEntry]}], "overlaps": [{port, proto, stacks: [{id, name, lane, holder?, kind}]}]}`. A running stack's `ports` are its daemon's `GET /v1/ports` (see [Ports](#ports)); a stack whose daemon does not run, or does not answer it (an older devstack), has what its stack file declares for the main working tree, each `kind: "declared"`, `lane: "main"`, moved by its shift on this machine: its services' `port`, its Compose groups' `announced_ports` and the ports on this machine their `urls` name (other published ports of the Compose files are not read). What a stopped stack's containers publish that run all the same (Docker started them again by their restart policy, or a stop kept them) is asked of Docker: those ports are `kind: "published"`, `listening: true`, in place of a declared entry of the same port, and the stack has `containers: true` ([ADR-0096](adr/0096-a-port-held-now-refuses-the-start-one-up-of-a-tree-at-a-time.md)). A stopped stack whose stack file is gone is left out; one whose file does not load has no ports. An overlap is one `port` and `proto` in more than one stack, each use listed once; an `instance` port does not count (the OS hands it out). Computed on request, nothing is polled | | `GET /hub/ws?path=` | cookie + Origin | WebSocket that carries the server-sent event stream at `` (`/hub/events`, `/hub/stacks/{id}/api/v1/...`, or `/hub/pool/shared/{lease}/api/v1/...[?pool=]` for a lane shared with this machine), one text message per event's `data`; how the dashboard reads every stream (a browser allows six HTTP/1.1 connections per host across all its tabs, WebSockets do not count; ADR-0021). The upstream is opened before the upgrade: `503` for a stack not running, `400` for another path. When the stream ends the socket closes | -| `GET /hub/events` | cookie | SSE: `{"type":"stacks","stacks":[StackEntry]}` and `{"type":"docker","docker":DockerEngine}` and `{"type":"release","current","newer":string|null,"error":string|null}` (a newer devstack; checked at start, every 12 h by the clock and when a dashboard connects and the last answer is over an hour old, unless `DEVSTACK_NO_UPDATE_CHECK`; `error` why the last check failed, no network or GitHub's rate limit, tried again after an hour and `null` once one succeeds, while a `newer` found before stays; older hubs leave it out) and `{"type":"update","update":{"running":bool,"error":string|null,"installed":string|null,"finished":ms|null}}` (the dashboard's update; `finished` is when the last one ended, `installed` the version it installed, told by the hub it started) and `{"type":"guests","guests":[Guest]}` (lanes of other members on this machine, every pool: `{pool, lease, member, owner, repo, lane, state: "offered"\|"running", since: unix s, cpus, memory}`, the leases whose node is this machine; read when the pool's stream says its leases or nodes changed) and `{"type":"worktrees","worktrees":{"":""}}` (a version of each registered stack's worktrees, running or not, ADR-0078: the hub looks at their folder once a second; a stack's lanes are read again when its version changes; older hubs never send it. Since ADR-0088 the version also moves when a checked-out branch or its upstream moves: their loose ref files, `packed-refs` and `FETCH_HEAD`, looked at without running git; the dashboard reads `branches` again then) and `{"type":"activity","at":ms}` (a record was added to the agents' activity, [ADR-0098](adr/0098-the-skills-page-shows-the-flow-of-the-hooks-and-the-agents-activity.md): read `/hub/activity` again; looked at every two seconds while a dashboard listens; older hubs never send it) and `{"type":"attention","items":[{stack, lane, service, text, detail, level}]}` (what needs attention in every stack, the items of `/hub/summary` with their stack's id, [ADR-0097](adr/0097-the-dashboards-mark-says-what-needs-attention.md): sent again when one changed; the dashboard's dot on its mark and favicon; older hubs never send it) and `{"type":"summary","stacks":[{id, state, ready, total, lanes}]}` (every stack's figures for the dashboard's start page, [ADR-0104](adr/0104-the-start-page-shows-every-stack-as-a-tile.md): `/hub/summary`'s stacks without their attention items; sent again when one changed; a start or stop the hub runs shows only once the daemon came or went; older hubs never send it) and `{"type":"pools","pools":{"":{"live":"connecting"\|"live"\|"lost"\|"old","error"?,"versions":{"members","nodes","leases","upstreams","telemetry"}}}}` (the pools this machine follows over their coordinators' streams, ADR-0073: `old` for a coordinator without one, whose parts are read when the pool area opens; `versions` of each part, read again when one is not the one read last; older hubs never send it), each first and on every change | +| `GET /hub/events` | cookie | SSE: `{"type":"stacks","stacks":[StackEntry]}` and `{"type":"docker","docker":DockerEngine}` and `{"type":"release","current","newer":string|null,"error":string|null}` (a newer devstack; checked at start, every 12 h by the clock and when a dashboard connects and the last answer is over an hour old, unless `DEVSTACK_NO_UPDATE_CHECK`; `error` why the last check failed, no network or GitHub's rate limit, tried again after an hour and `null` once one succeeds, while a `newer` found before stays; older hubs leave it out) and `{"type":"update","update":{"running":bool,"error":string|null,"installed":string|null,"finished":ms|null}}` (the dashboard's update; `finished` is when the last one ended, `installed` the version it installed, told by the hub it started) and `{"type":"guests","guests":[Guest]}` (lanes of other members on this machine, every pool: `{pool, lease, member, owner, repo, lane, state: "offered"\|"running", since: unix s, cpus, memory}`, the leases whose node is this machine; read when the pool's stream says its leases or nodes changed) and `{"type":"worktrees","worktrees":{"":""}}` (a version of each registered stack's worktrees, running or not, ADR-0078: the hub looks at their folder once a second; a stack's lanes are read again when its version changes; older hubs never send it. Since ADR-0088 the version also moves when a checked-out branch or its upstream moves: their loose ref files, `packed-refs` and `FETCH_HEAD`, looked at without running git; the dashboard reads `branches` again then) and `{"type":"activity","at":ms}` (a record was added to the agents' activity, [ADR-0098](adr/0098-the-skills-page-shows-the-flow-of-the-hooks-and-the-agents-activity.md): read `/hub/activity` again; looked at every two seconds while a dashboard listens; older hubs never send it) and `{"type":"attention","items":[{stack, lane, service, text, detail, level}]}` (what needs attention in every stack, the items of `/hub/summary` with their stack's id, [ADR-0097](adr/0097-the-dashboards-mark-says-what-needs-attention.md): sent again when one changed; the dashboard's dot on its mark and favicon; older hubs never send it) and `{"type":"summary","stacks":[{id, state, ready, total, lanes, jobs, lane_ready, lane_total}]}` (every stack's figures for the dashboard's start page, [ADR-0104](adr/0104-the-start-page-shows-every-stack-as-a-tile.md): `/hub/summary`'s stacks without their attention items; sent again when one changed; a start or stop the hub runs shows only once the daemon came or went; older hubs never send it) and `{"type":"pools","pools":{"":{"live":"connecting"\|"live"\|"lost"\|"old","error"?,"versions":{"members","nodes","leases","upstreams","telemetry"}}}}` (the pools this machine follows over their coordinators' streams, ADR-0073: `old` for a coordinator without one, whose parts are read when the pool area opens; `versions` of each part, read again when one is not the one read last; older hubs never send it), each first and on every change | | `POST /hub/update` | cookie + Origin | `202`: `devstack update` in the background (output in `hub/update.log`); on success it restarts the hub on the new version, so the dashboard reconnects to it, and the new hub's `update` event names the installed version (the old hub leaves `hub/update.json` for it; a hub that starts on the old version while the updater runs waits for it and reports a failure); on failure the `update` event carries the end of its output. `409` while one runs (checked and claimed in one step). Running stacks switch at their next restart | | `POST /hub/update/check` | cookie + Origin | look for a newer release now: `{"current", "newer": string\|null}`, the same as the next `release` event; asked again within 30 s, the last answer (GitHub allows 60 unauthenticated requests an hour), and the last answer too while GitHub's rate limit lasts (its error names the time it ends). `409` with `DEVSTACK_NO_UPDATE_CHECK`, `502` when GitHub cannot be asked, `504` after 30 s | | `POST /hub/stacks/scan` | cookie + Origin | `{"path", "add"?, "depth"?, "git_only"?, "configured_only"?}`: the folders below a folder (default one level, `depth` is clamped to 1 to 6; a repository only at its root, linked worktrees skipped) that are git repositories (`git_only`, default `true`) and have a `devstack.toml` (`configured_only`, default `true`); both `false` is a 400 (ADR-0089). `[{repo, id, name, error, configured, registered, added}]`: `configured` false is a folder without a stack file, named after the folder; with `add` the valid new ones are registered | diff --git a/ui/src/api/mock/index.ts b/ui/src/api/mock/index.ts index ce848ccf..bc8c458a 100644 --- a/ui/src/api/mock/index.ts +++ b/ui/src/api/mock/index.ts @@ -9,6 +9,7 @@ // ?mock=skills shop's stack file has no `reviewed`; its agent skills name an older devstack // ?mock=startfailed the docs stack's last start from the dashboard failed // ?mock=strays the stopped docs stack's containers run (Docker started them again, ADR-0096) +// ?mock=longjob shop's migrate job runs for hours; crm's main tree is stopped while a lane runs a job (#611) // Add a stack with a path containing "broken": a stack file that does not load // ?mock=nodocker the Docker engine is stopped; "Start Docker" brings it up after 4 s // ?mock=nopool this machine is in no pool; ?mock=poolmember: a member, not an admin @@ -271,6 +272,14 @@ class MockHub { if (q.includes('nofile')) docs.entry.no_file = true; if (q.includes('badfile')) this.brokenFile = docs; if (q.includes('strays')) docs.strayContainers = true; + // `?mock=longjob`: shop's migrate runs for hours; crm's main tree is stopped while lane run-8 trains (#611). + if (q.includes('longjob')) { + const migrate = shop.view.services.find((v) => v.name === 'migrate'); + if (migrate) migrate.status = { state: 'running' }; + for (const v of crm.view.services) v.status = { state: 'stopped' }; + crm.startedLanes.add('run-8'); + crm.laneFigures = { ready: 1, total: 4, jobs: 1 }; + } if (q.includes('startfailed')) docs.entry.start_error = 'Error: port 4000 (site) is taken by another process (node.exe, pid 4242)\n devstack doctor names it; stop it or change the port in devstack.toml'; // `?mock=skills`: shop was set up with an older devstack. // `?mock=worktrees`: a worktree appears in docs (not running) after 4 s, as one made by `git worktree add` elsewhere. @@ -336,12 +345,16 @@ class MockHub { return (this.empty ? [] : this.stacks).map((s) => { const services = s.entry.running ? s.view.services : []; const attention = items.some((a) => a.stack === s.entry.id); + const lanes = s.entry.running ? s.laneFigures : { ready: 0, total: 0, jobs: 0 }; return { id: s.entry.id, state: attention ? 'attention' : s.entry.running ? 'ok' : 'stopped', ready: services.filter((v) => statusBucket(v) === 'healthy').length, total: services.length, lanes: s.entry.running ? s.startedLanes.size : 0, + jobs: services.filter((v) => statusBucket(v) === 'job').length + lanes.jobs, + lane_ready: lanes.ready, + lane_total: lanes.total, }; }); } diff --git a/ui/src/api/mock/stack.ts b/ui/src/api/mock/stack.ts index 9c8f02ad..344844be 100644 --- a/ui/src/api/mock/stack.ts +++ b/ui/src/api/mock/stack.ts @@ -42,6 +42,8 @@ export class MockStack { } /** Mock lanes started from the dashboard (`agent-login-fix` runs from the start; the shop's `review-cart` too, on a node). */ startedLanes = new Set(); + /** The started lanes' services as the hub's summary sums them (`?mock=longjob`); the mock has no lane streams of its own. */ + laneFigures = { ready: 0, total: 0, jobs: 0 }; /** Worktrees without a stack file of their own (ADR-0055) until one is copied in. */ noStackFile = new Set(['C:\\work\\_wt\\1333']); /** Its containers run though its daemon does not (ADR-0096; `?mock=strays`). */ diff --git a/ui/src/api/types.ts b/ui/src/api/types.ts index 9c43a83e..831fedc9 100644 --- a/ui/src/api/types.ts +++ b/ui/src/api/types.ts @@ -69,7 +69,9 @@ export type HubEvent = /** * A stack at a glance (`summary` events, as `GET /hub/summary` has it without * the attention items): `ready` of `total` of the main tree's services run, - * healthy or done; `lanes` started. + * healthy or done; `lanes` started; `jobs` running in the main tree and the + * lanes; `lane_ready` of `lane_total` the lanes' services, summed. Older hubs + * leave the last three out. */ export type StackGlance = { id: string; @@ -77,6 +79,9 @@ export type StackGlance = { ready: number; total: number; lanes: number; + jobs?: number; + lane_ready?: number; + lane_total?: number; }; /** diff --git a/ui/src/components/ShortcutCard.vue b/ui/src/components/ShortcutCard.vue index 0614e905..8ef3d252 100644 --- a/ui/src/components/ShortcutCard.vue +++ b/ui/src/components/ShortcutCard.vue @@ -2,7 +2,7 @@ import { computed } from 'vue'; import type { ServiceView } from '@/api/types'; import { linkLabel, serviceUrl, webUrl } from '@/lib/format'; -import { statusBucket } from '@/lib/status'; +import { statusBucket, type Bucket } from '@/lib/status'; import { useStack } from '@/stores/stack'; import Icon from '@/components/icons/Icon.vue'; @@ -15,7 +15,7 @@ const url = computed(() => { return webUrl(s.link) || webUrl(s.url) || s.port ? serviceUrl(s) : null; }); const bucket = computed(() => statusBucket(props.service)); -const tone: Record, string> = { healthy: 'ok', starting: 'accent', failed: 'danger', idle: 'neutral' }; +const tone: Record = { healthy: 'ok', starting: 'accent', job: 'info', failed: 'danger', idle: 'neutral' };