Skip to content

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

fix(crud): handle attachment consumption and conflict checking

Steven Enamakeled1b86fee9db
diff --git a/crates/openhuman-core/src/threads/ops/crud.rs b/crates/openhuman-core/src/threads/ops/crud.rs
index aeb6ad11cd..7eb5095496 100644
--- a/crates/openhuman-core/src/threads/ops/crud.rs
+++ b/crates/openhuman-core/src/threads/ops/crud.rs
@@ -240,6 +240,15 @@ async fn persist_queued_user_message_with_config(
if existing.sender != "user" || existing.content != text || stored_parts != opaque_parts {
return Err("queued message request ID conflicts with an existing row".into());
}
+ if !opaque_parts.is_empty() {
+ crate::threads::attachments::consume_staged_parts(
+ ctx,
+ thread_id,
+ opaque_parts,
+ &row_id,
+ )
+ .await?;
+ }
return Ok(message_to_record(existing));
}
@@ -266,10 +275,22 @@ async fn persist_queued_user_message_with_config(
)
.await
.map_err(|error| error.to_string())?;
- outcome
+ let persisted = outcome
.value
.data
- .ok_or_else(|| "queued message append returned no row".into())
+ .ok_or_else(|| "queued message append returned no row".to_string())?;
+ if persisted.id != row_id
+ || persisted.sender != "user"
+ || persisted.content != text
+ || persisted.attachments != opaque_parts
+ {
+ if !opaque_parts.is_empty() {
+ let _ = crate::threads::attachments::discard_staged_parts(ctx, thread_id, opaque_parts)
+ .await;
+ }
+ return Err("queued message request ID conflicts with a concurrently persisted row".into());
+ }
+ Ok(persisted)
}
async fn message_append_with_config(