Propagate response tickets to Guardian reviews (#42758)

## What changed

- Request and parse server-issued Guardian tickets for eligible Codex backend responses.
- Scope each ticket to the response that produced a Guardian review or classifier request, including HTTP and WebSocket retries, without adding it to model-visible or persisted context.
- Validate ticket shape, reserve its metadata keys, redact it from debug and request-body logging, and attach it only at the Guardian transport boundary.

## Testing

- Cover ticket parsing, endpoint and authentication routing, retry scoping, classifier retries, and redaction for compressed and uncompressed requests.

GitOrigin-RevId: 6219dd15c9f19ed3387de516aac1b8e7c9cdb0e3
This commit is contained in:
jif authored and copyberry committed 2026-09-04 12:56:26 +00:00
1 parent 97e46694e1
commit cc4b8bdeb8
32 files changed
+562 -44

No files matched your search

+38 -1
View File
@@ -1104,6 +1104,31 @@ impl ModelClient {
&& provider.aws.is_none()
}
fn set_guardian_ticket_request(
&self,
metadata: &mut Option<HashMap<String, String>>,
auth: Option<&CodexAuth>,
endpoint: ResponsesEndpoint,
) {
if let Some(metadata) = metadata.as_mut() {
metadata.remove("guardian_ticket_requested");
}
if self.free_guardian_enabled
&& endpoint == ResponsesEndpoint::Responses
&& !crate::guardian::is_basic_session_source(&self.state.session_source)
&& matches!(
auth,
Some(CodexAuth::Chatgpt(_) | CodexAuth::ChatgptAuthTokens(_))
)
&& self.uses_codex_backend(auth)
&& self.state.provider.info().supports_codex_backend_routes()
{
metadata
.get_or_insert_with(HashMap::new)
.insert("guardian_ticket_requested".to_owned(), "true".to_owned());
}
}
fn build_routing_hint_header(
&self,
auth: Option<&CodexAuth>,
@@ -1326,6 +1351,7 @@ impl ModelClientSession {
},
compression,
turn_state: Some(Arc::clone(&self.turn_state)),
guardian_ticket: responses_metadata.guardian_ticket.clone(),
}
}
@@ -1615,6 +1641,11 @@ impl ModelClientSession {
service_tier.clone(),
responses_metadata,
)?;
self.client.set_guardian_ticket_request(
&mut request.client_metadata,
client_setup.auth.as_ref(),
endpoint,
);
if endpoint == ResponsesEndpoint::Guardian {
request.service_tier = None;
}
@@ -1859,7 +1890,7 @@ impl ModelClientSession {
.prepare_response_items_for_request(&mut request.input);
Some(original_item_ids)
};
let ws_payload = ResponseCreateWsRequest {
let mut ws_payload = ResponseCreateWsRequest {
previous_response_id,
input: incremental_items.as_deref().unwrap_or(&request.input),
generate: if warmup { Some(false) } else { None },
@@ -1869,6 +1900,11 @@ impl ModelClientSession {
),
..ResponseCreateWsRequest::from(&request)
};
self.client.set_guardian_ticket_request(
&mut ws_payload.client_metadata,
client_setup.auth.as_ref(),
endpoint,
);
let mut ws_request = ResponsesWsRequest::ResponseCreate(ws_payload);
stamp_ws_stream_request_start_ms(&mut ws_request);
if !previous_response_id_from_untraced_warmup {
@@ -1886,6 +1922,7 @@ impl ModelClientSession {
ws_request,
self.websocket_session.connection_reused(),
Some(Arc::clone(&self.turn_state)),
responses_metadata.guardian_ticket.as_ref(),
)
.await;
if let Some(original_item_ids) = original_item_ids {