Treat access program denials as terminal errors (#60476)

## What changed

Recognize `access_program_not_enabled` in HTTP 403 responses and response stream errors as a dedicated, non-retryable error. Preserve HTTP diagnostic details and provider stream messages, with a default message when none is supplied.

Stop SSE streams immediately on this error and avoid triggering WebSocket fallback for explicit access program denials. Add a fixed diagnostic label for doctor output and telemetry.

## Testing

Extend coverage for HTTP and WebSocket denials, immediate SSE termination despite retry headers, and doctor diagnostic redaction.

GitOrigin-RevId: 3a41f7bb80ad5e13a87e831b458d17cdd19a4b62
This commit is contained in:
Charlie Marsh
2026-11-10 00:08:32 +00:00
committed by copyberry
parent bb360e5db8
commit 5b98eaafeb
10 changed files with 55 additions and 1 deletions
+15
View File
@@ -151,6 +151,9 @@ pub enum CodexErrorDetails {
/// The server rejected the selected workspace.
#[error("{0}")]
InvalidWorkspaceSelected(UnexpectedResponseError),
/// The provider denied the access program required for this request.
#[error("{0}")]
AccessProgramNotEnabled(ProviderRejection),
/// Unexpected HTTP status code.
#[error("{0}")]
UnexpectedStatus(UnexpectedResponseError),
@@ -470,6 +473,7 @@ impl CodexErr {
| CodexErrorDetails::CyberPolicy { .. }
| CodexErrorDetails::BioPolicy { .. }
| CodexErrorDetails::InvalidWorkspaceSelected(_)
| CodexErrorDetails::AccessProgramNotEnabled(_)
| CodexErrorDetails::MisalignmentPolicyViolation { .. } => None,
CodexErrorDetails::ServerOverloaded
| CodexErrorDetails::PolicyCapacityUnavailable
@@ -545,6 +549,7 @@ impl CodexErr {
},
CodexErrorDetails::ConnectionFailed(_)
| CodexErrorDetails::InvalidWorkspaceSelected(_)
| CodexErrorDetails::AccessProgramNotEnabled(_)
| CodexErrorDetails::UnexpectedStatus(_) => CodexErrorInfo::HttpConnectionFailed {
http_status_code: self.http_status_code_value(),
},
@@ -591,6 +596,7 @@ impl CodexErr {
CodexErrorDetails::ModelNotFound { status, .. } => *status,
CodexErrorDetails::RetryLimit(err) => Some(err.status),
CodexErrorDetails::InvalidWorkspaceSelected(err)
| CodexErrorDetails::AccessProgramNotEnabled(ProviderRejection::Http(err))
| CodexErrorDetails::UnexpectedStatus(err) => Some(err.status),
CodexErrorDetails::ConnectionFailed(err) => err.source.status(),
CodexErrorDetails::ResponseStreamFailed(err) => err.source.status(),
@@ -631,6 +637,15 @@ impl std::fmt::Display for ResponseStreamFailed {
}
}
/// A provider can reject a request before or after opening the response stream.
#[derive(Debug, Error)]
pub enum ProviderRejection {
#[error(transparent)]
Http(UnexpectedResponseError),
#[error("{0}")]
Stream(String),
}
#[derive(Clone, Debug)]
pub struct UnexpectedResponseError {
pub status: StatusCode,