Persist verified user answers in Guardian thread context (#42579)

## Why

Guardian authorization reviews need host-verified `request_user_input` answers to
remain aligned with thread history across compaction, resume, and rollback.

## What changed

- Record verified question-and-answer pairs in retained thread context when
  `GuardianThreadContext` is enabled, and source both local and delegated Guardian
  review evidence from that context.
- Preserve complete answer records within the evidence budget. Mark authorization
  context incomplete when records are unavailable or oversized, and defer cached
  fast approvals in that case.
- Keep the existing runtime-only answer path for threads that do not enable the
  thread-owned context.

## Testing

- Cover answer retention through compaction and resume, removal after rollback,
  source-call eviction, oversized answers, delegated review evidence, and legacy
  behavior.

GitOrigin-RevId: 01f6f4541515434a0d00fdde318ff59f2f8bd2eb
This commit is contained in:
felixxia-oai
2026-09-03 16:41:11 +00:00
committed by copyberry
parent 7a7c188682
commit 1d74c3ba1e
22 changed files with 960 additions and 397 deletions
+5 -17
View File
@@ -11,7 +11,6 @@ use crate::session::step_settings::StepSettingsUpdate;
use codex_diagnostics::Gauge;
use codex_diagnostics::GaugeGuard;
use codex_exec_server::SelectedCapabilityRootsStatus;
use codex_extension_api::ConversationHistorySnapshot;
use codex_extension_api::ThreadIdleCause;
use codex_features::Feature;
use codex_history::RolloutItem;
@@ -160,18 +159,10 @@ pub use codex_guardian_context::GuardianRootMessage;
pub struct GuardianAuthorizationVersion {
/// User-message/reset revision, preserved across compaction and internal context.
pub user_message_revision: u64,
/// Number of successful, host-produced answers to genuine user-input requests.
/// Successful host answers captured by the temporary legacy path.
pub user_input_response_count: usize,
}
impl GuardianAuthorizationVersion {
/// Captures history replacement and genuine user input from the same snapshot.
pub fn from_history(history: &dyn ConversationHistorySnapshot) -> Self {
Self {
user_message_revision: history.user_message_revision(),
user_input_response_count: 0,
}
}
/// False when required retained answers were lost or do not fit the request budget.
pub retained_context_complete: bool,
}
/// Bounded root conversation and authorization state from one history snapshot.
@@ -817,11 +808,8 @@ impl CodexThread {
pub async fn guardian_authorization_version(&self) -> GuardianAuthorizationVersion {
let history = self.session.conversation_history_snapshot().await;
self.thread_extension_data()
.get::<GuardianReviewEvidence>()
.map_or_else(
|| GuardianAuthorizationVersion::from_history(history.as_ref()),
|evidence| evidence.authorization_version(history.as_ref()),
)
.get_or_init(GuardianReviewEvidence::default)
.authorization_version(history.as_ref())
}
/// Returns bounded root conversation evidence and its authorization version atomically.