Honor model-provided Guardian review policies (#42744)

## What changed

- Add optional per-model Guardian modes for computer use, shell, code mode,
  file changes, MCP, network, and permission requests.
- Apply disabled, synchronous, or adaptive review by action category while
  preserving legacy configuration when model policy is absent.
- Bind cached risk scores to the active model policy, thread settings, and
  environment selections so outdated scores cannot approve later actions.
- Keep unknown review modes on the synchronous path and ignore unknown policy
  fields for forward compatibility.

## Testing

- Cover policy serialization, legacy fallback, scoped tool classification,
  disabled categories, and score invalidation after policy changes.

GitOrigin-RevId: f334a5f4fffb198da66cde3a400233e0df650516
This commit is contained in:
jif authored and copyberry committed 2026-09-04 11:59:18 +00:00
1 parent 9d253c885c
commit 4e48cd02da
26 files changed
+654 -186

No files matched your search

+13 -1
View File
@@ -33,6 +33,12 @@ use crate::config_types::ServiceTier;
use crate::config_types::Verbosity;
use crate::protocol::MultiAgentVersion;
#[path = "openai_models/guardian.rs"]
mod guardian;
pub use guardian::GuardianModelPolicy;
pub use guardian::GuardianReviewMode;
pub use guardian::GuardianScope;
#[path = "openai_models/guardian_v2.rs"]
mod guardian_v2;
@@ -390,6 +396,11 @@ const fn is_true(value: &bool) -> bool {
/// Model metadata returned by the Codex backend `/models` endpoint.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, TS, JsonSchema)]
pub struct ModelInfo {
/// Model-owned approval coverage. Absent preserves legacy settings; an empty map disables
/// ordinary Guardian review. Keys are computer_use, shell, code_mode, file_changes, mcp, network,
/// and permissions. This does not override mandatory safety or administrator requirements.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub guardian: Option<GuardianModelPolicy>,
pub slug: String,
pub display_name: String,
pub description: Option<String>,
@@ -961,7 +972,7 @@ mod tests {
);
}
fn test_model(spec: Option<ModelMessages>) -> ModelInfo {
pub(super) fn test_model(spec: Option<ModelMessages>) -> ModelInfo {
ModelInfo {
slug: "test-model".to_string(),
display_name: "Test Model".to_string(),
@@ -999,6 +1010,7 @@ mod tests {
used_fallback_model_metadata: false,
supports_search_tool: false,
use_responses_lite: false,
guardian: None,
node_repl_auto_review_required: false,
node_repl_disabled: false,
auto_review_model_override: None,