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: bound the contents list message and drop an empty concluding reply\n\nTwo findings from the same review.\n\n**The contents list still cleared its share with no rows in it.** Truncating to\nzero rows was half a fix: the header and reserved footer are ~118 tokens and\nthe floor a small window gets is 64, so the message was rendered over its share\nregardless. It falls back to one short line naming the count, and says nothing\nat all if even that will not fit — losing the pointer is bad, but an\nunshrinkable system message over the bound makes the trim evict transcript,\nwhich is worse. The test that was meant to pin this asserted\n`< 64 + FOOTER_ALLOWANCE + 64`, loose enough to accept exactly the overshoot it\nwas watching for; it now asserts the message fits the share.\n\n**A concluding call that answers with nothing left an empty assistant message\nin the history**, which `extend(outcome.conversation)` folds in before the\nout-of-band wrap-up builds its request from it. Anthropic rejects empty\ncontent, so "the model said nothing" became a failed turn, and the message\npersisted into the next request's prefix besides. The predicate lives in\n`core.rs` as `is_empty_assistant_chat` — both because `core_session.rs` is at\nthe 750-line layout limit and because it is the testable half.\n\nReported by CodeRabbit on #6068.\n\n
sanil-230510f64bb2bb
diff --git a/src/openhuman/agent/harness/session/turn/core.rs b/src/openhuman/agent/harness/session/turn/core.rsindex 2724d2a720..03892d1a08 100644--- a/src/openhuman/agent/harness/session/turn/core.rs+++ b/src/openhuman/agent/harness/session/turn/core.rs@@ -171,6 +171,21 @@ fn short_failure_detail(content: &str) -> Option<String> {/// row is touched — when the tail is not an assistant `Chat` (defensive; a clean/// finish, a cap checkpoint, and the #4093 close all end on one) a fresh/// assistant message is appended rather than mutating an older entry.+#[cfg(test)]+#[path = "core_tests.rs"]+mod tests;++/// Whether a history row is an assistant `Chat` with nothing in it.+///+/// The cap path's concluding call can answer with empty text, and that message+/// is folded into the history before the out-of-band wrap-up builds its request+/// from it. Anthropic rejects a message with empty content, so it has to go+/// (CodeRabbit on #6068).+pub(super) fn is_empty_assistant_chat(message: &ConversationMessage) -> bool {+ matches!(message, ConversationMessage::Chat(chat)+ if chat.role == "assistant" && chat.content.trim().is_empty())+}+fn replace_last_assistant_reply(history: &mut Vec<ConversationMessage>, text: &str) {match history.last_mut() {Some(ConversationMessage::Chat(chat)) if chat.role == "assistant" => {diff --git a/src/openhuman/agent/harness/session/turn/core_session.rs b/src/openhuman/agent/harness/session/turn/core_session.rsindex 3a3564cba1..a4dde8e5ed 100644--- a/src/openhuman/agent/harness/session/turn/core_session.rs+++ b/src/openhuman/agent/harness/session/turn/core_session.rs@@ -252,6 +252,13 @@ impl Agent {// back empty: a run with the middleware uninstalled, a budget of one// model call, or a concluding call that answered with nothing. Kept// intact so no path loses the behaviour it had before #6014.+ // The concluding call answered with nothing, and the `extend` above+ // folded that empty assistant message into `self.history`. Anthropic+ // rejects empty content, so sending it would turn "the model said+ // nothing" into a failed turn (CodeRabbit on #6068).+ if self.history.last().is_some_and(is_empty_assistant_chat) {+ self.history.pop();+ }let base = self.tool_dispatcher.to_provider_messages(&self.history);let (summary, summary_usage) = self.summarize_turn_wrapup(diff --git a/src/openhuman/agent/harness/session/turn/core_tests.rs b/src/openhuman/agent/harness/session/turn/core_tests.rsnew file mode 100644index 0000000000..d63c2e7c54--- /dev/null+++ b/src/openhuman/agent/harness/session/turn/core_tests.rs@@ -0,0 +1,33 @@+//! What the cap path must not send to a provider (#6068).+//!+//! Sibling `*_tests.rs` file rather than an inline module, per the Rust layout+//! gate. `is_empty_assistant_chat` is `pub(super)` inside a private `core`+//! module, so this is the one place it is reachable from.++use super::*;++#[test]+fn an_empty_assistant_reply_is_recognised_for_removal() {+ let empty = ConversationMessage::Chat(ChatMessage::assistant(String::new()));+ let blank = ConversationMessage::Chat(ChatMessage::assistant(" \n".to_string()));+ let real =+ ConversationMessage::Chat(ChatMessage::assistant("here is what I found".to_string()));+ let user = ConversationMessage::Chat(ChatMessage::user("do the thing".to_string()));++ assert!(+ is_empty_assistant_chat(&empty),+ "empty content must be dropped"+ );+ assert!(+ is_empty_assistant_chat(&blank),+ "whitespace-only content is empty to a provider too"+ );+ assert!(+ !is_empty_assistant_chat(&real),+ "a real conclusion must never be dropped"+ );+ assert!(+ !is_empty_assistant_chat(&user),+ "only the assistant's own empty turn is at issue"+ );+}diff --git a/src/openhuman/agent/tinyagents/middleware_part_06.rs b/src/openhuman/agent/tinyagents/middleware_part_06.rsindex 4a69a806ae..f414baf000 100644--- a/src/openhuman/agent/tinyagents/middleware_part_06.rs+++ b/src/openhuman/agent/tinyagents/middleware_part_06.rs@@ -458,11 +458,29 @@ impl Middleware<()> for ArtifactIndexTocMiddleware {text you saw for them is a preview; the full content is at the path below and can be \read with the file-reading tool when you need detail the preview does not carry.\n\n");+ // One line that still names the count, for a share too small to hold+ // the header at all (CodeRabbit on #6068). Truncating to zero rows was+ // half the fix: the fixed text is ~118 tokens and the floor a small+ // window gets is 64, so the message still cleared its share with no+ // rows in it.+ let compact =+ format!("_{total} tool result(s) were written to disk — ask by tool name to locate one._");if self.input_budget > 0 {+ let cap = self.input_budget.max(1);+ let fixed = estimate_text_tokens(&header).saturating_add(FOOTER_ALLOWANCE);+ if fixed > cap {+ // Even the compact line has to fit. Saying nothing loses the+ // pointer, which is bad; pushing an unshrinkable system message+ // over the bound makes the trim evict transcript instead, which+ // is worse.+ if estimate_text_tokens(&compact) <= cap {+ request.messages.push(TaMessage::system(compact));+ }+ return Ok(());+ }// Already this middleware's share of the turn's allowance — the// split happens once, at the install site, so the two things that// add to the request cannot each spend the whole of it.- let cap = self.input_budget.max(1);// Seeded with the fixed text, so the cap bounds the whole message// rather than the rows alone (CodeRabbit on #6068). The header is a// paragraph; against the 64-token floor a small window gets, it isdiff --git a/src/openhuman/agent/tinyagents/middleware_tests_part_03_tests.rs b/src/openhuman/agent/tinyagents/middleware_tests_part_03_tests.rsindex fc1633e44e..cb5e376b6b 100644--- a/src/openhuman/agent/tinyagents/middleware_tests_part_03_tests.rs+++ b/src/openhuman/agent/tinyagents/middleware_tests_part_03_tests.rs@@ -719,13 +719,17 @@ async fn a_share_smaller_than_the_header_renders_no_rows() {"no row fits the share, so none may be forced: {text}");assert!(- text.contains("10 more stored result(s) not listed here"),- "every result was omitted and that must be disclosed: {text}"- );- // Nothing beyond the fixed text was spent.+ text.contains("10 tool result(s) were written to disk"),+ "the count must still be named so the results stay findable: {text}"+ );+ // The bound that matters: the whole rendered message inside the share.+ // Truncating to zero rows was not enough — the header and footer alone are+ // ~118 tokens against this 64-token floor, and the earlier form of this+ // assertion (`< 64 + FOOTER_ALLOWANCE + 64`) was loose enough to accept+ // exactly that overshoot (CodeRabbit on #6068).assert!(- estimate_text_tokens(&text) < 64 + FOOTER_ALLOWANCE + 64,- "the message must carry the fixed text and nothing more: {}",+ estimate_text_tokens(&text) <= 64,+ "the message must fit the share it was given: {}",estimate_text_tokens(&text));}