Files
codex/codex-rs/core/src/session/retained_context.rs
T
felixxia-oai 8260619cb6 Centralize Guardian context mode and checkpoint policy (#43458)
## What changed

Resolve `GuardianContextMode` once at session construction and share it across history retention, replay, evidence capture, compaction, and review consumers.

Extract synchronous reviewer context policy and consolidate Guardian V2 parent checkpoint selection so sampling and fast approval use the same eligibility checks. Preserve legacy checkpoint omission and strict compatibility requirements for thread-owned context.

## Testing

Adapt existing review and history tests to the explicit context mode. Move checkpoint tests alongside the extracted selector, retaining coverage for latest-item identity, unusable checkpoints, and complete-item size limits.

GitOrigin-RevId: c73fb6fea556921acfffe758a5f709d7494019dd
2026-09-07 12:53:57 +00:00

36 lines
1.2 KiB
Rust

//! Orders retained inputs and records host-verified facts at the context checkpoint boundary.
use crate::context::GuardianContextMode;
use codex_history::RetainedContextEvent;
use codex_history::RolloutItem;
use super::Session;
use super::thread_settings;
impl Session {
/// Legacy mode neither reserves a sequence nor takes the session-state lock.
pub(crate) async fn reserve_user_input_order(&self) -> Option<u64> {
if self.guardian_context_mode == GuardianContextMode::Legacy {
return None;
}
Some(self.state.lock().await.history.reserve_input_order())
}
pub(crate) async fn record_retained_context(&self, mut event: RetainedContextEvent) {
event.bound();
// Share the checkpoint persistence lock so a fact cannot land on the wrong side
// of the checkpoint/suffix boundary. Ephemeral threads use the same live state.
let _guard = thread_settings::acquire_persistence_lock(self).await;
if self
.state
.lock()
.await
.history
.record_retained_context(&event)
{
self.persist_rollout_items(&[RolloutItem::RetainedContext(event)])
.await;
}
}
}