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
27 changes: 17 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ and listed with their assets on the
[GitHub Desktop] · Manage programs…", the Git clients checked in the path
menu's programs. Paste a repository's `https://` address instead of a
folder, and its clone dialog opens with it filled in; then paste the
folder it was cloned to. New: `POST /hub/clone`.
folder it was cloned to. New: `POST /hub/clone`; an address with a query
or fragment, also percent-encoded, is refused.

### 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
kernel may drop; Windows the private working set (the whole one on a
Windows before 10 21H2, which lacks it); 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
Expand All @@ -34,21 +35,27 @@ and listed with their assets on the
- **A lane's need for the pool names its builds** (ADR-0119). The lease
step says "… memory (of it builds …)" and `remote_lane_need` in
`daemon.log` logs `builds`: the most the lane's build job took, as its
daemon measured it (a node asks each lane's daemon). Placement still takes
daemon measured it (a node asks each lane's daemon and reads at most
1 MiB of its answer). Placement still takes
the whole memory; a node before this release sends no part.
- **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.
`singleton` the stop of main keeps for running lanes, and what it comes
`after`, no longer shows main as running with a Stop button; the stop says
what keeps running, and for which lanes. A service's view says
`kept_for_lanes`.
- **`prepare` runs in the main tree too** (#630). Before a service starts
there (`up`, `start`, `restart`), its `prepare` runs in place when the
files of its `inputs` changed since it last ran there, or a directory of
its `outputs` is gone; the first start after this release runs it once.
A merge that brought new packages no longer leaves the dev server on the
old `node_modules`. The running instance is stopped first, so `npm ci`
can replace the files Windows keeps locked. A failing `prepare` stops the
start with its tail. While a service runs, here or in a lane, a change to
its `inputs` is a notice naming `devstack restart`; `restart_on` with the
can replace the files Windows keeps locked, and so are other running
services with the same `outputs` (they start again after it); a start
that would prepare under such a service is refused and says so. A failing
`prepare` stops the start with its tail. A `prepare` that rewrites its own
inputs (`npm install` and the lockfile) is not due again. While a service
runs, here or in a lane, a change to its `inputs` is a notice naming
`devstack restart` (gone when it stops); `restart_on` with the
lockfile makes it happen on every change. The main tree still does not use
the store (ADR-0062, amendment 2026-11-26).

Expand Down
3 changes: 3 additions & 0 deletions crates/devstack-daemon/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ pub struct ServiceView {
/// = true`, or the deprecated `lanes = false`, ADR-0080): the stack
/// page lists it as the stack's, not a lane's. Older daemons omit it.
pub singleton: bool,
/// The main tree's stop keeps it while lanes run: a `singleton`, or a
/// service one comes `after` (`supervisor::kept_for_lanes`).
pub kept_for_lanes: bool,
/// Where its last `prepare` outputs came from (ADR-0062): the store or
/// a run. Since this daemon started; none before its first `prepare`.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
194 changes: 163 additions & 31 deletions crates/devstack-daemon/src/supervisor/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,30 +505,86 @@ impl Supervisor {
svc: &Service,
cancel: &dyn Fn() -> bool,
) -> Result<(), String> {
if let Some(job) = self.tree_prepare_job(name, svc)?
&& let Some(view) = self.run_prepare(name, job, cancel)?
{
self.set_prepare(name, view);
if let Some(job) = self.tree_prepare_job(name, svc)? {
// What another running service reads is not replaced under it.
let sharers = self.sharers(name, svc);
if !sharers.is_empty() {
return Err(format!(
"`prepare` of {name} would replace what {} runs on (the same `outputs`): `devstack restart {name}` stops {} first, or stop {} and start {name} again",
sharers.join(", "),
if sharers.len() == 1 { "it" } else { "them" },
sharers.join(", "),
));
}
let (mark, shared) = (
job.mark.clone(),
job.shared.as_ref().map(|s| s.mark.clone()),
);
if let Some(view) = self.run_prepare(name, job, cancel)? {
self.set_prepare(name, view);
}
// The inputs as `prepare` left them (`npm install` rewrites the
// lockfile): otherwise its own write makes it due again.
if let Some(key) = self.tree_key(svc)? {
for m in std::iter::once(mark).chain(shared) {
std::fs::write(&m, &key).map_err(|e| e.to_string())?;
}
}
}
self.clear_notice(&format!("prepare.inputs.{name}"));
Ok(())
}

/// The key of `svc`'s `prepare` over the inputs as they are in the tree
/// (the main tree, or a lane's worktree); `None` without `prepare`.
fn tree_key(&self, svc: &Service) -> Result<Option<String>, String> {
let Some(p) = &svc.prepare else {
return Ok(None);
};
let files = self
.snapshot
.lock()
.unwrap()
.list()
.map_err(|e| e.to_string())?;
let inputs = devstack_build::watch_set(&p.inputs).map_err(|e| e.to_string())?;
let hashed: Vec<(String, String)> = files
.into_iter()
.filter(|rel| inputs.as_ref().is_some_and(|g| g.is_match(rel)))
.filter_map(|rel| {
let bytes = std::fs::read(self.repo.join(&rel)).ok()?;
Some((rel, blake3::hash(&bytes).to_hex().to_string()))
})
.collect();
prepare_key(p, svc, hashed.iter().map(|(r, h)| (r.as_str(), h.clone()))).map(Some)
}

/// Where the key of `name`'s last `prepare` is kept: in the main tree's
/// state, or in the lane's copy.
fn prepare_mark(&self, name: &str) -> PathBuf {
if self.runs_from_copy() {
self.layout.lane("main").join("prepared").join(name)
} else {
self.state_dir.join("prepared-tree").join(name)
}
}

/// `rel`, a file of the `inputs` of `name`'s `prepare`, changed: while it
/// runs, it runs on what `prepare` made before, until its next start
/// prepares again (#630). Said, unless its `restart_on` restarts it.
pub fn prepare_inputs_changed(&self, name: &str, rel: &str) {
/// prepares again (#630). Said, unless its `restart_on` restarts it
/// (`restarts`, as the watcher matched it).
pub fn prepare_inputs_changed(&self, name: &str, rel: &str, restarts: bool) {
let running = self.slots.lock().unwrap().get(name).is_some_and(from_tree);
if !running || restarts {
return;
}
// Its own `prepare` wrote it, or it came back to what was prepared.
let Some(svc) = self.stack().services.get(name).cloned() else {
return;
};
let running = self.slots.lock().unwrap().get(name).is_some_and(from_tree);
let restarts = devstack_build::watch_set(&svc.restart_on)
.ok()
.flatten()
.is_some_and(|g| {
g.is_match(rel) || rel.match_indices('/').any(|(i, _)| g.is_match(&rel[..i]))
});
if !running || restarts {
if let Ok(Some(key)) = self.tree_key(&svc)
&& std::fs::read_to_string(self.prepare_mark(name)).is_ok_and(|k| k == key)
{
return;
}
self.set_notice(
Expand All @@ -540,6 +596,33 @@ impl Supervisor {
);
}

/// The other services that run from the tree and whose `prepare` makes
/// some of the same `outputs` as `svc`'s.
pub(super) fn sharers(&self, name: &str, svc: &Service) -> Vec<String> {
let norm = |o: &String| o.replace('\\', "/").trim_matches('/').to_string();
let Some(mine) = svc
.prepare
.as_ref()
.map(|p| p.outputs.iter().map(norm).collect::<Vec<_>>())
else {
return Vec::new();
};
let stack = self.stack();
let slots = self.slots.lock().unwrap();
stack
.services
.iter()
.filter(|(n, _)| n.as_str() != name)
.filter(|(_, s)| {
s.prepare
.as_ref()
.is_some_and(|p| p.outputs.iter().map(norm).any(|o| mine.contains(&o)))
})
.filter(|(n, _)| slots.get(n.as_str()).is_some_and(from_tree))
.map(|(n, _)| n.clone())
.collect()
}

/// The `prepare` of `svc` the main tree needs before it starts there;
/// `None` when it has none, or it ran for these inputs and its outputs
/// are there.
Expand All @@ -548,25 +631,9 @@ impl Supervisor {
name: &str,
svc: &Service,
) -> Result<Option<PrepareJob>, String> {
let Some(p) = &svc.prepare else {
let (Some(p), Some(key)) = (&svc.prepare, self.tree_key(svc)?) else {
return Ok(None);
};
let files = self
.snapshot
.lock()
.unwrap()
.list()
.map_err(|e| e.to_string())?;
let inputs = devstack_build::watch_set(&p.inputs).map_err(|e| e.to_string())?;
let hashed: Vec<(String, String)> = files
.into_iter()
.filter(|rel| inputs.as_ref().is_some_and(|g| g.is_match(rel)))
.filter_map(|rel| {
let bytes = std::fs::read(self.repo.join(&rel)).ok()?;
Some((rel, blake3::hash(&bytes).to_hex().to_string()))
})
.collect();
let key = prepare_key(p, svc, hashed.iter().map(|(r, h)| (r.as_str(), h.clone())))?;
let marks = self.state_dir.join("prepared-tree");
let mark = marks.join(name);
let outputs: Vec<PathBuf> = p.outputs.iter().map(|o| self.repo.join(o)).collect();
Expand Down Expand Up @@ -2021,6 +2088,71 @@ mod tests {
assert_eq!(lock(), "{\"v\":2}");
}

// Review before 0.54.0, Nr. 5: a `prepare` that rewrites one of its own
// inputs (`npm install` normalises the lockfile) is not due again, and
// its own write is no change to tell about.
#[cfg(windows)]
#[test]
fn a_prepare_that_rewrites_its_inputs_is_not_due_again() {
use crate::state::Status;
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
let d = tempfile::tempdir().unwrap();
let stack = "version = 1\n[stack]\nname = \"t\"\n[services.web]\nkind = \"devserver\"\nrun = \"x\"\nport = 4200\nprepare = { run = \"mkdir deps 2>nul & echo normalised> package-lock.json\", inputs = [\"package-lock.json\"], outputs = [\"deps\"] }\n";
let sup = warm_repo(d.path(), stack, &[("package-lock.json", "{}")], &rt);
let svc = sup.stack().services["web"].clone();
sup.tree_ready("web", &svc, &|| false).unwrap();
assert!(
sup.tree_prepare_job("web", &svc).unwrap().is_none(),
"due again after its own write"
);
sup.set_status("web", Status::Starting);
sup.prepare_inputs_changed("web", "package-lock.json", false);
assert!(sup.notices().is_empty(), "{:?}", sup.notices());
// A change of somebody else's is one.
std::fs::write(d.path().join("package-lock.json"), "{\"v\":2}").unwrap();
sup.prepare_inputs_changed("web", "package-lock.json", false);
assert_eq!(sup.notices().len(), 1);
// Gone with the service (Nr. 6).
sup.stop("web").unwrap();
assert!(sup.notices().is_empty(), "{:?}", sup.notices());
}

// Review before 0.54.0, Nr. 2: outputs another running service shares
// are not prepared under it (Windows keeps its files locked; elsewhere
// they vanish under it).
#[cfg(windows)]
#[test]
fn outputs_a_running_service_shares_are_not_prepared_under_it() {
use crate::state::Status;
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
let d = tempfile::tempdir().unwrap();
let prep = "prepare = { run = \"mkdir deps 2>nul & copy /y package-lock.json deps\\\\lock.json\", inputs = [\"package-lock.json\"], outputs = [\"deps\"] }";
let stack = format!(
"version = 1\n[stack]\nname = \"t\"\n[services.web]\nkind = \"devserver\"\nrun = \"x\"\nport = 4200\n{prep}\n[services.admin]\nkind = \"devserver\"\nrun = \"x\"\nport = 4201\n{prep}\n"
);
let sup = warm_repo(d.path(), &stack, &[("package-lock.json", "{\"v\":1}")], &rt);
let services = sup.stack().services.clone();
sup.tree_ready("web", &services["web"], &|| false).unwrap();
sup.set_status("admin", Status::Starting);
std::fs::write(d.path().join("package-lock.json"), "{\"v\":2}").unwrap();
let e = sup
.tree_ready("web", &services["web"], &|| false)
.unwrap_err();
assert!(e.contains("admin"), "{e}");
assert_eq!(
sup.sharers("web", &services["web"]),
vec!["admin".to_string()]
);
sup.set_status("admin", Status::Stopped);
sup.tree_ready("web", &services["web"], &|| false).unwrap();
}

// #630: a `prepare` that fails in the main tree stops the start with its
// tail, and the next start tries again.
#[cfg(windows)]
Expand Down
Loading
Loading