From a74ff683bd9b296cfbfe50ed95ccd23426dd832e Mon Sep 17 00:00:00 2001 From: Sebastian Gieseler Date: Mon, 9 Nov 2026 15:13:36 +0100 Subject: [PATCH] fix: a lane takes its changed stack file at the up after its down (#487) `devstack down` in a worktree stops the lane's services but keeps the lane in the daemon, and the lane kept the stack file it read when it was first opened: the `up` that followed ran without a new variable, silently. Now `up` (and a start through `POST /v1/lanes`) opens a lane of which nothing runs again when its worktree's file changed; a file that does not load is the answer and the lane stays as it was. `status` says how a change applies, for a lane and for the main tree (whose daemon stays while lanes run). Bug-Class: stale-config Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 12 ++ crates/devstack-daemon/src/api.rs | 14 ++- crates/devstack-daemon/src/lanes.rs | 43 ++++++- crates/devstack-daemon/src/supervisor/mod.rs | 8 +- crates/devstack/src/client.rs | 10 +- crates/devstack/tests/daemon_lifecycle.rs | 115 +++++++++++++++++++ docs/stack-file.md | 4 +- ui/src/views/EventsView.vue | 2 +- 8 files changed, 201 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04c0bd5e..202ce7a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,18 @@ and listed with their assets on the for a week (ADR-0098). The agent's own tools (its shell, its edits) do not pass devstack and are not shown. +### Fixed + +- **A lane takes its changed stack file at its next start.** `devstack down` + in a worktree stops the lane's services but keeps the lane in the daemon, + and the `up` that followed ran with the stack file the lane had read the + first time: a new variable or service in the worktree's `devstack.toml` + took no effect, without a word, until the main tree's daemon ended (#487). + Now the `up` after a `down` reads the file again (a file that does not + load is the answer, and the lane stays as it was); while the lane runs, + `devstack status` and the dashboard say the file changed. For the main + tree, `status` now says that its daemon stays while lanes run. + ## [0.42.0] - 2026-11-06 A pool's skill can now speak at the end of the work: a `lane-stop` diff --git a/crates/devstack-daemon/src/api.rs b/crates/devstack-daemon/src/api.rs index 8012cfde..6233e192 100644 --- a/crates/devstack-daemon/src/api.rs +++ b/crates/devstack-daemon/src/api.rs @@ -1388,11 +1388,21 @@ async fn lane_forward( } return r.forward(out).await; } + // `up` in a lane stopped by `down`: its stack file as it is now (#487). + let up = req.method() == axum::http::Method::POST && rest == "up"; let l = { let lanes = lanes.clone(); - match tokio::task::spawn_blocking(move || lanes.get(&lane)).await { + match tokio::task::spawn_blocking(move || { + if up { + // A stack file that does not load now: the lane stays as it was. + lanes.reread(&lane).map_err(|e| (StatusCode::CONFLICT, e))?; + } + lanes.get(&lane).map_err(|e| (StatusCode::NOT_FOUND, e)) + }) + .await + { Ok(Ok(l)) => l, - Ok(Err(e)) => return err(StatusCode::NOT_FOUND, e), + Ok(Err((status, e))) => return err(status, e), Err(e) => return err(StatusCode::INTERNAL_SERVER_ERROR, e.to_string()), } }; diff --git a/crates/devstack-daemon/src/lanes.rs b/crates/devstack-daemon/src/lanes.rs index f66b5010..5f4cffdb 100644 --- a/crates/devstack-daemon/src/lanes.rs +++ b/crates/devstack-daemon/src/lanes.rs @@ -2063,7 +2063,12 @@ impl Lanes { }) } - fn open(&self, entry: &LaneEntry) -> Result, String> { + /// What a lane runs: its worktree, its stack file, the stack read from + /// it (with its profile, ports moved by its offset), and the offset. + fn read_stack( + &self, + entry: &LaneEntry, + ) -> Result<(PathBuf, PathBuf, devstack_config::Stack, u16), String> { let repo = devstack_proc::long_path(&entry.path); if !repo.is_dir() { return Err(format!("{} is gone", repo.display())); @@ -2088,6 +2093,11 @@ impl Lanes { .files_offset(entry.number) .ok_or_else(|| format!("lane number {} is beyond the port range", entry.number))?; let stack = lane_stack(&stack, offset)?; + Ok((repo, file, stack, offset)) + } + + fn open(&self, entry: &LaneEntry) -> Result, String> { + let (repo, file, stack, offset) = self.read_stack(entry)?; let state = self.state_dir(&entry.name); std::fs::create_dir_all(&state).map_err(|e| e.to_string())?; let sup = Supervisor::new_lane( @@ -2139,6 +2149,35 @@ impl Lanes { } /// A started lane. + /// A started lane whose worktree's stack file changed since the lane + /// read it, and of which nothing runs (`devstack down` in it): opened + /// again from the file as it is now, so the `up` that follows runs that + /// (#487). `down` keeps a lane in the daemon, which read its file once. + /// One that runs, or serves the main ports, keeps what it read (its + /// status says the file changed). A file that does not load now is the + /// answer, and the lane stays as it was. + pub fn reread(&self, name: &str) -> Result<(), String> { + let Some(old) = self.map.lock().unwrap().get(name).cloned() else { + return Ok(()); + }; + if !old.sup.stack_file_changed() || old.sup.runs_anything() || old.sup.owns_main() { + return Ok(()); + } + self.read_stack(&old.entry)?; + let workers = old.sup.lane_workers(); + self.map.lock().unwrap().remove(name); + old.sup.close(); + let lane = self.open(&old.entry)?; + lane.sup.set_lane_workers(workers); + self.map.lock().unwrap().insert(name.to_string(), lane); + crate::diag::info( + "lane_reread", + serde_json::json!({ "lane": name, "worktree": old.entry.path }), + ); + self.announce(); + Ok(()) + } + pub fn get(&self, name: &str) -> Result, String> { if let Some(l) = self.map.lock().unwrap().get(name) { return Ok(l.clone()); @@ -2290,6 +2329,8 @@ impl Lanes { ) })?; let name = entry.name.clone(); + // Started, stopped by `down`, its stack file changed: read again. + self.reread(&name)?; if let Some(l) = self.map.lock().unwrap().get(&name) { let stack = l.sup.stack(); let runs = stack.profile.as_ref().map(|p| p.name.as_str()); diff --git a/crates/devstack-daemon/src/supervisor/mod.rs b/crates/devstack-daemon/src/supervisor/mod.rs index 2dbd08f3..15a93a2d 100644 --- a/crates/devstack-daemon/src/supervisor/mod.rs +++ b/crates/devstack-daemon/src/supervisor/mod.rs @@ -727,12 +727,18 @@ impl Supervisor { if !self.stack_file.is_file() { return; } - let changed = stack_file_hash(&self.stack_file) != self.stack_file_hash; + let changed = self.stack_file_changed(); if self.config_changed.swap(changed, Ordering::SeqCst) != changed { self.emit(EventBody::Config { changed }); } } + /// The stack file differs from what this tree read when it started + /// (line endings aside); a file that is gone is no change. + pub fn stack_file_changed(&self) -> bool { + self.stack_file.is_file() && stack_file_hash(&self.stack_file) != self.stack_file_hash + } + pub(crate) fn emit(&self, body: EventBody) { self.emit_with(body, None); } diff --git a/crates/devstack/src/client.rs b/crates/devstack/src/client.rs index ed71ef0b..deb3bf51 100644 --- a/crates/devstack/src/client.rs +++ b/crates/devstack/src/client.rs @@ -786,9 +786,17 @@ pub fn status_text(stack: &Value) -> String { ); } if stack["config_changed"].as_bool() == Some(true) { + // A lane reads its file again at the `up` after a `down` (#487); + // the main tree's daemon only when it starts, and lanes that run + // keep it (ADR-0024). let _ = writeln!( out, - "! the stack file changed since the daemon started; it applies with `devstack down` + `devstack up`\n" + "{}\n", + if stack["lane"].is_string() { + "! the stack file changed since this lane started; it applies with `devstack down` + `devstack up` here" + } else { + "! the stack file changed since the daemon started; it applies with `devstack down` + `devstack up` (while lanes run, the daemon stays: `devstack down --all` stops them too)" + } ); } if let Some(e) = stack["watcher_error"].as_str() { diff --git a/crates/devstack/tests/daemon_lifecycle.rs b/crates/devstack/tests/daemon_lifecycle.rs index ee426896..f9af50dd 100644 --- a/crates/devstack/tests/daemon_lifecycle.rs +++ b/crates/devstack/tests/daemon_lifecycle.rs @@ -1702,6 +1702,121 @@ run = "{brief}" s.ok(&["down"]); } +/// A lane takes its worktree's stack file as it is when it starts again: +/// `devstack down` in the worktree stops the lane's services but keeps the +/// lane in the daemon, and the `up` after an edit of the file ran with what +/// the lane read the first time (#487). Without the .NET SDK. +#[test] +fn a_lane_started_again_reads_its_changed_stack_file() { + if !enabled("DEVSTACK_INTEGRATION") { + eprintln!("skipped: set DEVSTACK_INTEGRATION=1"); + return; + } + let s = Stack::new(false); + let out = tempfile::tempdir().unwrap(); + let mark = out.path().join("mark.txt"); + let file = |value: &str| { + let run = if cfg!(windows) { + format!("echo %MARK%>\"%MARK_FILE%\" & {}", runs_for(600)) + } else { + format!("echo $MARK > \"$MARK_FILE\"; {}", runs_for(600)) + }; + format!( + "version = 1\n[stack]\nname = \"reread\"\n[services.dev]\nkind = \"devserver\"\nrun = '{run}'\nenv = {{ MARK = \"{value}\", MARK_FILE = '{}' }}\n", + mark.display() + ) + }; + std::fs::write(s.file(), file("one")).unwrap(); + std::fs::write(s.dir.path().join(".gitignore"), ".devstack/\n").unwrap(); + let git = |dir: &Path, args: &[&str]| { + let o = Command::new("git") + .args(["-c", "user.name=t", "-c", "user.email=t@t"]) + .args(args) + .current_dir(dir) + .output() + .unwrap(); + assert!( + o.status.success(), + "git {args:?}: {}", + String::from_utf8_lossy(&o.stderr) + ); + }; + git(s.dir.path(), &["config", "core.autocrlf", "false"]); + git(s.dir.path(), &["add", "-A"]); + git(s.dir.path(), &["commit", "-qm", "init"]); + let wt = s + .dir + .path() + .parent() + .unwrap() + .join(format!("wt-reread-{}", s.port)); + git( + s.dir.path(), + &[ + "worktree", + "add", + "-q", + "-b", + "reread", + wt.to_str().unwrap(), + ], + ); + let wt_cli = |args: &[&str]| { + let o = Command::new(BIN) + .args(args) + .arg("-f") + .arg(wt.join("devstack.toml")) + .env("LOCALAPPDATA", s.token_home.path()) + .env("XDG_STATE_HOME", s.token_home.path()) + .env("DEVSTACK_NO_HUB", "1") + .output() + .unwrap(); + format!( + "{}{}", + String::from_utf8_lossy(&o.stdout), + String::from_utf8_lossy(&o.stderr) + ) + }; + let marked = |value: &str| { + wait_for( + || std::fs::read_to_string(&mark).is_ok_and(|t| t.trim() == value), + Duration::from_secs(30), + ) + }; + + let up = wt_cli(&["up"]); + assert!(marked("one"), "{up}\n{}", s.diag()); + + // The file changes while the lane runs: it keeps what it read, and says so. + std::fs::write(wt.join("devstack.toml"), file("two")).unwrap(); + assert!( + wait_for( + || wt_cli(&["status"]).contains("stack file changed"), + Duration::from_secs(15) + ), + "{}", + wt_cli(&["status"]) + ); + // `down` and `up` in the worktree: the lane runs the file as it is now. + let down = wt_cli(&["down"]); + std::fs::remove_file(&mark).unwrap(); + let up = wt_cli(&["up"]); + assert!( + marked("two"), + "{down}\n{up}\nmark: {:?}\n{}", + std::fs::read_to_string(&mark), + s.diag() + ); + assert!(!wt_cli(&["status"]).contains("stack file changed")); + + wt_cli(&["down"]); + s.ok(&["down", "--all"]); + git( + s.dir.path(), + &["worktree", "remove", "--force", wt.to_str().unwrap()], + ); +} + /// A public link: `devstack tunnel` runs cloudflared (a fake here, which /// prints what a Quick Tunnel prints) to the service's fixed port, says its /// address once registered, keeps it across a restart and ends it with the diff --git a/docs/stack-file.md b/docs/stack-file.md index 1c48e61b..9671e2af 100644 --- a/docs/stack-file.md +++ b/docs/stack-file.md @@ -18,7 +18,9 @@ commands people and agents can trigger. Schema version 1 ([ADR-0017](adr/0017-st editor's TOML extension at it (Taplo: `#:schema ./devstack.schema.json` as the first line). - **A running daemon does not reload the file.** `devstack status` says when it - changed since the start; it applies with `devstack down` + `devstack up`. + changed since the start; it applies with `devstack down` + `devstack up`. A + lane reads its worktree's file again at the `up` after its `down`; the main + tree's daemon stays while lanes run (`devstack down --all` stops them too). - **No file yet?** `devstack init` writes a first draft from what the repository shows (Compose files, .NET web projects, Node dev servers, Go main packages, Django, FastAPI and Flask apps, Spring Boot through Maven or Gradle), every guess marked diff --git a/ui/src/views/EventsView.vue b/ui/src/views/EventsView.vue index 49dea386..630ecc9b 100644 --- a/ui/src/views/EventsView.vue +++ b/ui/src/views/EventsView.vue @@ -130,7 +130,7 @@ function describe(r: Row): Desc { return { icon: 'terminal', tone: e.status === 'failed' ? 'danger' : e.status === 'succeeded' ? 'ok' : 'accent', title: `run #${e.run}`, text: e.status }; case 'config': return e.changed - ? { icon: 'file', tone: 'warn', title: 'Stack file', text: 'Changed since the daemon started; applies with the next start' } + ? { icon: 'file', tone: 'warn', title: 'Stack file', text: stack.lane ? 'Changed since this lane started; applies with its next start' : 'Changed since the daemon started; applies with the next start' } : { icon: 'file', tone: 'ok', title: 'Stack file', text: 'Back to what the daemon runs with' }; case 'watcher': return e.error