mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:50:52 +00:00
Use reset checks for attached Guardian V3 reviews (#63948)
## Why Attached reviewers need to detect root history resets that can invalidate an approval. Preparing an attached review previously fetched root conversation evidence even though the reviewer did not use it for preparation. ## What changed - Check the root history version before starting an attached review and while it runs. Local MultiAgent V2 workers resolve the currently loaded root thread, and hosted workers use the host's root snapshot. - Skip root evidence capture when preparing or prewarming attached reviewers. Skip per-attempt evidence collection for attached observers and sessions without an evidence store. Live reviewers with an evidence store still record their verdicts. ## Testing Add coverage for root history version changes on reset, version stability on append, root resolution after reload, and verdict recording when the first approval reuses a prewarmed reviewer. GitOrigin-RevId: b3ff7e58883d5f72bea3d774e05ba2f678df45fc
This commit is contained in:
@@ -1,13 +1,24 @@
|
||||
//! Captures a completed Guardian model context using the existing fork replay format.
|
||||
//! This snapshot is in memory only; transcript durability remains part of turn completion.
|
||||
//! Reads Guardian history lifetimes and captures completed reviewer contexts for fork replay.
|
||||
//! Both operate on live state. Transcript durability remains part of turn completion.
|
||||
|
||||
use super::session::Session;
|
||||
use codex_history::CompactedItem;
|
||||
use codex_history::RolloutItem;
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::protocol::EventMsg;
|
||||
use codex_protocol::protocol::MultiAgentVersion;
|
||||
use codex_protocol::protocol::TokenCountEvent;
|
||||
|
||||
impl Session {
|
||||
/// Only MultiAgent V2 workers use a separate root history for review.
|
||||
pub(crate) async fn guardian_root_history_version(&self) -> Option<(ThreadId, u64)> {
|
||||
if self.multi_agent_version() != Some(MultiAgentVersion::V2) {
|
||||
return None;
|
||||
}
|
||||
let version = self.state.lock().await.history.reset_version;
|
||||
Some((self.thread_id, version))
|
||||
}
|
||||
|
||||
pub(crate) async fn guardian_fork_history(&self) -> Vec<RolloutItem> {
|
||||
let state = self.state.lock().await;
|
||||
let history = &state.history;
|
||||
|
||||
@@ -4,13 +4,32 @@ use crate::context_manager::ContextManager;
|
||||
use crate::session::tests::make_session_and_context;
|
||||
use codex_history::InitialHistory;
|
||||
use codex_protocol::models::ResponseItem;
|
||||
use codex_protocol::protocol::MultiAgentVersion;
|
||||
use codex_protocol::protocol::ThreadHistoryMode;
|
||||
use codex_protocol::protocol::TokenUsage;
|
||||
use codex_thread_context_ids_test_support::thread_context_ids;
|
||||
use core_test_support::responses::user_message_item;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::json;
|
||||
use test_case::test_case;
|
||||
|
||||
#[tokio::test]
|
||||
async fn guardian_root_version_changes_on_history_reset_but_not_on_append() {
|
||||
let (mut root, turn) = make_session_and_context().await;
|
||||
root.multi_agent_version = MultiAgentVersion::V2.into();
|
||||
let before = root.guardian_root_history_version().await.unwrap();
|
||||
assert_eq!(before.0, root.thread_id);
|
||||
|
||||
let message = user_message_item("Update the README.");
|
||||
root.record_conversation_items(&turn, turn.model_info(), &[message])
|
||||
.await;
|
||||
assert_eq!(root.guardian_root_history_version().await, Some(before));
|
||||
|
||||
root.replace_history(Vec::new(), /*reference_context_item*/ None)
|
||||
.await;
|
||||
assert_ne!(root.guardian_root_history_version().await.unwrap(), before);
|
||||
}
|
||||
|
||||
#[test_case(GuardianContextMode::Legacy, ThreadHistoryMode::Legacy; "legacy_context_legacy_storage")]
|
||||
#[test_case(GuardianContextMode::ThreadOwned, ThreadHistoryMode::Legacy; "thread_owned_context_legacy_storage")]
|
||||
#[test_case(GuardianContextMode::Legacy, ThreadHistoryMode::Paginated; "legacy_context_paginated_storage")]
|
||||
|
||||
Reference in New Issue
Block a user