Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude/skills/devstack/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Run from the repository root (devstack looks for `devstack.toml` there; `-f` oth
| `devstack hot-reload <service> 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 <path> -b <branch>` | 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 <name>` 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 <name>` removes the link) or remove only the link (`cmd /c rmdir <dir>` on Windows, without `/s`; `rm <dir>` 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 <name>` removes the link) or remove only the link (`cmd /c rmdir <dir>` on Windows, without `/s`; `rm <dir>` 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 <name> [--on <node>]` | 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 <dir> <commit>`, `devstack lane start <name>` (its ports are the main ports plus its offset, `devstack lane list`), test against those, `devstack lane stop <name>`, `git worktree remove <dir>`. 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 <name> --profile <p> --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 <name>` / `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 <name>` | 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) |
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
104 changes: 100 additions & 4 deletions crates/devstack-daemon/src/supervisor/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf> = 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,
Expand All @@ -66,6 +83,7 @@ impl Supervisor {
run: p.run.clone(),
store: self.store_use(name, p, snap),
before_run: None,
counted,
}))
}

Expand Down Expand Up @@ -583,10 +601,14 @@ impl Supervisor {
.iter()
.any(|rel| links_to(&worktree.join(rel), &roots[i].join(rel)))
});
let counted =
|i: usize| -> Vec<PathBuf> { 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
Expand Down Expand Up @@ -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)",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<Box<dyn Fn() -> 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<PathBuf>,
}

impl PrepareJob {
Expand All @@ -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).
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()],
Expand Down
44 changes: 43 additions & 1 deletion crates/devstack/src/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,40 @@ fn docker(needed: Option<bool>) -> Vec<Finding> {
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<Finding> {
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<u64>) -> 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);
Expand Down Expand Up @@ -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!(
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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/<service>.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.
Expand Down
2 changes: 1 addition & 1 deletion docs/adr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
5 changes: 4 additions & 1 deletion docs/stack-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Loading
Loading