Skip to content

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

fix(inbound): run trigger hand-off in its own task

Steven Enamakel9021e98fa967
diff --git a/crates/openhuman-core/src/config/schema/inbound_tests.rs b/crates/openhuman-core/src/config/schema/inbound_tests.rs
index cc9e522377..b2b26fec68 100644
--- a/crates/openhuman-core/src/config/schema/inbound_tests.rs
+++ b/crates/openhuman-core/src/config/schema/inbound_tests.rs
@@ -22,9 +22,15 @@ fn a_partial_section_keeps_the_other_defaults() {
#[test]
fn the_triage_timeout_stays_under_the_module_callback_deadline() {
let mut c = InboundConfig::default();
- assert_eq!(c.triage_timeout().as_millis(), u128::from(MAX_TRIAGE_TIMEOUT_MS));
+ assert_eq!(
+ c.triage_timeout().as_millis(),
+ u128::from(MAX_TRIAGE_TIMEOUT_MS)
+ );
c.triage_timeout_ms = 90_000;
- assert_eq!(c.triage_timeout().as_millis(), u128::from(MAX_TRIAGE_TIMEOUT_MS));
+ assert_eq!(
+ c.triage_timeout().as_millis(),
+ u128::from(MAX_TRIAGE_TIMEOUT_MS)
+ );
c.triage_timeout_ms = 0;
assert_eq!(c.triage_timeout().as_millis(), 1);
c.triage_timeout_ms = 5_000;
diff --git a/crates/openhuman-core/src/inbound/deliver_tests.rs b/crates/openhuman-core/src/inbound/deliver_tests.rs
index 4b7c0ecbd5..e332dbaa8f 100644
--- a/crates/openhuman-core/src/inbound/deliver_tests.rs
+++ b/crates/openhuman-core/src/inbound/deliver_tests.rs
@@ -238,10 +238,8 @@ fn classifications_are_bounded() {
async fn a_redelivered_accepted_turn_is_not_decided_twice() {
// The module's callback deadline passed while the first triage was still
// deciding; it redelivers the same turn. One decision, one apply.
- let triage = ScriptedTriage::new([
- decision(TriageAction::React),
- decision(TriageAction::React),
- ]);
+ let triage =
+ ScriptedTriage::new([decision(TriageAction::React), decision(TriageAction::React)]);
let deliverer = deliverer(&triage);
for attempt in [1, 2] {
let response = deliverer
@@ -252,7 +250,11 @@ async fn a_redelivered_accepted_turn_is_not_decided_twice() {
assert_eq!(triage.runs(), 1, "the redelivery was triaged again");
let _ = triage.until_applied(1, Duration::from_secs(5)).await;
tokio::time::sleep(Duration::from_millis(50)).await;
- assert_eq!(triage.applied().len(), 1, "the redelivery was applied again");
+ assert_eq!(
+ triage.applied().len(),
+ 1,
+ "the redelivery was applied again"
+ );
}
#[test]
diff --git a/crates/openhuman-core/src/integrations/composio/bus/trigger_subscriber.rs b/crates/openhuman-core/src/integrations/composio/bus/trigger_subscriber.rs
index ae6b8d3469..1b8eef3541 100644
--- a/crates/openhuman-core/src/integrations/composio/bus/trigger_subscriber.rs
+++ b/crates/openhuman-core/src/integrations/composio/bus/trigger_subscriber.rs
@@ -187,16 +187,21 @@ impl EventHandler<DomainEvent> for ComposioTriggerSubscriber {
// persists it, rejects a redelivery of the same trigger, paces a
// flood, and calls the host back (`Deliver`) to triage it, retrying a
// deferred triage then. Off or unavailable, triage runs directly.
- let config = ctx.load_config().await.ok();
- route_trigger(
- ctx,
- config,
- envelope,
- Arc::new(RemoteTriage),
- #[cfg(feature = "inbound-queues")]
- None,
- )
- .await;
+ // Its own task: the hand-off may wait for the module's first load and
+ // retries an unanswered ingest, which must never hold up this
+ // subscriber's loop (a stalled loop lags and loses broadcast events).
+ tokio::spawn(async move {
+ let config = ctx.load_config().await.ok();
+ route_trigger(
+ ctx,
+ config,
+ envelope,
+ Arc::new(RemoteTriage),
+ #[cfg(feature = "inbound-queues")]
+ None,
+ )
+ .await;
+ });
}
}
diff --git a/crates/openhuman-core/src/skills/webhooks/bus.rs b/crates/openhuman-core/src/skills/webhooks/bus.rs
index c9d38b43ab..c978cd92d5 100644
--- a/crates/openhuman-core/src/skills/webhooks/bus.rs
+++ b/crates/openhuman-core/src/skills/webhooks/bus.rs
@@ -129,34 +129,36 @@ impl EventHandler<DomainEvent> for WebhookRequestSubscriber {
payload,
);
// With the inbound event queues on, the request is queued
- // (persisted, deduplicated by correlation id, paced) and
- // triaged when the module delivers it, a deferral retried
- // then; the 202 below is the only response. Off or
- // unavailable, triage runs directly as before.
- let config = ctx.load_config().await.ok();
- let queued = route_agent_trigger(
- config,
- &envelope,
- &correlation_id,
- #[cfg(feature = "inbound-queues")]
- None,
- )
- .await;
- if !queued {
- triage_agent_directly(
- ctx,
- envelope,
- correlation_id.clone(),
- Arc::new(crate::triage::RemoteTriage),
- );
- }
+ // (persisted, deduplicated per request, paced) and triaged
+ // when the module delivers it, a deferral retried then;
+ // the 202 below is the only response. Off or unavailable,
+ // triage runs directly as before and its result follows
+ // as a second response. Its own task, so neither the
+ // module's first load nor a resent ingest holds up this
+ // subscriber's loop.
+ let corr = correlation_id.clone();
+ tokio::spawn(async move {
+ let config = ctx.load_config().await.ok();
+ let queued = route_agent_trigger(
+ config,
+ &envelope,
+ &corr,
+ #[cfg(feature = "inbound-queues")]
+ None,
+ )
+ .await;
+ if !queued {
+ triage_agent_directly(
+ ctx,
+ envelope,
+ corr,
+ Arc::new(crate::triage::RemoteTriage),
+ );
+ }
+ });
// Return 202 Accepted immediately so the event handler
// doesn't block the broadcast channel.
- let message = if queued {
- "Queued for agent triage"
- } else {
- "Agent triage started"
- };
+ let message = "Agent triage accepted";
let resp = WebhookResponseData {
correlation_id: correlation_id.clone(),
status_code: 202,