The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(agent): keep the unavailable notice intact, and stop it overclaiming\n\nTwo review findings on the disclosure, both about the notice rather than\nthe outcome plumbing.\n\nThe notice was prefixed before the truncation stages, and the per-tool char\ncap runs `content.chars().take(cap)`. The notice is ~165 chars, so a tool\ndeclaring a `max_result_size_chars` below that had the cap slice straight\nthrough it — removing the reason text and the do-not-re-run sentence and\nleaving a fragment that still reads as ordinary tool output. The stage that\nexists to stop a silent re-dispatch loop was therefore removed exactly when\nthe payload was most aggressively truncated.\n\nThe notice is now held in a local and applied after every cap. The payload\nis still capped to the tool's declared limit — deferring the notice must\nnot smuggle a tool past its own contract — and a regression test with a\n12-char cap against a 1,600-char payload asserts both halves: the complete\nnotice leads the content, and the payload still carries the tool-cap\nmarker. As a side effect the caps now bound the tool's own output rather\nthan openhuman's annotation about it, which is what a tool's declared cap\nis a contract about.\n\nSeparately, every variant asserted that "re-running this tool will return\nthe same result". That is false. `Failed` leaves the breaker open for\nfurther attempts, so a second summarization can genuinely succeed, and an\nAPI-backed tool is time-varying regardless — so the sentence could suppress\na recovery the model had good reason to attempt. Reworded to\n"Re-running it will not produce a summary", which is the only claim this\ncode can actually make and still carries the anti-loop property the notice\nwas added for. The doc comment now says why the stronger phrasing was\nwrong, so it does not get restored as a tightening.\n
M3gA-Mindb4404d6e3306
diff --git a/src/openhuman/agent/tinyagents/middleware.rs b/src/openhuman/agent/tinyagents/middleware.rsindex 3a101fc55e..b0c61f1a2e 100644--- a/src/openhuman/agent/tinyagents/middleware.rs+++ b/src/openhuman/agent/tinyagents/middleware.rs@@ -718,6 +718,17 @@ impl Middleware<()> for ToolOutputMiddleware {// `if let Ok(Some(payload)) = …`, which discarded `Err(_)` and// `Ok(None)` identically — so a failed summarization reached the// model as an unannounced raw dump and it re-called the same tool.+ // Held until after the caps below rather than prefixed here. The notice+ // is ~165 chars; a tool declaring a `max_result_size_chars` smaller than+ // that had step 3 run `chars().take(cap)` straight through it, cutting+ // the reason text and the do-not-re-run sentence mid-word — so the one+ // stage that exists to stop a re-dispatch loop was removed exactly when+ // the output was most aggressively truncated. Capping the payload first+ // and prefixing afterwards also means a tool's declared cap bounds the+ // tool's own output, which is what it is a contract about, rather than+ // openhuman's annotation about it.+ let mut pending_notice: Option<&'static str> = None;+if !compaction_exempt {if let Some(ps) = &self.payload_summarizer {match ps@@ -747,7 +758,7 @@ impl Middleware<()> for ToolOutputMiddleware {?reason,"[tinyagents::mw] payload_summarizer unavailable; disclosing raw output");- result.content = format!("{}\n\n{}", reason.notice(), result.content);+ pending_notice = Some(reason.notice());}// Reserved for fatal misconfiguration. Previously// indistinguishable from "nothing to do"; the model is now@@ -759,11 +770,7 @@ impl Middleware<()> for ToolOutputMiddleware {error = %error,"[tinyagents::mw] payload_summarizer errored; disclosing raw output");- result.content = format!(- "{}\n\n{}",- UnavailableReason::Failed.notice(),- result.content- );+ pending_notice = Some(UnavailableReason::Failed.notice());}}}@@ -887,6 +894,15 @@ impl Middleware<()> for ToolOutputMiddleware {}result.content = capped;}++ // 5. The disclosure, last, so no cap above can eat it. The model has to+ // be able to read *why* the payload is raw and that re-running will+ // not summarize it — a half-truncated notice is worse than none,+ // because it still looks like tool output.+ if let Some(notice) = pending_notice {+ result.content = format!("{notice}\n\n{}", result.content);+ }+Ok(())}}@@ -3578,6 +3594,71 @@ mod tests {assert_eq!(mw.tool_char_cap("other"), None);}+ /// openhuman#5722 review: the disclosure used to be prefixed *before* the+ /// per-tool char cap, so a tool declaring a cap shorter than the notice had+ /// `chars().take(cap)` slice through the notice itself — dropping the+ /// reason and the do-not-re-run sentence, and leaving the model a truncated+ /// fragment that still reads as tool output. The notice is applied after+ /// every cap now, so it survives intact whatever the tool declared.+ #[tokio::test]+ async fn an_unavailable_notice_survives_a_tool_cap_shorter_than_itself() {+ let mut tool_policies = HashMap::new();+ tool_policies.insert(+ "terse".to_string(),+ TaToolPolicy::classified().with_runtime(tinyagents::harness::tool::ToolRuntime {+ timeout_ms: None,+ timeout: tinyagents::harness::tool::ToolTimeout::Inherit,+ max_retries: None,+ idempotent: false,+ cancelable: true,+ sandbox: tinyagents::harness::tool::SandboxMode::Inherit,+ // Far shorter than the ~165-char notice.+ max_result_bytes: Some(12),+ streaming: false,+ }),+ );+ let mw = ToolOutputMiddleware {+ // Large enough that the byte-budget backstop never fires, so this+ // observes the per-tool cap alone.+ budget_bytes: 10_000_000,+ payload_summarizer: Some(StubSummarizer::ok(SummarizeOutcome::Unavailable(+ UnavailableReason::Failed,+ ))),+ artifact_store: None,+ tokenjuice_compaction_enabled: false,+ tokenjuice_compression:+ crate::openhuman::inference::tokenjuice::AgentTokenjuiceCompression::Off,+ tool_policies,+ };++ let mut result = tool_result("terse", &"payload ".repeat(200));+ mw.after_tool(&mut ctx(), &(), &mut result).await.unwrap();++ let notice = UnavailableReason::Failed.notice();+ assert!(+ result.content.starts_with(notice),+ "the complete notice must lead the content, got {:?}",+ result.content.chars().take(200).collect::<String>()+ );+ assert!(+ result+ .content+ .contains("Re-running it will not produce a summary."),+ "the do-not-re-run sentence is the whole point of the notice and must survive"+ );+ // The payload itself is still capped — deferring the notice must not+ // smuggle the tool past its own declared limit.+ let payload = result+ .content+ .strip_prefix(notice)+ .expect("notice prefix")+ .trim_start();+ assert!(+ payload.contains("[truncated by tool cap:"),+ "the raw payload must still be truncated to the tool's cap, got {payload:?}"+ );+ }+#[tokio::test]async fn tool_output_honors_a_tools_own_cap() {let mut tool_policies = HashMap::new();diff --git a/src/openhuman/agent/tinyagents/payload_summarizer.rs b/src/openhuman/agent/tinyagents/payload_summarizer.rsindex ad077f3077..460dff608a 100644--- a/src/openhuman/agent/tinyagents/payload_summarizer.rs+++ b/src/openhuman/agent/tinyagents/payload_summarizer.rs@@ -94,31 +94,43 @@ pub enum UnavailableReason {impl UnavailableReason {/// The model-facing notice for this reason.///- /// **Prefixed** to the tool result, never appended: the downstream+ /// **Prefixed** to the tool result, never appended, and prefixed by the+ /// caller *after* its truncation stages have run. Both halves matter. The/// per-tool char cap keeps the head (`content.chars().take(cap)`), so an- /// appended notice is the first thing truncation removes.+ /// appended notice is the first thing truncation removes — but a notice+ /// prefixed *before* that cap is no safer, because a tool declaring a+ /// `max_result_size_chars` below this string's length truncates the notice+ /// itself. Applying it last is the only placement that survives both.///- /// Every variant ends by saying a retry is pointless. Without that, the- /// model's reasonable response to a truncated dump is to call the same- /// tool again — the silent re-dispatch loop that reads to a user as a- /// hang.+ /// Every variant ends by telling the model not to re-run the tool *for a+ /// summary*. Without that, the model's reasonable response to a truncated+ /// dump is to call the same tool again — the silent re-dispatch loop that+ /// reads to a user as a hang.+ ///+ /// Note what this deliberately does **not** say: that a re-run returns the+ /// same bytes. It usually will not. `Failed` leaves the breaker open for+ /// further attempts, so a second summarization can genuinely succeed, and+ /// an API-backed tool is time-varying regardless. Asserting result identity+ /// would be false in the direction that suppresses a legitimate retry the+ /// model had good reason to make. The claim is scoped to the only thing+ /// this code actually knows: re-running will not conjure a summary.#[must_use]pub fn notice(self) -> &'static str {match self {Self::PayloadTooLarge => concat!("[openhuman: summarization unavailable — this output exceeds the summarizer's ","size cap, so the raw output follows and may be truncated. ",- "Re-running this tool will return the same result.]"+ "Re-running it will not produce a summary.]"),Self::Disabled => concat!("[openhuman: summarization unavailable — it is switched off for this session ","after repeated failures, so the raw output follows. ",- "Re-running this tool will return the same result.]"+ "Re-running it will not produce a summary.]"),Self::Failed => concat!("[openhuman: summarization unavailable — the summarizer did not return a usable ","summary, so the raw output follows. ",- "Re-running this tool will return the same result.]"+ "Re-running it will not produce a summary.]"),}}@@ -688,7 +700,7 @@ mod tests {] {let notice = reason.notice();assert!(- notice.contains("Re-running this tool will return the same result."),+ notice.contains("Re-running it will not produce a summary."),"{reason:?} must tell the model not to retry: {notice}");assert!(