Skip to content

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

fix(composio): charge pre-gate work against the connect park bound

Steven Enamakel35b9ab65dfba
diff --git a/crates/openhuman-core/src/integrations/composio/tools.rs b/crates/openhuman-core/src/integrations/composio/tools.rs
index fb0266e8c6..6dadafc780 100644
--- a/crates/openhuman-core/src/integrations/composio/tools.rs
+++ b/crates/openhuman-core/src/integrations/composio/tools.rs
@@ -59,7 +59,7 @@ pub use authorize::ComposioAuthorizeTool;
#[cfg(test)]
use connect::{
composio_connect_tool_timeout, connection_is_active, parse_composio_connect_timeout,
- ComposioConnectTool, DEFAULT_COMPOSIO_CONNECT_TIMEOUT_SECS,
+ remaining_park_bound, ComposioConnectTool, DEFAULT_COMPOSIO_CONNECT_TIMEOUT_SECS,
};
pub use list_connections::ComposioListConnectionsTool;
pub use list_toolkits::ComposioListToolkitsTool;
diff --git a/crates/openhuman-core/src/integrations/composio/tools/connect.rs b/crates/openhuman-core/src/integrations/composio/tools/connect.rs
index 3d05b926c4..7675d0cc9d 100644
--- a/crates/openhuman-core/src/integrations/composio/tools/connect.rs
+++ b/crates/openhuman-core/src/integrations/composio/tools/connect.rs
@@ -82,6 +82,25 @@ pub(super) fn composio_connect_tool_timeout(
}
}
+/// Smallest park the gate is given once pre-gate work has used up the bound,
+/// so the card is still raised (and abandoned cleanly) rather than skipped.
+const COMPOSIO_CONNECT_MIN_PARK: std::time::Duration = std::time::Duration::from_secs(1);
+
+/// The park bound left for the approval gate after `pre_gate` was spent on
+/// config loading and the connection/catalog reads that precede it.
+///
+/// The tool's own deadline ([`composio_connect_tool_timeout`]) is one budget
+/// for the whole call: park bound plus slack for the post-approval liveness
+/// check. Handing the gate the full bound after slow pre-gate reads let the
+/// tool deadline fire while the gate still waited, which lost the gate's
+/// actionable "card not completed" result to a bare timeout.
+pub(super) fn remaining_park_bound(
+ park_bound: Option<std::time::Duration>,
+ pre_gate: std::time::Duration,
+) -> Option<std::time::Duration> {
+ park_bound.map(|bound| bound.saturating_sub(pre_gate).max(COMPOSIO_CONNECT_MIN_PARK))
+}
+
/// Pure core of [`composio_connect_timeout`], kept env-free so it is
/// deterministically unit-testable. An absent/unparseable value falls back to
/// [`DEFAULT_COMPOSIO_CONNECT_TIMEOUT_SECS`]; `0` yields `None` (opt out of the
@@ -221,6 +240,9 @@ impl ComposioConnectTool {
// `google_drive` where Composio expects `googledrive` (#3993).
let toolkit = canonicalize_toolkit_slug(raw_toolkit);
tracing::debug!(raw = %raw_toolkit, toolkit = %toolkit, "[composio] tool connect.execute");
+ // The tool deadline covers this whole call, so the gate's park is
+ // charged for the reads that precede it (see `remaining_park_bound`).
+ let started = std::time::Instant::now();
// The inline connect card only has a surface on an interactive chat
// turn (the web-chat path installs `APPROVAL_CHAT_CONTEXT`). On
@@ -332,12 +354,20 @@ impl ComposioConnectTool {
// the parked future and orphan the waiter/routing) per the codex review
// on this PR. The reply is shaped so the agent RELAYS it and does NOT
// immediately retry `composio_connect` (a retry would just park again).
+ let pre_gate = started.elapsed();
+ let park_bound = remaining_park_bound(composio_connect_timeout(), pre_gate);
+ tracing::debug!(
+ toolkit = %toolkit,
+ pre_gate_ms = pre_gate.as_millis() as u64,
+ park_bound_secs = park_bound.map(|bound| bound.as_secs()),
+ "[composio] connect.execute: parking on the connect card"
+ );
let (outcome, _request_id) = match gate
.intercept_audited_bounded(
"composio_connect",
&summary,
json!({ "toolkit": toolkit }),
- composio_connect_timeout(),
+ park_bound,
)
.await
{
diff --git a/crates/openhuman-core/src/integrations/composio/tools_direct_mode_routing_tests.rs b/crates/openhuman-core/src/integrations/composio/tools_direct_mode_routing_tests.rs
index aac6bfa427..9add3b93f2 100644
--- a/crates/openhuman-core/src/integrations/composio/tools_direct_mode_routing_tests.rs
+++ b/crates/openhuman-core/src/integrations/composio/tools_direct_mode_routing_tests.rs
@@ -360,3 +360,28 @@ fn parse_composio_connect_timeout_honors_override_and_zero_opt_out() {
// `0` → opt out of the composio-side bound (fall back to the gate TTL).
assert_eq!(parse_composio_connect_timeout(Some("0")), None);
}
+
+#[test]
+fn composio_connect_charges_pre_gate_work_to_the_park_bound() {
+ use std::time::Duration;
+ let bound = Duration::from_secs(DEFAULT_COMPOSIO_CONNECT_TIMEOUT_SECS);
+ let tool_budget = match composio_connect_tool_timeout(Some(bound)) {
+ tinytools::ToolTimeout::Millis(ms) => Duration::from_millis(ms),
+ other => panic!("expected an explicit budget, got {other:?}"),
+ };
+ // 50 s of slow config/connection/catalog reads before the card is raised:
+ // pre-gate + park must still end before the tool deadline, with the
+ // remaining slack left for the post-approval liveness check.
+ let pre_gate = Duration::from_secs(50);
+ let park = remaining_park_bound(Some(bound), pre_gate).unwrap();
+ assert_eq!(park, bound - pre_gate);
+ assert!(pre_gate + park < tool_budget);
+
+ // Pre-gate work that used the whole bound still raises a short park.
+ assert_eq!(
+ remaining_park_bound(Some(bound), bound * 2),
+ Some(Duration::from_secs(1))
+ );
+ // Opting out of the bound stays unbounded.
+ assert_eq!(remaining_park_bound(None, pre_gate), None);
+}