mirror of
https://github.com/openai/codex.git
synced 2026-11-20 22:40:37 +00:00
Preserve bio policy errors as a distinct non-retryable error (#46306)
## Why Streaming `bio_policy` failures were classified as generic invalid requests, losing their policy-specific classification. ## What changed - Add `BioPolicy` errors across the API and core protocol, recognizing streaming failures and HTTP 400 responses, including wrapped WebSocket errors. - Preserve server messages and use a biological-risk fallback when the message is missing or blank. - Treat bio policy errors as non-retryable in core and guardian handling, and classify them in diagnostics and telemetry. - Map `BioPolicy` to `other` in the app-server v2 protocol. ## Testing Add coverage for error classification, message preservation and fallbacks, HTTP and wrapped WebSocket responses, guardian retry decisions, and app-server conversion. Extend the core integration test to verify that bio policy failures emit a typed error and complete the turn after a single request. GitOrigin-RevId: 78c2647e8fc8f80297cb8a23fff06ab141099632
This commit is contained in:
@@ -181,6 +181,53 @@ fn map_api_error_uses_cyber_policy_fallback_for_missing_message() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn map_api_error_preserves_bio_policy() {
|
||||
let err = map_api_error(ApiError::BioPolicy {
|
||||
message: "This request was blocked by bio policy.".to_string(),
|
||||
});
|
||||
assert_eq!(err.to_codex_protocol_error(), CodexErrorInfo::BioPolicy);
|
||||
assert_eq!(err.to_string(), "This request was blocked by bio policy.");
|
||||
assert!(!err.is_retryable());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn map_api_error_maps_http_and_wrapped_websocket_bio_policy() {
|
||||
for wrapped in [false, true] {
|
||||
for message in [
|
||||
Some("This request was blocked by bio policy."),
|
||||
None,
|
||||
Some(""),
|
||||
Some(" "),
|
||||
] {
|
||||
let mut body = serde_json::json!({"error": {"code": "bio_policy"}});
|
||||
if let Some(message) = message {
|
||||
body["error"]["message"] = serde_json::json!(message);
|
||||
}
|
||||
if wrapped {
|
||||
body["type"] = serde_json::json!("error");
|
||||
body["status"] = serde_json::json!(400);
|
||||
}
|
||||
let err = map_api_error(ApiError::Transport(TransportError::Http {
|
||||
status: http::StatusCode::BAD_REQUEST,
|
||||
url: None,
|
||||
headers: None,
|
||||
body: Some(body.to_string()),
|
||||
}));
|
||||
|
||||
let expected = message
|
||||
.filter(|message| !message.trim().is_empty())
|
||||
.unwrap_or("This content was flagged for possible biological risk.");
|
||||
let CodexErrorDetails::BioPolicy { message } = err.details() else {
|
||||
panic!("expected CodexErrorDetails::BioPolicy, got {err:?}");
|
||||
};
|
||||
assert_eq!(message, expected);
|
||||
assert_eq!(err.to_codex_protocol_error(), CodexErrorInfo::BioPolicy);
|
||||
assert!(!err.is_retryable());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn map_api_error_maps_misalignment_policy_violation_from_400_body() {
|
||||
assert_misalignment_policy_violation_from_http_body(http::StatusCode::BAD_REQUEST);
|
||||
|
||||
Reference in New Issue
Block a user