Skip to content

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

fix(cron): key reminder sends by run to avoid duplicate delivery

Steven Enamakel7924a64e743e
diff --git a/crates/openhuman-core/src/cron/channel_bridge.rs b/crates/openhuman-core/src/cron/channel_bridge.rs
index 1dcc1180c3..ac4040117c 100644
--- a/crates/openhuman-core/src/cron/channel_bridge.rs
+++ b/crates/openhuman-core/src/cron/channel_bridge.rs
@@ -105,6 +105,7 @@ pub async fn send_to_channel(
reply_target: &str,
thread_id: Option<&str>,
text: &str,
+ idempotency_key: &str,
) -> Result<(), String> {
let Some(bridge) = current() else {
return Err("channel runtime is not running".to_string());
@@ -113,7 +114,12 @@ pub async fn send_to_channel(
let Some(ch) = bridge.channels.get(&key) else {
return Err(format!("channel '{key}' is not available"));
};
- let message = SendMessage::new(text, reply_target).in_thread(thread_id.map(str::to_string));
+ // Run-specific key: a retry after an ambiguous send must not duplicate the
+ // reminder, while identical reminders from different runs must not collide
+ // (the content-derived default key would reuse one key for both).
+ let mut message =
+ SendMessage::new(text, reply_target).in_thread(thread_id.map(str::to_string));
+ message.idempotency_key = Some(idempotency_key.to_string());
ch.send(&message)
.await
.map_err(|e| format!("channel send failed: {e}"))
diff --git a/crates/openhuman-core/src/cron/scheduler/origin_delivery.rs b/crates/openhuman-core/src/cron/scheduler/origin_delivery.rs
index 82139fbf03..29b87fddfc 100644
--- a/crates/openhuman-core/src/cron/scheduler/origin_delivery.rs
+++ b/crates/openhuman-core/src/cron/scheduler/origin_delivery.rs
@@ -156,8 +156,14 @@ pub(crate) async fn deliver_to_origin(
..
} => {
let text = strip_openhuman_link_markup(text);
- channel_bridge::send_to_channel(channel, reply_target, thread_id.as_deref(), &text)
- .await
+ channel_bridge::send_to_channel(
+ channel,
+ reply_target,
+ thread_id.as_deref(),
+ &text,
+ &origin_request_id(&job.id, run_id),
+ )
+ .await
.map_err(|e| anyhow!(e))?;
channel_bridge::append_assistant_message(history_key, &text);
tracing::debug!(