Treat incomplete responses as terminal errors (#53451)

## Why

Incomplete responses such as `max_output_tokens` were classified as stream errors, allowing retries and compaction model fallback after the response had hit its output limit.

## What changed

Introduce `ResponseIncomplete` errors that preserve the server-provided reason and stop stream processing immediately. Make these errors non-retryable and stop compaction without falling back to the selected model. Record incomplete responses separately in sampler failure metrics.

## Testing

Add regression tests that verify incomplete responses surface a terminal error without retries over SSE and WebSocket, and that compaction stops without retrying or switching models for both local and remote compaction.

GitOrigin-RevId: 6e107d441b9bf03fa47ea47b88eeb94b71a9f729
This commit is contained in:
jif
2026-10-12 18:53:49 +00:00
committed by copyberry
parent c308e127e0
commit bc9cad3473
12 changed files with 209 additions and 4 deletions
+4
View File
@@ -29,6 +29,7 @@ pub fn map_api_error(err: ApiError) -> CodexErr {
| ApiError::Api { .. }
| ApiError::Stream(_)
| ApiError::ContentFilter
| ApiError::ResponseIncomplete(_)
| ApiError::ContextWindowExceeded
| ApiError::QuotaExceeded
| ApiError::UsageNotIncluded
@@ -58,6 +59,9 @@ fn map_api_error_details(err: ApiError) -> CodexErr {
}
ApiError::Stream(msg) => CodexErr::Stream(msg),
ApiError::ContentFilter => CodexErr::new(CodexErrorDetails::ContentFilter),
ApiError::ResponseIncomplete(incomplete) => {
CodexErr::new(CodexErrorDetails::ResponseIncomplete(incomplete))
}
ApiError::ServerOverloaded { .. } => CodexErr::ServerOverloaded,
ApiError::FlexUnavailable => CodexErr::new(CodexErrorDetails::FlexUnavailable),
ApiError::Api { status, message } => {