Skip to content

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

fix(threads): derive channel row id deterministically for retry idempotence

Steven Enamakel3ec1942b70bc
diff --git a/crates/openhuman-core/src/threads/store/bus.rs b/crates/openhuman-core/src/threads/store/bus.rs
index ffd055a414..474845b173 100644
--- a/crates/openhuman-core/src/threads/store/bus.rs
+++ b/crates/openhuman-core/src/threads/store/bus.rs
@@ -383,6 +383,9 @@ pub(crate) async fn persist_channel_message(
"sourceMessageId".into(),
serde_json::json!(provider_message_id),
);
+ // Preserve the established channel-row ID contract for retry idempotence;
+ // the provider receipt is still bound separately to this persisted row.
+ let row_id = format!("{role}:{provider_message_id}");
let now = chrono::Utc::now().to_rfc3339();
let workspace = workspace_dir.to_path_buf();
ensure_thread(
@@ -398,20 +401,10 @@ pub(crate) async fn persist_channel_message(
working_dir: None,
},
)?;
- let existing = get_messages(ctx, workspace.clone(), thread_id)?
- .into_iter()
- .find(|message| {
- message.sender == role
- && message
- .extra_metadata
- .get("sourceMessageId")
- .and_then(serde_json::Value::as_str)
- == Some(provider_message_id)
- });
- let row_id = if let Some(existing) = existing {
- existing.id
- } else {
- let row_id = uuid::Uuid::new_v4().to_string();
+ let exists = get_messages(ctx, workspace.clone(), thread_id)?
+ .iter()
+ .any(|message| message.id == row_id);
+ if !exists {
append_message(
ctx,
workspace,
@@ -425,8 +418,7 @@ pub(crate) async fn persist_channel_message(
created_at: now,
},
)?;
- row_id
- };
+ }
if role == "user" {
crate::threads::channel_projection::bind_row(
ctx,