From 562b6af7cdd8dac656da8430253d632fb2732164 Mon Sep 17 00:00:00 2001 From: Sebastian Gieseler Date: Thu, 29 Oct 2026 21:34:22 +0100 Subject: [PATCH 1/2] fix(cli): devstack up --on moves a lane started elsewhere A lane started on a node stays started after `devstack down` (its lease and place stay, its services stop), and `up` only started its services again where it ran: `--on local` was passed over. An `--on` that names another place than the lane's (this machine, or another node) now moves it there, as `devstack lane move` does; without `--on` it stays. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 8 +++++++ crates/devstack/src/client.rs | 42 +++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3970bd66..7ee282a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,14 @@ and listed with their assets on the ## [Unreleased] +### Fixed + +- **`devstack up --on` moves a started lane**: a lane started on a node + stayed there after `devstack down` (its lease and place stay, only its + services stop), and `devstack up --on local` started it there again. + `--on local` now brings it here, and `--on ` takes it to that node, + as `devstack lane move` does; without `--on` it stays where it runs. + ## [0.30.0] - 2026-10-29 The skills of a pool's set can be taken one by one: each switched on or diff --git a/crates/devstack/src/client.rs b/crates/devstack/src/client.rs index 269cbe24..853f5dbe 100644 --- a/crates/devstack/src/client.rs +++ b/crates/devstack/src/client.rs @@ -993,6 +993,12 @@ pub fn up( // In a worktree, no `--on`: where this machine starts lanes by default // (ADR-0025); `--on local` keeps it here. The main tree runs here. let explicit = on.filter(|o| !devstack_node::member::is_here(o)); + // `--on local` (or this machine's own name) said in so many words: a + // lane started on a node comes here, as `lane move --to local` does. + let asked_here = on.is_some_and(|o| { + devstack_node::member::is_here(o.trim()) + || devstack_daemon::remote::is_this_machine(o.trim()) + }); let resolved = if worktree().is_some() { devstack_daemon::remote::effective_on(on) } else { @@ -1045,6 +1051,30 @@ pub fn up( ); } } + // Started already somewhere else than `--on` names (here, or another + // node): it moves there, a cold start there that takes over once ready, + // as `devstack lane move` does. Without `--on`, a started lane stays + // where it runs. + let mut moved = false; + if let Some(name) = c.lane().filter(|l| *l != "-").map(str::to_string) { + let now = lane_node(&c, &name)?; + // A node named (not a pool's own choice) other than where it runs. + let node = on.and_then(|o| { + devstack_node::member::resolve_on(&devstack_daemon::remote::state_dir(), o) + .ok() + .filter(|(_, n)| n != "pool") + .map(|(_, n)| n) + }); + let to = match (node, asked_here) { + (Some(n), _) if now.as_deref() != Some(n.as_str()) => on.map(str::to_string), + (None, true) if now.is_some() => Some("local".to_string()), + _ => None, + }; + if let Some(to) = to { + lane_move(stack_file, &name, &to)?; + moved = true; + } + } // Started already, here or on a node: nothing restarts it (#314). if c.lane().is_some_and(|l| l != "-") && (workers || force) { eprintln!( @@ -1052,6 +1082,7 @@ pub fn up( ); } if let Some(wt) = worktree() + && !moved && (on.is_some() || c.lane().is_none_or(|l| l == "-")) { if let Some(node) = on { @@ -1778,6 +1809,17 @@ fn follow_steps( (done, handle) } +/// The node the lane `name` runs on; `None`: this machine. +fn lane_node(c: &Client, name: &str) -> Result> { + let (_, body) = c.call_raw("GET", "/v1/lanes", None)?; + let lanes: Vec = serde_json::from_str(&body).unwrap_or_default(); + Ok(lanes + .iter() + .find(|l| l["name"] == name) + .and_then(|l| l["node"].as_str()) + .map(str::to_string)) +} + pub fn lane_move(stack_file: &Path, name: &str, to: &str) -> Result<()> { let c = main_client(stack_file)?; println!("moving lane `{name}` to {to}: starting it there; it takes over once it is ready..."); From fd4a62daeec00f321c2db06b1357fc1730968704 Mon Sep 17 00:00:00 2001 From: Sebastian Gieseler Date: Thu, 29 Oct 2026 22:04:03 +0100 Subject: [PATCH 2/2] fix(mcp): up follows where lanes start by default, and moves a lane started elsewhere The MCP tool `up` started a lane here when `on` was not given, past the machine's default (`devstack pool default-on`), and an `on` naming another place than where a started lane ran started it there again, as `devstack up` did before. Both now share the CLI's resolution: names_here, move_wanted, and a move without output (the tool's stdout is its protocol). Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 ++ crates/devstack/src/client.rs | 76 +++++++++++++++++++++++++---------- crates/devstack/src/mcp.rs | 22 +++++++++- 3 files changed, 78 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ee282a1..dc037087 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ and listed with their assets on the services stop), and `devstack up --on local` started it there again. `--on local` now brings it here, and `--on ` takes it to that node, as `devstack lane move` does; without `--on` it stays where it runs. +- **The MCP tool `up` does as `devstack up`**: in a worktree without `on` + it starts the lane where this machine starts lanes by default (*Where + lanes start*), not always here, and an `on` that names another place + than where a started lane runs moves it there. ## [0.30.0] - 2026-10-29 diff --git a/crates/devstack/src/client.rs b/crates/devstack/src/client.rs index 853f5dbe..5611ec71 100644 --- a/crates/devstack/src/client.rs +++ b/crates/devstack/src/client.rs @@ -995,10 +995,7 @@ pub fn up( let explicit = on.filter(|o| !devstack_node::member::is_here(o)); // `--on local` (or this machine's own name) said in so many words: a // lane started on a node comes here, as `lane move --to local` does. - let asked_here = on.is_some_and(|o| { - devstack_node::member::is_here(o.trim()) - || devstack_daemon::remote::is_this_machine(o.trim()) - }); + let asked_here = names_here(on); let resolved = if worktree().is_some() { devstack_daemon::remote::effective_on(on) } else { @@ -1056,24 +1053,9 @@ pub fn up( // as `devstack lane move` does. Without `--on`, a started lane stays // where it runs. let mut moved = false; - if let Some(name) = c.lane().filter(|l| *l != "-").map(str::to_string) { - let now = lane_node(&c, &name)?; - // A node named (not a pool's own choice) other than where it runs. - let node = on.and_then(|o| { - devstack_node::member::resolve_on(&devstack_daemon::remote::state_dir(), o) - .ok() - .filter(|(_, n)| n != "pool") - .map(|(_, n)| n) - }); - let to = match (node, asked_here) { - (Some(n), _) if now.as_deref() != Some(n.as_str()) => on.map(str::to_string), - (None, true) if now.is_some() => Some("local".to_string()), - _ => None, - }; - if let Some(to) = to { - lane_move(stack_file, &name, &to)?; - moved = true; - } + if let Some((name, to)) = move_wanted(&c, on, asked_here)? { + lane_move(stack_file, &name, &to)?; + moved = true; } // Started already, here or on a node: nothing restarts it (#314). if c.lane().is_some_and(|l| l != "-") && (workers || force) { @@ -1809,6 +1791,56 @@ fn follow_steps( (done, handle) } +/// `on` as given names this machine (`local`, `here`, its own member name). +pub(crate) fn names_here(on: Option<&str>) -> bool { + on.is_some_and(|o| { + devstack_node::member::is_here(o.trim()) + || devstack_daemon::remote::is_this_machine(o.trim()) + }) +} + +/// The worktree's lane is started (here or on a node), and `on` (resolved: +/// `None` here) or `asked_here` names another place than where it runs: +/// the lane and where it is to move. A pool's own choice (`pool`) is no +/// other place; without either, a started lane stays where it runs. +pub(crate) fn move_wanted( + c: &Client, + on: Option<&str>, + asked_here: bool, +) -> Result> { + let Some(name) = c.lane().filter(|l| *l != "-").map(str::to_string) else { + return Ok(None); + }; + let now = lane_node(c, &name)?; + let node = on.and_then(|o| { + devstack_node::member::resolve_on(&devstack_daemon::remote::state_dir(), o) + .ok() + .filter(|(_, n)| n != "pool") + .map(|(_, n)| n) + }); + let to = match (node, asked_here) { + (Some(n), _) if now.as_deref() != Some(n.as_str()) => on.map(str::to_string), + (None, true) if now.is_some() => Some("local".to_string()), + _ => None, + }; + Ok(to.map(|t| (name, t))) +} + +/// Move the lane `name` to `to` and wait until it runs there, without a +/// word (for `devstack mcp`, whose output is its protocol). +pub(crate) fn lane_move_quiet(stack_file: &Path, name: &str, to: &str) -> Result<()> { + let c = main_client(stack_file)?; + let (status, body) = c.call_raw( + "POST", + &format!("/v1/lanes/{name}/move"), + Some(serde_json::json!({ "to": to })), + )?; + if status >= 400 { + bail!("{}", error_text(&body)); + } + Ok(()) +} + /// The node the lane `name` runs on; `None`: this machine. fn lane_node(c: &Client, name: &str) -> Result> { let (_, body) = c.call_raw("GET", "/v1/lanes", None)?; diff --git a/crates/devstack/src/mcp.rs b/crates/devstack/src/mcp.rs index 87df6436..135f0960 100644 --- a/crates/devstack/src/mcp.rs +++ b/crates/devstack/src/mcp.rs @@ -566,14 +566,23 @@ fn call(name: &str, args: &Value, file: &Path) -> Result { "the profile starts the main working tree with fresh data (its volumes go): ask the user, then `yes`, or run it in a lane" ); } - let on = args["on"].as_str().filter(|o| !o.trim().is_empty()); - if on.is_some_and(|o| !devstack_node::member::is_here(o)) + let asked = args["on"].as_str().filter(|o| !o.trim().is_empty()); + if asked.is_some_and(|o| !devstack_node::member::is_here(o)) && client::worktree().is_none() { anyhow::bail!( "`on` runs a worktree's lane on a node: this is the main working tree" ); } + // As `devstack up`: in a worktree, no `on` is where this machine + // starts lanes by default (ADR-0025); `local` keeps it here. + let asked_here = client::names_here(asked); + let resolved = if client::worktree().is_some() { + devstack_daemon::remote::effective_on(asked) + } else { + None + }; + let on = resolved.as_deref(); // Like `devstack up`: start Docker Desktop if the stack needs it // (a lane on a node needs no Docker here), and say so. let mut notes = String::new(); @@ -600,7 +609,16 @@ fn call(name: &str, args: &Value, file: &Path) -> Result { ); } } + // Started already elsewhere than `on` names: it moves there, as + // `devstack up --on` and `lane move` do. + let mut moved = false; + if let Some((name, to)) = client::move_wanted(&c, on, asked_here)? { + client::lane_move_quiet(file, &name, &to)?; + notes.push_str(&format!("lane `{name}` moved to {to}\n")); + moved = true; + } if let Some(wt) = client::worktree() + && !moved && (on.is_some() || c.lane().is_none_or(|l| l == "-")) { // A start on a node is followed within the same timeout.