diff --git a/.claude/skills/devstack/SKILL.md b/.claude/skills/devstack/SKILL.md index 7ede9df7..3ee0295d 100644 --- a/.claude/skills/devstack/SKILL.md +++ b/.claude/skills/devstack/SKILL.md @@ -57,7 +57,7 @@ Run from the repository root (devstack looks for `devstack.toml` there; `-f` oth | `devstack hot-reload on\|off` | for a debugging session: the toolchain's watcher (e.g. `dotnet watch`) from the source tree instead of builds and candidates; needs `hot_reload` in the stack file. Switch it off again afterwards | | `devstack up` in a `git worktree` | starts that worktree's **lane** (every worktree is one) in the main tree's daemon: its own builds, ports moved by +100 (+200, ...), its own containers (a Compose project per lane, ports moved alike; `shared` services come from the main tree), no background workers (`--workers` turns them on; `--force` skips the memory check). Every command in the worktree then acts on the lane (`devstack lane list` shows all) | | `git worktree add -b ` | a new worktree is a lane at once, not started (devstack never creates or removes worktrees; use git or your tool); tell the user its dashboard page (`devstack ui --link` in it). A lane runs from a copy of its worktree, so `git worktree remove` works while it runs and stops it. `devstack lane stop ` stops a lane and keeps the worktree | -| a directory in a worktree that `prepare` links (`node_modules`, see `devstack lane list`: `linked`) | it is **the lane's copy**, not the worktree's own: on Windows a junction, which looks like a folder. Do not reinstall, delete or clean it there (`npm ci`, `rm -rf`, `git clean -x`, an IDE's "delete node_modules"): that empties what the lane runs from (for a lane on a node, its copy from the store), and a running dev server then fails. To install your own, ask the user, then stop the lane (`devstack lane stop ` removes the link) or remove only the link (`cmd /c rmdir ` on Windows, without `/s`; `rm ` elsewhere, no trailing slash), then install | +| a directory in a worktree that `prepare` links (`node_modules`, see `devstack lane list`: `linked`) | it is **the lane's copy**, not the worktree's own: on Windows a junction, which looks like a folder. Do not reinstall, delete or clean it there (`npm ci`, `rm -rf`, `git clean -x`, an IDE's "delete node_modules"): that empties what the lane runs from (for a lane on a node, its copy from the store), and a running dev server then fails. To install your own, ask the user, then stop the lane (`devstack lane stop ` removes the link) or remove only the link (`cmd /c rmdir ` on Windows, without `/s`; `rm ` elsewhere, no trailing slash), then install. devstack prepares a copy emptied this way again (a notice says so), but the lane's dev server fails until then | | `devstack lane start [--on ]` | start a lane from the main tree (or anywhere in the repository), as `devstack up` in its worktree does; `status` in the main tree lists the lanes in one line. **To run another branch or commit beside the main stack** (an end-to-end run against a given commit, a review): `git worktree add `, `devstack lane start ` (its ports are the main ports plus its offset, `devstack lane list`), test against those, `devstack lane stop `, `git worktree remove `. A commit without a stack file of its own runs with the main tree's. **For an acceptance run** use the stack file's profile if it has one (`status` lists none; `[profiles]` in the file): `devstack lane start --profile

--run` starts the lane as the profile says (a build instead of a dev server, workers, fresh data, the suite's env) and runs its suite command. A worktree another tool or script created is a lane too: starting it gives its own ports, containers and database without building a separate environment | | `devstack lane reset ` / `devstack lane prune [--older-than 7d] [--dry-run]` | throw a stopped lane's data away (it starts fresh, seeded again); remove what lanes whose worktree is gone left behind, here and on the pool's nodes. A lane on a node keeps its data there between starts. Ask the user before either: data goes | | `devstack promote --lane ` | the lane's services, dev servers included, answer on the main ports; ask the user first, `--lane main` gives them back. A lane on a node may take them only on a dedicated node (a server) | diff --git a/CHANGELOG.md b/CHANGELOG.md index 424acd2e..ff9ff64a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ and listed with their assets on the a lane that did not fit there started and the engine hung. The containers' part is now checked against what is free in the VM, the services' part against the host, and the refusal names the limit. + `devstack doctor` shows the VM's memory, what the running containers + use of it and the host's free memory. - **A refused start on the pool says how to go on** (#310): the error now names `devstack pool placement`, another node and `devstack up --on local`, and when the pool is the machine's default, that running here is @@ -26,7 +28,11 @@ and listed with their assets on the - **The skills warn about a linked `node_modules`** (#311): a directory `prepare.link` puts in a worktree is the lane's copy; reinstalling or deleting it there empties what the lane runs from. The `devstack` and - `devstack-config` skills say so and how to get one's own. + `devstack-config` skills say so and how to get one's own. devstack + counts the entries of a linked directory once prepared; one that lost + more than a tenth of them is prepared again (a local lane at its + service's next start, with a notice and `prepare_copy_emptied` in the + log; a lane on a node at the next look, into its other copy). - **The upgrade prompt checks the version and asks before a restart** (#312): it starts with `devstack --version`, and before restarting the stack it has the agent look for lanes and other sessions and ask; the diff --git a/crates/devstack-daemon/src/supervisor/copy.rs b/crates/devstack-daemon/src/supervisor/copy.rs index cc6ed01d..0b47780a 100644 --- a/crates/devstack-daemon/src/supervisor/copy.rs +++ b/crates/devstack-daemon/src/supervisor/copy.rs @@ -56,8 +56,25 @@ impl Supervisor { // the link into it, ADR-0044) is prepared again. let linked_there = !self.links_prepared() || p.link.iter().all(|l| snap.dir.join(l).is_dir()); + let counted: Vec = p.link.iter().map(|l| snap.dir.join(l)).collect(); if linked_there && std::fs::read_to_string(&mark).is_ok_and(|k| k == key) { - return Ok(None); + // Emptied through the worktree's link (an `npm ci` there, #311): + // prepared again, and said so. + let Some((rel, now, then)) = emptied(&mark, &counted, &p.link) else { + return Ok(None); + }; + crate::diag::warn( + "prepare_copy_emptied", + serde_json::json!({ "lane": self.lane, "service": name, "path": rel, + "entries": now, "prepared_with": then }), + ); + self.set_notice( + &format!("prepare.emptied.{name}"), + NoticeLevel::Warn, + format!( + "`{rel}` of {name} had lost what `prepare` made ({now} of {then} entries): something emptied it, likely a reinstall through the worktree's link. It is prepared again; leave a linked directory alone in the worktree." + ), + ); } Ok(Some(PrepareJob { key, @@ -66,6 +83,7 @@ impl Supervisor { run: p.run.clone(), store: self.store_use(name, p, snap), before_run: None, + counted, })) } @@ -583,10 +601,14 @@ impl Supervisor { .iter() .any(|rel| links_to(&worktree.join(rel), &roots[i].join(rel))) }); + let counted = + |i: usize| -> Vec { p.link.iter().map(|l| roots[i].join(l)).collect() }; let ready = |i: usize| { + let mark = copies[i].join("prepared").join(name); p.link.iter().all(|l| roots[i].join(l).is_dir()) - && std::fs::read_to_string(copies[i].join("prepared").join(name)) - .is_ok_and(|k| k == key) + && std::fs::read_to_string(&mark).is_ok_and(|k| k == key) + // Emptied through the worktree's link (#311): not ready. + && emptied(&mark, &counted(i), &p.link).is_none() }; let mut state = "linked"; let to = match current @@ -630,6 +652,7 @@ impl Supervisor { .map(|_| ()) .map_err(|e| e.to_string()) })), + counted: counted(to), }; match self.run_prepare(name, job, cancel) { Ok(v) if v.source == "store" => state = "linked (store)", @@ -712,6 +735,7 @@ impl Supervisor { version: p.version.clone(), }), before_run: Some(complete), + counted: Vec::new(), }; let key = match self.store_key(name, &job, cancel)? { Ok(k) => k, @@ -911,6 +935,9 @@ pub(super) struct PrepareJob { /// worktree linked for a lane on a node gets its source only when it /// has to prepare (ADR-0063). before_run: Option Result<(), String> + Send>>, + /// The directories whose entries are counted beside the mark (#311): + /// those linked into the worktree, where a reinstall can empty them. + counted: Vec, } impl PrepareJob { @@ -919,10 +946,43 @@ impl PrepareJob { if let Some(parent) = self.mark.parent() { std::fs::create_dir_all(parent).map_err(|e| e.to_string())?; } - std::fs::write(&self.mark, &self.key).map_err(|e| e.to_string()) + std::fs::write(&self.mark, &self.key).map_err(|e| e.to_string())?; + let counts: String = self + .counted + .iter() + .map(|d| format!("{}\n", entries(d))) + .collect(); + std::fs::write(entries_file(&self.mark), counts).map_err(|e| e.to_string()) } } +/// Beside a mark: the entries each counted directory had once prepared. +fn entries_file(mark: &Path) -> PathBuf { + let mut s = mark.as_os_str().to_owned(); + s.push(".entries"); + s.into() +} + +/// The entries right in `dir` (a `node_modules`' packages and scopes). +fn entries(dir: &Path) -> usize { + std::fs::read_dir(dir).map_or(0, |r| r.count()) +} + +/// The first of `dirs` (named `rels`) that has lost more than a tenth of +/// the entries it had when it was prepared, with now and then (#311); none +/// when nothing was counted (a mark from before). +fn emptied(mark: &Path, dirs: &[PathBuf], rels: &[String]) -> Option<(String, usize, usize)> { + let text = std::fs::read_to_string(entries_file(mark)).ok()?; + dirs.iter() + .zip(rels) + .zip(text.lines()) + .find_map(|((dir, rel), then)| { + let then: usize = then.trim().parse().ok()?; + let now = entries(dir); + (now * 10 < then * 9).then(|| (rel.clone(), now, then)) + }) +} + /// The key of `prepare` `p` of `svc` over the files of a copy (path, blake3 /// of the content): its command, its directory and the files of `inputs` /// (ADR-0002's way: what changes it, nothing else). @@ -1327,6 +1387,41 @@ mod tests { assert!(git_ignores(&repo, "web/node_modules")); } + #[test] + fn a_copy_emptied_through_its_link_is_noticed() { + let d = tempfile::tempdir().unwrap(); + let deps = d.path().join("copy/node_modules"); + for i in 0..10 { + std::fs::create_dir_all(deps.join(format!("pkg{i}"))).unwrap(); + } + let mark = d.path().join("prepared/web"); + let rels = ["web/node_modules".to_string()]; + // A mark from before counted nothing: no check. + assert_eq!(emptied(&mark, std::slice::from_ref(&deps), &rels), None); + PrepareJob { + key: "k".into(), + mark: mark.clone(), + cwd: d.path().into(), + run: "x".into(), + store: Err(None), + before_run: None, + counted: vec![deps.clone()], + } + .done() + .unwrap(); + assert_eq!(emptied(&mark, std::slice::from_ref(&deps), &rels), None); + // One package less is a tool's doing; most of them gone is not. + std::fs::remove_dir(deps.join("pkg0")).unwrap(); + assert_eq!(emptied(&mark, std::slice::from_ref(&deps), &rels), None); + for i in 1..8 { + std::fs::remove_dir(deps.join(format!("pkg{i}"))).unwrap(); + } + assert_eq!( + emptied(&mark, std::slice::from_ref(&deps), &rels), + Some(("web/node_modules".into(), 2, 10)) + ); + } + #[test] fn a_lane_on_a_node_gets_its_worktree_linked_to_a_copy_from_the_store() { let rt = tokio::runtime::Builder::new_current_thread() @@ -1705,6 +1800,7 @@ mod tests { mark: d.path().join("mark"), cwd: copy.clone(), run: "git --version".into(), + counted: Vec::new(), store: Ok(StoreUse { root: copy.clone(), outputs: vec!["deps".into()], diff --git a/crates/devstack/src/doctor.rs b/crates/devstack/src/doctor.rs index a21404c1..d35105a6 100644 --- a/crates/devstack/src/doctor.rs +++ b/crates/devstack/src/doctor.rs @@ -142,13 +142,40 @@ fn docker(needed: Option) -> Vec { MIN_COMPOSE.0, MIN_COMPOSE.1, MIN_COMPOSE.2 ), )], - _ => vec![f(Level::Ok, format!("Docker {version}, Compose {c}"))], + _ => { + let mut out = vec![f(Level::Ok, format!("Docker {version}, Compose {c}"))]; + out.extend(memory()); + out + } }, } } } } +/// Where a lane's containers take their memory (#309): Docker Desktop's VM +/// has a limit of its own, which the lane's memory check holds them to. +fn memory() -> Option { + let vm = devstack_compose::Docker::default().engine_memory()?; + Some(f( + Level::Info, + memory_text(vm, devstack_proc::memory_available()), + )) +} + +fn memory_text(vm: devstack_compose::EngineMemory, host_free: Option) -> String { + let gb = |b: u64| b as f64 / (1u64 << 30) as f64; + format!( + "Memory: containers run in Docker Desktop's VM, {:.1} GB, {:.1} GB of it used by the containers that run, {:.1} GB free; a lane's containers must fit there{} (raise the limit in Docker Desktop, or in `.wslconfig` for WSL 2)", + gb(vm.total), + gb(vm.used), + gb(vm.total.saturating_sub(vm.used)), + host_free + .map(|h| format!(", its services on the host ({:.1} GB free)", gb(h))) + .unwrap_or_default() + ) +} + /// How long a version query of another tool may take: a hanging Docker CLI /// must not hang `doctor` (and the MCP tool of the same name). const TOOL_TIMEOUT: Duration = Duration::from_secs(15); @@ -488,6 +515,21 @@ pub fn text(findings: &[Finding]) -> String { mod tests { use super::*; + #[test] + fn the_memory_line_names_docker_desktops_vm() { + const GB: u64 = 1 << 30; + let vm = devstack_compose::EngineMemory { + total: 31 * GB, + used: 20 * GB, + }; + let t = memory_text(vm, Some(36 * GB)); + assert!( + t.contains("31.0 GB") && t.contains("11.0 GB free") && t.contains("36.0 GB free"), + "{t}" + ); + assert!(!memory_text(vm, None).contains("host")); + } + #[test] fn the_program_of_a_command_line() { assert_eq!( diff --git a/docs/adr/0063-a-lane-on-a-node-links-its-worktree-to-a-copy-from-the-local-store.md b/docs/adr/0063-a-lane-on-a-node-links-its-worktree-to-a-copy-from-the-local-store.md index 073f2f11..ce586a40 100644 --- a/docs/adr/0063-a-lane-on-a-node-links-its-worktree-to-a-copy-from-the-local-store.md +++ b/docs/adr/0063-a-lane-on-a-node-links-its-worktree-to-a-copy-from-the-local-store.md @@ -1,6 +1,6 @@ # ADR-0063: A lane on a node links its worktree to a copy from the local store -- **Status:** Accepted (2026-10-26); built, noted 2026-10-26; addendum 2026-10-27 (two copies: new inputs are prepared beside the one the worktree has) +- **Status:** Accepted (2026-10-26); built, noted 2026-10-26; addendum 2026-10-27 (two copies: new inputs are prepared beside the one the worktree has; an emptied copy is prepared again) - **Date:** 2026-10-26 - **Deciders:** project owner - **Related:** [#277](https://github.com/nuetzliches/devstack/issues/277), [#159](https://github.com/nuetzliches/devstack/issues/159), [ADR-0044](0044-a-lanes-prepared-directories-can-be-linked-into-its-worktree.md) (point 5 replaced here for lanes on a node), [ADR-0062](0062-what-prepare-makes-is-kept-in-a-store-per-machine-and-repository-keyed-by-its-inputs.md), [ADR-0025](0025-a-lane-can-run-on-another-node.md), [ADR-0029](0029-source-sync-and-port-forwarding-for-remote-lanes.md) @@ -121,6 +121,14 @@ why; the next look tries again. Inputs that go back to those of the other copy only move the link. A failed `prepare` is logged (`prepare_failed`, with its log). The disk a lane's copies take doubles at most. +*Amended 2026-10-27 (#311):* a copy that is linked is also checked for +being whole. With its mark, each linked directory's entries are counted +(`prepared/.entries`); one that has lost more than a tenth of them +since (a reinstall through the worktree's link empties it) is no copy of +its key, so the next look prepares the other copy. A local lane's copy +(ADR-0044) is checked the same way before its service starts, prepared +again in place, and said in a notice. + ## What this ADR does not say - That the lane on the node uses this machine's store. It uses its node's. diff --git a/docs/adr/README.md b/docs/adr/README.md index ec387ca4..cf8b8ed6 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -111,7 +111,7 @@ stay. | [0060](0060-the-tray-is-a-client-of-the-hub.md) | The tray is a client of the hub, a process of its own, on every desktop | Accepted | | [0061](0061-the-dashboard-opens-in-its-installed-app.md) | The dashboard opens in its installed app, when there is one | Accepted | | [0062](0062-what-prepare-makes-is-kept-in-a-store-per-machine-and-repository-keyed-by-its-inputs.md) | What `prepare` makes is kept in a store per machine and repository, keyed by its inputs | Accepted; measured and built on the developer's machine, and on nodes, noted 2026-10-26 | -| [0063](0063-a-lane-on-a-node-links-its-worktree-to-a-copy-from-the-local-store.md) | A lane on a node links its worktree to a copy from the local store | Accepted; built, noted 2026-10-26; addendum 2026-10-27 (two copies, the link moves when the new one is whole) | +| [0063](0063-a-lane-on-a-node-links-its-worktree-to-a-copy-from-the-local-store.md) | A lane on a node links its worktree to a copy from the local store | Accepted; built, noted 2026-10-26; addendum 2026-10-27 (two copies, the link moves when the new one is whole; an emptied copy is prepared again) | | [0064](0064-every-compose-call-is-told-the-lane-it-runs-for.md) | Every Compose call is told the lane it runs for | Accepted; addendum 2026-10-26 (a lane on a node: native `{lane}`, `{lane_suffix}`, `DEVSTACK_LANE` follow its name) | | [0065](0065-the-store-is-warmed-for-a-ref-before-a-lane-needs-it.md) | The store is warmed for a ref before a lane needs it | Accepted; built, noted 2026-10-26 | | [0066](0066-a-measured-cpu-need-is-capped-at-half-of-what-its-node-gives-lanes.md) | A measured CPU need is capped at half of what its node gives lanes | Accepted | diff --git a/docs/stack-file.md b/docs/stack-file.md index ef610178..c38812d3 100644 --- a/docs/stack-file.md +++ b/docs/stack-file.md @@ -605,7 +605,10 @@ status` and the dashboard say per path `linked`, `linked (store)`, `preparing`, `linked (stale)` or `not linked` with why. New inputs are prepared in a second copy while the worktree keeps the one it has; the link moves once that copy is whole, and stays where it was when its `prepare` -fails (`linked (stale)`, with why). Without `outputs` it is not linked, and +fails (`linked (stale)`, with why). A linked directory that lost most of +what `prepare` made (a reinstall in the worktree goes through the link into +the lane's copy) is prepared again: for a lane here when its service next +starts, with a notice, for a lane on a node at the next look. Without `outputs` it is not linked, and says so. The links go when the lane stops on its node, moves or goes; the copy stays for its next start. diff --git a/skills/devstack/SKILL.md b/skills/devstack/SKILL.md index f42e961a..e05d5df9 100644 --- a/skills/devstack/SKILL.md +++ b/skills/devstack/SKILL.md @@ -57,7 +57,7 @@ Run from the repository root (devstack looks for `{{devstack:stack_file}}` there | `devstack hot-reload on\|off` | for a debugging session: the toolchain's watcher (e.g. `dotnet watch`) from the source tree instead of builds and candidates; needs `hot_reload` in the stack file. Switch it off again afterwards | | `devstack up` in a `git worktree` | starts that worktree's **lane** (every worktree is one) in the main tree's daemon: its own builds, ports moved by +100 (+200, ...), its own containers (a Compose project per lane, ports moved alike; `shared` services come from the main tree), no background workers (`--workers` turns them on; `--force` skips the memory check). Every command in the worktree then acts on the lane (`devstack lane list` shows all) | | `git worktree add -b ` | a new worktree is a lane at once, not started (devstack never creates or removes worktrees; use git or your tool); tell the user its dashboard page (`devstack ui --link` in it). A lane runs from a copy of its worktree, so `git worktree remove` works while it runs and stops it. `devstack lane stop ` stops a lane and keeps the worktree | -| a directory in a worktree that `prepare` links (`node_modules`, see `devstack lane list`: `linked`) | it is **the lane's copy**, not the worktree's own: on Windows a junction, which looks like a folder. Do not reinstall, delete or clean it there (`npm ci`, `rm -rf`, `git clean -x`, an IDE's "delete node_modules"): that empties what the lane runs from (for a lane on a node, its copy from the store), and a running dev server then fails. To install your own, ask the user, then stop the lane (`devstack lane stop ` removes the link) or remove only the link (`cmd /c rmdir

` on Windows, without `/s`; `rm ` elsewhere, no trailing slash), then install | +| a directory in a worktree that `prepare` links (`node_modules`, see `devstack lane list`: `linked`) | it is **the lane's copy**, not the worktree's own: on Windows a junction, which looks like a folder. Do not reinstall, delete or clean it there (`npm ci`, `rm -rf`, `git clean -x`, an IDE's "delete node_modules"): that empties what the lane runs from (for a lane on a node, its copy from the store), and a running dev server then fails. To install your own, ask the user, then stop the lane (`devstack lane stop ` removes the link) or remove only the link (`cmd /c rmdir ` on Windows, without `/s`; `rm ` elsewhere, no trailing slash), then install. devstack prepares a copy emptied this way again (a notice says so), but the lane's dev server fails until then | | `devstack lane start [--on ]` | start a lane from the main tree (or anywhere in the repository), as `devstack up` in its worktree does; `status` in the main tree lists the lanes in one line. **To run another branch or commit beside the main stack** (an end-to-end run against a given commit, a review): `git worktree add `, `devstack lane start ` (its ports are the main ports plus its offset, `devstack lane list`), test against those, `devstack lane stop `, `git worktree remove `. A commit without a stack file of its own runs with the main tree's. **For an acceptance run** use the stack file's profile if it has one (`status` lists none; `[profiles]` in the file): `devstack lane start --profile

--run` starts the lane as the profile says (a build instead of a dev server, workers, fresh data, the suite's env) and runs its suite command. A worktree another tool or script created is a lane too: starting it gives its own ports, containers and database without building a separate environment | | `devstack lane reset ` / `devstack lane prune [--older-than 7d] [--dry-run]` | throw a stopped lane's data away (it starts fresh, seeded again); remove what lanes whose worktree is gone left behind, here and on the pool's nodes. A lane on a node keeps its data there between starts. Ask the user before either: data goes | | `devstack promote --lane ` | the lane's services, dev servers included, answer on the main ports; ask the user first, `--lane main` gives them back. A lane on a node may take them only on a dedicated node (a server) |