Route Guardian inference through dedicated endpoints (#40892)

## What changed

- Add the opt-in `features.guardianv2.free_guardian` setting to route eligible
  Guardian reviews to `/guardian` and asynchronous classifications to
  `/guardian-classifier`.
- Support endpoint selection for both HTTP and WebSocket Responses clients,
  including endpoint-aware connection reuse.
- Keep `/responses` for API-key authentication, custom provider URLs,
  non-Guardian models, and configurations where the option is disabled.
- Omit routing hints and `service_tier` from requests sent to the dedicated
  Guardian endpoints.

## Testing

- Cover route selection across authentication modes, provider URLs, HTTP
  fallback, WebSocket review sessions, and classifier sampling.

GitOrigin-RevId: 9c88673c710d009e0239559b9245a4e6c4f4befc
This commit is contained in:
jif authored and copyberry committed 2026-08-26 14:36:48 +00:00
1 parent 10d5a603ae
commit 62fb56ee56
22 files changed
+488 -87

No files matched your search

+75
View File
@@ -18,6 +18,7 @@ use crate::test_support::responses_metadata as test_responses_metadata;
use codex_api::AgentIdentityTelemetry;
use codex_api::ApiError;
use codex_api::ResponseEvent;
use codex_api::ResponsesEndpoint;
use codex_api::TransportError;
use codex_http_client::HttpClientFactory;
use codex_http_client::OutboundProxyPolicy;
@@ -975,6 +976,80 @@ fn model_client_with_counting_attestation(
(model_client, attestation_calls)
}
#[test]
fn guardian_reviewer_uses_dedicated_endpoint_only_with_codex_backend_auth() {
let (mut model_client, _) =
model_client_with_counting_attestation(/*include_attestation*/ true);
Arc::get_mut(&mut model_client.state)
.expect("test client should have unique session state")
.session_source = SessionSource::SubAgent(SubAgentSource::Other("guardian".to_owned()));
assert_eq!(
model_client.responses_endpoint(
Some(&CodexAuth::create_dummy_chatgpt_auth_for_testing()),
"codex-auto-review",
),
ResponsesEndpoint::Responses
);
model_client = model_client.with_free_guardian_enabled(/*free_guardian_enabled*/ true);
assert_eq!(
model_client.responses_endpoint(
Some(&CodexAuth::create_dummy_chatgpt_auth_for_testing()),
"codex-auto-review",
),
ResponsesEndpoint::Guardian
);
assert_eq!(
model_client.responses_endpoint(
Some(&CodexAuth::create_dummy_chatgpt_auth_for_testing()),
"required-reviewer-model",
),
ResponsesEndpoint::Responses
);
assert_eq!(
model_client.responses_endpoint(
Some(&CodexAuth::create_dummy_chatgpt_auth_for_testing()),
"parent-fallback-model",
),
ResponsesEndpoint::Responses
);
assert_eq!(
model_client.responses_endpoint(
Some(&CodexAuth::from_api_key("test-api-key")),
"codex-auto-review",
),
ResponsesEndpoint::Responses
);
Arc::get_mut(&mut model_client.state)
.expect("test client should have unique session state")
.provider = create_model_provider(
ModelProviderInfo::create_openai_provider(Some("https://proxy.example.com/v1".to_owned())),
Some(AuthManager::from_auth_for_testing(
CodexAuth::create_dummy_chatgpt_auth_for_testing(),
)),
);
assert_eq!(
model_client.responses_endpoint(
Some(&CodexAuth::create_dummy_chatgpt_auth_for_testing()),
"codex-auto-review",
),
ResponsesEndpoint::Responses
);
Arc::get_mut(&mut model_client.state)
.expect("test client should have unique session state")
.session_source = SessionSource::Exec;
assert_eq!(
model_client.responses_endpoint(
Some(&CodexAuth::create_dummy_chatgpt_auth_for_testing()),
"codex-auto-review",
),
ResponsesEndpoint::Responses
);
}
#[tokio::test]
async fn websocket_handshake_includes_attestation_for_chatgpt_codex_responses() {
let (model_client, attestation_calls) =