mirror of
https://github.com/openai/codex.git
synced 2026-11-19 22:30:42 +00:00
Fix retry classification for throttling and quota errors (#45602)
## Why `slow_down` errors were treated as terminal server overloads, while exhausted credit balances and spend limits fell through to retryable stream errors. ## What changed - Classify `slow_down` as a retryable rate limit in HTTP 503 responses and SSE failures, preserving the server message and parsing retry delays from SSE error messages. - Map `credit_balance_exhausted`, `organization_spend_limit_exceeded`, and `project_spend_limit_exceeded` SSE errors to quota exhaustion so they terminate without retries. ## Testing Extend tests to cover HTTP error classification and retryability, `slow_down` stream retry exhaustion and message-provided delays, and a single `UsageLimitExceeded` error with no retries for each quota error code. GitOrigin-RevId: 7985eba71ba4a6fe897a45957e448fadd42f3963
This commit is contained in:
@@ -52,21 +52,29 @@ fn map_api_error_preserves_retry_delay() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn map_api_error_maps_server_overloaded_from_503_body() {
|
||||
let body = serde_json::json!({
|
||||
"error": {
|
||||
"code": "server_is_overloaded"
|
||||
}
|
||||
})
|
||||
.to_string();
|
||||
let err = map_api_error(ApiError::Transport(TransportError::Http {
|
||||
status: http::StatusCode::SERVICE_UNAVAILABLE,
|
||||
url: Some("http://example.com/v1/responses".to_string()),
|
||||
headers: None,
|
||||
body: Some(body),
|
||||
}));
|
||||
|
||||
assert!(matches!(err.details(), CodexErrorDetails::ServerOverloaded));
|
||||
fn map_api_error_distinguishes_capacity_from_slow_down() {
|
||||
for (code, expected, retryable) in [
|
||||
(
|
||||
"server_is_overloaded",
|
||||
CodexErrorInfo::ServerOverloaded,
|
||||
false,
|
||||
),
|
||||
("slow_down", CodexErrorInfo::RateLimitExceeded, true),
|
||||
("unknown_error", CodexErrorInfo::Other, true),
|
||||
] {
|
||||
let err = map_api_error(ApiError::Transport(TransportError::Http {
|
||||
status: http::StatusCode::SERVICE_UNAVAILABLE,
|
||||
url: None,
|
||||
headers: None,
|
||||
body: Some(
|
||||
serde_json::json!({"error": {"code": code, "message": "retry later"}}).to_string(),
|
||||
),
|
||||
}));
|
||||
assert_eq!(
|
||||
(err.to_codex_protocol_error(), err.is_retryable()),
|
||||
(expected, retryable)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user