Use trusted Guardian templates for managed policies (#60646)

## Why

User-configured model catalogs can supply Guardian prompt templates that omit policy slots or add conflicting instructions. Managed rules need a trusted template to reach the reviewer.

## What changed

- Use the bundled Guardian policy template when managed policy or additional rules are present, while preserving explicit host-provided templates.
- Remove `auto_review.extra_policy` and `auto_review.experimental_policy_template` from configuration and the schema. Warn when they are used, directing additional rules to `guardian_extra_policy` in managed `requirements.toml`.

## Testing

Add regression coverage for managed rules with user-supplied catalog templates, explicit host templates, and migration warnings for the removed settings.

GitOrigin-RevId: 7f00bfaa85051272ed70ceb2fcb64ffc297b8755
This commit is contained in:
Won Park
2026-11-10 19:30:21 +00:00
committed by copyberry
parent 2c2d99f0e3
commit a2b7c4a655
12 changed files with 134 additions and 114 deletions
-4
View File
@@ -591,10 +591,6 @@ pub struct AutoReviewToml {
pub circuit_break_action: Option<CircuitBreakAction>,
/// Additional policy instructions inserted into the guardian prompt.
pub policy: Option<String>,
/// Additional policy text inserted into the Guardian template's `{{ extra_policy }}` slot.
pub extra_policy: Option<String>,
/// Experimental full Guardian prompt template containing the tenant policy placeholder.
pub experimental_policy_template: Option<String>,
/// Experimental replacement for the history-retrieval instructions when history tools
/// and Apps are enabled. Omitted or blank values use the built-in prompt.
pub experimental_conversation_history_prompt: Option<String>,
+6
View File
@@ -315,6 +315,12 @@ pub(crate) fn ignored_config_warning(
["auto_review", "experimental_denial_reconsideration_prompt"] => {
" Remove auto_review.experimental_denial_reconsideration_prompt from config.toml; Guardian retries replay the original request without a reconsideration prompt."
}
["auto_review", "experimental_policy_template"] => {
" Remove auto_review.experimental_policy_template from config.toml."
}
["auto_review", "extra_policy"] => {
" To enforce additional Guardian rules, set guardian_extra_policy in managed requirements.toml."
}
["windows", "sandbox_private_desktop"] => {
" Remove windows.sandbox_private_desktop; legacy Windows sandboxes always use a private desktop."
}
+18 -8
View File
@@ -279,20 +279,30 @@ include_view_image_tool = false
);
}
#[test]
fn removed_private_desktop_setting_has_migration_hint() {
#[test_case::test_case(
"[windows]\nsandbox_private_desktop = false",
"Codex is ignoring 1 unrecognized configuration setting. Check for typos or deprecated settings.\n session-flags: `windows.sandbox_private_desktop` is ignored. Remove windows.sandbox_private_desktop; legacy Windows sandboxes always use a private desktop.";
"private_desktop"
)]
#[test_case::test_case(
"[auto_review]\nextra_policy = 'Additional rules.'\nexperimental_policy_template = 'Custom template.'",
concat!(
"Codex is ignoring 2 unrecognized configuration settings. Check for typos or deprecated settings.",
"\n session-flags: `auto_review.experimental_policy_template` is ignored. Remove auto_review.experimental_policy_template from config.toml.",
"\n session-flags: `auto_review.extra_policy` is ignored. To enforce additional Guardian rules, set guardian_extra_policy in managed requirements.toml.",
);
"guardian_policy"
)]
fn removed_settings_have_migration_hints(contents: &str, expected: &str) {
let config = ConfigLayerStack::new(
vec![layer(
ConfigLayerSource::SessionFlags,
"[windows]\nsandbox_private_desktop = false",
)],
vec![layer(ConfigLayerSource::SessionFlags, contents)],
ConfigRequirements::default(),
ConfigRequirementsToml::default(),
)
.unwrap();
assert_eq!(
ignored_config_warning(&config, &[]).unwrap(),
"Codex is ignoring 1 unrecognized configuration setting. Check for typos or deprecated settings.\n session-flags: `windows.sandbox_private_desktop` is ignored. Remove windows.sandbox_private_desktop; legacy Windows sandboxes always use a private desktop."
ignored_config_warning(&config, &[]).as_deref(),
Some(expected)
);
}