Separate Codex error details from retry metadata (#34996)

## What changed

- Wrap `CodexErrorDetails` and an optional retry delay in `CodexErr`, allowing any mapped error to preserve server-provided retry timing.
- Generate the payload-free `CodexErrKind` classification alongside the error details and reuse it for analytics.
- Update error handling sites to inspect `CodexErr::details()` while preserving existing display, debug, protocol mapping, and retryability behavior.

## Testing

- Add coverage for legacy debug formatting, error-specific retryability, and retry-delay propagation through API error mapping.

GitOrigin-RevId: d3ab8a305f2a2ee21d0c0a8c8c388b06dda9c59a
This commit is contained in:
Adam Perry @ OpenAI authored and copyberry committed 2026-07-23 19:32:26 +00:00
1 parent 265cd2e100
commit 7bafdada8b
40 files changed
+741 -435

No files matched your search

@@ -1,5 +1,6 @@
use codex_api::ApiError;
use codex_protocol::error::CodexErr;
use codex_protocol::error::CodexErrorDetails;
use http::StatusCode;
pub(super) const BEDROCK_EXPIRED_SIGNATURE_MESSAGE: &str = concat!(
@@ -9,12 +10,18 @@ pub(super) const BEDROCK_EXPIRED_SIGNATURE_MESSAGE: &str = concat!(
);
pub(super) fn map_api_error(error: ApiError) -> CodexErr {
let mut error = codex_api::map_api_error(error);
if let CodexErr::UnexpectedStatus(response) = &mut error
let error = codex_api::map_api_error(error);
if let CodexErrorDetails::UnexpectedStatus(response) = error.details()
&& response.status == StatusCode::UNAUTHORIZED
&& response.body.contains("Signature expired:")
{
let mut response = response.clone();
response.user_message = Some(BEDROCK_EXPIRED_SIGNATURE_MESSAGE.to_string());
let mapped_error = CodexErr::new(CodexErrorDetails::UnexpectedStatus(response));
return match error.retry_delay() {
Some(retry_delay) => mapped_error.with_retry_delay(retry_delay),
None => mapped_error,
};
}
error
}
@@ -1,6 +1,6 @@
use codex_api::ApiError;
use codex_api::TransportError;
use codex_protocol::error::CodexErr;
use codex_protocol::error::CodexErrorDetails;
use http::HeaderMap;
use http::HeaderValue;
use http::StatusCode;
@@ -29,7 +29,7 @@ fn expired_signature_has_actionable_guidance() {
"Signature expired: 20260609T133205Z is now earlier than 20260614T062525Z",
));
let CodexErr::UnexpectedStatus(response) = &error else {
let CodexErrorDetails::UnexpectedStatus(response) = error.details() else {
panic!("expected unexpected status error, got {error:?}");
};
assert_eq!(
@@ -51,7 +51,7 @@ fn other_unauthorized_errors_remain_generic() {
"The security token included in the request is invalid",
));
let CodexErr::UnexpectedStatus(response) = &error else {
let CodexErrorDetails::UnexpectedStatus(response) = error.details() else {
panic!("expected unexpected status error, got {error:?}");
};
assert_eq!(response.user_message, None);
@@ -70,7 +70,7 @@ fn signature_errors_with_other_statuses_remain_generic() {
"Signature expired: old is now earlier than new",
));
let CodexErr::UnexpectedStatus(response) = &error else {
let CodexErrorDetails::UnexpectedStatus(response) = error.details() else {
panic!("expected unexpected status error, got {error:?}");
};
assert_eq!(response.user_message, None);