cai
2026-08-11 db6463d9f98f740d4e8b6d3a0a25b65688196321
fix(asr): normalize origin rejection statuses
2 files modified
48 ■■■■■ changed files
src/asr_realtime.rs 40 ●●●●● patch | view | raw | blame | history
src/main.rs 8 ●●●● patch | view | raw | blame | history
src/asr_realtime.rs
@@ -37,6 +37,17 @@
}
impl AudioIngressMetadata {
    pub(crate) const ORIGIN_STATUSES: [&'static str; 8] = [
        "controlled_fixture_bound",
        "ordinary_mic_absent",
        "participant_attributes_absent",
        "participant_attributes_invalid",
        "sequence_absent",
        "sequence_replayed_or_regressed",
        "wrong_participant_or_track",
        "origin_unprovable",
    ];
    pub(crate) fn origin_status(attributes: &HashMap<String, String>) -> &'static str {
        let source = attributes.get("inputSourceCategory").map(String::as_str);
        let sequence = attributes.get("clientFixtureSequence").map(String::as_str);
@@ -48,6 +59,14 @@
            (Some("controlled_fixture"), None) => "sequence_absent",
            (Some("controlled_fixture"), Some(_)) => "participant_attributes_invalid",
            (Some(_), _) | (None, Some(_)) => "participant_attributes_invalid",
        }
    }
    pub(crate) fn rejection_status(reason: &str) -> &'static str {
        match reason {
            "incomplete_metadata" => "participant_attributes_absent",
            "invalid_source_or_sequence" => "participant_attributes_invalid",
            _ => "origin_unprovable",
        }
    }
@@ -558,6 +577,27 @@
            "ordinary_mic_absent",
            AudioIngressMetadata::origin_status(&HashMap::new())
        );
        assert_eq!(
            "participant_attributes_absent",
            AudioIngressMetadata::rejection_status("incomplete_metadata")
        );
        assert_eq!(
            "participant_attributes_invalid",
            AudioIngressMetadata::rejection_status("invalid_source_or_sequence")
        );
        assert_eq!(
            "sequence_replayed_or_regressed",
            AudioIngressMetadata::rejection_status("sequence_replayed")
        );
        assert_eq!(
            "wrong_participant_or_track",
            AudioIngressMetadata::rejection_status("wrong_participant")
        );
        assert_eq!(
            "origin_unprovable",
            AudioIngressMetadata::rejection_status("unknown")
        );
        assert_eq!(8, AudioIngressMetadata::ORIGIN_STATUSES.len());
    }
    #[test]
src/main.rs
@@ -3243,6 +3243,10 @@
    F: FnOnce() -> std::collections::HashMap<String, String>,
{
    if !is_bound_user_participant(participant_identity, expected_participant) {
        warn!(
            "audioIngressOriginStatus" = "wrong_participant_or_track",
            "runtime helper rejected audio participant before VAD/session"
        );
        return (vad.in_speech, vad.in_speech, None);
    }
    observe_frame_and_start_session(
@@ -3281,7 +3285,8 @@
        Ok(metadata) => metadata,
        Err(reason) => {
            warn!(call_id = %call_id, trace_id = %trace_id, turn_id = %turn_id,
                reason, origin_status, "runtime helper asr_realtime_metadata_rejected");
                reason, audioIngressOriginStatus = %AudioIngressMetadata::rejection_status(reason),
                "runtime helper asr_realtime_metadata_rejected");
            return;
        }
    };
@@ -3291,6 +3296,7 @@
            &metadata.client_fixture_sequence,
        ) {
            warn!(call_id = %call_id, trace_id = %trace_id, turn_id = %turn_id,
                audioIngressOriginStatus = "sequence_replayed_or_regressed",
                "runtime helper asr_realtime_metadata_sequence_rejected");
            return;
        }