mirror of
https://github.com/openai/codex.git
synced 2026-11-16 06:54:36 +00:00
Use model-specific auto-review outcome instructions (#39741)
## What changed - Add `rejection_instructions` and `timeout_instructions` to catalog-provided auto-review messages. - Use the acting model's instructions for denied and timed-out reviews across tool approvals, shell escalation, and MCP elicitation responses. - Fall back to the existing instructions only when a catalog value is absent, while preserving explicit empty-string overrides. ## Testing - Cover catalog overrides, legacy fallbacks, empty values, and separation between acting-model and reviewer-model messages. GitOrigin-RevId: c5b2c2dbdaefd45d1d658651dd1abaeb6d8c93da
This commit is contained in:
1 parent
88da5520d4
commit
4f38432d87
12 files changed
+292
-33
No files matched your search
@@ -10,6 +10,7 @@ use codex_extension_api::ThreadIdleCause;
|
||||
use codex_features::Feature;
|
||||
use codex_protocol::config_types::ApprovalsReviewer;
|
||||
use codex_protocol::openai_models::MODEL_SPECIALTY_CYBER;
|
||||
use codex_protocol::openai_models::ModelInfo;
|
||||
use codex_protocol::protocol::AskForApproval;
|
||||
use codex_protocol::protocol::CodexErrorInfo;
|
||||
use codex_protocol::protocol::EventMsg;
|
||||
@@ -101,8 +102,14 @@ pub(crate) fn new_guardian_review_id() -> String {
|
||||
uuid::Uuid::new_v4().to_string()
|
||||
}
|
||||
|
||||
pub(crate) fn guardian_timeout_message() -> String {
|
||||
GUARDIAN_TIMEOUT_INSTRUCTIONS.to_string()
|
||||
pub(crate) fn guardian_timeout_message(model_info: &ModelInfo) -> String {
|
||||
model_info
|
||||
.model_messages
|
||||
.as_ref()
|
||||
.and_then(|messages| messages.auto_review.as_ref())
|
||||
.and_then(|messages| messages.timeout_instructions.as_deref())
|
||||
.unwrap_or(GUARDIAN_TIMEOUT_INSTRUCTIONS)
|
||||
.to_string()
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -665,8 +672,15 @@ async fn run_guardian_review(
|
||||
} else {
|
||||
assessment.rationale.trim()
|
||||
};
|
||||
let rejection_instructions = turn
|
||||
.model_info
|
||||
.model_messages
|
||||
.as_ref()
|
||||
.and_then(|messages| messages.auto_review.as_ref())
|
||||
.and_then(|messages| messages.rejection_instructions.as_deref())
|
||||
.unwrap_or(GUARDIAN_REJECTION_INSTRUCTIONS);
|
||||
ReviewDecision::denied(format!(
|
||||
"This action was rejected due to unacceptable risk.\nReason: {rationale}\n{GUARDIAN_REJECTION_INSTRUCTIONS}"
|
||||
"This action was rejected due to unacceptable risk.\nReason: {rationale}\n{rejection_instructions}"
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1912,6 +1912,8 @@ mod tests {
|
||||
auto_review: Some(AutoReviewMessages {
|
||||
policy: Some("Use the catalog Guardian policy.".to_string()),
|
||||
policy_template: Some(catalog_template.to_string()),
|
||||
rejection_instructions: None,
|
||||
timeout_instructions: None,
|
||||
}),
|
||||
permissions: None,
|
||||
multi_agent: None,
|
||||
@@ -1948,6 +1950,8 @@ mod tests {
|
||||
auto_review: Some(AutoReviewMessages {
|
||||
policy: Some(String::new()),
|
||||
policy_template: None,
|
||||
rejection_instructions: None,
|
||||
timeout_instructions: None,
|
||||
}),
|
||||
permissions: None,
|
||||
multi_agent: None,
|
||||
@@ -1992,6 +1996,8 @@ mod tests {
|
||||
auto_review: Some(AutoReviewMessages {
|
||||
policy: Some(catalog_policy.to_string()),
|
||||
policy_template: Some(String::new()),
|
||||
rejection_instructions: None,
|
||||
timeout_instructions: None,
|
||||
}),
|
||||
permissions: None,
|
||||
multi_agent: None,
|
||||
|
||||
@@ -1427,10 +1427,28 @@ async fn cancelled_guardian_review_emits_terminal_abort_without_warning() {
|
||||
|
||||
#[test]
|
||||
fn guardian_timeout_message_distinguishes_timeout_from_policy_denial() {
|
||||
let message = guardian_timeout_message();
|
||||
let mut model = codex_models_manager::model_info::model_info_from_slug("acting-model");
|
||||
model.model_messages = None;
|
||||
let message = guardian_timeout_message(&model);
|
||||
assert!(message.contains("did not finish before its deadline"));
|
||||
assert!(message.contains("retry once"));
|
||||
assert!(!message.contains("unacceptable risk"));
|
||||
|
||||
for timeout_instructions in [None, Some("Catalog timeout instructions."), Some("")] {
|
||||
model.model_messages = Some(
|
||||
serde_json::from_value(serde_json::json!({
|
||||
"auto_review": {
|
||||
"policy": "review policy",
|
||||
"timeout_instructions": timeout_instructions,
|
||||
},
|
||||
}))
|
||||
.expect("model messages should deserialize"),
|
||||
);
|
||||
assert_eq!(
|
||||
guardian_timeout_message(&model),
|
||||
timeout_instructions.unwrap_or(&message),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
Reference in new issue
Block a user