Skip to content

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

test(threads): cover transcript voice metadata paging and duplicate content

Steven Enamakelf6548e5a1217
diff --git a/crates/openhuman-core/src/threads/ops/transcript_tests.rs b/crates/openhuman-core/src/threads/ops/transcript_tests.rs
index 314a8afbd6..2fc7498585 100644
--- a/crates/openhuman-core/src/threads/ops/transcript_tests.rs
+++ b/crates/openhuman-core/src/threads/ops/transcript_tests.rs
@@ -145,8 +145,10 @@ async fn transcript_projection_includes_voice_metadata_from_persisted_thread_row
.await
.unwrap();
for (id, content, sender, note_id, request_id) in [
- ("user-voice", "hello", "user", "recording-1", None),
- ("assistant-voice", "hi there", "agent", "reply-1", Some("req-1")),
+ ("user-voice", "hello", "user", Some("recording-1"), Some("req-1")),
+ ("assistant-voice", "hi there", "agent", Some("reply-1"), Some("req-1")),
+ ("user-plain", "hello", "user", None, Some("req-2")),
+ ("assistant-plain", "hi again", "agent", None, Some("req-2")),
] {
blocking::append_message(
ctx.clone(),
@@ -157,7 +159,10 @@ async fn transcript_projection_includes_voice_metadata_from_persisted_thread_row
content: content.into(),
message_type: "text".into(),
extra_metadata: {
- let mut metadata = json!({"voiceNote": {"noteId": note_id, "durationMs": 5000}});
+ let mut metadata = json!({});
+ if let Some(note_id) = note_id {
+ metadata["voiceNote"] = json!({"noteId": note_id, "durationMs": 5000});
+ }
if let Some(request_id) = request_id {
metadata["requestId"] = json!(request_id);
}
@@ -171,6 +176,33 @@ async fn transcript_projection_includes_voice_metadata_from_persisted_thread_row
.unwrap();
}
write_thread(&ctx).await;
+ let locator = super::super::support::transcript_store(&ctx, THREAD)
+ .await
+ .unwrap()
+ .locator();
+ let root_meta = meta("orchestrator", "root");
+ let prior = vec![
+ TranscriptMessage::user("hello"),
+ TranscriptMessage::assistant("hi there"),
+ ];
+ let complete = vec![
+ TranscriptMessage::user("hello"),
+ TranscriptMessage::assistant("hi there"),
+ TranscriptMessage::user("hello"),
+ TranscriptMessage::assistant("hi again"),
+ ];
+ locator
+ .open_session(&SessionRef::scoped(THREAD, "orchestrator"), root_meta.clone())
+ .unwrap()
+ .append_turn(TranscriptTurn {
+ prev: &prior,
+ next: &complete,
+ meta: &root_meta,
+ turn_usage: Some(&usage(100, 10)),
+ request_id: Some("req-2"),
+ tools: None,
+ })
+ .unwrap();
let page = transcript_get(
&ctx,
@@ -185,17 +217,27 @@ async fn transcript_projection_includes_voice_metadata_from_persisted_thread_row
.value
.data
.unwrap();
- let user = page
+ let voice_user = page
.items
.iter()
.find_map(|item| match item {
tinyagents_session::transcript::view::DisplayItem::UserMessage {
content,
+ request_id,
extra_metadata,
..
- } if content == "hello" => extra_metadata.as_ref(),
+ } if content == "hello" && request_id.as_deref() == Some("req-1") => extra_metadata.as_ref(),
_ => None,
});
+ let plain_duplicate_user = page.items.iter().find_map(|item| match item {
+ tinyagents_session::transcript::view::DisplayItem::UserMessage {
+ content,
+ request_id,
+ extra_metadata,
+ ..
+ } if content == "hello" && request_id.as_deref() == Some("req-2") => extra_metadata.as_ref(),
+ _ => None,
+ });
let assistant = page
.items
.iter()
@@ -207,67 +249,41 @@ async fn transcript_projection_includes_voice_metadata_from_persisted_thread_row
} if content == "hi there" => extra_metadata.as_ref(),
_ => None,
});
- assert_eq!(user.and_then(|value| value.pointer("/voiceNote/noteId")), Some(&json!("recording-1")));
+ assert_eq!(voice_user.and_then(|value| value.pointer("/voiceNote/noteId")), Some(&json!("recording-1")));
+ assert!(plain_duplicate_user.is_none_or(|value| value.get("voiceNote").is_none()));
assert_eq!(assistant.and_then(|value| value.pointer("/voiceNote/noteId")), Some(&json!("reply-1")));
-
- let newest_page = transcript_get(
- &ctx,
- TranscriptGetRequest {
- thread_id: THREAD.into(),
- cursor: None,
- limit: Some(1),
- },
- )
- .await
- .unwrap()
- .value
- .data
- .unwrap();
- assert!(newest_page.items.iter().any(|item| matches!(
- item,
- tinyagents_session::transcript::view::DisplayItem::AssistantMessage {
- content,
- extra_metadata: Some(metadata),
- ..
- } if content == "hi there" && metadata.pointer("/voiceNote/noteId") == Some(&json!("reply-1"))
- )), "the voice metadata follows the assistant item onto its paginated page");
-
- blocking::append_message(
- ctx.clone(),
- workspace,
- THREAD.into(),
- ConversationMessage {
- id: "user-voice-duplicate".into(),
- content: "hello".into(),
- message_type: "text".into(),
- extra_metadata: json!({"voiceNote": {"noteId": "recording-2"}}),
- sender: "user".into(),
- created_at: "2026-10-15T00:00:03Z".into(),
- },
- )
- .await
- .unwrap();
- let ambiguous = transcript_get(
- &ctx,
- TranscriptGetRequest {
- thread_id: THREAD.into(),
- cursor: None,
- limit: None,
- },
- )
- .await
- .unwrap()
- .value
- .data
- .unwrap();
- assert!(ambiguous.items.iter().all(|item| !matches!(
- item,
- tinyagents_session::transcript::view::DisplayItem::UserMessage {
- content,
- extra_metadata: Some(metadata),
- ..
- } if content == "hello" && metadata.get("voiceNote").is_some()
- )), "repeated identical content is not guessed onto either user row");
+ let mut cursor = None;
+ let mut voice_reply_on_its_page = false;
+ loop {
+ let page = transcript_get(
+ &ctx,
+ TranscriptGetRequest {
+ thread_id: THREAD.into(),
+ cursor,
+ limit: Some(1),
+ },
+ )
+ .await
+ .unwrap()
+ .value
+ .data
+ .unwrap();
+ voice_reply_on_its_page |= page.items.iter().any(|item| matches!(
+ item,
+ tinyagents_session::transcript::view::DisplayItem::AssistantMessage {
+ content,
+ request_id,
+ extra_metadata: Some(metadata),
+ ..
+ } if content == "hi there" && request_id.as_deref() == Some("req-1")
+ && metadata.pointer("/voiceNote/noteId") == Some(&json!("reply-1"))
+ ));
+ cursor = page.next_cursor;
+ if cursor.is_none() {
+ break;
+ }
+ }
+ assert!(voice_reply_on_its_page, "voice metadata survives paging to its assistant row");
}
#[tokio::test]