From 77f31b44bb2a997ca757baf45117c5f2902dfafe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?m=C3=BCde?= Date: Sun, 5 Jul 2026 22:43:23 +0200 Subject: [PATCH] refactor(agent): fire_and_forget helper, drop dead default_model + compact_percent fallback, fix stale comment --- hive-ag3nt/src/bin/hive.rs | 48 ++++++++++++++++++-------------------- hive-ag3nt/src/events.rs | 6 ----- hive-ag3nt/src/turn.rs | 7 +++--- 3 files changed, 27 insertions(+), 34 deletions(-) diff --git a/hive-ag3nt/src/bin/hive.rs b/hive-ag3nt/src/bin/hive.rs index 1bc1df0d..0748f356 100644 --- a/hive-ag3nt/src/bin/hive.rs +++ b/hive-ag3nt/src/bin/hive.rs @@ -276,39 +276,37 @@ trait Surface { /// Talks `AgentRequest` / `AgentResponse`. struct AgentSurface; +/// Issue an `Ok`-expecting fire-and-forget broker request, logging any +/// rejection / unexpected response / transport error under `label`. Shared by +/// the `Surface` methods that don't need the reply (`ack_turn`, +/// `requeue_inflight`, `graceful_stop_complete`). +async fn fire_and_forget(socket: &Path, req: AgentRequest, label: &str) { + match client::request::<_, AgentResponse>(socket, &req).await { + Ok(AgentResponse::Ok) => {} + Ok(AgentResponse::Err { message }) => { + tracing::warn!(%message, "{label} rejected by broker"); + } + Ok(other) => tracing::warn!(?other, "{label} unexpected response"), + Err(e) => tracing::warn!(error = ?e, "{label} transport error"), + } +} + impl Surface for AgentSurface { async fn ack_turn(socket: &Path) { - match client::request::<_, AgentResponse>(socket, &AgentRequest::AckTurn).await { - Ok(AgentResponse::Ok) => {} - Ok(AgentResponse::Err { message }) => { - tracing::warn!(%message, "ack_turn rejected by broker"); - } - Ok(other) => tracing::warn!(?other, "ack_turn unexpected response"), - Err(e) => tracing::warn!(error = ?e, "ack_turn transport error"), - } + fire_and_forget(socket, AgentRequest::AckTurn, "ack_turn").await; } async fn requeue_inflight(socket: &Path) { - match client::request::<_, AgentResponse>(socket, &AgentRequest::RequeueInflight).await { - Ok(AgentResponse::Ok) => {} - Ok(AgentResponse::Err { message }) => { - tracing::warn!(%message, "requeue_inflight rejected by broker"); - } - Ok(other) => tracing::warn!(?other, "requeue_inflight unexpected response"), - Err(e) => tracing::warn!(error = ?e, "requeue_inflight transport error"), - } + fire_and_forget(socket, AgentRequest::RequeueInflight, "requeue_inflight").await; } async fn graceful_stop_complete(socket: &Path) { - match client::request::<_, AgentResponse>(socket, &AgentRequest::GracefulStopComplete).await - { - Ok(AgentResponse::Ok) => {} - Ok(AgentResponse::Err { message }) => { - tracing::warn!(%message, "graceful_stop_complete rejected by broker"); - } - Ok(other) => tracing::warn!(?other, "graceful_stop_complete unexpected response"), - Err(e) => tracing::warn!(error = ?e, "graceful_stop_complete transport error"), - } + fire_and_forget( + socket, + AgentRequest::GracefulStopComplete, + "graceful_stop_complete", + ) + .await; } async fn inbox_unread(socket: &Path) -> u64 { diff --git a/hive-ag3nt/src/events.rs b/hive-ag3nt/src/events.rs index 1b94893c..7cba626f 100644 --- a/hive-ag3nt/src/events.rs +++ b/hive-ag3nt/src/events.rs @@ -466,12 +466,6 @@ pub fn configured_model() -> Option<&'static str> { .map(|s| &*Box::leak(s.into_boxed_str())) } -/// Return the model to use when no config and no persisted override exist. -#[must_use] -pub fn default_model() -> &'static str { - configured_model().unwrap_or(DEFAULT_MODEL) -} - /// Compiled-in fallback effort level — matches the `effortLevel` baked /// into `prompts/claude-settings.json`. pub const DEFAULT_EFFORT: &str = "medium"; diff --git a/hive-ag3nt/src/turn.rs b/hive-ag3nt/src/turn.rs index ea03bdb4..eed75b8e 100644 --- a/hive-ag3nt/src/turn.rs +++ b/hive-ag3nt/src/turn.rs @@ -92,8 +92,8 @@ pub struct TurnFiles { } impl TurnFiles { - /// Write all three files into the per-agent runtime dir alongside - /// `socket`. Idempotent — overwrites whatever was there. + /// Write the two per-turn files (MCP config + system prompt) into the + /// agent's config dir. Idempotent — overwrites whatever was there. /// /// # Errors /// @@ -238,7 +238,8 @@ fn compact_percent() -> u8 { } let pct = env_u64("HIVE_COMPACT_WATERMARK_PERCENT").unwrap_or(u64::from(DEFAULT_COMPACT_PERCENT)); - u8::try_from(pct.min(100)).unwrap_or(DEFAULT_COMPACT_PERCENT) + // `min(100)` is ≤ 100, so this `try_from` is infallible. + u8::try_from(pct.min(100)).expect("value clamped to <= 100 fits in u8") } /// The agent's durable session type: the constant-title [`InfiniteSession`]