Skip to content

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

test(channels): cover concurrent duplicate channel delivery

Steven Enamakelf1d9be981dd3
diff --git a/crates/openhuman-core/src/channels/host/host_tests.rs b/crates/openhuman-core/src/channels/host/host_tests.rs
index fe28775426..6e1f9967eb 100644
--- a/crates/openhuman-core/src/channels/host/host_tests.rs
+++ b/crates/openhuman-core/src/channels/host/host_tests.rs
@@ -88,20 +88,51 @@ async fn typed_channel_projection_uses_scoped_persisted_row_bindings_after_resta
&thread_id,
)
.unwrap();
- let row_id = crate::threads::store::persist_channel_message(
- &alice,
- &workspace,
- &channel,
- &conversation,
- &thread_id,
- "Provider conversation",
- provider_id,
- "user",
- "hello from Telegram",
- serde_json::json!({"voiceNote": {"opaqueId": "voice-asset-7"}}),
+ let barrier = Arc::new(std::sync::Barrier::new(8));
+ let runtime = tokio::runtime::Handle::current();
+ let writers = (0..8).map(|_| {
+ let barrier = Arc::clone(&barrier);
+ let runtime = runtime.clone();
+ let alice = alice.clone();
+ let workspace = workspace.clone();
+ let channel = channel.clone();
+ let conversation = conversation.clone();
+ let thread_id = thread_id.clone();
+ tokio::task::spawn_blocking(move || {
+ barrier.wait();
+ runtime.block_on(crate::threads::store::persist_channel_message(
+ &alice,
+ &workspace,
+ &channel,
+ &conversation,
+ &thread_id,
+ "Provider conversation",
+ provider_id,
+ "user",
+ "hello from Telegram",
+ serde_json::json!({"voiceNote": {"opaqueId": "voice-asset-7"}}),
+ ))
+ })
+ });
+ let row_ids = futures::future::join_all(writers)
+ .await
+ .into_iter()
+ .map(|result| result.unwrap().unwrap())
+ .collect::<Vec<_>>();
+ assert!(row_ids.iter().all(|id| id == "user:provider-receipt-42"));
+ let row_id = row_ids[0].clone();
+ let persisted = crate::threads::store::blocking::get_messages(
+ alice.clone(),
+ workspace.clone(),
+ thread_id.clone(),
)
.await
.unwrap();
+ assert_eq!(
+ persisted.iter().filter(|message| message.id == row_id).count(),
+ 1,
+ "concurrent duplicate channel delivery persists one authoritative row"
+ );
assert_eq!(row_id, "user:provider-receipt-42");
// Bob has a same-named row in another profile, but has no trusted binding