Skip to content

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

refactor(harness): consolidate time-awareness middleware setup

Steven Enamakel5d8aa4960794
diff --git a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
index 51c35dec3f..d11bdb7002 100644
--- a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
@@ -358,22 +358,14 @@ 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);
+ // Time awareness (#6953): turn-budget notes and clamped-shell-timeout notes.
+ // Pushed before the repeat guard so their `after_tool` runs last (notes
+ // survive output caps and stay out of the guard's fingerprint).
+ let wall_clock = harness.policy().limits.max_wall_clock_ms;
+ let wall_clock = wall_clock.map(std::time::Duration::from_millis);
+ harness.push_middleware(Arc::new(TurnClockMiddleware::new(wall_clock)));
+ let shell_turn_budget = middleware::ShellTurnBudget::new(wall_clock);
harness.push_middleware(Arc::new(shell_turn_budget.notes()));
-
if let Some(mw) = &repeat_progress {
harness.push_middleware(mw.clone());
}
@@ -692,10 +684,7 @@ 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.
+ // Clamp shell `timeout_secs` to the turn remainder (#6953), on recovered args.
harness.push_middleware(Arc::new(shell_turn_budget.clamp()));
// Bare packed-tool routing (`before_tool`, #6276): a call that names a