mirror of
https://github.com/openai/codex.git
synced 2026-11-19 22:30:42 +00:00
Surface Responses stream errors as soon as they arrive (#62356)
## Why If a provider keeps an SSE connection open after reporting a failure, Codex can hit the idle timeout and lose the original error and its retry advice. ## What changed End the SSE stream immediately on `response.failed` or a recognized `error` event. Classify statusless quota, plan usage, invalid prompt, and misalignment errors consistently across both event forms. Preserve `Retry-After` for overload and capacity errors, preferring error-level headers over event-level headers when both provide valid advice. ## Testing Add SSE regression tests that hold the connection open and verify immediate error delivery, terminal error handling, and retry delays. Extend WebSocket coverage for statusless errors received before the close handshake. GitOrigin-RevId: 69afd1d3b18ca3139e9b7ad98ae1481a432179f0
This commit is contained in:
@@ -103,6 +103,23 @@ pub(crate) fn parse_terminal_provider_error(
|
||||
.and_then(Value::as_str)
|
||||
.filter(|message| !message.trim().is_empty());
|
||||
match (code, status) {
|
||||
("insufficient_quota" | "credit_balance_exhausted", None) => Some(ApiError::QuotaExceeded),
|
||||
("usage_not_included", None) => Some(ApiError::UsageNotIncluded),
|
||||
("invalid_prompt", None) => Some(ApiError::InvalidPrompt {
|
||||
message: error
|
||||
.get("message")
|
||||
.and_then(Value::as_str)
|
||||
.unwrap_or("Invalid request.")
|
||||
.to_owned(),
|
||||
}),
|
||||
("misalignment_policy_violation", None) => Some(ApiError::MisalignmentPolicyViolation {
|
||||
message: message
|
||||
.unwrap_or("This request was blocked due to a misalignment policy violation.")
|
||||
.to_owned(),
|
||||
misalignment: error.get("misalignment").cloned().and_then(|details| {
|
||||
serde_json::from_value::<MisalignmentErrorDetails>(details).ok()
|
||||
}),
|
||||
}),
|
||||
("api_key_spend_limit_exceeded", None | Some(StatusCode::TOO_MANY_REQUESTS)) => {
|
||||
Some(ApiError::SpendLimitExceeded(SpendLimitScope::ApiKey))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user