Skip to content

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.

fix(host): keep the server names each Codex session started with

leepokaifb0dae186940
diff --git a/host/src/agent/bot/codex_names.rs b/host/src/agent/bot/codex_names.rs
index 8223df7e..9541e075 100644
--- a/host/src/agent/bot/codex_names.rs
+++ b/host/src/agent/bot/codex_names.rs
@@ -3,12 +3,12 @@
//! named like one of the user's Codex servers (`notion`) then never reaches the bot (#217), so it gets a free name.
use serde_json::Value;
-use std::collections::{HashMap, HashSet};
+use std::collections::{BTreeMap, HashSet};
use std::path::{Path, PathBuf};
use toml_edit::{DocumentMut, Item};
/// Codync's servers that got another name for this agent: requested name -> the name the agent knows.
-pub(super) type Renamed = HashMap<String, String>;
+pub(super) type Renamed = BTreeMap<String, String>;
/// What the agent calls Codync's server `name`.
pub(super) fn name_of<'a>(renamed: &'a Renamed, name: &'a str) -> &'a str {
diff --git a/host/src/agent/bot/launch.rs b/host/src/agent/bot/launch.rs
index fadf1251..a68c5c39 100644
--- a/host/src/agent/bot/launch.rs
+++ b/host/src/agent/bot/launch.rs
@@ -163,6 +163,7 @@ pub(crate) async fn start_agent(command: &str, cwd: &str, env: &[(String, String
fast_options: HashMap::new(),
reports_compaction: false,
usage: HashMap::new(),
+ renamed: HashMap::new(),
})
}
diff --git a/host/src/agent/bot/mod.rs b/host/src/agent/bot/mod.rs
index 729ae9e2..92b81793 100644
--- a/host/src/agent/bot/mod.rs
+++ b/host/src/agent/bot/mod.rs
@@ -125,7 +125,6 @@ pub fn spawn(hub: Arc<Hub>, base: BotConfig) -> BotHandle {
cancel_deadline: None,
exit_tail: None,
tools_changed: false,
- renamed: codex_names::Renamed::new(),
restart_after_turn: false,
fast_support,
idle_checked: Instant::now(),
@@ -188,6 +187,8 @@ pub(crate) struct Conn {
reports_compaction: bool,
/// Each session's context use and window size at its last `usage_update`.
usage: HashMap<String, (u64, u64)>,
+ /// Codync's MCP servers each session knows by another name (`codex_names`), as it was created or loaded with.
+ renamed: HashMap<String, codex_names::Renamed>,
}
impl Conn {
@@ -303,8 +304,6 @@ struct Actor {
/// Connectors changed: restart the agent before the next turn so the
/// session is resumed with the new MCP servers.
tools_changed: bool,
- /// Codync's MCP servers the agent knows by another name (`codex_names`), so their calls are still recognized.
- renamed: codex_names::Renamed,
/// A change that restarts the agent (`restart_agent`) came during a turn: it restarts once the turn ends.
restart_after_turn: bool,
/// What the agent says about Fast mode; clients see it in the bot's runtime.
diff --git a/host/src/agent/bot/session.rs b/host/src/agent/bot/session.rs
index 85da4dc8..2eb63cdb 100644
--- a/host/src/agent/bot/session.rs
+++ b/host/src/agent/bot/session.rs
@@ -76,6 +76,13 @@ impl Actor {
params
}
+ /// What the turn's session calls Codync's MCP servers that it knows by another name.
+ pub(super) fn renamed(&self) -> &codex_names::Renamed {
+ static NONE: codex_names::Renamed = codex_names::Renamed::new();
+ let sid = self.turn_session.as_ref();
+ self.conn.as_ref().zip(sid).and_then(|(c, sid)| c.renamed.get(sid)).unwrap_or(&NONE)
+ }
+
/// ACP connectors, team collaboration, and optional team management and computer control.
pub(super) fn mcp_servers(&self) -> Result<Value> {
let Ok(exe) = std::env::current_exe() else {
@@ -183,7 +190,7 @@ impl Actor {
}
}
let mut servers = self.mcp_servers()?;
- self.renamed = if self.conn.as_ref().is_some_and(|c| c.adapter == Adapter::Codex) {
+ let renamed = if self.conn.as_ref().is_some_and(|c| c.adapter == Adapter::Codex) {
// A `CODEX_HOME` saved for Codex (`setAgentEnv`) is where its own config is.
let saved = crate::agent::auth::env(&self.hub.store, &self.cfg.backend).unwrap_or_else(|e| {
tracing::warn!(error = format!("{e:#}"), "couldn't read Codex's saved environment");
@@ -242,6 +249,7 @@ impl Actor {
res
};
conn.loaded.insert(sid.clone(), Instant::now());
+ conn.renamed.insert(sid.clone(), renamed);
self.note_options(&sid, &res, Listing::Session);
if let Some(s) = snapshot {
// Its system prompt now names the bot and holds memory as rendered.
@@ -274,6 +282,7 @@ impl Actor {
let Some(conn) = self.conn.as_mut() else { bail!("agent not running") };
let sid = res["sessionId"].as_str().ok_or_else(|| anyhow!("agent returned no sessionId"))?.to_owned();
conn.loaded.insert(sid.clone(), Instant::now());
+ conn.renamed.insert(sid.clone(), renamed);
let options = select_model(&conn.acp, &res, &sid, &self.cfg).await?;
self.note_options(&sid, &options, Listing::Session);
self.set_session(slot, Some(&sid));
diff --git a/host/src/agent/bot/updates.rs b/host/src/agent/bot/updates.rs
index 9e8180ed..2074a372 100644
--- a/host/src/agent/bot/updates.rs
+++ b/host/src/agent/bot/updates.rs
@@ -83,9 +83,9 @@ impl Actor {
"locations": u["locations"].clone(),
});
merge_tool_content(&mut data, &u["content"]);
- mark_bookkeeping(&self.cfg, &self.renamed, &mut data);
+ mark_bookkeeping(&self.cfg, self.renamed(), &mut data);
crate::chat::memory::turns::touched(&self.hub, &self.cfg, &data);
- let working = activity(&data, &self.renamed).to_owned();
+ let working = activity(&data, self.renamed()).to_owned();
if let Some(e) = self.add(EntryKind::Tool, turn, data) {
self.tools.insert(tool_id, e.id);
}
@@ -104,9 +104,9 @@ impl Actor {
e.data["locations"] = u["locations"].clone();
}
merge_tool_content(&mut e.data, &u["content"]);
- mark_bookkeeping(&self.cfg, &self.renamed, &mut e.data);
+ mark_bookkeeping(&self.cfg, self.renamed(), &mut e.data);
crate::chat::memory::turns::touched(&self.hub, &self.cfg, &e.data);
- let working = (e.data["status"] == "in_progress").then(|| activity(&e.data, &self.renamed).to_owned());
+ let working = (e.data["status"] == "in_progress").then(|| activity(&e.data, self.renamed()).to_owned());
self.hub.set_entry(&entry_id, &e.data);
if let Some(working) = working {
self.set_activity(&working);