/// Keeps `print_upstream_sync` explicit because it sits on CLI orchestration, where operators need deterministic exits and artifact paths.
/// Inputs are the typed parameters; output is the return value or side effect.
fn print_upstream_sync(state: lesavka_common::lesavka::UpstreamSyncState) {
    println!("planner_session_id={}", state.session_id);
    println!("planner_phase={}", state.phase);
    println!(
        "planner_latest_camera_remote_pts_us={}",
        state
            .latest_camera_remote_pts_us
            .map(|value| value.to_string())
            .unwrap_or_else(|| "pending".to_string())
    );
    println!(
        "planner_latest_microphone_remote_pts_us={}",
        state
            .latest_microphone_remote_pts_us
            .map(|value| value.to_string())
            .unwrap_or_else(|| "pending".to_string())
    );
    println!(
        "planner_last_video_presented_pts_us={}",
        state
            .last_video_presented_pts_us
            .map(|value| value.to_string())
            .unwrap_or_else(|| "pending".to_string())
    );
    println!(
        "planner_last_audio_presented_pts_us={}",
        state
            .last_audio_presented_pts_us
            .map(|value| value.to_string())
            .unwrap_or_else(|| "pending".to_string())
    );
    println!(
        "planner_live_lag_ms={}",
        state
            .live_lag_ms
            .map(|value| format!("{value:.1}"))
            .unwrap_or_else(|| "pending".to_string())
    );
    println!(
        "planner_skew_ms={}",
        state
            .planner_skew_ms
            .map(|value| format!("{value:+.1}"))
            .unwrap_or_else(|| "pending".to_string())
    );
    println!("planner_stale_audio_drops={}", state.stale_audio_drops);
    println!("planner_stale_video_drops={}", state.stale_video_drops);
    println!("planner_skew_video_drops={}", state.skew_video_drops);
    println!("planner_freshness_reanchors={}", state.freshness_reanchors);
    println!("planner_startup_timeouts={}", state.startup_timeouts);
    println!("planner_video_freezes={}", state.video_freezes);
    println!(
        "planner_client_capture_skew_ms={}",
        state
            .client_capture_skew_ms
            .map(|value| format!("{value:+.1}"))
            .unwrap_or_else(|| "pending".to_string())
    );
    println!(
        "planner_client_send_skew_ms={}",
        state
            .client_send_skew_ms
            .map(|value| format!("{value:+.1}"))
            .unwrap_or_else(|| "pending".to_string())
    );
    println!(
        "planner_server_receive_skew_ms={}",
        state
            .server_receive_skew_ms
            .map(|value| format!("{value:+.1}"))
            .unwrap_or_else(|| "pending".to_string())
    );
    println!(
        "planner_camera_client_queue_age_ms={}",
        state
            .camera_client_queue_age_ms
            .map(|value| format!("{value:.1}"))
            .unwrap_or_else(|| "pending".to_string())
    );
    println!(
        "planner_microphone_client_queue_age_ms={}",
        state
            .microphone_client_queue_age_ms
            .map(|value| format!("{value:.1}"))
            .unwrap_or_else(|| "pending".to_string())
    );
    println!(
        "planner_camera_server_receive_age_ms={}",
        state
            .camera_server_receive_age_ms
            .map(|value| format!("{value:.1}"))
            .unwrap_or_else(|| "pending".to_string())
    );
    println!(
        "planner_microphone_server_receive_age_ms={}",
        state
            .microphone_server_receive_age_ms
            .map(|value| format!("{value:.1}"))
            .unwrap_or_else(|| "pending".to_string())
    );
    println!(
        "planner_client_capture_abs_skew_p95_ms={}",
        state
            .client_capture_abs_skew_p95_ms
            .map(|value| format!("{value:.1}"))
            .unwrap_or_else(|| "pending".to_string())
    );
    println!(
        "planner_client_send_abs_skew_p95_ms={}",
        state
            .client_send_abs_skew_p95_ms
            .map(|value| format!("{value:.1}"))
            .unwrap_or_else(|| "pending".to_string())
    );
    println!(
        "planner_server_receive_abs_skew_p95_ms={}",
        state
            .server_receive_abs_skew_p95_ms
            .map(|value| format!("{value:.1}"))
            .unwrap_or_else(|| "pending".to_string())
    );
    println!(
        "planner_camera_client_queue_age_p95_ms={}",
        state
            .camera_client_queue_age_p95_ms
            .map(|value| format!("{value:.1}"))
            .unwrap_or_else(|| "pending".to_string())
    );
    println!(
        "planner_microphone_client_queue_age_p95_ms={}",
        state
            .microphone_client_queue_age_p95_ms
            .map(|value| format!("{value:.1}"))
            .unwrap_or_else(|| "pending".to_string())
    );
    println!(
        "planner_sink_handoff_skew_ms={}",
        state
            .sink_handoff_skew_ms
            .map(|value| format!("{value:+.1}"))
            .unwrap_or_else(|| "pending".to_string())
    );
    println!(
        "planner_sink_handoff_abs_skew_p95_ms={}",
        state
            .sink_handoff_abs_skew_p95_ms
            .map(|value| format!("{value:.1}"))
            .unwrap_or_else(|| "pending".to_string())
    );
    println!(
        "planner_camera_sink_late_ms={}",
        state
            .camera_sink_late_ms
            .map(|value| format!("{value:+.1}"))
            .unwrap_or_else(|| "pending".to_string())
    );
    println!(
        "planner_microphone_sink_late_ms={}",
        state
            .microphone_sink_late_ms
            .map(|value| format!("{value:+.1}"))
            .unwrap_or_else(|| "pending".to_string())
    );
    println!(
        "planner_camera_sink_late_p95_ms={}",
        state
            .camera_sink_late_p95_ms
            .map(|value| format!("{value:.1}"))
            .unwrap_or_else(|| "pending".to_string())
    );
    println!(
        "planner_microphone_sink_late_p95_ms={}",
        state
            .microphone_sink_late_p95_ms
            .map(|value| format!("{value:.1}"))
            .unwrap_or_else(|| "pending".to_string())
    );
    println!(
        "planner_client_timing_window_samples={}",
        state.client_timing_window_samples
    );
    println!(
        "planner_sink_handoff_window_samples={}",
        state.sink_handoff_window_samples
    );
    println!("uvc_contract_status={}", state.uvc_contract_status);
    println!("uvc_transport={}", state.uvc_transport);
    println!(
        "uvc_enforced_frame_cap_bytes={}",
        state
            .uvc_enforced_frame_cap_bytes
            .map(|value| value.to_string())
            .unwrap_or_else(|| "unavailable".to_string())
    );
    println!(
        "uvc_advertised_frame_bytes={}",
        state
            .uvc_advertised_frame_bytes
            .map(|value| value.to_string())
            .unwrap_or_else(|| "unavailable".to_string())
    );
    println!(
        "uvc_committed_frame_bytes={}",
        state
            .uvc_committed_frame_bytes
            .map(|value| value.to_string())
            .unwrap_or_else(|| "unavailable".to_string())
    );
    println!(
        "uvc_committed_payload_bytes={}",
        state
            .uvc_committed_payload_bytes
            .map(|value| value.to_string())
            .unwrap_or_else(|| "unavailable".to_string())
    );
    println!("uvc_contract_divergent={}", state.uvc_contract_divergent);
    println!(
        "uvc_contract_missing_reads={}",
        state.uvc_contract_missing_reads
    );
    println!(
        "uvc_contract_divergent_reads={}",
        state.uvc_contract_divergent_reads
    );
    println!("uvc_contract_detail={}", state.uvc_contract_detail);
    println!("uvc_integrity_status={}", state.uvc_integrity_status);
    println!("uvc_integrity_detail={}", state.uvc_integrity_detail);
    println!("uvc_rejected_oversize={}", state.uvc_rejected_oversize);
    println!("uvc_rejected_invalid={}", state.uvc_rejected_invalid);
    println!("uvc_fallback_idle={}", state.uvc_fallback_idle);
    println!("uvc_held_last_good={}", state.uvc_held_last_good);
    println!("uvc_stale_replay={}", state.uvc_stale_replay);
    println!("uvc_read_errors={}", state.uvc_read_errors);
    println!(
        "uvc_strict_validation_failures={}",
        state.uvc_strict_validation_failures
    );
    println!("uvc_dqbuf_errors={}", state.uvc_dqbuf_errors);
    println!("uvc_qbuf_errors={}", state.uvc_qbuf_errors);
    println!("uvc_kernel_errors={}", state.uvc_kernel_errors);
    println!("planner_detail={}", state.last_reason);
}
