Skip to content

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

fix(search): scale execute tool deadline with the tool budget

Steven Enamakel45fa350f9c6d
diff --git a/crates/openhuman-core/src/modules/search/proxy.rs b/crates/openhuman-core/src/modules/search/proxy.rs
index 6def1b1240..673fd804e5 100644
--- a/crates/openhuman-core/src/modules/search/proxy.rs
+++ b/crates/openhuman-core/src/modules/search/proxy.rs
@@ -22,9 +22,28 @@ use crate::config::Config;
/// as a bus timeout although the module was still working. 90 s stays under
/// the harness's own default tool deadline
/// ([`crate::tools::timeout::DEFAULT_TIMEOUT_SECS`], 120 s), so the module's
-/// answer, not the harness kill, decides the result.
+/// answer, not the harness kill, decides the result. This is the floor; a
+/// larger configured tool budget extends it (see [`execute_tool_timeout_for`]).
pub(super) const EXECUTE_TOOL_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(90);
+/// Headroom left between the bus deadline and the harness's tool deadline so
+/// the module's own answer (or its bus error) reaches the harness first.
+const EXECUTE_TOOL_HEADROOM_SECS: u64 = 30;
+
+/// Bus deadline for `ExecuteTool` under a harness tool budget of
+/// `tool_budget_secs`: the budget minus [`EXECUTE_TOOL_HEADROOM_SECS`], never
+/// below [`EXECUTE_TOOL_TIMEOUT`]. A user who raises the action timeout (for a
+/// slow provider) gets a search call that can use it; at the 120 s default
+/// this is exactly the 90 s floor. Below the floor the harness deadline is the
+/// tighter bound anyway.
+pub(super) fn execute_tool_timeout_for(tool_budget_secs: u64) -> std::time::Duration {
+ std::time::Duration::from_secs(
+ tool_budget_secs
+ .saturating_sub(EXECUTE_TOOL_HEADROOM_SECS)
+ .max(EXECUTE_TOOL_TIMEOUT.as_secs()),
+ )
+}
+
fn last_config() -> &'static tokio::sync::Mutex<Option<u64>> {
static LAST: OnceLock<tokio::sync::Mutex<Option<u64>>> = OnceLock::new();
LAST.get_or_init(|| tokio::sync::Mutex::new(None))
@@ -172,19 +191,21 @@ pub async fn execute_tool(
.await
}
-/// `ExecuteTool` through `proxy`, under [`EXECUTE_TOOL_TIMEOUT`] rather than
-/// the bus default.
+/// `ExecuteTool` through `proxy`, under a deadline derived from the effective
+/// tool budget ([`execute_tool_timeout_for`]) rather than the bus default.
pub(super) async fn call_execute_tool<R: serde::de::DeserializeOwned>(
proxy: tinybus::Proxy,
request: ExecuteToolRequest,
) -> tinybus::Result<R> {
+ let timeout =
+ execute_tool_timeout_for(crate::tools::timeout::tool_execution_timeout_secs());
tracing::debug!(
tool = %request.name,
- timeout_secs = EXECUTE_TOOL_TIMEOUT.as_secs(),
+ timeout_secs = timeout.as_secs(),
"[modules][search] ExecuteTool"
);
proxy
- .with_timeout(EXECUTE_TOOL_TIMEOUT)
+ .with_timeout(timeout)
.call(names::methods::EXECUTE_TOOL, (request,))
.await
}
diff --git a/crates/openhuman-core/src/modules/search/proxy_tests.rs b/crates/openhuman-core/src/modules/search/proxy_tests.rs
index 0db278d00e..50e9716ba2 100644
--- a/crates/openhuman-core/src/modules/search/proxy_tests.rs
+++ b/crates/openhuman-core/src/modules/search/proxy_tests.rs
@@ -129,3 +129,21 @@ fn the_execute_tool_deadline_stays_under_the_harness_tool_deadline() {
"the harness would kill the call before the module could answer"
);
}
+
+#[test]
+fn the_execute_tool_deadline_follows_a_raised_tool_budget() {
+ // A user who raises the action timeout to 10 minutes must not have the
+ // search call cut off at the fixed 90 s floor.
+ assert_eq!(
+ execute_tool_timeout_for(600),
+ std::time::Duration::from_secs(570)
+ );
+ assert!(execute_tool_timeout_for(600).as_secs() < 600);
+ // The default budget keeps today's 90 s, and a tighter budget never drops
+ // the bus deadline below the floor (the harness deadline is tighter).
+ assert_eq!(
+ execute_tool_timeout_for(crate::tools::timeout::DEFAULT_TIMEOUT_SECS),
+ EXECUTE_TOOL_TIMEOUT
+ );
+ assert_eq!(execute_tool_timeout_for(10), EXECUTE_TOOL_TIMEOUT);
+}