mirror of
https://github.com/openai/codex.git
synced 2026-11-16 06:54:36 +00:00
Move Guardian reviewer startup into the pool (#45521)
## What changed Replace `ReviewerSessionFactory` with a startup callback installed through `ReviewerPool::new`. Review requests supply shared setup data and reuse context, while the pool uses its callback to create both reusable and forked reviewers. Update Guardian session setup, prewarming, and existing test fixtures to use the new pool API. GitOrigin-RevId: fa171503afcee8bdbdf6822573bea8ded50ce117
This commit is contained in:
1 parent
78dfc1349e
commit
e84a594636
6 files changed
+112
-104
No files matched your search
@@ -882,6 +882,7 @@ impl codex_guardian_reviewer::ReviewerRuntime for GuardianReviewSession {
|
||||
mod tests;
|
||||
|
||||
impl codex_guardian_reviewer::ReviewerSession for GuardianReviewSession {
|
||||
type Setup = setup::PreparedGuardianContext;
|
||||
type Context = GuardianReviewSessionReuseKey;
|
||||
type Snapshot = GuardianReviewForkSnapshot;
|
||||
|
||||
|
||||
@@ -4,10 +4,9 @@
|
||||
use super::*;
|
||||
use codex_guardian_reviewer::ReviewerPool;
|
||||
use codex_guardian_reviewer::ReviewerRequest;
|
||||
use codex_guardian_reviewer::ReviewerSessionFactory;
|
||||
use codex_guardian_reviewer::SessionDisposition;
|
||||
|
||||
pub(super) struct PreparedGuardianContext {
|
||||
pub(crate) struct PreparedGuardianContext {
|
||||
parent: Arc<Session>,
|
||||
context: GuardianReviewContext,
|
||||
config: Config,
|
||||
@@ -128,14 +127,8 @@ impl PreparedGuardianContext {
|
||||
}
|
||||
}
|
||||
|
||||
impl ReviewerSessionFactory for PreparedGuardianContext {
|
||||
type Session = GuardianReviewSession;
|
||||
|
||||
fn context(&self, previous: Option<&GuardianReviewSession>) -> GuardianReviewSessionReuseKey {
|
||||
self.reuse_key(previous)
|
||||
}
|
||||
|
||||
async fn spawn(
|
||||
impl PreparedGuardianContext {
|
||||
pub(crate) async fn spawn(
|
||||
&self,
|
||||
context: GuardianReviewSessionReuseKey,
|
||||
kind: GuardianReviewSessionKind,
|
||||
@@ -169,15 +162,18 @@ impl ReviewerSessionFactory for PreparedGuardianContext {
|
||||
}
|
||||
|
||||
pub(super) struct PreparedReview {
|
||||
factory: PreparedGuardianContext,
|
||||
context: Arc<PreparedGuardianContext>,
|
||||
params: GuardianReviewSessionParams,
|
||||
}
|
||||
|
||||
impl ReviewerRequest for PreparedReview {
|
||||
type Factory = PreparedGuardianContext;
|
||||
type Session = GuardianReviewSession;
|
||||
|
||||
fn factory(&self) -> &PreparedGuardianContext {
|
||||
&self.factory
|
||||
fn setup(&self) -> Arc<PreparedGuardianContext> {
|
||||
Arc::clone(&self.context)
|
||||
}
|
||||
fn context(&self, previous: Option<&GuardianReviewSession>) -> GuardianReviewSessionReuseKey {
|
||||
self.context.reuse_key(previous)
|
||||
}
|
||||
fn deadline(&self) -> tokio::time::Instant {
|
||||
self.params.deadline
|
||||
@@ -228,7 +224,7 @@ pub(crate) async fn run_guardian_review_session(
|
||||
pub(super) async fn prepare_review(
|
||||
params: GuardianReviewSessionParams,
|
||||
) -> anyhow::Result<PreparedReview> {
|
||||
let factory = PreparedGuardianContext::prepare(
|
||||
let context = PreparedGuardianContext::prepare(
|
||||
Arc::clone(¶ms.parent_session),
|
||||
params.parent_context.clone(),
|
||||
params.spawn_config.clone(),
|
||||
@@ -237,19 +233,35 @@ pub(super) async fn prepare_review(
|
||||
params.compaction_model_hash.as_deref(),
|
||||
)
|
||||
.await?;
|
||||
Ok(PreparedReview { factory, params })
|
||||
Ok(PreparedReview {
|
||||
context: Arc::new(context),
|
||||
params,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn prewarm_guardian_review_session(
|
||||
parent: Arc<Session>,
|
||||
turn: Arc<TurnContext>,
|
||||
) -> BoxFuture<'static, anyhow::Result<()>> {
|
||||
// Keep the Session -> Guardian -> Session startup future on the heap.
|
||||
Box::pin(async move {
|
||||
let context = prepare_prewarm(Arc::clone(&parent), turn).await?;
|
||||
let key = context.reuse_key(/*previous*/ None);
|
||||
parent
|
||||
.guardian_review_session()
|
||||
.prewarm(Arc::new(context), key)
|
||||
.await
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn prepare_prewarm(
|
||||
parent: Arc<Session>,
|
||||
turn: Arc<TurnContext>,
|
||||
) -> BoxFuture<'static, anyhow::Result<PreparedGuardianContext>> {
|
||||
Box::pin(async move {
|
||||
let context = GuardianReviewContext::from(turn);
|
||||
let config = guardian_review_session_config(&parent, &context).await?;
|
||||
let history = parent.clone_history().await;
|
||||
let factory = PreparedGuardianContext::prepare(
|
||||
PreparedGuardianContext::prepare(
|
||||
Arc::clone(&parent),
|
||||
context,
|
||||
config.spawn_config,
|
||||
@@ -257,7 +269,6 @@ pub(crate) fn prewarm_guardian_review_session(
|
||||
&config.node_repl_policy,
|
||||
config.compaction_model_hash.as_deref(),
|
||||
)
|
||||
.await?;
|
||||
parent.guardian_review_session().prewarm(&factory).await
|
||||
.await
|
||||
})
|
||||
}
|
||||
@@ -5,7 +5,6 @@ use crate::agents_md_manager::AgentsMdManager;
|
||||
use crate::context_manager::ContextManager;
|
||||
use codex_guardian_reviewer::ReviewerRequest;
|
||||
use codex_guardian_reviewer::ReviewerSession;
|
||||
use codex_guardian_reviewer::ReviewerSessionFactory;
|
||||
use codex_history::CodexHarnessMetadata;
|
||||
use codex_history::ResponseItemEnvelope;
|
||||
use codex_protocol::openai_models::AutoReviewMessages;
|
||||
@@ -73,8 +72,7 @@ async fn run_review_preserves_evidence_during_parent_compaction() {
|
||||
.node_repl_auto_review_required,
|
||||
)
|
||||
.with_node_repl_policy(¶ms.node_repl_policy);
|
||||
let manager = GuardianReviewSessionManager::default();
|
||||
prewarm_test_session(&manager, reviewer).await;
|
||||
let manager = prewarm_test_session(¶ms, reviewer).await;
|
||||
// Capture the review context, then compact the parent before the reviewer builds its prompt.
|
||||
let prepared = setup::prepare_review(params).await.unwrap();
|
||||
let checkpoint: ResponseItem = serde_json::from_value(serde_json::json!({
|
||||
@@ -314,7 +312,7 @@ async fn spawned_guardian_reuse_key_matches_inherited_instructions() {
|
||||
};
|
||||
let prepared = setup::prepare_review(params).await.expect("prepare review");
|
||||
let review = prepared
|
||||
.factory()
|
||||
.setup()
|
||||
.spawn(
|
||||
stale_key,
|
||||
GuardianReviewSessionKind::TrunkNew,
|
||||
@@ -901,8 +899,7 @@ async fn run_review_removes_trunk_when_event_stream_is_broken() {
|
||||
)
|
||||
.with_environments(params.parent_context.environments())
|
||||
.with_node_repl_policy(¶ms.node_repl_policy);
|
||||
let manager = Arc::new(GuardianReviewSessionManager::default());
|
||||
prewarm_test_session(&manager, review_session).await;
|
||||
let manager = Arc::new(prewarm_test_session(¶ms, review_session).await);
|
||||
let manager_for_review = Arc::clone(&manager);
|
||||
let review =
|
||||
tokio::spawn(async move { run_guardian_review_session(manager_for_review, params).await });
|
||||
@@ -1174,32 +1171,22 @@ async fn interrupt_and_drain_turn_ignores_prior_turn_completion() {
|
||||
}
|
||||
|
||||
// Reuse the existing in-memory reviewer fixture through the production prewarm path.
|
||||
async fn prewarm_test_session(pool: &GuardianReviewSessionManager, session: GuardianReviewSession) {
|
||||
struct ReadySession {
|
||||
context: GuardianReviewSessionReuseKey,
|
||||
session: Mutex<Option<GuardianReviewSession>>,
|
||||
}
|
||||
impl codex_guardian_reviewer::ReviewerSessionFactory for ReadySession {
|
||||
type Session = GuardianReviewSession;
|
||||
fn context(
|
||||
&self,
|
||||
_previous: Option<&GuardianReviewSession>,
|
||||
) -> GuardianReviewSessionReuseKey {
|
||||
self.context.clone()
|
||||
}
|
||||
async fn spawn(
|
||||
&self,
|
||||
_context: GuardianReviewSessionReuseKey,
|
||||
_kind: GuardianReviewSessionKind,
|
||||
_snapshot: Option<GuardianReviewForkSnapshot>,
|
||||
_cancellation: CancellationToken,
|
||||
) -> anyhow::Result<GuardianReviewSession> {
|
||||
Ok(self.session.lock().await.take().expect("one fixture spawn"))
|
||||
}
|
||||
}
|
||||
let factory = ReadySession {
|
||||
context: session.reuse_key.clone(),
|
||||
session: Mutex::new(Some(session)),
|
||||
};
|
||||
pool.prewarm(&factory).await.unwrap();
|
||||
async fn prewarm_test_session(
|
||||
params: &GuardianReviewSessionParams,
|
||||
session: GuardianReviewSession,
|
||||
) -> GuardianReviewSessionManager {
|
||||
let key = session.reuse_key.clone();
|
||||
let session = Arc::new(Mutex::new(Some(session)));
|
||||
let pool = GuardianReviewSessionManager::new(move |_, _, _, _, _| {
|
||||
let session = Arc::clone(&session);
|
||||
Box::pin(async move { Ok(session.lock().await.take().expect("one fixture spawn")) })
|
||||
});
|
||||
let context = setup::prepare_prewarm(
|
||||
Arc::clone(¶ms.parent_session),
|
||||
Arc::clone(params.parent_context.turn()),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
pool.prewarm(Arc::new(context), key).await.unwrap();
|
||||
pool
|
||||
}
|
||||
Reference in new issue
Block a user