Distinguish policy-restricted capacity failures from server overloads (#57452)

## What changed

- Recognize `policy_capacity_unavailable` in HTTP and streaming API errors and expose it as `policyCapacityUnavailable` through the app-server protocol and generated bindings.
- Display “Policy-restricted capacity is unavailable. Please try again later.” while preserving overload retry behavior based on `Retry-After`.
- Handle the new error in TUI overload rendering, reviewer retries, and error telemetry.

## Testing

Add coverage for HTTP and streaming error classification, retry advice, WebSocket terminal error attribution, protocol serialization, and TUI rendering with and without an upstream message.

GitOrigin-RevId: 1b9536fba1e11cc891dcf689aee35410d82f5412
This commit is contained in:
Tom Leach (@toml)
2026-10-27 13:31:38 +00:00
committed by copyberry
parent 824b7666fb
commit 6a6e2fb1f0
42 changed files with 232 additions and 54 deletions
@@ -11,6 +11,45 @@ fn map_api_error_maps_server_overloaded() {
assert!(matches!(err.details(), CodexErrorDetails::ServerOverloaded));
}
#[tokio::test(start_paused = true)]
async fn http_policy_capacity_preserves_retry_advice_and_terminal_behavior() {
use std::time::Duration;
for (code, expected) in [
(
"policy_capacity_unavailable",
CodexErrorInfo::PolicyCapacityUnavailable,
),
("server_is_overloaded", CodexErrorInfo::ServerOverloaded),
] {
for advice in [RetryAfter::from_delay(Duration::from_secs(3)), None] {
let error = map_api_error(ApiError::Transport(TransportError::Http {
status: http::StatusCode::SERVICE_UNAVAILABLE,
url: None,
headers: None,
body: Some(
serde_json::json!({"error": {
"code": code, "type": "service_unavailable_error",
}})
.to_string(),
),
retry_after: advice,
}));
assert_eq!(
(
error.to_codex_protocol_error(),
error.retry_after(),
error.retry_delay(/*retry_count*/ 1)
),
(
expected.clone(),
advice,
advice.map(|_| Duration::from_secs(3))
)
);
}
}
}
#[test]
fn map_api_error_preserves_content_filter_retry_and_public_error() {
let err = map_api_error(ApiError::ContentFilter);