refactor(agent): fire_and_forget helper, drop dead default_model + compact_percent fallback, fix stale comment
This commit is contained in:
parent
9721be7bc3
commit
77f31b44bb
3 changed files with 27 additions and 34 deletions
|
|
@ -276,39 +276,37 @@ trait Surface {
|
||||||
/// Talks `AgentRequest` / `AgentResponse`.
|
/// Talks `AgentRequest` / `AgentResponse`.
|
||||||
struct AgentSurface;
|
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 {
|
impl Surface for AgentSurface {
|
||||||
async fn ack_turn(socket: &Path) {
|
async fn ack_turn(socket: &Path) {
|
||||||
match client::request::<_, AgentResponse>(socket, &AgentRequest::AckTurn).await {
|
fire_and_forget(socket, AgentRequest::AckTurn, "ack_turn").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"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn requeue_inflight(socket: &Path) {
|
async fn requeue_inflight(socket: &Path) {
|
||||||
match client::request::<_, AgentResponse>(socket, &AgentRequest::RequeueInflight).await {
|
fire_and_forget(socket, AgentRequest::RequeueInflight, "requeue_inflight").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"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn graceful_stop_complete(socket: &Path) {
|
async fn graceful_stop_complete(socket: &Path) {
|
||||||
match client::request::<_, AgentResponse>(socket, &AgentRequest::GracefulStopComplete).await
|
fire_and_forget(
|
||||||
{
|
socket,
|
||||||
Ok(AgentResponse::Ok) => {}
|
AgentRequest::GracefulStopComplete,
|
||||||
Ok(AgentResponse::Err { message }) => {
|
"graceful_stop_complete",
|
||||||
tracing::warn!(%message, "graceful_stop_complete rejected by broker");
|
)
|
||||||
}
|
.await;
|
||||||
Ok(other) => tracing::warn!(?other, "graceful_stop_complete unexpected response"),
|
|
||||||
Err(e) => tracing::warn!(error = ?e, "graceful_stop_complete transport error"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn inbox_unread(socket: &Path) -> u64 {
|
async fn inbox_unread(socket: &Path) -> u64 {
|
||||||
|
|
|
||||||
|
|
@ -466,12 +466,6 @@ pub fn configured_model() -> Option<&'static str> {
|
||||||
.map(|s| &*Box::leak(s.into_boxed_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
|
/// Compiled-in fallback effort level — matches the `effortLevel` baked
|
||||||
/// into `prompts/claude-settings.json`.
|
/// into `prompts/claude-settings.json`.
|
||||||
pub const DEFAULT_EFFORT: &str = "medium";
|
pub const DEFAULT_EFFORT: &str = "medium";
|
||||||
|
|
|
||||||
|
|
@ -92,8 +92,8 @@ pub struct TurnFiles {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TurnFiles {
|
impl TurnFiles {
|
||||||
/// Write all three files into the per-agent runtime dir alongside
|
/// Write the two per-turn files (MCP config + system prompt) into the
|
||||||
/// `socket`. Idempotent — overwrites whatever was there.
|
/// agent's config dir. Idempotent — overwrites whatever was there.
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
|
|
@ -238,7 +238,8 @@ fn compact_percent() -> u8 {
|
||||||
}
|
}
|
||||||
let pct =
|
let pct =
|
||||||
env_u64("HIVE_COMPACT_WATERMARK_PERCENT").unwrap_or(u64::from(DEFAULT_COMPACT_PERCENT));
|
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`]
|
/// The agent's durable session type: the constant-title [`InfiniteSession`]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue