aKode fase 5: 429 con Retry-After/X-RateLimit-Reset e messaggi in italiano, filtro modelli nel primo avvio, correzioni della rinomina

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
andrea.difonzo
2026-11-11 11:41:54 +01:00
parent 86e7c72e5f
commit 8b73331037
130 changed files with 1204 additions and 410 deletions

View File

@@ -152,11 +152,9 @@ async fn http_retry_deadline_survives_mapping_and_respects_terminal_errors() {
error.to_string()
),
(
CodexErrorInfo::ResponseTooManyFailedAttempts {
http_status_code: Some(429),
},
Some(429),
"exceeded retry limit, last status: 429 Too Many Requests".to_string(),
CodexErrorInfo::RateLimitExceeded,
None,
"rate limit exceeded: sensitive upstream detail".to_string(),
),
);
}
@@ -575,9 +573,7 @@ fn map_api_error_distinguishes_http_quota_errors_from_rate_limits() {
serde_json::json!({"type": "rate_limit_error", "code": "slow_down"}),
] {
let expected = if error["type"] == "rate_limit_error" {
CodexErrorInfo::ResponseTooManyFailedAttempts {
http_status_code: Some(429),
}
CodexErrorInfo::RateLimitExceeded
} else {
CodexErrorInfo::UsageLimitExceeded
};
@@ -893,3 +889,38 @@ fn runtime_auth_denials_stop_retries_without_losing_http_diagnostics() {
}
}
}
/// A plain provider 429 is a retryable rate limit; a daily allowance that is used up is terminal.
#[test]
fn map_api_error_classifies_provider_rate_limits() {
let map = |body: &str| {
map_api_error(ApiError::Transport(TransportError::Http {
retry_after: None,
status: http::StatusCode::TOO_MANY_REQUESTS,
url: None,
headers: None,
body: Some(body.to_string()),
}))
};
let err = map(r#"{"error":{"message":"Rate limit exceeded: limit_rpm/google/gemma","code":429}}"#);
assert_eq!(err.to_codex_protocol_error(), CodexErrorInfo::RateLimitExceeded);
assert!(err.retry_delay(/*retry_count*/ 1).is_some());
for body in [
r#"{"error":{"message":"Rate limit exceeded: free-models-per-day. Add 10 credits to unlock 1000 free model requests per day","code":429}}"#,
"daily request quota reached",
] {
let err = map(body);
assert_eq!(
err.to_codex_protocol_error(),
CodexErrorInfo::UsageLimitExceeded,
"{body}"
);
assert_eq!(err.retry_delay(/*retry_count*/ 1), None, "{body}");
assert!(
err.to_string().starts_with("Limite giornaliero del provider esaurito."),
"{err}"
);
}
}