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(session-host): name output-budget truncation in closing instruction
Steven Enamakeld9da57bc33d1
diff --git a/crates/openhuman-core/src/agent/session_host/driver/grounded_close.rs b/crates/openhuman-core/src/agent/session_host/driver/grounded_close.rsindex a7e20edbe7..8223de3837 100644--- a/crates/openhuman-core/src/agent/session_host/driver/grounded_close.rs+++ b/crates/openhuman-core/src/agent/session_host/driver/grounded_close.rs@@ -142,6 +142,36 @@ pub(super) async fn repair_required_output(})}+/// The tool-less closing instruction for `outcome`: the cap checkpoint when the+/// run stopped at its call cap, otherwise the final-answer directive — which+/// names the run's real stop cause (a breaker halt, or a reply that ran out of+/// output tokens while reasoning) rather than claiming the model finished.+fn close_instruction(+ outcome: &TinyagentsTurnOutcome,+ needs_cap_close: bool,+ rendered: &str,+) -> String {+ if needs_cap_close {+ return format!(+ "{}\n\n<tool_records>\n{}\n</tool_records>",+ wrap_harness_instruction(turn_checkpoint::MAX_ITER_CHECKPOINT_INSTRUCTION),+ if rendered.is_empty() {+ "(no tool calls completed)"+ } else {+ rendered+ }+ );+ }+ if outcome.truncated {+ tracing::info!(+ model_calls = outcome.model_calls,+ tool_calls = outcome.tool_calls,+ "[session-runtime] closing a turn whose last reply ran out of output tokens"+ );+ }+ final_answer_instruction(outcome.breaker_halt.as_deref(), outcome.truncated, rendered)+}+/// Return `None` when the loop's terminal text is already usable.#[allow(clippy::too_many_arguments)]pub(super) async fn close_if_needed(@@ -165,19 +195,7 @@ pub(super) async fn close_if_needed(}let records = results_from_tool_outcomes(&outcome.tool_outcomes);let rendered = render_tool_results(&records, turn_checkpoint::GROUNDING_TOTAL_CHARS);- let instruction = if needs_cap_close {- format!(- "{}\n\n<tool_records>\n{}\n</tool_records>",- wrap_harness_instruction(turn_checkpoint::MAX_ITER_CHECKPOINT_INSTRUCTION),- if rendered.is_empty() {- "(no tool calls completed)"- } else {- &rendered- }- )- } else {- final_answer_instruction(outcome.breaker_halt.as_deref(), &rendered)- };+ let instruction = close_instruction(outcome, needs_cap_close, &rendered);let base: Vec<TranscriptMessage> = base_history.iter().filter_map(message_to_native_chat_message)diff --git a/crates/openhuman-core/src/agent/session_host/driver/grounded_close_tests.rs b/crates/openhuman-core/src/agent/session_host/driver/grounded_close_tests.rsindex 5bb02d7d15..4cb7cbbe4f 100644--- a/crates/openhuman-core/src/agent/session_host/driver/grounded_close_tests.rs+++ b/crates/openhuman-core/src/agent/session_host/driver/grounded_close_tests.rs@@ -184,3 +184,55 @@ async fn an_empty_candidate_is_re_asked_before_the_fallback() {"an empty candidate is not sent to the checker");}++fn blank_outcome(truncated: bool) -> TinyagentsTurnOutcome {+ TinyagentsTurnOutcome {+ text: String::new(),+ resolved_route: None,+ history: Vec::new(),+ conversation: Vec::new(),+ model_calls: 3,+ tool_calls: 1,+ input_tokens: 0,+ output_tokens: 0,+ cached_input_tokens: 0,+ charged_amount_usd: 0.0,+ early_exit_tool: None,+ hit_cap: false,+ wrap_up_injected: false,+ breaker_halt: None,+ truncated,+ tool_outcomes: Vec::new(),+ }+}++/// #6951: a turn that ended because the model ran out of output tokens while+/// reasoning is closed with that cause named, not with "you have finished+/// using tools" — which told the model its unfinished work was done.+#[test]+fn a_truncated_turn_is_closed_with_the_output_budget_named() {+ let truncated = close_instruction(&blank_outcome(true), false, RECORDS);+ assert!(+ truncated.contains("ran out of output tokens"),+ "{truncated}"+ );+ assert!(+ !truncated.contains("You have finished using tools"),+ "{truncated}"+ );+ assert!(truncated.contains("<tool_records>"), "{truncated}");++ let finished = close_instruction(&blank_outcome(false), false, RECORDS);+ assert!(+ finished.contains("You have finished using tools"),+ "{finished}"+ );+}++/// The cap checkpoint still wins when the run also hit its call cap.+#[test]+fn a_capped_truncated_turn_gets_the_cap_checkpoint() {+ let out = close_instruction(&blank_outcome(true), true, RECORDS);+ assert!(!out.contains("ran out of output tokens"), "{out}");+ assert!(out.contains("<tool_records>"), "{out}");+}