mirror of
https://github.com/openai/codex.git
synced 2026-12-03 00:41:03 +00:00
Record provider error subreasons in turn analytics (#65356)
## Why Broad error categories make it hard to distinguish a model missing from the accessible catalog, an unsupported request value, and a route rate limit from other failures in the same categories. ## What changed Carry three structured provider subreasons through `CodexErr` and record them in `codex_error_subreason` only when they match the turn's terminal failure. - `model_not_in_accessible_catalog` for a matching HTTP 400 model-not-found error. - `unsupported_value` for an HTTP 400 invalid-request error with that code. - `route_rate_limit_exceeded` for a route-specific HTTP 429 that exhausts retries. ## Testing Cover subreason mapping, including wrapped WebSocket invalid requests, and verify that turn analytics omit subreasons for successful turns and mismatched terminal errors. Exercise recovery from a route-specific HTTP 429 using `Retry-After`. GitOrigin-RevId: 02d82082334e775020850e1a52ba7baff401cff1
This commit is contained in:
@@ -83,8 +83,18 @@ pub enum SpendLimitScope {
|
||||
Organization,
|
||||
}
|
||||
|
||||
/// A producer-supplied reason retained for diagnostics.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, serde::Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum CodexErrorSubreason {
|
||||
ModelNotInAccessibleCatalog,
|
||||
UnsupportedValue,
|
||||
RouteRateLimitExceeded,
|
||||
}
|
||||
|
||||
pub struct CodexErr {
|
||||
details: CodexErrorDetails,
|
||||
subreason: Option<CodexErrorSubreason>,
|
||||
retry_after: Option<RetryAfter>,
|
||||
agent_context: Option<AgentErrorContext>,
|
||||
}
|
||||
@@ -322,6 +332,7 @@ impl From<CodexErrorDetails> for CodexErr {
|
||||
fn from(details: CodexErrorDetails) -> Self {
|
||||
Self {
|
||||
details,
|
||||
subreason: None,
|
||||
retry_after: None,
|
||||
agent_context: None,
|
||||
}
|
||||
@@ -387,6 +398,7 @@ macro_rules! codex_err_unit_constructors {
|
||||
#[allow(non_upper_case_globals)]
|
||||
pub const $variant: Self = Self {
|
||||
details: CodexErrorDetails::$variant,
|
||||
subreason: None,
|
||||
retry_after: None,
|
||||
agent_context: None,
|
||||
};
|
||||
@@ -469,6 +481,15 @@ impl CodexErr {
|
||||
&self.details
|
||||
}
|
||||
|
||||
pub fn subreason(&self) -> Option<CodexErrorSubreason> {
|
||||
self.subreason
|
||||
}
|
||||
|
||||
pub fn with_subreason(mut self, subreason: Option<CodexErrorSubreason>) -> Self {
|
||||
self.subreason = subreason;
|
||||
self
|
||||
}
|
||||
|
||||
/// Whether retrying this request requires switching from WebSocket to HTTP.
|
||||
pub fn requires_http_fallback(&self) -> bool {
|
||||
matches!(self.retry_policy(), RetryPolicy::FallBackToHttp)
|
||||
|
||||
Reference in New Issue
Block a user