mirror of
https://github.com/openai/codex.git
synced 2026-11-16 06:54:36 +00:00
Preserve root authorization context in Guardian reviews (#42832)
## Why Guardian reviews for delegated workers need the current root instructions and verified answers even after the parent context is compacted. Approvals must also become stale when that root authorization changes. ## What changed - Build bounded root review evidence from retained context, preserving source order and answer scope while prioritizing user instructions over optional assistant context. - Recover retained instructions from Guardian history after compaction and mark authorization incomplete when required instructions or answers are unavailable. - Version root authorization in synchronous and reusable review sessions so an allow result is cancelled when its evidence changes. - Strip parent-only Guardian approvals when forking worker history in retained-context mode. ## Testing - Cover retained and legacy context modes, oversized evidence, message limits, parent compaction, and authorization changes during review. GitOrigin-RevId: 658219b7cee08f2752adcea9966268fd21727976
This commit is contained in:
1 parent
de7874067f
commit
87628df77a
12 files changed
+588
-103
No files matched your search
@@ -525,6 +525,12 @@ pub(super) async fn run_synchronous_review(
|
||||
|
||||
let schema = guardian_output_schema();
|
||||
let terminal_action = action_summary.clone();
|
||||
let root_authorization_version = session
|
||||
.services
|
||||
.agent_control
|
||||
.root_user_authorization(session.thread_id)
|
||||
.await
|
||||
.map(|snapshot| snapshot.authorization_version);
|
||||
let review_evidence = if let Some(evidence) = session
|
||||
.services
|
||||
.thread_extension_data
|
||||
@@ -534,12 +540,6 @@ pub(super) async fn run_synchronous_review(
|
||||
// stale even if it later completes against a newer prompt snapshot.
|
||||
let history = session.conversation_history_snapshot().await;
|
||||
let authorization_version = evidence.authorization_version(history.as_ref());
|
||||
let root_authorization_version = session
|
||||
.services
|
||||
.agent_control
|
||||
.root_user_authorization(session.thread_id)
|
||||
.await
|
||||
.map(|snapshot| snapshot.authorization_version);
|
||||
format_guardian_action_pretty(&request).ok().map(|action| {
|
||||
(
|
||||
evidence,
|
||||
@@ -551,7 +551,7 @@ pub(super) async fn run_synchronous_review(
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let (outcome, analytics_result) = Box::pin(run_guardian_review_session_with_retry(
|
||||
let (mut outcome, analytics_result) = Box::pin(run_guardian_review_session_with_retry(
|
||||
session.clone(),
|
||||
context,
|
||||
request,
|
||||
@@ -561,6 +561,19 @@ pub(super) async fn run_synchronous_review(
|
||||
GUARDIAN_REVIEW_MAX_ATTEMPTS,
|
||||
))
|
||||
.await;
|
||||
if session.enabled(Feature::GuardianThreadContext)
|
||||
&& matches!(&outcome, GuardianReviewOutcome::Completed(assessment) if assessment.outcome == GuardianAssessmentOutcome::Allow)
|
||||
&& root_authorization_version
|
||||
!= session
|
||||
.services
|
||||
.agent_control
|
||||
.root_user_authorization(session.thread_id)
|
||||
.await
|
||||
.map(|snapshot| snapshot.authorization_version)
|
||||
{
|
||||
// A completed approval cannot outlive the root evidence it evaluated.
|
||||
outcome = GuardianReviewOutcome::Error(GuardianReviewError::Cancelled);
|
||||
}
|
||||
|
||||
let completed_at_ms = now_unix_timestamp_ms();
|
||||
let completed_review = matches!(&outcome, GuardianReviewOutcome::Completed(_));
|
||||
|
||||
@@ -194,6 +194,7 @@ struct GuardianReviewSessionReuseKey {
|
||||
// Only include settings that affect spawned-session behavior and parent
|
||||
// history rewrites that invalidate existing reviewer context.
|
||||
parent_history_version: u64,
|
||||
root_authorization_version: Option<crate::codex_thread::GuardianAuthorizationVersion>,
|
||||
node_repl_auto_review_required: bool,
|
||||
node_repl_policy: String,
|
||||
model: Option<String>,
|
||||
@@ -225,6 +226,7 @@ impl GuardianReviewSessionReuseKey {
|
||||
parent_history_version: u64,
|
||||
) -> Self {
|
||||
Self {
|
||||
root_authorization_version: None,
|
||||
parent_history_version: if spawn_config
|
||||
.features
|
||||
.enabled(Feature::GuardianReuseParentCompaction)
|
||||
@@ -433,13 +435,24 @@ impl GuardianReviewSessionManager {
|
||||
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 root_authorization_version =
|
||||
if parent_session.enabled(Feature::GuardianThreadContext) {
|
||||
parent_session
|
||||
.services
|
||||
.agent_control
|
||||
.root_user_authorization(parent_session.thread_id)
|
||||
.await
|
||||
.map(|snapshot| snapshot.authorization_version)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let parent_compaction = spawn_config
|
||||
.features
|
||||
.enabled(Feature::GuardianReuseParentCompaction)
|
||||
.then(|| encrypted_parent_compaction(parent_history.raw_items()))
|
||||
.flatten();
|
||||
let parent_context = GuardianReviewContext::from(parent_turn);
|
||||
let reuse_key = GuardianReviewSessionReuseKey::from_spawn_config(
|
||||
let mut reuse_key = GuardianReviewSessionReuseKey::from_spawn_config(
|
||||
&spawn_config,
|
||||
parent_session.user_instructions().await,
|
||||
parent_history.history_version(),
|
||||
@@ -452,6 +465,7 @@ impl GuardianReviewSessionManager {
|
||||
.node_repl_auto_review_required,
|
||||
)
|
||||
.with_node_repl_policy(&session_config.node_repl_policy);
|
||||
reuse_key.root_authorization_version = root_authorization_version;
|
||||
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(
|
||||
@@ -523,6 +537,20 @@ impl GuardianReviewSessionManager {
|
||||
) -> (GuardianReviewSessionOutcome, GuardianReviewAnalyticsResult) {
|
||||
let deadline = params.deadline;
|
||||
let parent_history = params.parent_session.clone_history().await;
|
||||
let root_authorization_version = if params
|
||||
.parent_session
|
||||
.enabled(Feature::GuardianThreadContext)
|
||||
{
|
||||
params
|
||||
.parent_session
|
||||
.services
|
||||
.agent_control
|
||||
.root_user_authorization(params.parent_session.thread_id)
|
||||
.await
|
||||
.map(|snapshot| snapshot.authorization_version)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let parent_compaction = params
|
||||
.spawn_config
|
||||
.features
|
||||
@@ -543,6 +571,7 @@ impl GuardianReviewSessionManager {
|
||||
.node_repl_auto_review_required,
|
||||
)
|
||||
.with_node_repl_policy(¶ms.node_repl_policy);
|
||||
next_reuse_key.root_authorization_version = root_authorization_version;
|
||||
let mut spawned_trunk = false;
|
||||
let trunk_candidate = match run_before_review_deadline(
|
||||
deadline,
|
||||
|
||||
Reference in new issue
Block a user