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
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
14 changes: 12 additions & 2 deletions crates/devstack-daemon/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
}
};
Expand Down
43 changes: 42 additions & 1 deletion crates/devstack-daemon/src/lanes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2063,7 +2063,12 @@ impl Lanes {
})
}

fn open(&self, entry: &LaneEntry) -> Result<Arc<Lane>, 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()));
Expand All @@ -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<Arc<Lane>, 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(
Expand Down Expand Up @@ -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<Arc<Lane>, String> {
if let Some(l) = self.map.lock().unwrap().get(name) {
return Ok(l.clone());
Expand Down Expand Up @@ -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());
Expand Down
8 changes: 7 additions & 1 deletion crates/devstack-daemon/src/supervisor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 9 additions & 1 deletion crates/devstack/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
115 changes: 115 additions & 0 deletions crates/devstack/tests/daemon_lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion docs/stack-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ui/src/views/EventsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down