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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ and listed with their assets on the

### Fixed

- **A lane on a node carried over a restart is warned about against the
devstack that runs it now.** The warning that the node or the coordinator
runs another release was made once, when the lane was leased, and carried
over a restart as a text (ADR-0052): after an update to 0.20.0 the lane
still read "the node … runs devstack 0.20.0, this machine devstack
0.19.0" while every side ran 0.20.0. The daemon now carries the
coordinator's release instead and makes the warning again; a lane carried
by 0.20.0 loses the coordinator's part, which only that daemon knew.
- **The dashboard's prompts ask which branch a commit goes on.** They said
to ask before committing, not where: a coding agent took the branch
checked out, which may be another piece of work's. Each prompt now has
Expand Down
85 changes: 82 additions & 3 deletions crates/devstack-daemon/src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ pub struct RemoteLane {
pub warning: Option<String>,
/// What the node runs, as the lease offer said (`None`: it does not say).
node_release: Option<Release>,
/// What the coordinator runs, as the lease offer said: carried over a
/// restart, so the next daemon warns against its own release.
coordinator_release: Option<Release>,
worktree: PathBuf,
/// Where `[lanes] sync` files come from when the worktree has none.
main: PathBuf,
Expand Down Expand Up @@ -428,6 +431,7 @@ struct Parts<'a> {
node: NodeRef,
lease: String,
warning: Option<String>,
coordinator: Option<Release>,
worktree: &'a Path,
main: &'a Path,
extra: &'a [String],
Expand All @@ -450,8 +454,12 @@ pub struct Carried {
/// before that, whose lane relays none.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub udp_ports: Vec<(u16, u16)>,
/// What the coordinator ran when it granted the lease; absent from a
/// daemon before 0.20.1, which carried its warning as a text. The next
/// daemon makes the warning again against its own release
/// ([`carried_warning`]).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub warning: Option<String>,
pub coordinator: Option<Release>,
}

/// Watch `worktree` for changes to sync (ADR-0029 point 2): `dirty` is set
Expand Down Expand Up @@ -759,6 +767,7 @@ impl RemoteLane {
node: offer.node,
lease: offer.id,
warning,
coordinator: offer.coordinator,
worktree,
main,
extra,
Expand Down Expand Up @@ -789,6 +798,7 @@ impl RemoteLane {
lease: p.lease,
warning: p.warning,
node_release,
coordinator_release: p.coordinator,
worktree: p.worktree.to_path_buf(),
main: p.main.to_path_buf(),
extra: p.extra.to_vec(),
Expand Down Expand Up @@ -850,7 +860,7 @@ impl RemoteLane {
lease: self.lease.clone(),
ports: self.ports.clone(),
udp_ports: self.udp_ports.clone(),
warning: self.warning.clone(),
coordinator: self.coordinator_release.clone(),
}
}

Expand Down Expand Up @@ -892,14 +902,16 @@ impl RemoteLane {
}
Err(e) => return Err(format!("renewing its lease on {}: {e}", c.node.name)),
};
let warning = carried_warning(&c);
let lane = Self::assemble(
rt,
Parts {
name,
pool: c.pool,
node: c.node,
lease: c.lease,
warning: c.warning,
warning,
coordinator: c.coordinator,
worktree,
main,
extra,
Expand Down Expand Up @@ -1700,6 +1712,23 @@ fn release_warning(
Ok((!notes.is_empty()).then(|| notes.join("; ")))
}

/// The warning of a lane a daemon before this one followed (ADR-0052), made
/// against this machine's release: the daemon that leased it compared with
/// its own (`this machine devstack 0.19.0` after an update to 0.20.0). The
/// coordinator's release is known from a daemon that carried it (0.20.1).
fn carried_warning(c: &Carried) -> Option<String> {
let node = format!("the node {}", c.node.name);
let notes: Vec<String> = version::note(&node, c.node.devstack.as_ref())
.into_iter()
.chain(
c.coordinator
.as_ref()
.and_then(|r| version::note("the coordinator", Some(r))),
)
.collect();
(!notes.is_empty()).then(|| notes.join("; "))
}

/// Did a connection of a tunnel end because one end hung up (reset, aborted,
/// a write to a closed socket)? Windows says "aborted" (10053) where a
/// browser closes a connection it kept alive.
Expand Down Expand Up @@ -2086,4 +2115,54 @@ members = ["api"]
serde_json::from_str(&serde_json::to_string(&c).unwrap()).unwrap();
assert_eq!(again.udp_ports, [(5453, 5453)]);
}

#[test]
fn a_lane_carried_over_is_warned_about_against_this_release() {
use super::carried_warning;
let this = Release::this();
let older = Release {
version: "0.0.1".into(),
..this.clone()
};
// A 0.20.0 daemon carried the text its 0.19.0 predecessor made; the
// node and the coordinator run this release by now.
let c: super::Carried = serde_json::from_str(&format!(
r#"{{"pool":"default","lease":"l1","ports":[],
"node":{{"id":"n1","name":"build-1","api":"https://n",
"devstack":{{"version":"{v}","protocol":{p}}}}},
"warning":"the node build-1 runs devstack {v}, this machine devstack 0.0.1"}}"#,
v = this.version,
p = this.protocol
))
.unwrap();
assert_eq!(carried_warning(&c), None, "the same release everywhere");
let c = super::Carried {
coordinator: Some(older.clone()),
..c
};
let w = carried_warning(&c).unwrap();
assert!(
w.starts_with("the coordinator runs devstack 0.0.1") && w.contains(version::VERSION),
"{w}"
);
let c = super::Carried {
node: NodeRef {
devstack: None,
..c.node
},
coordinator: Some(this),
..c
};
let w = carried_warning(&c).unwrap();
assert!(w.contains("build-1") && w.contains("does not say"), "{w}");
let again: super::Carried = serde_json::from_str(
&serde_json::to_string(&super::Carried {
coordinator: Some(older.clone()),
..c
})
.unwrap(),
)
.unwrap();
assert_eq!(again.coordinator, Some(older));
}
}
17 changes: 17 additions & 0 deletions crates/devstack/tests/daemon_lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,14 @@ members = [\"api\", \"command.ping\"]
serde_json::from_str(&self.api("/info").expect("api answers /info")).unwrap()
}

fn daemon_port(&self) -> u16 {
let info: Value = serde_json::from_slice(
&std::fs::read(self.dir.path().join(".devstack/daemon.json")).unwrap(),
)
.unwrap();
info["port"].as_u64().unwrap() as u16
}

fn daemon_pid(&self) -> u32 {
let info: Value = serde_json::from_slice(
&std::fs::read(self.dir.path().join(".devstack/daemon.json")).unwrap(),
Expand Down Expand Up @@ -1605,7 +1613,16 @@ port = {port}
s.ok(&["start", "box"]);
let second = instance_port();
assert!(second != 0 && second != first, "{}", s.diag());
let daemon_port = s.daemon_port();
kill_hard(s.daemon_pid());
// Until it is gone, `up` may still reach the dying daemon.
assert!(
wait_for(
|| std::net::TcpStream::connect(("127.0.0.1", daemon_port)).is_err(),
Duration::from_secs(10)
),
"the daemon survived its kill"
);
s.ok(&["up"]);
assert!(
stops().contains(&format!("stopped-{second}")),
Expand Down
Loading