From 3fd0184208acec26973251fa98526c56cff2ac71 Mon Sep 17 00:00:00 2001 From: 123kupola <123kupola@gmail.com> Date: Sun, 28 Jun 2026 01:30:04 +0200 Subject: [PATCH] fix(daemon): extract hardcoded values in autospawn registration (Sam & Claude) --- crates/colibri-daemon/src/socket.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/crates/colibri-daemon/src/socket.rs b/crates/colibri-daemon/src/socket.rs index a28c4f0..2aa8dcd 100644 --- a/crates/colibri-daemon/src/socket.rs +++ b/crates/colibri-daemon/src/socket.rs @@ -630,6 +630,9 @@ pub async fn autospawn_agent_if_configured(state: &SharedState) { if resp.ok { info!("autospawn: agent spawned"); + // Extract hostname once — used by both agent registration and hw profile. + let hostname = std::env::var("HOSTNAME").unwrap_or_else(|_| "unknown".to_string()); + // Resolve agent_id from the spawn response for both registration and RPC. let agent_id = resp .data @@ -642,14 +645,10 @@ pub async fn autospawn_agent_if_configured(state: &SharedState) { // can route queued tasks to it. Without this, tasks stay stuck in // "queued" — the scheduler only assigns work to registered agents. if let Some(ref aid) = agent_id { - let hostname = std::env::var("HOSTNAME").unwrap_or_else(|_| "unknown".to_string()); + let caps = serde_json::json!(["shell", "freebsd", "code"]); match state.store.try_lock() { Ok(store) => { - if let Err(e) = store.register_agent( - aid, - serde_json::json!(["shell", "freebsd", "code"]), - Some(&hostname), - ) { + if let Err(e) = store.register_agent(aid, caps.clone(), Some(&hostname)) { warn!(agent_id = %aid, error = %e, "autospawn: failed to register agent in store"); } else { info!(agent_id = %aid, hostname = %hostname, "autospawn: agent registered for task work"); @@ -659,11 +658,7 @@ pub async fn autospawn_agent_if_configured(state: &SharedState) { warn!("autospawn: store locked; agent registration deferred"); } Err(std::sync::TryLockError::Poisoned(e)) => { - if let Err(e) = e.into_inner().register_agent( - aid, - serde_json::json!(["shell", "freebsd", "code"]), - Some(&hostname), - ) { + if let Err(e) = e.into_inner().register_agent(aid, caps, Some(&hostname)) { warn!(agent_id = %aid, error = %e, "autospawn: failed to register agent (poisoned store)"); } } @@ -692,7 +687,6 @@ pub async fn autospawn_agent_if_configured(state: &SharedState) { // Register hardware profile with mother if configured (best-effort). if let Some(hw_json) = hw_profile_for_mother { - let hostname = std::env::var("HOSTNAME").unwrap_or_else(|_| "unknown".to_string()); // Spawn a detached tokio task so SSH retries don't block the daemon. let hw_json = hw_json.clone(); tokio::spawn(async move { -- 2.45.3