Skip to content

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

feat(inbound): warm event queues at boot and cache shipped settings

Steven Enamakeleb2179a70e6b
diff --git a/crates/openhuman-core/src/inbound/events.rs b/crates/openhuman-core/src/inbound/events.rs
index 1a7ba1b4c3..2c8c225fdb 100644
--- a/crates/openhuman-core/src/inbound/events.rs
+++ b/crates/openhuman-core/src/inbound/events.rs
@@ -4,9 +4,11 @@
//!
//! - `source` `composio:<toolkit>` or `webhook:<tunnel>`, which the shipped
//! `pipeline.json` source policies match (`composio:*`, `webhook:*`);
-//! - `event_id` the source's own id (the Composio trigger uuid, or id; the
-//! webhook's correlation id), so a redelivery of the same trigger has the
-//! same `source:event_id` and the queues reject it;
+//! - `event_id` the source's own id, so a redelivery has the same
+//! `source:event_id` and the queues reject it. For a Composio trigger that
+//! is its uuid (or id): a trigger the backend redelivers is handled once.
+//! For an agent webhook it is the request's correlation id, which is per
+//! request: a resent request with a new correlation id is a new event;
//! - a `conversation_key` unique to the event, so two triggers are never
//! coalesced into one turn: each is triaged on its own;
//! - kind `Trigger` (never ambient chatter), and the envelope itself in `raw`,
diff --git a/crates/openhuman-core/src/inbound/settings.rs b/crates/openhuman-core/src/inbound/settings.rs
index 1cd526eaed..7af05f0875 100644
--- a/crates/openhuman-core/src/inbound/settings.rs
+++ b/crates/openhuman-core/src/inbound/settings.rs
@@ -118,10 +118,13 @@ static CURRENT: RwLock<Option<Arc<Resolved>>> = RwLock::new(None);
/// The resolution the module was last configured with, or the shipped one.
#[must_use]
pub fn current() -> Arc<Resolved> {
+ static SHIPPED: std::sync::OnceLock<Arc<Resolved>> = std::sync::OnceLock::new();
let guard = CURRENT
.read()
.unwrap_or_else(std::sync::PoisonError::into_inner);
- guard.clone().unwrap_or_else(|| Arc::new(shipped()))
+ guard
+ .clone()
+ .unwrap_or_else(|| Arc::clone(SHIPPED.get_or_init(|| Arc::new(shipped()))))
}
fn remember(resolved: Resolved) -> Arc<Resolved> {
diff --git a/crates/openhuman-core/src/modules/boot.rs b/crates/openhuman-core/src/modules/boot.rs
index effa1f3012..aaf6526496 100644
--- a/crates/openhuman-core/src/modules/boot.rs
+++ b/crates/openhuman-core/src/modules/boot.rs
@@ -76,6 +76,33 @@ pub async fn load_declared_modules(config: &Config) {
}
warm_connector_catalogs(config);
+ #[cfg(feature = "inbound-queues")]
+ warm_inbound_queues(config);
+}
+
+/// Load the inbound event queues in the background when inbound events are
+/// routed through them. The module runs its own pass timer, so loading it is
+/// what resumes delivering the work a previous run left queued — a deferral
+/// waiting for its time, a retry in back-off — instead of waiting for the
+/// next inbound event to load it. Off the boot path, like the connector
+/// warm-up; a failed load is logged and the next event tries again.
+#[cfg(feature = "inbound-queues")]
+fn warm_inbound_queues(config: &Config) {
+ if !crate::inbound::active(config) {
+ log::debug!("[modules] inbound event queues warm-up skipped: routing is off");
+ return;
+ }
+ // Unit tests share one process-wide module slot (see the connector warm-up).
+ if cfg!(test) {
+ return;
+ }
+ let config = config.clone();
+ tokio::spawn(async move {
+ log::debug!("[modules] inbound event queues warm-up starting");
+ if let Err(reason) = ops::ensure_loaded(&config, super::event_queues::MODULE_ID).await {
+ log::warn!("[modules] inbound event queues did not load at boot: {reason}");
+ }
+ });
}
/// Read the connector module's curated catalogs into the host in the
diff --git a/docs/gitbooks/en/developing/components.md b/docs/gitbooks/en/developing/components.md
index 6f69afcd87..199775de8b 100644
--- a/docs/gitbooks/en/developing/components.md
+++ b/docs/gitbooks/en/developing/components.md
@@ -82,13 +82,15 @@ The module reads its own `TINYMEMES_*` overrides from the process environment, s
With the switch off, `[inbound] enabled = false`, or the module unavailable on this host, events take the direct triage path as before. An event too large to queue (over 192 KiB encoded) also takes the direct path.
+A delivery is acknowledged once triage has decided, and the decision is applied in its own task. A long agent run therefore never holds a queue lease, but an apply that fails is reported rather than retried. A deferral counts as a delivery attempt: a trigger still deferring after the lane's `max_attempts` (5) is dead-lettered and can be redriven. Webhooks are deduplicated per request, by correlation id. When the queues are active the module is loaded in the background at startup, so work a previous run left queued is delivered without waiting for the next event.
+
| `[inbound]` key | Default | Meaning |
| --- | --- | --- |
| `enabled` | `true` | route inbound events through the queues |
| `queues_path` | unset | a `queues.json` replacing the module's shipped one; the host declares exactly these queues on the module's storage scope |
| `pipeline_path` | unset | a `pipeline.json` replacing the shipped one (gate, coalescing, salience, lanes, cadences, retry back-off) |
| `queue_url` | `storage` | where the queues live: the module's storage scope, or `amqp://` / `amqps://` for a RabbitMQ broker in builds with the storage `rabbitmq` driver |
-| `triage_timeout_ms` | `90000` | how long one delivered event's triage may take before the delivery is retried |
+| `triage_timeout_ms` | `25000` | how long one delivered event's triage may take before the delivery is retried; at most 25 s, below the module's 30 s callback deadline; read at startup |
## Wallet