Skip to content

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

fix(channels): key inbound voice facts by runner request id

Steven Enamakel7bcbdb6bc720
diff --git a/crates/openhuman-core/src/channels/host/voice.rs b/crates/openhuman-core/src/channels/host/voice.rs
index 75bbdc05ed..c33a56698e 100644
--- a/crates/openhuman-core/src/channels/host/voice.rs
+++ b/crates/openhuman-core/src/channels/host/voice.rs
@@ -76,23 +76,19 @@ fn turn_facts(scope: &HostVoiceScope, tenant: &crate::core::runtime::Tenant) ->
.unwrap_or_default()
}
-/// Record an inbound envelope's voice facts. The inbound message id is the
-/// turn id the module echoes back in its voice scope.
+/// Record an inbound envelope's voice facts under the runner request id that
+/// the module echoes back as `HostVoiceScope.turn_id`.
pub(crate) fn record_inbound_envelope(
envelope: &ChannelInboundEnvelope,
tenant: &crate::core::runtime::Tenant,
+ turn_id: &str,
) {
let inbound_has_voice = envelope
.parts
.iter()
.any(|part| matches!(part, ContentPart::VoiceNote { .. }));
record_turn(
- turn_key(
- tenant,
- &envelope.channel,
- &envelope.conversation,
- &envelope.message_id,
- ),
+ turn_key(tenant, &envelope.channel, &envelope.conversation, turn_id),
VoiceTurnFacts {
inbound_has_voice,
explicitly_requested: false,
diff --git a/crates/openhuman-core/src/channels/host/voice_tests.rs b/crates/openhuman-core/src/channels/host/voice_tests.rs
index dd65584879..6e859ebc8e 100644
--- a/crates/openhuman-core/src/channels/host/voice_tests.rs
+++ b/crates/openhuman-core/src/channels/host/voice_tests.rs
@@ -46,8 +46,8 @@ fn envelope(conversation: &str, message: &str, voice: bool) -> ChannelInboundEnv
#[test]
fn mirror_policy_reports_inbound_voice_from_recorded_envelope() {
let tenant = crate::core::runtime::Tenant::default();
- record_inbound_envelope(&envelope("c-voice", "m1", true), &tenant);
- record_inbound_envelope(&envelope("c-text", "m2", false), &tenant);
+ record_inbound_envelope(&envelope("c-voice", "m1", true), &tenant, "m1");
+ record_inbound_envelope(&envelope("c-text", "m2", false), &tenant, "m2");
let cfg = ChannelVoiceConfig::default();
let voice = resolve_policy(&cfg, &scope("telegram", "c-voice", "m1"), &tenant);
assert_eq!(voice.mode, HostVoiceReplyMode::Mirror);
@@ -60,11 +60,19 @@ fn mirror_policy_reports_inbound_voice_from_recorded_envelope() {
fn voice_facts_are_correlated_with_the_runner_request_id() {
let tenant = crate::core::runtime::Tenant::default();
let inbound = envelope("voice-conversation", "provider-message-id", true);
- record_inbound_envelope(&inbound, &tenant);
+ record_inbound_envelope(
+ &inbound,
+ &tenant,
+ "telegram:provider-message-id:runner-uuid",
+ );
let policy = resolve_policy(
&ChannelVoiceConfig::default(),
- &scope("telegram", "voice-conversation", "telegram:provider-message-id:runner-uuid"),
+ &scope(
+ "telegram",
+ "voice-conversation",
+ "telegram:provider-message-id:runner-uuid",
+ ),
&tenant,
);
@@ -72,6 +80,28 @@ fn voice_facts_are_correlated_with_the_runner_request_id() {
policy.inbound_has_voice,
"reply policy is queried with the runner request ID, not the provider message ID"
);
+ assert!(
+ !resolve_policy(
+ &ChannelVoiceConfig::default(),
+ &scope("telegram", "voice-conversation", "provider-message-id"),
+ &tenant,
+ )
+ .inbound_has_voice,
+ "a provider message ID is not an alias for the runner request ID"
+ );
+ assert!(
+ !resolve_policy(
+ &ChannelVoiceConfig::default(),
+ &scope(
+ "telegram",
+ "other-conversation",
+ "telegram:provider-message-id:runner-uuid"
+ ),
+ &tenant,
+ )
+ .inbound_has_voice,
+ "voice facts remain bound to the full conversation scope"
+ );
}
#[test]
@@ -88,8 +118,8 @@ fn same_conversation_and_turn_ids_do_not_cross_voice_facts_between_accounts() {
};
let tenant = crate::core::runtime::Tenant::default();
- record_inbound_envelope(&voice, &tenant);
- record_inbound_envelope(&text, &tenant);
+ record_inbound_envelope(&voice, &tenant, "shared-turn");
+ record_inbound_envelope(&text, &tenant, "shared-turn");
let alice = resolve_policy(
&ChannelVoiceConfig::default(),
@@ -117,7 +147,7 @@ fn voice_facts_require_matching_configured_account_and_full_conversation() {
let mut voice = envelope("shared", "same-turn", true);
voice.conversation.thread_id = Some("thread-a".into());
voice.conversation.topic_id = Some("topic-a".into());
- record_inbound_envelope(&voice, &tenant);
+ record_inbound_envelope(&voice, &tenant, "same-turn");
let config = ChannelVoiceConfig::default();
let matching = HostVoiceScope {
@@ -156,8 +186,8 @@ fn same_channel_account_and_turn_ids_do_not_cross_voice_facts_between_tenants()
let envelope_voice = envelope("same-conversation", "same-turn", true);
let envelope_text = envelope("same-conversation", "same-turn", false);
- record_inbound_envelope(&envelope_voice, &alice);
- record_inbound_envelope(&envelope_text, &bob);
+ record_inbound_envelope(&envelope_voice, &alice, "same-turn");
+ record_inbound_envelope(&envelope_text, &bob, "same-turn");
assert!(
resolve_policy(
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
index f9a7705a31..6cb6a922a7 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
@@ -100,7 +100,6 @@ pub(crate) async fn process_channel_runtime_message(
return;
}
};
- crate::channels::host::voice::record_inbound_envelope(&envelope, &tenant);
let session_key = crate::core::runtime::tenant::tenant_key(&tenant, &canonical_session_key);
println!(
@@ -388,6 +387,7 @@ pub(crate) async fn process_channel_runtime_message(
let execution = match selected_host {
Some(host) => {
let request_id = format!("{}:{}:{}", msg.channel, msg.id, uuid::Uuid::new_v4());
+ crate::channels::host::voice::record_inbound_envelope(&envelope, &tenant, &request_id);
let trusted = Arc::new(crate::agent::turn_host::TrustedAgentTurn {
host_agent: host,
channel: msg.channel.clone(),