From ed4f661cec8573d96797ee9752b1846298cc307a Mon Sep 17 00:00:00 2001 From: Sebastian Gieseler Date: Tue, 24 Nov 2026 11:29:33 +0100 Subject: [PATCH] feat: a lane's memory counts what it owns and names its builds; main stops when only what serves its lanes runs (ADR-0119) A native service's memory is what its processes own: Linux the proportional set (and a cgroup's memory.current without inactive_file), Windows the private working set, macOS the physical footprint. Shared pages, such as the .NET runtime's, no longer count once per process. The dashboard names the build job's memory: the lane card says "of it builds", the overview lists Builds below the groups. The mock hub keeps its build servers warm after a build, as the daemon does. main counts as stopped when only a singleton it keeps for running lanes runs; its stop says what keeps running and for which lanes. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 18 +++++ crates/devstack-proc/src/lib.rs | 6 +- crates/devstack-proc/src/linux.rs | 72 +++++++++++++++++-- crates/devstack-proc/src/macos.rs | 36 ++++++++-- crates/devstack-proc/src/windows.rs | 56 +++++++++++++-- ...ounts-what-it-owns-and-names-its-builds.md | 68 ++++++++++++++++++ docs/adr/README.md | 1 + docs/plan.md | 6 +- ui/src/api/mock/stack.ts | 6 +- ui/src/components/LaneUsage.vue | 17 ++++- ui/src/stores/stack.ts | 28 ++++++-- ui/src/stores/stores.test.ts | 20 ++++++ ui/src/views/OverviewHome.vue | 2 +- ui/src/views/OverviewView.vue | 21 ++++++ ui/src/views/StackPage.vue | 11 ++- ui/src/views/UsageView.vue | 2 +- 16 files changed, 334 insertions(+), 36 deletions(-) create mode 100644 docs/adr/0119-a-lanes-memory-counts-what-it-owns-and-names-its-builds.md diff --git a/CHANGELOG.md b/CHANGELOG.md index da8e9acb..f85cd2ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,24 @@ and listed with their assets on the ## [Unreleased] +### Changed + +- **A service's memory is what its processes own** (ADR-0119). Shared + pages, such as the .NET runtime's, no longer count again with every + process of a tree: Linux takes the proportional set (`Pss`) instead of the + resident set, and a cgroup's `memory.current` without the file cache the + kernel may drop; Windows the private working set; macOS the physical + footprint. The numbers in the dashboard, `devstack top` and a lane's + need for the pool are lower, for a .NET stack by about a third. +- **The dashboard names the builds' memory** (ADR-0119). The lane card says + "of it builds …", and the overview lists *Builds* below the groups: the + build servers stay after a build so the next one is fast, and were in the + lane's number but in no group. +- **main is stopped when only what serves its lanes runs** (ADR-0119). A + `singleton` the stop of main keeps for running lanes no longer shows main + as running with a Stop button; the stop says what keeps running, and for + which lanes. + ### Fixed - **A stopped stack no longer shows the memory of its containers.** When diff --git a/crates/devstack-proc/src/lib.rs b/crates/devstack-proc/src/lib.rs index cc02c0d8..886f681e 100644 --- a/crates/devstack-proc/src/lib.rs +++ b/crates/devstack-proc/src/lib.rs @@ -198,8 +198,10 @@ pub struct Usage { /// cgroup (and on macOS) it is the sum over the live processes and may /// drop. pub cpu_us: u64, - /// Bytes: the summed working sets (Windows), `memory.current` of the - /// cgroup, else the summed resident sets (Linux, macOS). + /// Bytes, each process's own and its share of what it shares (ADR-0119): + /// the summed private working sets (Windows), `memory.current` of the + /// cgroup less its inactive file cache, else the summed proportional + /// sets (Linux), the summed physical footprints (macOS). pub memory: u64, pub processes: u32, } diff --git a/crates/devstack-proc/src/linux.rs b/crates/devstack-proc/src/linux.rs index 6b367eaf..873f12ea 100644 --- a/crates/devstack-proc/src/linux.rs +++ b/crates/devstack-proc/src/linux.rs @@ -19,7 +19,11 @@ pub(crate) fn memory_available() -> Option { } fn meminfo(key: &str) -> Option { - let text = fs::read_to_string("/proc/meminfo").ok()?; + kb_field(&fs::read_to_string("/proc/meminfo").ok()?, key) +} + +/// A ` kB` line of `/proc` (meminfo, smaps_rollup), in bytes. +fn kb_field(text: &str, key: &str) -> Option { let kb: u64 = text .lines() .find_map(|l| l.strip_prefix(key))? @@ -102,10 +106,34 @@ fn live(pid: i32) -> bool { }) } -/// CPU time (user plus kernel, microseconds) and resident set (bytes) of -/// one process; zero for what cannot be read. +/// CPU time (user plus kernel, microseconds) and memory (bytes) of one +/// process; zero for what cannot be read. pub(crate) fn process_usage(pid: u32) -> (u64, u64) { - (proc_cpu_us(pid), proc_rss(pid)) + ( + proc_cpu_us(pid), + proc_pss(pid).unwrap_or_else(|| proc_rss(pid)), + ) +} + +/// Its proportional set: each page it shares with others counted by its +/// share, so a tree's sum counts the .NET runtime's pages once, not with +/// every process (as the resident set does). `None` where the kernel does +/// not let us read it (another user's process): then the resident set. +fn proc_pss(pid: u32) -> Option { + kb_field( + &fs::read_to_string(format!("/proc/{pid}/smaps_rollup")).ok()?, + "Pss:", + ) +} + +/// `inactive_file` of a cgroup's `memory.stat`, in bytes. +fn inactive_file(memory_stat: &str) -> Option { + memory_stat + .lines() + .find_map(|l| l.strip_prefix("inactive_file "))? + .trim() + .parse() + .ok() } fn proc_cpu_us(pid: u32) -> u64 { @@ -227,7 +255,17 @@ impl Cgroup { .find_map(|l| l.strip_prefix("usage_usec ")) .and_then(|v| v.trim().parse().ok()) }); - let memory = read("memory.current").and_then(|s| s.trim().parse().ok()); + // Without the file cache the kernel may drop at once, as `docker + // stats` counts a container. + let memory = read("memory.current") + .and_then(|s| s.trim().parse::().ok()) + .map(|m| { + m.saturating_sub( + read("memory.stat") + .and_then(|s| inactive_file(&s)) + .unwrap_or(0), + ) + }); let summed = || crate::posix::summed_usage(pids); Usage { cpu_us: cpu_us.unwrap_or_else(|| summed().cpu_us), @@ -265,3 +303,27 @@ fn join_cgroup(procs: &std::ffi::CStr) -> std::io::Result<()> { } Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn a_process_counts_its_share_of_what_it_shares() { + let rollup = "55e0-7ffd ---p 00000000 00:00 0 [rollup]\nRss: 4096 kB\nPss: 1536 kB\nPss_Anon: 1024 kB\n"; + assert_eq!(kb_field(rollup, "Pss:"), Some(1536 * 1024), "not Pss_Anon"); + let me = std::process::id(); + let (pss, rss) = (proc_pss(me).unwrap(), proc_rss(me)); + assert!(pss > 0 && pss <= rss, "pss {pss}, rss {rss}"); + // Read again: the process lives, its pages change by a few. + let used = process_usage(me).1; + assert!(used.abs_diff(pss) < pss / 4, "used {used}, pss {pss}"); + } + + #[test] + fn a_cgroup_does_not_count_the_cache_it_can_drop() { + let stat = "anon 1000\nfile 9000\nactive_file 3000\ninactive_file 6000\n"; + assert_eq!(inactive_file(stat), Some(6000)); + assert_eq!(inactive_file("anon 1\n"), None); + } +} diff --git a/crates/devstack-proc/src/macos.rs b/crates/devstack-proc/src/macos.rs index 8c165ca0..68aa3f08 100644 --- a/crates/devstack-proc/src/macos.rs +++ b/crates/devstack-proc/src/macos.rs @@ -1,5 +1,5 @@ //! macOS: what the POSIX backend needs from the OS, from libproc (process -//! lists, start times, CPU time and resident sets), and the machine's memory +//! lists, start times, CPU time and physical footprints), and the machine's memory //! and CPU time from `sysctl` and the Mach host statistics (ADR-0054). //! There are no cgroups: a tree is its process group, and the shim notices //! the supervisor's death by polling `getppid()`. @@ -200,8 +200,8 @@ pub(crate) fn group(pgid: i32) -> Option> { ) } -/// CPU time (user plus kernel, microseconds) and resident set (bytes) of -/// one process; zero for what cannot be read. +/// CPU time (user plus kernel, microseconds) and memory (bytes) of one +/// process; zero for what cannot be read. pub(crate) fn process_usage(pid: u32) -> (u64, u64) { let Ok(pid) = i32::try_from(pid) else { return (0, 0); @@ -210,12 +210,29 @@ pub(crate) fn process_usage(pid: u32) -> (u64, u64) { // The times are Mach absolute time units, not nanoseconds. Some(t) => ( mach_to_ns(t.pti_total_user.saturating_add(t.pti_total_system)) / 1000, - t.pti_resident_size, + phys_footprint(pid).unwrap_or(t.pti_resident_size), ), None => (0, 0), } } +/// Its physical footprint, what Activity Monitor shows as its memory: its +/// own pages, without the shared libraries the resident set counts again +/// with every process of a tree. +fn phys_footprint(pid: c_int) -> Option { + // SAFETY: a zeroed plain-data struct, passed for the flavor that fills + // exactly one. + unsafe { + let mut info: libc::rusage_info_v2 = mem::zeroed(); + let ok = libc::proc_pid_rusage( + pid, + libc::RUSAGE_INFO_V2, + (&raw mut info).cast::(), + ); + (ok == 0).then_some(info.ri_phys_footprint) + } +} + /// macOS has no parent-death signal: a thread asks `getppid()` every 500 ms /// and sends `signal` to this process once the parent changed (the shim /// then belongs to launchd). @@ -346,10 +363,15 @@ mod tests { /// Apple silicon. Other tests run in this process meanwhile: only the /// lower bound is tight. #[test] - fn cpu_time_and_resident_set_are_in_microseconds_and_bytes() { + fn cpu_time_and_footprint_are_in_microseconds_and_bytes() { let me = std::process::id(); - let (before, rss) = process_usage(me); - assert!(rss >= 1 << 20, "{rss}"); + let (before, footprint) = process_usage(me); + assert!(footprint >= 1 << 20, "{footprint}"); + assert_eq!( + phys_footprint(me as i32), + Some(footprint), + "not the resident set" + ); let t0 = Instant::now(); let mut x = 0u64; while t0.elapsed() < Duration::from_millis(300) { diff --git a/crates/devstack-proc/src/windows.rs b/crates/devstack-proc/src/windows.rs index cbccf5de..b67763cb 100644 --- a/crates/devstack-proc/src/windows.rs +++ b/crates/devstack-proc/src/windows.rs @@ -118,7 +118,7 @@ impl Job { } /// Job accounting for CPU time (it includes exited processes), the summed - /// working sets of the live ones for memory. + /// private working sets of the live ones for memory. pub(crate) fn usage(&self) -> Usage { // SAFETY: valid job handle, correctly sized out struct. let cpu_us = unsafe { @@ -327,24 +327,42 @@ impl Tree { } } +/// The part of a process's working set no other process shares (what Task +/// Manager shows as memory): the shared pages, such as the .NET runtime's, +/// would count again with every process of a tree. A Windows without the +/// private figure (before Windows 10 21H2) gives the whole working set. fn working_set(pid: u32) -> u64 { use windows_sys::Win32::System::ProcessStatus::{ - K32GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS, + K32GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS, PROCESS_MEMORY_COUNTERS_EX2, }; use windows_sys::Win32::System::Threading::{ OpenProcess, PROCESS_QUERY_LIMITED_INFORMATION, PROCESS_VM_READ, }; - // SAFETY: plain Win32 calls; handle checked and closed. + // SAFETY: plain Win32 calls; handle checked and closed; each struct is + // passed with its own size, which tells the call how much it may fill. unsafe { let h = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_VM_READ, 0, pid); if h.is_null() { return 0; } - let mut c: PROCESS_MEMORY_COUNTERS = mem::zeroed(); - c.cb = mem::size_of::() as u32; - let ok = K32GetProcessMemoryInfo(h, &mut c, c.cb); + let mut x: PROCESS_MEMORY_COUNTERS_EX2 = mem::zeroed(); + x.cb = mem::size_of::() as u32; + let bytes = + if K32GetProcessMemoryInfo(h, &mut x as *mut _ as *mut PROCESS_MEMORY_COUNTERS, x.cb) + != 0 + { + x.PrivateWorkingSetSize as u64 + } else { + let mut c: PROCESS_MEMORY_COUNTERS = mem::zeroed(); + c.cb = mem::size_of::() as u32; + if K32GetProcessMemoryInfo(h, &mut c, c.cb) == 0 { + 0 + } else { + c.WorkingSetSize as u64 + } + }; CloseHandle(h); - if ok == 0 { 0 } else { c.WorkingSetSize as u64 } + bytes } } @@ -630,6 +648,30 @@ pub(crate) fn cpu_times() -> Option<(u64, u64)> { #[cfg(test)] mod tests { + #[test] + fn a_process_counts_its_private_working_set() { + use windows_sys::Win32::System::ProcessStatus::{ + K32GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS, + }; + use windows_sys::Win32::System::Threading::GetCurrentProcess; + let private = super::working_set(std::process::id()); + // SAFETY: the pseudo handle of this process, a struct of the size given. + let whole = unsafe { + let mut c: PROCESS_MEMORY_COUNTERS = std::mem::zeroed(); + c.cb = std::mem::size_of::() as u32; + assert_ne!( + K32GetProcessMemoryInfo(GetCurrentProcess(), &mut c, c.cb), + 0 + ); + c.WorkingSetSize as u64 + }; + // Its DLLs are shared with every other process: the private part is less. + assert!( + private > 0 && private < whole, + "private {private}, whole {whole}" + ); + } + #[test] fn a_job_with_more_processes_than_room_lists_them_all() { let job = super::Job::new().unwrap(); diff --git a/docs/adr/0119-a-lanes-memory-counts-what-it-owns-and-names-its-builds.md b/docs/adr/0119-a-lanes-memory-counts-what-it-owns-and-names-its-builds.md new file mode 100644 index 00000000..14efa2f9 --- /dev/null +++ b/docs/adr/0119-a-lanes-memory-counts-what-it-owns-and-names-its-builds.md @@ -0,0 +1,68 @@ +# ADR-0119: A lane's memory counts what it owns and names its builds; main is stopped when only what serves its lanes runs + +- **Status:** Accepted (card in the pull request); points 1, 2 and 4 built, point 3 follows +- **Date:** 2026-11-24 +- **Deciders:** project owner +- **Related:** [ADR-0009](0009-the-daemon-owns-every-process-tree.md) (process trees), [ADR-0020](0020-builds-share-one-long-lived-build-job.md) (the build job, its servers stay warm), [ADR-0049](0049-a-lanes-need-is-measured-disk-included.md) (a lane's need), [ADR-0080](0080-the-main-tree-answers-as-a-lane-shared-is-deprecated.md) (`singleton`), [ADR-0095](0095-the-daemon-ends-with-the-last-tree.md) (main stops alone), [ADR-0070](0070-a-review-card-comes-before-the-code-an-adr-records-what-was-built.md) + +## Context + +A lane of a .NET and Angular stack on a pool node showed 21.2 GB in the +dashboard. Its groups added up to 11.6 GB. The rest was the build job: 51 +MSBuild worker nodes from three rounds of parallel builds on a 24-core node, +kept warm on purpose (ADR-0020), counted in the lane but in no group. The +numbers were also too high: on Linux without a cgroup per service the daemon +summed each process's resident set, so the .NET runtime's shared pages +counted once per process (the build servers: 9.3 GB resident, 5.8 GB +proportional). The pool took the same numbers as the lane's need (25.4 GB). + +Stopping the main working tree while that lane ran looked as if it did +nothing: the stop kept `companion` (a `singleton`) for the lane, as it +should, but the dashboard still showed main as running, with its Stop +button, so it was pressed three times. + +## Decision + +The owner approved the points in the conversation on **2026-11-24**, all +four: + +| # | Category | Point | Beats | Reversing costs | +|---|---|---|---|---| +| 1 | contract | A native service's memory is what its processes own: Linux the proportional set (`Pss` of `smaps_rollup`) instead of the resident set, Windows the private working set instead of the whole, macOS `phys_footprint` instead of `resident_size` (untested here: CI only). | The sum counting shared pages, such as the .NET runtime's, again with every process. | Low; the numbers in telemetry and the stored needs drop once, the old ones leave after five runs. | +| 2 | term | "Builds" is a part of its own: the lane card says "of it builds X", the overview lists *Builds* beside the groups, so the sum adds up. | 10 GB in no group, the lane's number not explained. | Low, dashboard only. | +| 3 | contract | The need a lane reports to the pool names its builds apart (services and containers plus builds); placement still takes the sum, the log names the builds' part. | Needs like 25.4 GB nobody can explain; the build servers stay in the need, they take the node's memory until MSBuild ends them. | Medium: a field through node, coordinator and hub; older nodes leave it out. | +| 4 | term | Main counts as stopped when only what it keeps for running lanes runs: its state says so, the button is Start again, the stop's message names what keeps running. | A stop that looks as if it did nothing. | Low: one rule in the dashboard, which reads `kept`. | + +Decided while building, not on the card: with a cgroup per service (Linux, +delegated) the memory is `memory.current` less the cgroup's `inactive_file`, +as `docker stats` counts a container; a process whose `smaps_rollup` cannot +be read (another user's) falls back to its resident set, a Windows without +the private figure (before Windows 10 21H2) to the whole working set; a +container a kept `singleton` comes `after` still counts as main running; +point 3 comes in a pull request of its own, since the node measures a lane +as one container and has to ask the lane's daemon for its builds. + +As built (points 1, 2 and 4): + +1. **The measurement.** `devstack-proc`: `linux.rs` reads `Pss:` through + `kb_field` (shared with `meminfo`) and subtracts `inactive_file` from a + cgroup's `memory.current`; `windows.rs` asks `K32GetProcessMemoryInfo` + for `PROCESS_MEMORY_COUNTERS_EX2` and takes `PrivateWorkingSetSize`; + `macos.rs` takes `ri_phys_footprint` of `proc_pid_rusage`. Tests per + platform: the private part is below the whole and above zero. +2. **Builds in the dashboard.** `LaneUsage` takes `builds` (the report's + build job) and says "of it builds"; the overview shows a *Builds* row + with its processes and load below the groups while it takes memory. The + mock hub keeps its build servers warm after a build, as the daemon does. +3. **Main stopped.** The store's `mainActive` and `mainIdle` leave out a + `singleton` while a lane runs; the stop's toast reads `kept`, + `containers` and `lanes` of the daemon's `200`; the stack page's + "main stopped" names what keeps running. + +## Consequences + +- The memory devstack shows falls for every stack with several processes + per service, most for .NET; a pool's stored needs follow after five runs. +- The build servers are still counted, now where one sees them; ending them + sooner (fewer MSBuild nodes per build) is the user's build command's + choice, not devstack's. diff --git a/docs/adr/README.md b/docs/adr/README.md index e2fa8269..5de4556e 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -201,3 +201,4 @@ stay. | [0116](0116-admins-see-a-machine-that-asks-to-run-lanes.md) | Admins see a machine that asks to run lanes, and are told when one starts | Accepted (card in the pull request); built | | [0117](0117-the-dashboard-pushes-a-branch-that-is-ahead-of-its-upstream.md) | The dashboard pushes a branch that is ahead of its upstream, and the start page shows how far each stack is | Accepted (card in the pull request); built | | [0118](0118-lane-list-says-which-lanes-are-done.md) | `lane list` says which lanes are done, and devstack removes none of them | Accepted (card in the pull request); built; amended 2026-11-23 (`new`, no command for a name a shell reads) | +| [0119](0119-a-lanes-memory-counts-what-it-owns-and-names-its-builds.md) | A lane's memory counts what it owns and names its builds; main is stopped when only what serves its lanes runs | Accepted (card in the pull request); points 1, 2, 4 built, point 3 follows | diff --git a/docs/plan.md b/docs/plan.md index e2572b8c..315bafee 100644 --- a/docs/plan.md +++ b/docs/plan.md @@ -1286,7 +1286,7 @@ second worktree runs. | Measure | Native processes | Containers | |---|---|---| | CPU (% of one core, and total CPU time) | Windows: job accounting of the service's job; Linux: the service's cgroup (`cpu.stat`), else the sum over its process group | `docker stats` of the Compose services | -| Memory (working set / RSS) | Windows: sum over the job's processes; Linux: cgroup `memory.current`, else sum over the process group | `docker stats` | +| Memory (what a process does not share, ADR-0119) | Windows: the private working sets summed over the job's processes; Linux: cgroup `memory.current` less `inactive_file`, else the proportional sets (`Pss`) summed over the process group; macOS: the physical footprints summed | `docker stats` | | Processes | job / cgroup membership (ADR-0009) | — | | Disk | per lane: snapshot, artifacts, logs under `.devstack/` | named volumes of the Compose project (`docker system df -v`), sampled rarely | @@ -1306,8 +1306,8 @@ second worktree runs. per native sample, `devstack top [--watch]`; the dashboard follows in phase 2. Known limits of the numbers: -- Windows memory is the summed working set, so pages shared between the tree's - processes count more than once. +- Windows memory was the summed working set, so pages shared between the tree's + processes counted more than once; since ADR-0119 it is the private part. - Linux without a writable cgroup sums CPU time over the live processes; it can drop when a process exits, which the sampler reads as "no rate this round". Builds on such a host are not measured (they have no common cgroup). diff --git a/ui/src/api/mock/stack.ts b/ui/src/api/mock/stack.ts index 344844be..37cad279 100644 --- a/ui/src/api/mock/stack.ts +++ b/ui/src/api/mock/stack.ts @@ -432,8 +432,12 @@ export class MockStack { return { group: g.group, service: c.service, ...l }; }), ); + // Its build servers stay warm after a build (ADR-0020): memory without CPU. const bw = this.walk('builds', 220, 950e6); - const builds = { name: 'builds' as const, ...this.step(bw, this.buildsActive > 0), cpu_time_ms: 0, processes: this.buildsActive > 0 ? 7 : 0 }; + const building = this.buildsActive > 0; + const warm = this.entry.running; + const b = this.step(bw, building || warm); + const builds = { name: 'builds' as const, cpu: building ? b.cpu : 0, memory: b.memory, cpu_time_ms: 0, processes: building ? 7 : warm ? 4 : 0 }; const groups = this.view.groups.map((g) => { let cpu = 0; let memory = 0; diff --git a/ui/src/components/LaneUsage.vue b/ui/src/components/LaneUsage.vue index 1454d3fc..939d750a 100644 --- a/ui/src/components/LaneUsage.vue +++ b/ui/src/components/LaneUsage.vue @@ -9,8 +9,10 @@ import Sparkline from '@/components/Sparkline.vue'; import Icon from '@/components/icons/Icon.vue'; // `title`: the lane as the page names it. A lane on a node reports from its -// own daemon there, to which it is the main tree (`main`). -defineProps<{ lane: Lane; link?: boolean; title?: string }>(); +// own daemon there, to which it is the main tree (`main`). `builds`: the +// memory of its build job, part of `lane.memory` (its build servers stay +// warm after a build, ADR-0020): said, so the lane's number adds up. +defineProps<{ lane: Lane; link?: boolean; title?: string; builds?: number }>(); const stack = useStack(); @@ -86,6 +88,13 @@ function diskTotal(d: LaneDisk) { Memory {{ bytes(lane.memory) }} + of it builds {{ bytes(builds) }}
@@ -168,6 +177,10 @@ function diskTotal(d: LaneDisk) { line-height: 1.2; margin-bottom: 4px; } +.part { + font-size: 12px; + color: var(--text-muted); +} .bar { display: flex; height: 10px; diff --git a/ui/src/stores/stack.ts b/ui/src/stores/stack.ts index 7eff5183..7523eec8 100644 --- a/ui/src/stores/stack.ts +++ b/ui/src/stores/stack.ts @@ -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) === 'idle'), + () => running.value && lane.value === null && live.value && services.value.length > 0 && services.value.every((s) => statusBucket(s) === 'idle' || keptForLanes(s)), ); /** @@ -343,14 +343,22 @@ export const useStack = defineStore('stack', () => { } } /** - * Whether the main working tree runs something: its services, or with - * none its containers. Not known yet: it does while the daemon runs. + * A service that runs only because lanes do: a `singleton` the main tree's + * stop keeps for them (ADR-0080, the daemon's `down` names it in `kept`). + */ + function keptForLanes(s: ServiceView) { + return !!s.singleton && runningLanes.value.length > 0; + } + /** + * Whether the main working tree runs something: its services (not those + * it keeps for its lanes), or with none its containers. Not known yet: it + * does while the daemon runs. */ const mainActive = computed(() => { if (!running.value) return false; const mv = mainView.value; if (!mv) return true; - if (mv.services.length) return mv.services.some((x) => statusBucket(x) !== 'idle'); + if (mv.services.length) return mv.services.some((x) => statusBucket(x) !== 'idle' && !keptForLanes(x)); const containers = mv.infra.flatMap((g) => g.containers).filter((c) => c.managed !== false); return !containers.length || containers.some((c) => c.state === 'running'); }); @@ -610,7 +618,17 @@ export const useStack = defineStore('stack', () => { endStart(id.value, MAIN); const unmark = mark('lane-stop', MAIN); try { - await act({ label: 'Stop main', path: paths.api(id.value, v1.downTree), success: 'main stopped' }); + // While lanes run, the daemon keeps what serves them and says so (200). + await act<{ lanes?: string[]; kept?: string[]; containers?: string[] }>({ + label: 'Stop main', + path: paths.api(id.value, v1.downTree), + success: (b) => { + const kept = [...(b?.kept ?? []), ...(b?.containers ?? [])]; + if (!kept.length) return 'main stopped'; + const lanes = b?.lanes?.length ? `lane${b.lanes.length > 1 ? 's' : ''} ${b.lanes.join(', ')}` : 'its lanes'; + return `main stopped; ${kept.join(', ')} keep${kept.length > 1 ? '' : 's'} running for ${lanes}`; + }, + }); } finally { unmark(); } diff --git a/ui/src/stores/stores.test.ts b/ui/src/stores/stores.test.ts index d5c715f3..b1fc10c3 100644 --- a/ui/src/stores/stores.test.ts +++ b/ui/src/stores/stores.test.ts @@ -565,6 +565,26 @@ describe('stack store', () => { expect(stack.shownLane?.active).toBe(false); }); + it('is stopped when only what it keeps for its lanes runs, and its stop says what that is', async () => { + const stack = await shownStack(); + const events = fake.stream('/hub/stacks/shop/api/v1/events'); + const tray = { ...svc('tray', 'running'), singleton: true }; + events.handlers.onMessage({ type: 'snapshot', stack: view([svc('api', 'stopped'), tray]) } as never); + // No lane runs: the singleton is main's own. + events.handlers.onMessage({ type: 'lanes', lanes: [] }); + expect(stack.mainActive).toBe(true); + // A lane runs: main's stop kept it for the lane, main is stopped. + events.handlers.onMessage({ type: 'lanes', lanes: [feat] }); + expect(stack.mainActive).toBe(false); + expect(stack.mainLane?.active).toBe(false); + // Another of its services runs: it runs. + events.handlers.onMessage({ type: 'snapshot', stack: view([svc('api', 'healthy'), tray]) } as never); + expect(stack.mainActive).toBe(true); + fake.on('/hub/stacks/shop/api/v1/down?infra=true', ok({ lanes: ['feat'], kept: ['tray'], containers: [] })); + await stack.laneAction(stack.mainLane!, 'stop'); + expect(useUi().toasts.map((t) => t.title)).toContain('main stopped; tray keeps running for lane feat'); + }); + it('starts with its up and stops with its down, the daemon and the lanes kept', async () => { const stack = await shownStack(); fake.on('/hub/stacks/shop/api/v1/up', { status: 202, ok: true, body: null }); diff --git a/ui/src/views/OverviewHome.vue b/ui/src/views/OverviewHome.vue index 5ab4604c..daee20df 100644 --- a/ui/src/views/OverviewHome.vue +++ b/ui/src/views/OverviewHome.vue @@ -64,7 +64,7 @@ async function repairAll() {

{{ inFlight }} change{{ inFlight === 1 ? '' : 's' }} on the way; the running instances keep serving until the new builds are healthy.

- +
diff --git a/ui/src/views/OverviewView.vue b/ui/src/views/OverviewView.vue index 53722b87..dac5971b 100644 --- a/ui/src/views/OverviewView.vue +++ b/ui/src/views/OverviewView.vue @@ -110,6 +110,11 @@ function fold(key: string) { function groupLoad(key: string) { return stack.usage?.groups.find((g) => g.name === key) ?? null; } +/** The build job while it takes memory: its servers stay after a build. */ +const builds = computed(() => { + const b = stack.usage?.builds; + return b && b.memory > 0 ? b : null; +}); // A job that runs is neither healthy (#591) nor starting: it may run for hours (#611). const filterLabel: Record = { healthy: 'healthy', starting: 'starting', job: 'running as a job', failed: 'failing', idle: 'stopped or done', pending: 'not live yet' }; @@ -241,6 +246,18 @@ onBeforeUnmount(() => window.removeEventListener('keydown', onKey)); + +
+
+ + +

Builds

+ {{ builds.processes }} +
+ +
+
+
@@ -487,6 +504,10 @@ onBeforeUnmount(() => window.removeEventListener('keydown', onKey)); .fold h2 { margin: 0; } +.fold.static { + cursor: default; + padding-left: 22px; +} .section.folded .section-head { border-bottom: 0; } diff --git a/ui/src/views/StackPage.vue b/ui/src/views/StackPage.vue index 74989a72..76a110d0 100644 --- a/ui/src/views/StackPage.vue +++ b/ui/src/views/StackPage.vue @@ -17,7 +17,7 @@ import { ago, bytes, clock, duration, percent, useNow } from '@/lib/format'; import { journalLabel, viaText } from '@/lib/journal'; import { laneLabel, lastTab, MAIN, nodeLabel, started } from '@/lib/lanes'; import { laneView } from '@/lib/stackRoutes'; -import { statusLook } from '@/lib/status'; +import { statusBucket, statusLook } from '@/lib/status'; import { useHub } from '@/stores/hub'; import { useStack } from '@/stores/stack'; import { SHIFT_SKIP_HINT } from '@/stores/ui'; @@ -79,7 +79,14 @@ const state = computed(() => { const mainState = computed(() => { if (!stack.running || hubDown.value) return null; const profile = stack.mainView?.profile; - if (!stack.mainActive) return { tone: '', label: 'main stopped', title: 'The main working tree runs nothing; the daemon runs for its lanes. Its start card chooses a profile.' }; + if (!stack.mainActive) { + const kept = (stack.mainView?.services ?? []).filter((s) => s.singleton && statusBucket(s) !== 'idle').map((s) => s.name); + return { + tone: '', + label: 'main stopped', + title: `The main working tree runs nothing; the daemon runs for its lanes${kept.length ? `, and so ${kept.length > 1 ? 'do' : 'does'} ${kept.join(', ')}, which ${kept.length > 1 ? 'serve' : 'serves'} them` : ''}. Its start card chooses a profile.`, + }; + } return { tone: 'ok', label: profile ? `main runs · ${profile}` : 'main runs', diff --git a/ui/src/views/UsageView.vue b/ui/src/views/UsageView.vue index 50277036..dc95f44f 100644 --- a/ui/src/views/UsageView.vue +++ b/ui/src/views/UsageView.vue @@ -82,7 +82,7 @@ const filters: { v: 'all' | Kind; label: string }[] = [