From be5b36911a404a046c6c28dcca3b0a971edb4502 Mon Sep 17 00:00:00 2001 From: damocles Date: Thu, 2 Jul 2026 22:22:03 +0200 Subject: [PATCH] recv: hoist RECV_BATCH_MAX into hive-sh4re, drop magic 5 in wake hint --- hive-ag3nt/src/serve_common.rs | 6 +++--- hive-c0re/src/socket_server.rs | 11 ++++------- hive-sh4re/src/lib.rs | 10 ++++++++++ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/hive-ag3nt/src/serve_common.rs b/hive-ag3nt/src/serve_common.rs index 0e13b909..bdff6cf7 100644 --- a/hive-ag3nt/src/serve_common.rs +++ b/hive-ag3nt/src/serve_common.rs @@ -32,9 +32,9 @@ pub fn format_wake_prompt( String::new() } else { // Suggested batch size is clamped to the server-side recv cap - // (see `RECV_BATCH_MAX` in hive-c0re) so the hint never asks - // for more than one round-trip can deliver. - let batch = unread.min(5); + // so the hint never asks for more than one round-trip can + // deliver. + let batch = unread.min(u64::from(hive_sh4re::RECV_BATCH_MAX)); format!( "\n\n({unread} more message(s) pending in your inbox — call `mcp__hyperhive__recv` \ with `max: {batch}` to drain the next batch before acting. If the \ diff --git a/hive-c0re/src/socket_server.rs b/hive-c0re/src/socket_server.rs index 7f8aeb5c..de8446ec 100644 --- a/hive-c0re/src/socket_server.rs +++ b/hive-c0re/src/socket_server.rs @@ -149,13 +149,10 @@ async fn serve(stream: UnixStream, agent: String, coord: Arc) -> Re /// positive `wait_seconds`. pub(crate) const RECV_LONG_POLL_MAX: std::time::Duration = std::time::Duration::from_mins(3); -/// Server-side hard cap on `Recv.max`. Bounds the size of a single -/// round-trip so a confused caller can't drain the entire inbox in -/// one go and blow past wire-buffer sizes; everything above the cap -/// silently clamps. 5 keeps individual turns small — a big backlog -/// is drained over several recv calls instead of one giant pop -/// (#2150). -pub(crate) const RECV_BATCH_MAX: u32 = 5; +/// Server-side hard cap on `Recv.max` — canonical value lives in +/// `hive_sh4re::RECV_BATCH_MAX` so the harness's wake-prompt hint and +/// this enforcement site can't drift apart (#2150). +pub(crate) const RECV_BATCH_MAX: u32 = hive_sh4re::RECV_BATCH_MAX; pub(crate) fn recv_timeout(wait_seconds: Option) -> std::time::Duration { match wait_seconds { diff --git a/hive-sh4re/src/lib.rs b/hive-sh4re/src/lib.rs index 3913e120..3f422be3 100644 --- a/hive-sh4re/src/lib.rs +++ b/hive-sh4re/src/lib.rs @@ -7,6 +7,16 @@ pub mod paths; pub mod priv_proto; pub mod wire_time; +/// Server-side hard cap on `Recv.max` (see `AgentRequest::Recv`). Bounds +/// the size of a single round-trip so a confused caller can't drain the +/// entire inbox in one go and blow past wire-buffer sizes; everything +/// above the cap silently clamps. 5 keeps individual turns small — a big +/// backlog is drained over several recv calls instead of one giant pop +/// (#2150). Lives here so both the enforcing side (hive-c0re's +/// socket_server) and the hinting side (hive-ag3nt's wake prompt + tool +/// docs) reference one constant instead of a scattered magic value. +pub const RECV_BATCH_MAX: u32 = 5; + // ----------------------------------------------------------------------------- // Host admin socket — /run/hyperhive/host.sock // -----------------------------------------------------------------------------