cai
2026-08-12 f709c9ce06731147e010f02b11b438a0eb7b9c99
src/main.rs
@@ -145,6 +145,8 @@
}
fn record_controlled_fixture_probe_event(
    runtime_call_id: &str,
    runtime_trace_id: &str,
    stage: &'static str,
    call_id_hash: &str,
    trace_id_hash: &str,
@@ -161,6 +163,8 @@
    println!(
        "{}",
        controlled_fixture_probe_event(
            runtime_call_id,
            runtime_trace_id,
            stage,
            call_id_hash,
            trace_id_hash,
@@ -174,6 +178,8 @@
}
fn controlled_fixture_probe_event(
    runtime_call_id: &str,
    runtime_trace_id: &str,
    stage: &'static str,
    call_id_hash: &str,
    trace_id_hash: &str,
@@ -184,20 +190,32 @@
    reject_reason: Option<&'static str>,
) -> serde_json::Value {
    json!({
        "event": "controlled_fixture_attribute_probe",
        "stage": stage,
        "observed": observed,
        "ack_result": ack_result,
        "reject_reason": reject_reason,
        "call_id_hash": call_id_hash,
        "trace_id_hash": trace_id_hash,
        "generation": generation,
        "sequence_hash": sha256_hex(sequence),
        "type": "cv_activity",
        "callId": runtime_call_id,
        "traceId": runtime_trace_id,
        "turnId": null,
        "eventName": "controlled_fixture_attribute_probe",
        "eventWallTimeMs": current_time_millis(),
        "result": "ok",
        "reasonCode": null,
        "retryable": null,
        "extension": {
            "stage": stage,
            "observed": observed,
            "ack_result": ack_result,
            "reject_reason": reject_reason,
            "call_id_hash": call_id_hash,
            "trace_id_hash": trace_id_hash,
            "generation": generation,
            "sequence_hash": sha256_hex(sequence),
        },
    })
}
fn record_controlled_fixture_attribute_decision(
    decision: Result<(), &'static str>,
    runtime_call_id: &str,
    runtime_trace_id: &str,
    call_id_hash: &str,
    trace_id_hash: &str,
    generation: u64,
@@ -205,6 +223,8 @@
) -> (&'static str, Option<&'static str>, bool) {
    let classification = controlled_fixture_ack_classification(decision);
    record_controlled_fixture_probe_event(
        runtime_call_id,
        runtime_trace_id,
        "attributes_classified",
        call_id_hash,
        trace_id_hash,
@@ -219,6 +239,8 @@
async fn complete_controlled_fixture_ack_publish<F, E>(
    publish: F,
    runtime_call_id: &str,
    runtime_trace_id: &str,
    observed: bool,
    ack_result: &'static str,
    reject_reason: Option<&'static str>,
@@ -233,6 +255,8 @@
{
    if publish.await.is_ok() {
        record_controlled_fixture_probe_event(
            runtime_call_id,
            runtime_trace_id,
            "ack_publish_completed",
            call_id_hash,
            trace_id_hash,
@@ -246,6 +270,8 @@
        observed
    } else {
        record_controlled_fixture_probe_event(
            runtime_call_id,
            runtime_trace_id,
            "ack_publish_completed",
            call_id_hash,
            trace_id_hash,
@@ -1142,6 +1168,8 @@
                    Some(&participant_for_probe),
                    &sink,
                    user_participant_identity.as_deref(),
                    &call_id,
                    &trace_id,
                )
                .await;
                let observer_started = start_observer_after_controlled_fixture_probe(
@@ -1172,6 +1200,8 @@
                        None => (None, Some("no_current_participant"), false),
                    };
                    record_controlled_fixture_probe_event(
                        &call_id,
                        &trace_id,
                        if observer_started {
                            "audio_observer_allowed"
                        } else {
@@ -1207,6 +1237,8 @@
                {
                    if acknowledged_probe_sequences.contains(&probe.client_fixture_sequence) {
                        record_controlled_fixture_probe_event(
                            &call_id,
                            &trace_id,
                            "data_received",
                            &probe.call_id_hash,
                            &probe.call_trace_id_hash,
@@ -1228,6 +1260,8 @@
                );
                if let Some(probe) = pending_probe.as_ref() {
                    record_controlled_fixture_probe_event(
                        &call_id,
                        &trace_id,
                        "data_received",
                        &probe.call_id_hash,
                        &probe.call_trace_id_hash,
@@ -1244,6 +1278,8 @@
                    current_user_participant.as_ref(),
                    &sink,
                    user_participant_identity.as_deref(),
                    &call_id,
                    &trace_id,
                )
                .await;
            }
@@ -1294,12 +1330,16 @@
    participant: Option<&RemoteParticipant>,
    sink: &BotAudioOutputSink,
    expected_participant: Option<&str>,
    runtime_call_id: &str,
    runtime_trace_id: &str,
) -> Option<bool> {
    let Some(probe) = pending_probe.take() else {
        return None;
    };
    if acknowledged_probe_sequences.contains(&probe.sequence) {
        record_controlled_fixture_probe_event(
            runtime_call_id,
            runtime_trace_id,
            "attributes_classified",
            &probe.call_id_hash,
            &probe.call_trace_id_hash,
@@ -1313,6 +1353,8 @@
    }
    if Instant::now() > probe.expires_at {
        record_controlled_fixture_probe_event(
            runtime_call_id,
            runtime_trace_id,
            "attributes_classified",
            &probe.call_id_hash,
            &probe.call_trace_id_hash,
@@ -1326,6 +1368,8 @@
    }
    let Some(participant) = participant else {
        record_controlled_fixture_probe_event(
            runtime_call_id,
            runtime_trace_id,
            "attributes_classified",
            &probe.call_id_hash,
            &probe.call_trace_id_hash,
@@ -1340,6 +1384,8 @@
    };
    if participant.identity() != probe.sender {
        record_controlled_fixture_probe_event(
            runtime_call_id,
            runtime_trace_id,
            "attributes_classified",
            &probe.call_id_hash,
            &probe.call_trace_id_hash,
@@ -1361,6 +1407,8 @@
    .await;
    let (ack_result, reject_reason, observed) = record_controlled_fixture_attribute_decision(
        decision,
        runtime_call_id,
        runtime_trace_id,
        &probe.call_id_hash,
        &probe.call_trace_id_hash,
        probe.generation,
@@ -1373,6 +1421,8 @@
    };
    let local_participant = sink.room.local_participant();
    record_controlled_fixture_probe_event(
        runtime_call_id,
        runtime_trace_id,
        "ack_publish_started",
        &probe.call_id_hash,
        &probe.call_trace_id_hash,
@@ -1391,6 +1441,8 @@
    Some(
        complete_controlled_fixture_ack_publish(
            publish,
            runtime_call_id,
            runtime_trace_id,
            observed,
            ack_result,
            reject_reason,
@@ -5346,6 +5398,8 @@
        ];
        for (stage, result, reason) in stages {
            let event = controlled_fixture_probe_event(
                call_id,
                trace_id,
                stage,
                &call_id_hash,
                &trace_id_hash,
@@ -5355,12 +5409,12 @@
                result,
                reason,
            );
            assert_eq!(event["call_id_hash"], call_id_hash);
            assert_eq!(event["trace_id_hash"], trace_id_hash);
            assert_eq!(event["stage"], stage);
            assert_eq!(event["type"], "cv_activity");
            assert_eq!(event["eventName"], "controlled_fixture_attribute_probe");
            assert_eq!(event["extension"]["call_id_hash"], call_id_hash);
            assert_eq!(event["extension"]["trace_id_hash"], trace_id_hash);
            assert_eq!(event["extension"]["stage"], stage);
            let output = event.to_string();
            assert!(!output.contains(call_id));
            assert!(!output.contains(trace_id));
            assert!(!output.contains(sequence));
        }
        assert!(!start_observer_after_controlled_fixture_probe(
@@ -5372,6 +5426,8 @@
        let (ack_result, reject_reason, observed) = controlled_fixture_ack_classification(Ok(()));
        let allowed = controlled_fixture_probe_event(
            call_id,
            trace_id,
            "audio_observer_allowed",
            &call_id_hash,
            &trace_id_hash,
@@ -5381,7 +5437,7 @@
            Some(ack_result),
            reject_reason,
        );
        assert_eq!(allowed["trace_id_hash"], trace_id_hash);
        assert_eq!(allowed["extension"]["trace_id_hash"], trace_id_hash);
        assert!(start_observer_after_controlled_fixture_probe(
            true,
            Some(observed),
@@ -5468,6 +5524,8 @@
        let mut acknowledged = HashSet::new();
        let probe_result = complete_controlled_fixture_ack_publish(
            async { Err::<(), ()>(()) },
            "runtime-call-publish-failure",
            "runtime-trace-publish-failure",
            true,
            "observed",
            None,
@@ -5501,6 +5559,8 @@
        let observed_result = complete_controlled_fixture_ack_publish(
            async { Ok::<(), ()>(()) },
            "runtime-call-publish-success",
            "runtime-trace-publish-success",
            true,
            "observed",
            None,