mirror of
https://github.com/openai/codex.git
synced 2026-10-18 17:18:52 +00:00
Move the exponential backoff helper into `codex-async-utils` so `codex-cloud-config` can use it without a runtime dependency on `codex-core`. Keep `codex-core` as a development dependency for cloud-config tests. Preserve the existing retry delays and jitter, and re-export `backoff` from `codex_core::util` for existing callers. GitOrigin-RevId: 338f3194e166e77003da532310ff5be78a0eac9e
102 lines
2.8 KiB
Rust
102 lines
2.8 KiB
Rust
pub use codex_async_utils::backoff;
|
|
use tracing::error;
|
|
|
|
/// Emit structured feedback metadata as key/value pairs.
|
|
///
|
|
/// This logs a tracing event with `target: "feedback_tags"`. If
|
|
/// `codex_feedback::CodexFeedback::metadata_layer()` is installed, these fields are captured and
|
|
/// later attached as tags when feedback is uploaded.
|
|
///
|
|
/// Values are wrapped with [`tracing::field::DebugValue`], so the expression only needs to
|
|
/// implement [`std::fmt::Debug`].
|
|
///
|
|
/// Example:
|
|
///
|
|
/// ```rust
|
|
/// let provider_id = "openai";
|
|
/// let request_id = "req-123";
|
|
///
|
|
/// codex_core::feedback_tags!(model = "gpt-5", cached = true);
|
|
/// codex_core::feedback_tags!(provider = provider_id, request_id = request_id);
|
|
/// ```
|
|
#[macro_export]
|
|
macro_rules! feedback_tags {
|
|
($( $key:ident = $value:expr ),+ $(,)?) => {
|
|
::tracing::info!(
|
|
target: "feedback_tags",
|
|
$( $key = ::tracing::field::debug(&$value) ),+
|
|
);
|
|
};
|
|
}
|
|
|
|
struct Auth401FeedbackSnapshot<'a> {
|
|
request_id: &'a str,
|
|
cf_ray: &'a str,
|
|
error: &'a str,
|
|
error_code: &'a str,
|
|
}
|
|
|
|
impl<'a> Auth401FeedbackSnapshot<'a> {
|
|
fn from_optional_fields(
|
|
request_id: Option<&'a str>,
|
|
cf_ray: Option<&'a str>,
|
|
error: Option<&'a str>,
|
|
error_code: Option<&'a str>,
|
|
) -> Self {
|
|
Self {
|
|
request_id: request_id.unwrap_or(""),
|
|
cf_ray: cf_ray.unwrap_or(""),
|
|
error: error.unwrap_or(""),
|
|
error_code: error_code.unwrap_or(""),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub(crate) fn emit_feedback_auth_recovery_tags(
|
|
auth_recovery_mode: &str,
|
|
auth_recovery_phase: &str,
|
|
auth_recovery_outcome: &str,
|
|
auth_request_id: Option<&str>,
|
|
auth_cf_ray: Option<&str>,
|
|
auth_error: Option<&str>,
|
|
auth_error_code: Option<&str>,
|
|
) {
|
|
let auth_401 = Auth401FeedbackSnapshot::from_optional_fields(
|
|
auth_request_id,
|
|
auth_cf_ray,
|
|
auth_error,
|
|
auth_error_code,
|
|
);
|
|
feedback_tags!(
|
|
auth_recovery_mode = auth_recovery_mode,
|
|
auth_recovery_phase = auth_recovery_phase,
|
|
auth_recovery_outcome = auth_recovery_outcome,
|
|
auth_401_request_id = auth_401.request_id,
|
|
auth_401_cf_ray = auth_401.cf_ray,
|
|
auth_401_error = auth_401.error,
|
|
auth_401_error_code = auth_401.error_code
|
|
);
|
|
}
|
|
|
|
pub(crate) fn error_or_panic(message: impl std::string::ToString) {
|
|
if cfg!(debug_assertions) {
|
|
panic!("{}", message.to_string());
|
|
} else {
|
|
error!("{}", message.to_string());
|
|
}
|
|
}
|
|
|
|
/// Trim a thread name and return `None` if it is empty after trimming.
|
|
pub fn normalize_thread_name(name: &str) -> Option<String> {
|
|
let trimmed = name.trim();
|
|
if trimmed.is_empty() {
|
|
None
|
|
} else {
|
|
Some(trimmed.to_string())
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "util_tests.rs"]
|
|
mod tests;
|