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): stop the compact→retrieve→re-run infinite loop
yh928091312160f4e
diff --git a/src/openhuman/inference/tokenjuice/tools.rs b/src/openhuman/inference/tokenjuice/tools.rsindex 3cc786ba11..a86bfacef7 100644--- a/src/openhuman/inference/tokenjuice/tools.rs+++ b/src/openhuman/inference/tokenjuice/tools.rs@@ -125,9 +125,19 @@ impl Tool for TokenjuiceRetrieveTool {}fn miss_message(token: &str) -> String {+ // Deliberately does NOT say "re-run the tool". Re-running regenerates the+ // same oversized result, which is compacted and offloaded again under a new+ // token that can be evicted just as fast — so a blind re-run turns one cache+ // miss into an unbounded compact→retrieve→re-run loop (observed live: a+ // parent agent re-delegated forever on an evicted subagent result). Tell the+ // model to proceed with the compacted summary it already has instead.format!(- "tokenjuice_retrieve: no cached original for token '{token}' \- (it may have been evicted; re-run the tool to regenerate it)"+ "tokenjuice_retrieve: the full original for token '{token}' is no longer cached \+ (evicted, or from an earlier session). Do NOT re-run the same tool call to \+ regenerate it — that will produce the same oversized result and be compacted \+ again. Proceed using the compacted summary already shown above; only if a \+ specific missing detail is essential, retry with narrower arguments (a tighter \+ query, filter, or smaller limit) so the result is small enough to keep in full.")}diff --git a/src/openhuman/inference/tokenjuice/tools_tests.rs b/src/openhuman/inference/tokenjuice/tools_tests.rsindex ca82e5318f..1276d9b5dc 100644--- a/src/openhuman/inference/tokenjuice/tools_tests.rs+++ b/src/openhuman/inference/tokenjuice/tools_tests.rs@@ -35,3 +35,19 @@ async fn missing_token_is_error() {let res2 = tool.execute(json!({})).await.unwrap();assert!(res2.is_error);}++#[test]+fn miss_message_does_not_instruct_a_blind_re_run() {+ // See `miss_message` — "re-run the tool" here is what turned a single+ // eviction into an unbounded compact→retrieve→re-run loop.+ let msg = miss_message("deadbeefcafe").to_lowercase();+ assert!(!msg.contains("re-run the same tool") || msg.contains("do not re-run"));+ assert!(+ msg.contains("do not re-run"),+ "must discourage re-running: {msg}"+ );+ assert!(+ msg.contains("compacted summary"),+ "must point at the summary: {msg}"+ );+}diff --git a/src/openhuman/tools/impl/system/retrieve_tool_output.rs b/src/openhuman/tools/impl/system/retrieve_tool_output.rsindex 9f10b732c4..628602ab2c 100644--- a/src/openhuman/tools/impl/system/retrieve_tool_output.rs+++ b/src/openhuman/tools/impl/system/retrieve_tool_output.rs@@ -77,9 +77,21 @@ impl Tool for RetrieveToolOutputTool {);Ok(ToolResult::success(original))}+ // Deliberately does NOT say "re-run the tool". Re-running+ // regenerates the same oversized result, which is compacted and+ // offloaded again under a new hash that can be evicted just as fast+ // — so a blind re-run turns one cache miss into an unbounded+ // compact→retrieve→re-run loop (observed live: a parent agent+ // re-delegated forever on an evicted subagent result). Tell the+ // model to proceed with the compacted summary it already has.Ok(None) => Ok(ToolResult::error(format!(- "retrieve_tool_output: no cached original for hash '{hash}' \- (it may have been evicted; re-run the tool to regenerate it)"+ "retrieve_tool_output: the full original for hash '{hash}' is no longer \+ cached (evicted, or from an earlier session). Do NOT re-run the same tool \+ call to regenerate it — that produces the same oversized result and is \+ compacted again. Proceed using the compacted summary already shown above; \+ only if a specific missing detail is essential, retry with narrower \+ arguments (a tighter query, filter, or smaller limit) so the result is \+ small enough to keep in full."))),Err(error) => Ok(ToolResult::error(error)),}diff --git a/src/openhuman/tools/impl/system/retrieve_tool_output_tests.rs b/src/openhuman/tools/impl/system/retrieve_tool_output_tests.rsindex e9f69cbbe5..6bc84e545f 100644--- a/src/openhuman/tools/impl/system/retrieve_tool_output_tests.rs+++ b/src/openhuman/tools/impl/system/retrieve_tool_output_tests.rs@@ -21,3 +21,28 @@ async fn missing_hash_is_error() {let res2 = tool.execute(json!({})).await.unwrap();assert!(res2.is_error);}++#[tokio::test]+async fn a_cache_miss_does_not_tell_the_model_to_re_run() {+ // The loop this guards against: a miss that says "re-run the tool" makes+ // the agent regenerate the same oversized result, which is compacted and+ // evicted again — an unbounded compact→retrieve→re-run loop.+ let tool = RetrieveToolOutputTool::new();+ let msg = tool+ .execute(json!({ "hash": "deadbeefcafe" }))+ .await+ .unwrap()+ .output();+ assert!(+ !msg.to_lowercase().contains("re-run the tool"),+ "a miss must not instruct a blind re-run: {msg}"+ );+ assert!(+ msg.to_lowercase().contains("do not re-run"),+ "a miss must explicitly discourage re-running: {msg}"+ );+ assert!(+ msg.contains("compacted summary"),+ "a miss must point the model at the summary it already has: {msg}"+ );+}