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
3 changes: 3 additions & 0 deletions .claude/skills/devstack-config/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ without a stack file starts from `devstack init` (a draft with TODOs).
a `package.json` and no `prepare`). When git hooks need it (`npx eslint` in a
pre-commit hook), `prepare.link = ["web/node_modules"]` links it into the
worktree; `.gitignore` then needs `node_modules` without a trailing slash.
The linked directory is the lane's copy: reinstalling or deleting it in
the worktree empties what the lane runs from (say so in project notes
that tell agents to run `npm ci`).
Name what it makes as `outputs = ["web/node_modules"]` (and `version =
"node --version"`): the next lane with the same lockfile copies it from
the machine's store instead of running `npm ci` again. `link` must be
Expand Down
4 changes: 3 additions & 1 deletion .claude/skills/devstack/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +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 |
| `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 Expand Up @@ -180,7 +181,8 @@ Register it once (project `.mcp.json` or user configuration):
| dashboard: "runs devstack X, Y is installed" | the stack still runs the old daemon: "Restart stack" there, or `devstack down` + `devstack up` |
| a job `failed` after a long wait | jobs end after 30 minutes unless the stack file sets `timeout`; read its log, then ask the user before raising it (skill `devstack-config`) |
| `devstack down` names services that did not stop | they still run: `devstack status`, then `devstack stop <service>`; ask before ending a process yourself |
| `devstack up --on`: the node refuses the lane | the message names what the lane's Compose files ask that a node does not allow (privileged, host mounts, devices, build `tags`, a service key the node does not know, ...) or that the pool has not granted that node; the lane can still run here (`devstack up`) |
| `devstack up --on`: the node refuses the lane | the message names what the lane's Compose files ask that a node does not allow (privileged, host mounts, devices, build `tags`, a service key the node does not know, ...) or that the pool has not granted that node; the lane can still run on this machine with `devstack up --on local` (a plain `devstack up` goes to the machine's default, which may be the pool again) |
| `devstack up`: "no node of the pool can take the lane now" | the pool is this machine's default (`devstack pool default-on`) and is full: `devstack pool placement <lane>` says what is free where; try again later, or run it here with `devstack up --on local`. The user chose the pool as the default: ask before running it here |
| `devstack up --on` (or the MCP `up` with `on`) was interrupted or timed out while the lane started on the node | the start goes on there: `devstack lane list` shows its step; the same `devstack up --on <node>` again follows it to the end. A first start can take minutes (images pulled and built). It ends when the lane's daemon answers; its containers come up after, and its services start once those are healthy. A container that does not get healthy shows in `devstack status` with its group's error; `devstack logs <container>` has its output |

## 7. Problems in devstack itself
Expand Down
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,29 @@ and listed with their assets on the

## [Unreleased]

### Fixed

- **A lane's memory check looks at Docker Desktop's VM** (#309): on Windows
and macOS the check compared the whole need with the host's free memory,
while the containers run in Docker Desktop's VM with a limit of its own;
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.
- **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
the user's call. `--on <this machine's name or id>` runs the lane here
instead of being refused as a node not granted lanes. The skill's rows
say the same.
- **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.
- **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
restart keeps the containers (`down --keep-infra`).

## [0.25.0] - 2026-10-27

A stop takes the stack's containers too, as stopping a lane already did;
Expand Down
54 changes: 54 additions & 0 deletions crates/devstack-compose/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,45 @@ pub struct VolumeSize {
pub size: u64,
}

/// The memory of the machine the engine runs containers on, when that is a
/// VM of its own (Docker Desktop on Windows and macOS, #309): its total, and
/// what every running container uses in it now.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct EngineMemory {
pub total: u64,
pub used: u64,
}

impl Docker {
/// [`EngineMemory`] of Docker Desktop's VM; `None` for an engine that
/// runs on the host itself (its containers take the host's memory) or
/// one that does not answer. Takes about two seconds (`docker stats`).
pub fn engine_memory(&self) -> Option<EngineMemory> {
let a: Vec<OsString> = vec![
"info".into(),
"--format".into(),
"{{.MemTotal}}|{{.OperatingSystem}}".into(),
];
let out = self.run(Path::new("."), &a, budget::QUICK).ok()?;
let (total, os) = parse_engine_info(&String::from_utf8_lossy(&out.stdout))?;
if !os.contains("Docker Desktop") {
return None;
}
let a: Vec<OsString> = vec![
"stats".into(),
"--no-stream".into(),
"--format".into(),
"json".into(),
];
let out = self.run(Path::new("."), &a, budget::QUICK).ok()?;
let used = parse_stats(&String::from_utf8_lossy(&out.stdout))
.ok()?
.iter()
.map(|c| c.memory)
.sum();
Some(EngineMemory { total, used })
}

/// One `docker stats --no-stream` sample of the named containers. Takes
/// about two seconds: Docker measures over an interval.
pub fn stats(&self, names: &[String]) -> Result<Vec<ContainerStats>> {
Expand Down Expand Up @@ -1471,6 +1509,13 @@ pub fn parse_volumes(json: &str) -> std::result::Result<Vec<VolumeSize>, String>
.collect())
}

/// `docker info --format "{{.MemTotal}}|{{.OperatingSystem}}"`: the bytes
/// and the engine's OS name.
pub fn parse_engine_info(text: &str) -> Option<(u64, String)> {
let (total, os) = text.trim().split_once('|')?;
Some((total.trim().parse().ok()?, os.trim().to_string()))
}

/// Docker's human sizes: `12B`, `37.56kB`, `1.2MB` (SI), `35.27MiB`, `31.35GiB` (binary).
pub fn parse_size(s: &str) -> Option<u64> {
let s = s.trim();
Expand Down Expand Up @@ -1558,6 +1603,15 @@ mod tests {

#[test]
fn stats_and_sizes() {
assert_eq!(
parse_engine_info("33610137600|Docker Desktop\n"),
Some((33_610_137_600, "Docker Desktop".into()))
);
assert_eq!(
parse_engine_info("16000000000|Ubuntu 24.04.1 LTS"),
Some((16_000_000_000, "Ubuntu 24.04.1 LTS".into()))
);
assert_eq!(parse_engine_info(""), None);
let text = r#"{"BlockIO":"1.63GB / 0B","CPUPerc":"12.50%","Container":"cb21","ID":"cb21","MemPerc":"0.11%","MemUsage":"35.27MiB / 31.35GiB","Name":"probe-db-1","NetIO":"1MB / 1MB","PIDs":"11"}"#;
let s = parse_stats(text).unwrap();
assert_eq!(s[0].name, "probe-db-1");
Expand Down
102 changes: 91 additions & 11 deletions crates/devstack-daemon/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,12 +551,18 @@ async fn lanes_start(State(s): State<AppState>, Json(body): Json<LaneStart>) ->
}
}

/// What a lane takes: about what the main tree takes now, containers
/// included (ADR-0030).
fn lane_need(main: &crate::supervisor::Supervisor, usage: &crate::usage::Sampler) -> u64 {
/// What a lane takes: about what the main tree takes now (ADR-0030), as
/// its services' part and its containers' part: they may live in different
/// memory (#309).
fn lane_need_parts(
main: &crate::supervisor::Supervisor,
usage: &crate::usage::Sampler,
) -> (u64, u64) {
let r = usage.report(main, false);
r.services.iter().map(|e| e.load.memory).sum::<u64>()
+ r.containers.iter().map(|e| e.load.memory).sum::<u64>()
(
r.services.iter().map(|e| e.load.memory).sum::<u64>(),
r.containers.iter().map(|e| e.load.memory).sum::<u64>(),
)
}

/// What a lane on a node is expected to need, as this machine estimates it
Expand Down Expand Up @@ -633,20 +639,66 @@ fn disk_fits(
fn memory_fits(
main: &crate::supervisor::Supervisor,
usage: &crate::usage::Sampler,
) -> Result<(), String> {
let (services, containers) = lane_need_parts(main, usage);
let free = devstack_proc::memory_available();
// Docker Desktop runs the containers in a VM with a limit of its own;
// the host's free memory does not say whether they fit (#309).
let vm = if containers > 0 {
main.docker().engine_memory()
} else {
None
};
memory_verdict(services, containers, free, vm)
}

/// [`memory_fits`] on numbers: with `vm` the containers are checked against
/// what is free in it and only the services against the host.
fn memory_verdict(
services: u64,
containers: u64,
free: Option<u64>,
vm: Option<devstack_compose::EngineMemory>,
) -> Result<(), String> {
const MARGIN: u64 = 1 << 30;
let need = lane_need(main, usage);
let Some(free) = devstack_proc::memory_available() else {
let gb = |b: u64| b as f64 / (1u64 << 30) as f64;
let ways = "stop another lane or close something, start it on another machine of the pool \
(`devstack up --on <node>`, see `devstack pool`), or start it anyway with `devstack up --force`";
if let Some(vm) = vm {
let vm_free = vm.total.saturating_sub(vm.used);
if containers > 0 && vm_free < containers + MARGIN {
return Err(format!(
"a lane's containers need about {:.1} GB (what the main tree's take now), and Docker Desktop's VM, \
where they run, has {:.1} GB with {:.1} GB used by the containers that run: {:.1} GB are free there, \
whatever the host has (raise its limit in Docker Desktop, or in `.wslconfig` for WSL 2). {ways}",
gb(containers),
gb(vm.total),
gb(vm.used),
gb(vm_free)
));
}
let Some(free) = free else {
return Ok(());
};
if services == 0 || free >= services + MARGIN {
return Ok(());
}
return Err(format!(
"a lane's services need about {:.1} GB (what the main tree's take now; its containers fit in Docker Desktop's VM), \
{:.1} GB are free on this machine: {ways}",
gb(services),
gb(free)
));
}
let need = services + containers;
let Some(free) = free else {
return Ok(()); // not measurable here: no reason to refuse
};
if need == 0 || free >= need + MARGIN {
return Ok(());
}
let gb = |b: u64| b as f64 / (1u64 << 30) as f64;
Err(format!(
"a lane needs about {:.1} GB (what the main tree takes now, containers included), {:.1} GB are free: \
stop another lane or close something, start it on another machine of the pool \
(`devstack up --on <node>`, see `devstack pool`), or start it anyway with `devstack up --force`",
"a lane needs about {:.1} GB (what the main tree takes now, containers included), {:.1} GB are free: {ways}",
gb(need),
gb(free)
))
Expand Down Expand Up @@ -1890,6 +1942,34 @@ mod tests {
use super::*;
use axum::body::Body;

const GB: u64 = 1 << 30;

#[test]
fn containers_in_docker_desktops_vm_are_checked_against_the_vm() {
// The case of #309: the host has plenty, the VM does not.
let vm = devstack_compose::EngineMemory {
total: 31 * GB,
used: 20 * GB,
};
let e = memory_verdict(GB, 19 * GB, Some(36 * GB), Some(vm)).unwrap_err();
assert!(
e.contains("Docker Desktop's VM") && e.contains("--force"),
"{e}"
);
// Room in the VM: only the services count against the host.
let vm = devstack_compose::EngineMemory {
total: 31 * GB,
used: 5 * GB,
};
assert!(memory_verdict(GB, 19 * GB, Some(3 * GB), Some(vm)).is_ok());
let e = memory_verdict(4 * GB, 19 * GB, Some(3 * GB), Some(vm)).unwrap_err();
assert!(e.contains("services"), "{e}");
// An engine on the host: everything against the host, as before.
assert!(memory_verdict(GB, 19 * GB, Some(36 * GB), None).is_ok());
assert!(memory_verdict(GB, 19 * GB, Some(10 * GB), None).is_err());
assert!(memory_verdict(GB, 19 * GB, None, None).is_ok());
}

fn refused(body: Body, len: Option<usize>) -> Response {
let mut b = Response::builder()
.status(StatusCode::CONFLICT)
Expand Down
16 changes: 15 additions & 1 deletion crates/devstack-daemon/src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub fn local_member(pool: &str) -> Local {
/// its pool is not joined.
pub fn effective_on(on: Option<&str>) -> Option<String> {
match on.map(str::trim).filter(|o| !o.is_empty()) {
Some(o) if devstack_node::member::is_here(o) => None,
Some(o) if devstack_node::member::is_here(o) || is_this_machine(o) => None,
Some(o) => Some(o.to_string()),
None => {
let d = devstack_node::member::default_on(&state_dir())?;
Expand All @@ -231,6 +231,20 @@ pub fn effective_on(on: Option<&str>) -> Option<String> {
}
}

/// `on` names this machine in its pool, by its member id or name: the
/// pool would refuse it as a node not granted lanes (#310); it means
/// `local`.
pub fn is_this_machine(on: &str) -> bool {
let Ok((pool, node)) = resolve_on(on) else {
return false;
};
local_member(&pool)
.membership()
.ok()
.flatten()
.is_some_and(|m| m.id.eq_ignore_ascii_case(&node) || m.name.eq_ignore_ascii_case(&node))
}

/// `--on` split into the pool and the node asked for (ADR-0034 point 3).
pub fn resolve_on(on: &str) -> Result<(String, String), String> {
devstack_node::member::resolve_on(&state_dir(), on)
Expand Down
Loading
Loading