Add isolated reviews to the guardian reviewer pool (#57522)

## What changed

Add `ReviewerPool::review_isolated` to run a review in a temporary session without reading or changing the reusable reviewer. Build the request context without a previous session and spawn without a cached snapshot.

## Testing

Add a test verifying that an isolated review receives no snapshot, uses a separate session, and preserves the prewarmed session for the next regular review.

GitOrigin-RevId: 6cceff0c399f30f3c3303b0bf5232c274c902e3a
This commit is contained in:
swastik-oai
2026-10-27 17:29:03 +00:00
committed by copyberry
parent 6574bcdba8
commit 19d730175f
2 changed files with 48 additions and 0 deletions
@@ -329,6 +329,19 @@ impl<S: ReviewerSession> ReviewerPool<S> {
(outcome, analytics)
}
/// Reviews in a temporary session without reading or changing the reusable reviewer.
/// The request builds its context without a previous session or cached snapshot.
pub async fn review_isolated<R>(
&self,
request: &R,
) -> (GuardianReviewSessionOutcome, GuardianReviewAnalyticsResult)
where
R: ReviewerRequest<Session = S>,
{
let context = request.context(/*previous*/ None);
Box::pin(self.review_ephemeral(request, context, /*snapshot*/ None)).await
}
async fn review_ephemeral<R>(
&self,
request: &R,
@@ -188,3 +188,38 @@ async fn fresh_attempt_bypasses_cached_session_and_snapshot(busy: bool) {
.await;
assert_eq!(selections.recv().await, Some(if busy { 0 } else { 1 }));
}
#[tokio::test]
async fn isolated_review_preserves_reusable_session() {
let spawns = Arc::new(AtomicUsize::default());
let pool = ReviewerPool::new(
Arc::new(ReviewerTasks::default()),
move |_, _, _, snapshot, _| {
assert_eq!(
snapshot, None,
"isolated review must not inherit a snapshot"
);
let id = spawns.fetch_add(/*val*/ 1, Ordering::SeqCst);
Box::pin(async move { Ok(Session(id)) })
},
);
pool.prewarm(Arc::new(()), ()).await.expect("prewarm trunk");
let (selected, mut selections) = tokio::sync::mpsc::unbounded_channel();
pool.review_isolated(&Request {
fresh: false,
selected: selected.clone(),
release: None,
})
.await;
assert_eq!(selections.recv().await, Some(1));
pool.review(Request {
fresh: false,
selected,
release: None,
})
.await;
assert_eq!(selections.recv().await, Some(0));
pool.shutdown().await;
}