Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.
Rust acpagent-client-protocolai-agentsai-assistantclaudeclaude-codecodexcoding-agentscursorgeminigemini-cligrok-bot-alternativeiosiphonelinuxmacosmcpopen-sourcerustself-hosted
fix(network): removing a computer never renames another
leepokai0a6fa1f22350
diff --git a/docs/features/codync-network.md b/docs/features/codync-network.mdindex ea2d8dcc..d914da59 100644--- a/docs/features/codync-network.md+++ b/docs/features/codync-network.md@@ -22,7 +22,8 @@ codync-host network peers | promote <computer> | remove <computer> [--cascade] |fallback when two computers can't connect directly: iroh's public relays (`public`, the default), the user's own`iroh-relay` (a URL), or none (`private`: same network, Tailscale or a VPN). A computer's name defaults to its hostname; a taken name gets a number (`laptop-2`), also when two admins admit the same name before their copies meet-(the later admission gets the number, on every copy).+(the later admission gets the number, on every copy). No computer's name changes when another is removed; one+admitted after a removal can take the freed name.## Who may do whatdiff --git a/host/crates/network/src/roster.rs b/host/crates/network/src/roster.rsindex 0000b6ad..2891455b 100644--- a/host/crates/network/src/roster.rs+++ b/host/crates/network/src/roster.rs@@ -328,9 +328,10 @@ impl Roster {deciders: tops.chain(promoted.keys().copied()).collect(),};self.removed = removed.keys().copied().collect();- admitted.retain(|id, _| !self.removed.contains(id));- self.members = distinct_names(admitted)+ let removed_at: BTreeMap<EndpointId, u64> = removed.iter().map(|(id, &(at, _))| (*id, at)).collect();+ self.members = distinct_names(admitted, &removed_at).into_iter()+ .filter(|(id, _)| !self.removed.contains(id)).map(|(id, name)| {let role = if Some(id) == owner {Role::Owner@@ -396,21 +397,27 @@ fn newest_locations(log: &BTreeSet<Signed>) -> BTreeMap<EndpointId, (&Signed, &E}/// Names every computer uniquely. Two admins can admit a `laptop` each before their copies meet:-/// the one admitted later (by time, then id) gets the first free number, the same on every copy.-fn distinct_names(admitted: BTreeMap<EndpointId, (u64, String)>) -> BTreeMap<EndpointId, String> {+/// the one admitted later (by time, then id) gets the first free number, the same on every copy. A+/// removed computer keeps its name from the computers admitted while it was in, so no one's name+/// moves when it goes (letters on their way still name them); one admitted after can take it.+fn distinct_names(+ admitted: BTreeMap<EndpointId, (u64, String)>,+ removed_at: &BTreeMap<EndpointId, u64>,+) -> BTreeMap<EndpointId, String> {let mut order: Vec<(u64, EndpointId, String)> =admitted.into_iter().map(|(id, (at, name))| (at, id, name)).collect();order.sort();- let mut taken = BTreeSet::new();+ // Each name given, and until when it is held: for good, or until its computer was removed.+ let mut held: BTreeMap<String, Option<u64>> = BTreeMap::new();let mut names = BTreeMap::new();- for (_, id, name) in order {- let mut unique = name.clone();- for n in 2.. {- if taken.insert(unique.to_lowercase()) {- break;- }- unique = format!("{name}-{n}");- }+ for (at, id, name) in order {+ let free = |n: &str| held.get(&n.to_lowercase()).is_none_or(|until| until.is_some_and(|t| t <= at));+ let unique = std::iter::once(name.clone())+ // One more number than there are names: one of them is free.+ .chain((2..=held.len() + 2).map(|n| format!("{name}-{n}")))+ .find(|n| free(n))+ .expect("a number is free");+ held.insert(unique.to_lowercase(), removed_at.get(&id).copied());names.insert(id, unique);}namesdiff --git a/host/crates/network/src/roster/tests.rs b/host/crates/network/src/roster/tests.rsindex 1eb1414c..f964ee7d 100644--- a/host/crates/network/src/roster/tests.rs+++ b/host/crates/network/src/roster/tests.rs@@ -176,4 +176,11 @@ fn two_admins_naming_a_laptop_at_once_still_get_distinct_names() {assert_eq!(a.members(), b.members());assert_eq!((a.name(&laptop.public()), a.name(&other.public())), ("laptop".into(), "Laptop-2".into()));assert_eq!(a.find("laptop-2"), Some(other.public()));+ // Removing the first laptop moves no one: the second stays laptop-2. A computer admitted later+ // may take the freed name.+ a.sign(&desk, 6, Change::Remove { id: laptop.public(), cascade: false }).unwrap();+ assert_eq!(a.name(&other.public()), "Laptop-2");+ let new = key();+ a.sign(&desk, 7, Change::Admit { id: new.public(), name: "laptop".into() }).unwrap();+ assert_eq!(a.name(&new.public()), "laptop");}