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
This commit is contained in:
felixxia-oai
2026-09-07 12:53:57 +00:00
committed by copyberry
parent f3f53ee949
commit 8260619cb6
26 changed files with 599 additions and 482 deletions
@@ -1,3 +1,4 @@
use crate::context::GuardianContextMode;
use crate::context::GuardianReviewEvidence;
use crate::function_tool::FunctionCallError;
use crate::tools::context::FunctionToolOutput;
@@ -111,7 +112,7 @@ impl RequestUserInputHandler {
// Capture and consumption use the same fixed thread feature setting. Legacy
// threads must not construct retained answers, persist them, or advance their revision.
if turn.config.features.enabled(Feature::GuardianApproval)
&& session.enabled(Feature::GuardianThreadContext)
&& session.guardian_context_mode == GuardianContextMode::ThreadOwned
{
let user_input = questions
.iter()
@@ -117,9 +117,7 @@ async fn request_user_input_sets_non_blocking_outside_plan_mode(
session
.services
.thread_extension_data
.insert(GuardianReviewEvidence::from_features(
session.features().get(),
));
.insert(GuardianReviewEvidence::new(session.guardian_context_mode));
let original_history = session.conversation_history_snapshot().await;
*session.active_turn.lock().await = Some(ActiveTurn::default());