Move synchronous Guardian orchestration into the reviewer extension (#44252)

## What changed

Move the synchronous review loop, outcome mapping, deadline helpers, and session pool into `codex-guardian-reviewer`. Core supplies adapters for evidence capture, authorization checks, session creation, and event publication through the new host interfaces.

Have `guardian-v2` initialize the reviewer pool and host separately, with the pool managing prewarming, session reuse, concurrent forks, invalidation, and shutdown.

## Testing

Extend the app-server reviewer lifecycle test to cover interrupted concurrent reviews as well as completed reviews, including resuming a reviewer after parent shutdown. Adapt core reviewer tests to use the pool and factory interfaces.

GitOrigin-RevId: 2d69bd20c169b20534764b98cbdb63f38564a530
This commit is contained in:
jif authored and copyberry committed 2026-09-09 17:59:10 +00:00
1 parent eb7bd64ef9
commit 2617ed2e1c
27 files changed
+1570 -1417

No files matched your search

@@ -1,17 +1,19 @@
//! Installs the synchronous reviewer independently of async scorer startup.
//! Reviewer state lives in the existing thread store and uses the shared ThreadManager.
//! Reviewer policy and pool state live in the extension; core supplies context and runtime handles.
use std::sync::Arc;
use std::sync::Weak;
use codex_core::ThreadManager;
use codex_core::config::Config;
use codex_core::guardian_review::GuardianReviewSessionManager;
use codex_core::guardian_review::GuardianReviewSession;
use codex_core::guardian_review::GuardianReviewSessionHost;
use codex_extension_api::ExtensionFuture;
use codex_extension_api::ExtensionRegistryBuilder;
use codex_extension_api::ThreadLifecycleContributor;
use codex_extension_api::ThreadReadyInput;
use codex_extension_api::ThreadStartInput;
use codex_guardian_reviewer::ReviewerPool;
/// Owns reviewer state through the same thread manager as the parent conversation.
#[derive(Clone, Debug)]
@@ -34,8 +36,11 @@ impl ThreadLifecycleContributor<Config> for GuardianExtension {
if input.session_source.is_internal() {
return;
}
input
.thread_store
.get_or_init(ReviewerPool::<GuardianReviewSession>::default);
input.thread_store.get_or_init(|| {
GuardianReviewSessionManager::with_thread_manager(self.thread_manager.clone())
GuardianReviewSessionHost::with_thread_manager(self.thread_manager.clone())
});
})
}
@@ -45,7 +50,7 @@ impl ThreadLifecycleContributor<Config> for GuardianExtension {
input: ThreadReadyInput<'a, Config>,
) -> ExtensionFuture<'a, ()> {
Box::pin(async move {
if let Some(sessions) = input.thread_store.get::<GuardianReviewSessionManager>() {
if let Some(sessions) = input.thread_store.get::<GuardianReviewSessionHost>() {
sessions.mark_ready();
}
})