Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(agent): stop the truncation trailer instructing a retry

M3gA-Mind6965ed2743cc
diff --git a/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod.rs b/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod.rs
index 3d4a385036..d82b7c7c1c 100644
--- a/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod.rs
+++ b/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod.rs
@@ -176,8 +176,25 @@ fn apply_tool_result_budget(content: String, budget_bytes: usize) -> (String, Bu
let dropped_bytes = original_bytes.saturating_sub(cut);
let mut out = String::with_capacity(cut + TRAILER_RESERVED);
out.push_str(&content[..cut]);
+ // Say what was lost, and say what NOT to do about it (#6408).
+ //
+ // The previous wording ended "re-run with a narrower query to see the
+ // rest", which is an instruction to repeat the call. For a listing tool
+ // with no narrowing argument in reach — `GITHUB_LIST_PULL_REQUESTS` is the
+ // reported case — the model has nothing to narrow, so it re-issues the
+ // identical call, gets the identical truncation, and repeats until the
+ // successful-repeat tracker halts the run: 8-14 calls per question, the
+ // token and quota burn, and an "Incomplete" the user cannot explain.
+ //
+ // Truncation here is deterministic: the same call returns the same bytes
+ // and the same cut. Saying so is what makes the retry stop, and giving the
+ // totals lets the model judge whether the head it kept is enough to answer
+ // from. Keep the `truncated by tool_result_budget` phrase — it is the
+ // grep handle several suites and the runbooks match on.
out.push_str(&format!(
- "\n\n[… {dropped_bytes} bytes truncated by tool_result_budget — re-run with a narrower query to see the rest …]"
+ "\n\n[… {dropped_bytes} of {original_bytes} bytes truncated by tool_result_budget. \
+ Repeating this call returns the same truncation — narrow the request \
+ (filter, paginate, or request a smaller range) or answer from the {cut} bytes above …]"
));
let final_bytes = out.len();
diff --git a/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod_tests.rs b/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod_tests.rs
index 6ddf2f4b48..e606ccf66e 100644
--- a/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod_tests.rs
+++ b/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod_tests.rs
@@ -59,6 +59,36 @@ async fn fallback_truncates_when_store_missing() {
assert!(out.len() < 4096);
}
+/// The truncation trailer must not tell the model to re-run the call (#6408).
+///
+/// The old wording ended "re-run with a narrower query to see the rest". A
+/// listing tool with no narrowing argument in reach leaves the model only the
+/// identical call, which returns the identical truncation, until the
+/// successful-repeat tracker halts the run. Assert the retry instruction is
+/// gone and the deterministic-truncation statement that replaces it is
+/// present, so a revert to the old trailer fails here.
+#[tokio::test]
+async fn truncation_trailer_does_not_instruct_a_retry() {
+ let raw = "z".repeat(4096);
+ let (out, outcome) =
+ apply_per_result_persistence(raw, None, None, "GITHUB_LIST_PULL_REQUESTS", None, 512).await;
+
+ assert!(!outcome.persisted, "fixture must truncate inline, not persist");
+ assert!(
+ !out.contains("re-run"),
+ "trailer must not instruct a re-run; got: {out}"
+ );
+ assert!(
+ out.contains("Repeating this call returns the same truncation"),
+ "trailer must say the truncation is deterministic; got: {out}"
+ );
+ // Both totals, so the model can judge whether the retained head suffices.
+ assert!(
+ out.contains("of 4096 bytes truncated by tool_result_budget"),
+ "trailer must report dropped-of-original bytes; got: {out}"
+ );
+}
+
#[tokio::test]
async fn persisted_preview_is_bounded_for_small_budget() {
let tmp = tempfile::tempdir().unwrap();