mirror of
https://github.com/openai/codex.git
synced 2026-11-16 06:54:36 +00:00
Source Guardian REPL policy from model metadata (#41919)
## What changed - Add `auto_review.node_repl_policy` to model messages for `node_repl` and `cua_repl` reviews. - Use the reviewer model's configured policy, falling back to the bundled policy when the field is absent and skipping injection when it is explicitly empty. - Include the effective policy in Guardian session reuse checks and reject unsafe parent-model fallback transitions that would change it. ## Testing - Cover catalog, bundled, and explicitly empty policies across Node and CUA review paths. - Verify that policy changes invalidate cached reviewer sessions and incompatible fallback transitions. GitOrigin-RevId: 51c0bdfed9b464091b6eb47d91ca5a0990d7a315
This commit is contained in:
1 parent
746798b2f7
commit
865bbf9a69
11 files changed
+144
-24
No files matched your search
@@ -33,6 +33,7 @@ use tokio::time::Instant;
|
||||
use tokio::time::sleep_until;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
use crate::context::GuardianNodeReplPolicy;
|
||||
use crate::context::GuardianReviewEvidence;
|
||||
use crate::session::session::Session;
|
||||
use crate::session::turn_context::TurnContext;
|
||||
@@ -822,6 +823,7 @@ pub(crate) fn spawn_approval_request_review(
|
||||
|
||||
pub(super) struct GuardianReviewSessionConfig {
|
||||
pub(super) spawn_config: crate::config::Config,
|
||||
pub(super) node_repl_policy: GuardianNodeReplPolicy,
|
||||
model: String,
|
||||
reasoning_effort: Option<codex_protocol::openai_models::ReasoningEffort>,
|
||||
default_review_model_id: String,
|
||||
@@ -923,6 +925,9 @@ pub(super) async fn guardian_review_session_config(
|
||||
}
|
||||
Ok(GuardianReviewSessionConfig {
|
||||
spawn_config,
|
||||
node_repl_policy: GuardianNodeReplPolicy::from_model_messages(
|
||||
guardian_model_info.model_messages.as_ref(),
|
||||
),
|
||||
model: guardian_model,
|
||||
reasoning_effort: guardian_reasoning_effort,
|
||||
default_review_model_id: default_review_model_id.to_string(),
|
||||
@@ -973,6 +978,7 @@ async fn run_guardian_review_session_before_deadline(
|
||||
parent_session: Arc::clone(&session),
|
||||
parent_context: context.clone(),
|
||||
spawn_config: session_config.spawn_config,
|
||||
node_repl_policy: session_config.node_repl_policy,
|
||||
request,
|
||||
reasons,
|
||||
schema,
|
||||
|
||||
@@ -107,6 +107,7 @@ pub(crate) struct GuardianReviewSessionParams {
|
||||
pub(crate) parent_session: Arc<Session>,
|
||||
pub(crate) parent_context: GuardianReviewContext,
|
||||
pub(crate) spawn_config: Config,
|
||||
pub(crate) node_repl_policy: GuardianNodeReplPolicy,
|
||||
pub(crate) request: GuardianApprovalRequest,
|
||||
pub(crate) reasons: ApprovalRequestReasons,
|
||||
pub(crate) schema: Value,
|
||||
@@ -193,6 +194,7 @@ struct GuardianReviewSessionReuseKey {
|
||||
// history rewrites that invalidate existing reviewer context.
|
||||
parent_history_version: u64,
|
||||
node_repl_auto_review_required: bool,
|
||||
node_repl_policy: String,
|
||||
model: Option<String>,
|
||||
model_provider_id: String,
|
||||
model_provider: ModelProviderInfo,
|
||||
@@ -231,6 +233,7 @@ impl GuardianReviewSessionReuseKey {
|
||||
0
|
||||
},
|
||||
node_repl_auto_review_required: false,
|
||||
node_repl_policy: String::new(),
|
||||
model: spawn_config.model.clone(),
|
||||
model_provider_id: spawn_config.model_provider_id.clone(),
|
||||
model_provider: spawn_config.model_provider.clone(),
|
||||
@@ -267,6 +270,11 @@ impl GuardianReviewSessionReuseKey {
|
||||
self.node_repl_auto_review_required = required;
|
||||
self
|
||||
}
|
||||
|
||||
fn with_node_repl_policy(mut self, policy: &GuardianNodeReplPolicy) -> Self {
|
||||
self.node_repl_policy = policy.body();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
fn encrypted_parent_compaction<'a, I>(items: I) -> Option<ResponseItem>
|
||||
@@ -420,9 +428,9 @@ impl GuardianReviewSessionManager {
|
||||
) -> BoxFuture<'_, anyhow::Result<()>> {
|
||||
// Boxing breaks the Session::new -> Guardian -> Session::new future recursion.
|
||||
Box::pin(async move {
|
||||
let spawn_config = guardian_review_session_config(&parent_session, &parent_turn)
|
||||
.await?
|
||||
.spawn_config;
|
||||
let session_config =
|
||||
guardian_review_session_config(&parent_session, &parent_turn).await?;
|
||||
let spawn_config = session_config.spawn_config;
|
||||
let parent_history = parent_session.clone_history().await;
|
||||
let parent_compaction = spawn_config
|
||||
.features
|
||||
@@ -441,7 +449,8 @@ impl GuardianReviewSessionManager {
|
||||
.turn()
|
||||
.model_info()
|
||||
.node_repl_auto_review_required,
|
||||
);
|
||||
)
|
||||
.with_node_repl_policy(&session_config.node_repl_policy);
|
||||
let spawn_cancel_token = self.cancellation_token.child_token();
|
||||
let spawn_cancel_guard = spawn_cancel_token.clone().drop_guard();
|
||||
let review_session = spawn_guardian_review_session(
|
||||
@@ -531,7 +540,8 @@ impl GuardianReviewSessionManager {
|
||||
.turn()
|
||||
.model_info()
|
||||
.node_repl_auto_review_required,
|
||||
);
|
||||
)
|
||||
.with_node_repl_policy(¶ms.node_repl_policy);
|
||||
let mut spawned_trunk = false;
|
||||
let trunk_candidate = match run_before_review_deadline(
|
||||
deadline,
|
||||
@@ -1328,8 +1338,11 @@ async fn ensure_guardian_node_repl_policy(
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let policy = GuardianNodeReplPolicy;
|
||||
let policy = ¶ms.node_repl_policy;
|
||||
let policy_body = policy.body();
|
||||
if policy_body.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
let already_injected = review_session
|
||||
.session
|
||||
.clone_history()
|
||||
@@ -1367,7 +1380,7 @@ async fn ensure_guardian_node_repl_policy(
|
||||
initialize_context.await?;
|
||||
}
|
||||
|
||||
let item: ResponseItem = ContextualUserFragment::into(policy);
|
||||
let item: ResponseItem = ContextualUserFragment::into(policy.clone());
|
||||
review_session
|
||||
.session
|
||||
.inject_client_response_items(vec![item], turn_context.as_ref())
|
||||
|
||||
@@ -100,6 +100,7 @@ async fn test_review_params() -> GuardianReviewSessionParams {
|
||||
parent_session: Arc::new(session),
|
||||
parent_context: GuardianReviewContext::from(Arc::new(turn)),
|
||||
spawn_config,
|
||||
node_repl_policy: GuardianNodeReplPolicy::from_model_messages(/*messages*/ None),
|
||||
request: GuardianApprovalRequest::ExecCommand {
|
||||
id: "shell-1".to_string(),
|
||||
command: vec!["git".to_string(), "status".to_string()],
|
||||
@@ -212,9 +213,24 @@ async fn guardian_review_session_config_change_invalidates_cached_session() {
|
||||
cached_reuse_key
|
||||
.clone()
|
||||
.with_node_repl_policy_eligibility(/*required*/ false),
|
||||
cached_reuse_key.with_node_repl_policy_eligibility(/*required*/ true),
|
||||
cached_reuse_key
|
||||
.clone()
|
||||
.with_node_repl_policy_eligibility(/*required*/ true),
|
||||
"switching parent-model Node REPL eligibility must invalidate reviewer history"
|
||||
);
|
||||
let messages = serde_json::from_value(serde_json::json!({
|
||||
"auto_review": { "node_repl_policy": "Catalog REPL policy." }
|
||||
}))
|
||||
.expect("catalog model messages");
|
||||
assert_ne!(
|
||||
cached_reuse_key.clone().with_node_repl_policy(
|
||||
&GuardianNodeReplPolicy::from_model_messages(/*messages*/ None),
|
||||
),
|
||||
cached_reuse_key.with_node_repl_policy(&GuardianNodeReplPolicy::from_model_messages(Some(
|
||||
&messages
|
||||
)),),
|
||||
"changing the effective Node REPL policy must invalidate reviewer history"
|
||||
);
|
||||
|
||||
let mut compaction_enabled_config = cached_spawn_config;
|
||||
compaction_enabled_config
|
||||
@@ -385,6 +401,7 @@ async fn guardian_review_session_config_prefers_managed_policy_and_uses_catalog_
|
||||
auto_review: Some(AutoReviewMessages {
|
||||
policy: Some("Use the catalog Guardian policy.".to_string()),
|
||||
policy_template: Some(catalog_template.to_string()),
|
||||
node_repl_policy: None,
|
||||
rejection_instructions: None,
|
||||
timeout_instructions: None,
|
||||
}),
|
||||
@@ -426,6 +443,7 @@ async fn guardian_review_session_config_preserves_explicit_empty_catalog_policy(
|
||||
auto_review: Some(AutoReviewMessages {
|
||||
policy: Some(String::new()),
|
||||
policy_template: None,
|
||||
node_repl_policy: None,
|
||||
rejection_instructions: None,
|
||||
timeout_instructions: None,
|
||||
}),
|
||||
@@ -475,6 +493,7 @@ async fn guardian_review_session_config_preserves_explicit_empty_catalog_templat
|
||||
auto_review: Some(AutoReviewMessages {
|
||||
policy: Some(catalog_policy.to_string()),
|
||||
policy_template: Some(String::new()),
|
||||
node_repl_policy: None,
|
||||
rejection_instructions: None,
|
||||
timeout_instructions: None,
|
||||
}),
|
||||
@@ -721,7 +740,8 @@ async fn run_review_removes_trunk_when_event_stream_is_broken() {
|
||||
.await
|
||||
.history_version(),
|
||||
)
|
||||
.with_environments(params.parent_context.environments());
|
||||
.with_environments(params.parent_context.environments())
|
||||
.with_node_repl_policy(¶ms.node_repl_policy);
|
||||
let manager = Arc::new(GuardianReviewSessionManager {
|
||||
state: Arc::new(Mutex::new(GuardianReviewSessionState {
|
||||
trunk: Some(Arc::new(review_session)),
|
||||
|
||||
Reference in new issue
Block a user