Route Guardian requests through /responses with identifying headers (#45736)

## What changed

- Replace dedicated Guardian endpoints with `/responses`, sending `x-codex-guardian: reviewer` or `x-codex-guardian: classifier` for eligible Codex backend requests over HTTP and WebSocket.
- Add model-scoped thread headers, recheck backend authentication on each request attempt, and reconnect WebSockets when the applicable headers change.
- Retain `features.guardianv2.free_guardian` for configuration compatibility while removing its routing gate; the backend now controls Guardian billing.

## Testing

Update tests for reviewer and classifier headers, model and authentication scoping, HTTP fallback, WebSocket reuse, and parent-response metadata across retries.

GitOrigin-RevId: 1c2b3c458ab77fb40aae4ee6784f6d827c60e76c
This commit is contained in:
jif
2026-09-15 17:09:11 +00:00
committed by copyberry
parent d4e11a9b97
commit eeded5ba1a
22 changed files with 246 additions and 286 deletions
+3 -35
View File
@@ -23,33 +23,9 @@ use std::sync::Arc;
use std::sync::OnceLock;
use tracing::instrument;
/// Responses-compatible inference routes supported by Codex backend.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub enum ResponsesEndpoint {
/// Regular user-owned model inference.
#[default]
Responses,
/// Full Guardian approval-review agent inference.
Guardian,
/// Lightweight asynchronous Guardian risk classification.
GuardianClassifier,
}
impl ResponsesEndpoint {
/// Returns the provider-relative path for this inference surface.
pub const fn path(self) -> &'static str {
match self {
Self::Responses => "/responses",
Self::Guardian => "/guardian",
Self::GuardianClassifier => "/guardian-classifier",
}
}
}
pub struct ResponsesClient<T: HttpTransport> {
session: EndpointSession<T>,
sse_telemetry: Option<Arc<dyn SseTelemetry>>,
endpoint: ResponsesEndpoint,
}
#[derive(Default)]
@@ -67,16 +43,9 @@ impl<T: HttpTransport> ResponsesClient<T> {
Self {
session: EndpointSession::new(transport, provider, auth),
sse_telemetry: None,
endpoint: ResponsesEndpoint::Responses,
}
}
/// Selects a Responses-compatible backend route for subsequent requests.
pub fn with_endpoint(mut self, endpoint: ResponsesEndpoint) -> Self {
self.endpoint = endpoint;
self
}
pub fn with_telemetry(
self,
request: Option<Arc<dyn RequestTelemetry>>,
@@ -85,7 +54,6 @@ impl<T: HttpTransport> ResponsesClient<T> {
Self {
session: self.session.with_request_telemetry(request),
sse_telemetry: sse,
endpoint: self.endpoint,
}
}
@@ -96,7 +64,7 @@ impl<T: HttpTransport> ResponsesClient<T> {
fields(
transport = "responses_http",
http.method = "POST",
api.path = self.endpoint.path()
api.path = "/responses"
)
)]
pub async fn stream_request(
@@ -135,7 +103,7 @@ impl<T: HttpTransport> ResponsesClient<T> {
fields(
transport = "responses_http",
http.method = "POST",
api.path = self.endpoint.path(),
api.path = "/responses",
turn.has_state = turn_state.is_some()
)
)]
@@ -168,7 +136,7 @@ impl<T: HttpTransport> ResponsesClient<T> {
.session
.stream_encoded_json_with(
Method::POST,
self.endpoint.path(),
"/responses",
extra_headers,
Some(body),
|req| {