mirror of
https://github.com/openai/codex.git
synced 2026-10-20 17:38:45 +00:00
## Why HTTP retries used local backoff even when the server supplied `Retry-After`. Relative retry delays also failed to account for time spent propagating errors or reporting retries. ## What changed - Parse `Retry-After` delay seconds and HTTP dates into a monotonic deadline captured when response headers arrive. - Honor that deadline for HTTP retries, falling back to local backoff when valid advice is absent. - Preserve deadlines through API and Bedrock error mapping, stream retries, and exhausted retry state. Expired advice remains a zero delay instead of triggering local backoff. ## Testing Add coverage for header parsing, deadline countdown and expiry, error mapping after exhausted HTTP retries, and delayed stream retry notifications. Update Responses and remote compaction tests to verify that HTTP retries honor `Retry-After`. GitOrigin-RevId: a2eff02946e5524f29e06f7ba1431e3d339261a4
58 lines
1.5 KiB
Rust
58 lines
1.5 KiB
Rust
//! Errors returned by the shared Codex HTTP transport.
|
|
|
|
use crate::client::HttpError;
|
|
use crate::retry_after::RetryAfter;
|
|
use http::HeaderMap;
|
|
use http::StatusCode;
|
|
use thiserror::Error;
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum TransportError {
|
|
#[error(transparent)]
|
|
Policy(#[from] crate::NetworkPolicyDenied),
|
|
#[error("http {status}: {body:?}")]
|
|
Http {
|
|
status: StatusCode,
|
|
url: Option<String>,
|
|
headers: Option<HeaderMap>,
|
|
body: Option<String>,
|
|
retry_after: Option<RetryAfter>,
|
|
},
|
|
#[error("retry limit reached")]
|
|
RetryLimit,
|
|
#[error("timeout")]
|
|
Timeout,
|
|
#[error("connection failed: {0}")]
|
|
Connection(#[source] HttpError),
|
|
#[error("network error: {0}")]
|
|
Network(String),
|
|
#[error("request build error: {0}")]
|
|
Build(String),
|
|
#[error("response body exceeds the {max_bytes} byte limit")]
|
|
ResponseTooLarge { max_bytes: usize },
|
|
}
|
|
|
|
impl TransportError {
|
|
/// Returns retry advice captured when this error response arrived.
|
|
pub fn retry_after(&self) -> Option<RetryAfter> {
|
|
match self {
|
|
Self::Http { retry_after, .. } => *retry_after,
|
|
Self::Policy(_)
|
|
| Self::RetryLimit
|
|
| Self::Timeout
|
|
| Self::Connection(_)
|
|
| Self::Network(_)
|
|
| Self::Build(_)
|
|
| Self::ResponseTooLarge { .. } => None,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum StreamError {
|
|
#[error("stream failed: {0}")]
|
|
Stream(String),
|
|
#[error("timeout")]
|
|
Timeout,
|
|
}
|