diff --git a/CHANGELOG.md b/CHANGELOG.md index 548ee926..42d40ede 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,6 +80,21 @@ and listed with their assets on the ### Fixed +- A lane's failed start on a node no longer stays on its start page after + the lane or the stack stopped: stopping the lane, stopping the main tree + (`devstack down`) or starting the lane here clears it, and the dashboard + drops it once the stack's daemon is gone. Before, it stayed ten minutes + whatever happened. +- After **Stop stack** the dashboard shows the stack's services stopped. + They did stop, but the daemon closes its API before it stops them and + exits, so the page kept showing them as running. +- Stopping a lane keeps it shown, with its start, instead of switching to + the main working tree, where the same button is "Stop stack". A lane whose + worktree was removed still gives way to the main tree. +- A lane's dot in the sidebar follows its services: the daemon announces + the lanes when their counts change (a lane on a node is read every 5 s), + and the shown lane counts from its own stream. Before, a lane started on + a node stayed yellow until the page switched to another tree. - A lane on a node no longer stops syncing when a file goes while it is sent (a package manager rewriting `node_modules`): the file is left out and the next sync sends what is there then. diff --git a/crates/devstack-daemon/src/api.rs b/crates/devstack-daemon/src/api.rs index 9440fc0d..8c712729 100644 --- a/crates/devstack-daemon/src/api.rs +++ b/crates/devstack-daemon/src/api.rs @@ -244,7 +244,12 @@ async fn down(State(s): State, Query(q): Query) -> Response let lanes = s.lanes.as_ref().map(|l| l.active()).unwrap_or_default(); let infra = q.infra && lanes.is_empty(); let sup = s.sup.clone(); - match tokio::task::spawn_blocking(move || sup.down(infra)).await { + let result = tokio::task::spawn_blocking(move || sup.down(infra)).await; + // The stack stopped: a lane's start or move that failed before is over. + if let Some(l) = &s.lanes { + l.forget_failed(None); + } + match result { Ok(failed) if !failed.is_empty() => err( StatusCode::CONFLICT, format!( diff --git a/crates/devstack-daemon/src/lanes.rs b/crates/devstack-daemon/src/lanes.rs index 303bda83..5c48fa9c 100644 --- a/crates/devstack-daemon/src/lanes.rs +++ b/crates/devstack-daemon/src/lanes.rs @@ -903,6 +903,7 @@ impl Lanes { .spawn(move || { let mut last = fingerprint(&dir); let mut since = std::time::Instant::now(); + let mut shown = Vec::new(); loop { std::thread::sleep(std::time::Duration::from_secs(1)); let Some(me) = weak.upgrade() else { return }; @@ -910,6 +911,14 @@ impl Lanes { return; } me.main_slot_check(); + // What changes without a call here: a lane's services + // starting and stopping, a lane on a node as read every + // few seconds, a failed start that expired. + let now = me.shown(); + if now != shown { + shown = now; + me.announce(); + } let now = fingerprint(&dir); if now != last || since.elapsed() >= std::time::Duration::from_secs(30) { last = now; @@ -920,6 +929,22 @@ impl Lanes { }); } + /// Of each lane, what the lists show that changes on its own. + fn shown(&self) -> Vec<(String, usize, usize, Option, bool)> { + self.views() + .into_iter() + .map(|v| { + ( + v.name, + v.running, + v.services, + v.node_error, + v.moving.is_some(), + ) + }) + .collect() + } + /// A lane on a node that serves the main ports and is gone (its lease /// over, its node not answering): the main tree takes them back /// (ADR-0025 point 4). @@ -1539,6 +1564,8 @@ impl Lanes { })(); self.pending.lock().unwrap().remove(&name); if result.is_ok() { + // Started here: a start on a node that failed before is over. + self.forget_failed(Some(&name)); self.announce(); } result @@ -1556,6 +1583,8 @@ impl Lanes { let t0 = std::time::Instant::now(); // A profile holds while the lane runs (ADR-0041). self.profiles.lock().unwrap().remove(name); + // Stopped: a start or move that failed before is no longer news. + self.forget_failed(Some(name)); let remote = self.remote.lock().unwrap().remove(name); if let Some(r) = remote { let node = r.node.name.clone(); @@ -1936,6 +1965,20 @@ impl Lanes { self.announce(); } + /// Forget the start or move of `name` (`None`: of every lane) that + /// failed: the lane started another way, or it or the stack stopped. + pub fn forget_failed(&self, name: Option<&str>) { + let gone = { + let mut moves = self.moves.lock().unwrap(); + let before = moves.len(); + moves.retain(|n, m| m.error.is_none() || name.is_some_and(|x| x != n)); + moves.len() != before + }; + if gone { + self.announce(); + } + } + /// Release a lane on a node, on a thread of its own: the call blocks on /// the node, and this may run on the runtime's. fn stop_remote(&self, r: Arc) { diff --git a/crates/devstack/tests/daemon_lifecycle.rs b/crates/devstack/tests/daemon_lifecycle.rs index 89df7735..12c07823 100644 --- a/crates/devstack/tests/daemon_lifecycle.rs +++ b/crates/devstack/tests/daemon_lifecycle.rs @@ -1962,10 +1962,26 @@ fn a_worktree_runs_as_a_lane() { "{list}" ); + // A start on a node that failed (there is no pool here) is said with + // the lane until it is stopped, or started another way. + let failed = || { + s.daemon_get("/v1/lanes") + .as_array() + .and_then(|a| a.iter().find(|l| l["name"] == lane.as_str()).cloned()) + .is_some_and(|l| l["moving"]["error"].is_string()) + }; + let on = wt_cli(&["up", "--on", "nowhere"]); + assert!(failed(), "{on}"); + wt_cli(&["lane", "stop", &lane]); + assert!(!failed(), "gone once the lane is stopped"); + let on = wt_cli(&["up", "--on", "nowhere"]); + assert!(failed(), "{on}"); + // 2. `up` in the worktree starts it: on its own ports, no workers. std::fs::write(wt.join("src/Site/index.html"), "

lane site

").unwrap(); let up = wt_cli(&["up"]); assert!(up.contains(&format!("lane `{lane}`")), "{up}"); + assert!(!failed(), "gone once the lane started here"); // Its ports are moved by 100 per lane number; a taken range is skipped. let list = s.ok(&["lane", "list"]); let offset: u16 = list diff --git a/docs/dashboard-api.md b/docs/dashboard-api.md index ccbd9d42..0fa00d59 100644 --- a/docs/dashboard-api.md +++ b/docs/dashboard-api.md @@ -283,7 +283,7 @@ type UsageReport = { | `GET /v1/infra/{group}/{service}/logs?tail=200&grep=&since=` | text, a container's output (`docker compose logs`), stdout and stderr merged by Docker's timestamps, each line starting with one; `since` as Docker takes it (`30m`); `502` when Docker fails. `/v1/services/{name}/logs` answers the same for a name that is no service but exactly one Compose service | | `GET /v1/infra/{group}/{service}/logs/stream?tail=500` | SSE (`tail` at most 5000): `{"type":"line","text":"..."}` per line of `docker compose logs --follow` (timestamped), the same events as a service's log stream; in a lane its own container, the main tree's for a `shared` one | | `GET /v1/lanes` | JSON, the lanes: the repository's other worktrees ([ADR-0024](adr/0024-a-lane-is-a-supervisor-in-the-main-trees-daemon.md)), `[{name, path, branch, number, port_offset, active, owns_main, running, services, node?, pool?, shared_with?, profile?, node_error?}]`; `active`: started; `node`: the node of the pool it runs on (absent: this machine), `pool`: that node's pool, `shared_with`: whom it is shared with (member ids, tags, `*`; absent: nobody), `profile`: the profile it runs with, `node_error`: what goes wrong with it now (a sync, a renewal, a port that cannot be forwarded here), each until it works again, several joined by `; `, `node_warning`: the node or the coordinator runs another devstack than this machine, or does not say which (from the lease on, so while it starts too; [ADR-0031](adr/0031-a-coordinator-places-lanes.md) point 8); `moving`: `{kind: start|move, to, step, steps, what, since, phases, phase_since, error?, failed_at?}` (`phases`: `[{phase, ms}]` over so far, `phase_since`: when the current one began) while a start on a node or a move runs, and for ten minutes after one failed | -| `POST /v1/lanes` | `{"path", "infra"?, "workers"?, "force"?, "on"?, "profile"?}`: start the lane of that worktree, with `profile` with that profile of its stack file ([ADR-0041](adr/0041-a-profile-says-how-a-lane-runs-for-a-purpose.md); `409` when the worktree's stack file has no such profile or it does not apply); with `on` (a node's name or member id, or `pool` for the coordinator to choose; in another pool than the default one `:`, or `` for its coordinator to choose, [ADR-0034](adr/0034-a-machine-can-belong-to-several-pools.md)) on that node of the pool instead, leased, synced and started there, its API passed through under `/v1/lanes/{lane}/v1/...` ([ADR-0025](adr/0025-a-lane-can-run-on-another-node.md)) (what `devstack up` in it does; `infra` starts the main tree's `shared` Compose services if needed, the lane's own containers start with its `up`; `workers` runs its background workers; `force` skips the memory check, which otherwise answers `409` with what the lane needs and what is free, ADR-0030), then `/v1/lanes/{lane}/v1/up` starts its services and its containers. `201` with its entry. With `on`: `202` with its entry once the lane is leased and admitted by the node; its sync and its start there (minutes on a first start: images pulled and built, containers created) go on in the background, shown as the entry's `moving` (`kind: "start"`, in `lanes` events and here). It runs there once `moving` is gone and `active` is `true`, which is once the lane's daemon answers there: its containers come up after, under it (#164; a node of an earlier release answers once they are healthy), and show as `created`, then `starting` and `healthy` in its `InfraView`s (then call `/v1/up`, which starts its services once their infrastructure is up); it failed when `moving` carries `error` (for ten minutes). What can be told at once is refused at once: no such worktree, a lane that runs elsewhere, no lease (`409` with the reason: no node, the coordinator or the node refuses, a node with another pool protocol). The same start asked again while it goes on answers `202` too; `201` when the lane runs on that node already. Up to 0.10.1 a start on a node answered `201` only when done. Worktrees are git's: there is no route that creates or removes one | +| `POST /v1/lanes` | `{"path", "infra"?, "workers"?, "force"?, "on"?, "profile"?}`: start the lane of that worktree, with `profile` with that profile of its stack file ([ADR-0041](adr/0041-a-profile-says-how-a-lane-runs-for-a-purpose.md); `409` when the worktree's stack file has no such profile or it does not apply); with `on` (a node's name or member id, or `pool` for the coordinator to choose; in another pool than the default one `:`, or `` for its coordinator to choose, [ADR-0034](adr/0034-a-machine-can-belong-to-several-pools.md)) on that node of the pool instead, leased, synced and started there, its API passed through under `/v1/lanes/{lane}/v1/...` ([ADR-0025](adr/0025-a-lane-can-run-on-another-node.md)) (what `devstack up` in it does; `infra` starts the main tree's `shared` Compose services if needed, the lane's own containers start with its `up`; `workers` runs its background workers; `force` skips the memory check, which otherwise answers `409` with what the lane needs and what is free, ADR-0030), then `/v1/lanes/{lane}/v1/up` starts its services and its containers. `201` with its entry. With `on`: `202` with its entry once the lane is leased and admitted by the node; its sync and its start there (minutes on a first start: images pulled and built, containers created) go on in the background, shown as the entry's `moving` (`kind: "start"`, in `lanes` events and here). It runs there once `moving` is gone and `active` is `true`, which is once the lane's daemon answers there: its containers come up after, under it (#164; a node of an earlier release answers once they are healthy), and show as `created`, then `starting` and `healthy` in its `InfraView`s (then call `/v1/up`, which starts its services once their infrastructure is up); it failed when `moving` carries `error` (for ten minutes, until the lane stops, the main tree's `/v1/down` or a start of it here). What can be told at once is refused at once: no such worktree, a lane that runs elsewhere, no lease (`409` with the reason: no node, the coordinator or the node refuses, a node with another pool protocol). The same start asked again while it goes on answers `202` too; `201` when the lane runs on that node already. Up to 0.10.1 a start on a node answered `201` only when done. Worktrees are git's: there is no route that creates or removes one | | `POST /v1/lanes/{lane}/share` | `{"with"}`: share a lane on a node with others in its pool: member ids, tags, `*` for every member; `[]` for nobody ([ADR-0035](adr/0035-lanes-can-be-shared-with-the-pool.md)). They open its services and view it, read only ([ADR-0040](adr/0040-a-shared-lane-can-be-watched-like-ones-own.md)); `view`, a separate list up to 0.11.1, is ignored. Kept per lane, told the coordinator while it runs on a node. Answers with the lanes (`LaneView.shared_with`) | | `POST /v1/lanes/{lane}/reset` | a stopped lane's data goes, here and on the nodes it ran on (ADR-0038): `[Pruned]` (`{place, lane, bytes, why, removed, error}`); `409` while it runs | | `POST /v1/lanes/prune` | `{"older_than"?: "7d", "dry_run"?: bool}`: what this repository's lanes leave behind: on this machine the Compose projects of lanes whose worktree is gone (only those whose files are in this repository's lane state), on the pool's nodes this machine's kept lanes of this repository that are gone or not used for `older_than`; `[Pruned]` | diff --git a/ui/src/components/Sidebar.vue b/ui/src/components/Sidebar.vue index b883bb75..95ae92eb 100644 --- a/ui/src/components/Sidebar.vue +++ b/ui/src/components/Sidebar.vue @@ -120,19 +120,27 @@ function mainDot(s: StackEntry): Dot { return mainActive.value[s.id] === false ? 'off' : 'on'; } const servedBy = (s: StackEntry) => (known.value[s.id] ?? []).find((l) => l.owns_main) ?? null; +/** + * How many of a lane's services run: the shown lane's from its own stream, + * which the list (the main tree's, not followed meanwhile) lags behind. + */ +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; +} /** A lane's state as a dot, like a stack's: the words are in its tooltip. */ -function laneDot(l: LaneView): Dot { +function laneDot(s: StackEntry, l: LaneView): Dot { if (!hub.reachable) return 'unknown'; if (l.moving?.error) return 'err'; if (!started(l)) return 'off'; - return l.running > 0 ? 'on' : 'warn'; + return laneRuns(s, l) > 0 ? 'on' : 'warn'; } -function laneTitle(l: LaneView): string { +function laneTitle(s: StackEntry, l: LaneView): string { const where = l.node ? `runs on ${nodeLabel(l)}` : `ports +${l.port_offset}`; if (l.moving?.error) return `${l.path}\n${l.moving.error}`; if (l.moving) return `${l.path}\n${l.moving.what}`; if (!started(l)) return `${l.path}\nnot started`; - return `${l.path}\n${l.running} of ${l.services} services running · ${where}${l.owns_main ? ' · serves the main ports' : ''}`; + return `${l.path}\n${laneRuns(s, l)} of ${l.services} services running · ${where}${l.owns_main ? ' · serves the main ports' : ''}`; } function openStack(s: StackEntry) { @@ -311,13 +319,13 @@ async function copyPath(s: StackEntry) { type="button" class="item lane" :class="{ active: isCurrent(s) && stack.lane === l.name, idle: !started(l) }" - :title="laneTitle(l)" + :title="laneTitle(s, l)" data-testid="sidebar-lane" :data-lane="l.name" @click="openLane(s, l)" >