Skip to content

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

fix(agent): restore turn policy after harness assembly

Steven Enamakela0749cf1b1ff
diff --git a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
index c4cb4ae74c..61088672a7 100644
--- a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
@@ -357,6 +357,22 @@ pub(super) fn assemble_turn_harness(
.with_cleared_placeholder(crate::agent::context::CLEARED_PLACEHOLDER),
)
});
+ // Time awareness (#6953). Pushed ahead of the repeat-progress guard, so
+ // these `after_tool` hooks run last: their notes land after every output
+ // cap (they survive truncation), and the guard fingerprints a result
+ // without a note that changes from call to call. `TurnClockMiddleware`
+ // adds `[turn budget: …]` to a result once per tenth of the budget past
+ // half. The shell half reports a clamped `timeout_secs`; its clamp is
+ // pushed after argument recovery below.
+ let turn_wall_clock = harness
+ .policy()
+ .limits
+ .max_wall_clock_ms
+ .map(std::time::Duration::from_millis);
+ harness.push_middleware(Arc::new(TurnClockMiddleware::new(turn_wall_clock)));
+ let shell_turn_budget = middleware::ShellTurnBudget::new(turn_wall_clock);
+ harness.push_middleware(Arc::new(shell_turn_budget.notes()));
+
if let Some(mw) = &repeat_progress {
harness.push_middleware(mw.clone());
}
@@ -675,6 +691,12 @@ pub(super) fn assemble_turn_harness(
// validation error. It never reaches approval/policy wrappers or the tool.
harness.push_middleware(Arc::new(ArgRecoveryMiddleware::new(tool_sets.clone())));
+ // Shell deadline clamp (`before_tool`, #6953): keep a shell command's
+ // `timeout_secs` inside the turn's remainder minus a reserve, so the turn
+ // is not killed mid-command. After argument recovery, so it edits the
+ // recovered object arguments.
+ harness.push_middleware(Arc::new(shell_turn_budget.clamp()));
+
// Bare packed-tool routing (`before_tool`, #6276): a call that names a
// withheld packed tool directly becomes the `use_skill` call that reaches
// it, ahead of admission, so every gate above still applies. Only when the
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_policy.rs b/crates/openhuman-core/src/agent/tinyagents/turn_policy.rs
index 45b7721b70..ed735b351f 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_policy.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_policy.rs
@@ -168,6 +168,10 @@ pub(crate) fn run_policy_for(max_iterations: usize, response_cache_enabled: bool
// delegations) are exempt in the harness and keep the remainder-only
// budget. Env-overridable, `0` disables.
policy.limits.max_model_call_ms = model_call_wall_clock_ms();
+ // Each executed tool row ends with `[took 12.3s]` (#6953). Without it the
+ // model cannot tell a fifteen-minute command from a fast one, so it cannot
+ // budget the rest of the turn against the ceiling above.
+ policy.tool_result_durations = true;
// Crate-owned retry (Phase 3a), lengthened for #6413.
//
// The former schedule — 2 retries at 500 ms and 1 s — spent about 1.5 s in