Files
codex/codex-rs/exec-server/src/client/connection_failure.rs
T
acrognale-oai db3cb33eca Honor network policy in remote control and recover remote execution (#47410)
## What changed

- Route remote-control enrollment, pairing, client management, and WebSocket connections through the authenticated HTTP client factory. Keep policy denials distinct from authentication failures and wait for policy changes before reconnecting.
- Preserve policy denials through exec-server connection failures so later connection attempts and capability discovery can recover. Keep direct executors running through temporary policy outages while rejecting permanent policy failures.
- Build cached HTTP transports on blocking workers, serialize construction, and retain successful builds after callers time out so request deadlines cover queued construction.

## Testing

Add regression coverage for policy recovery during remote startup, direct registration, accepted WebSocket reconnection, and capability discovery; queued transport construction timeouts; and remote-control WebSocket fallback with invalid custom CA files.

GitOrigin-RevId: c81db18e83de957175bb213d165281ac701089dd
2026-09-23 00:48:53 +00:00

67 lines
2.4 KiB
Rust

//! Preserve policy denials through terminal connection state and allow later policy recovery.
use codex_http_client::NetworkPolicyDenied;
use codex_http_client::RouteAwareRequestError;
use super::ExecServerError;
#[derive(Clone, thiserror::Error, Debug)]
pub(super) enum ConnectionFailure {
#[error("{0}")]
Disconnected(String),
#[error(transparent)]
Policy(NetworkPolicyDenied),
}
impl From<ConnectionFailure> for ExecServerError {
fn from(failure: ConnectionFailure) -> Self {
match failure {
ConnectionFailure::Disconnected(message) => Self::Disconnected(message),
ConnectionFailure::Policy(denial) => Self::ApplicationNetworkPolicy(denial),
}
}
}
impl ExecServerError {
pub(crate) fn application_network_policy_denial(&self) -> Option<NetworkPolicyDenied> {
match self {
Self::ConnectionAttempt(error) => error.application_network_policy_denial(),
Self::ApplicationNetworkPolicy(denial)
| Self::EnvironmentRegistryRequest(RouteAwareRequestError::Policy(denial)) => {
Some(*denial)
}
Self::WebSocketConnect { source, .. } => {
codex_websocket_client::network_policy_denial(source)
}
Self::Spawn(_)
| Self::WebSocketConnectTimeout { .. }
| Self::WebSocketConfiguration(_)
| Self::InitializeTimedOut { .. }
| Self::Closed
| Self::Disconnected(_)
| Self::ProvisioningFailed(_)
| Self::Json(_)
| Self::HttpRequest(_)
| Self::Protocol(_)
| Self::ProvisioningModeConflict { .. }
| Self::Server { .. }
| Self::EnvironmentRegistryHttp { .. }
| Self::EnvironmentRegistryConfig(_)
| Self::EnvironmentRegistryAuth(_)
| Self::EnvironmentRegistryRequest(
RouteAwareRequestError::Request(_)
| RouteAwareRequestError::Route(_)
| RouteAwareRequestError::Build(_)
| RouteAwareRequestError::UnsupportedRedirectScheme(_)
| RouteAwareRequestError::TooManyRedirects
| RouteAwareRequestError::Timeout,
) => None,
}
}
}
pub(crate) fn can_retry_connection_attempt(error: &ExecServerError) -> bool {
error.application_network_policy_denial().is_some()
|| super::recovery::is_retryable_recovery_error(error)
}