Add retained conversation support to Guardian async sampling (#49792)

## What changed

- Add request preparation that preserves committed classifier history and appends transcript deltas, filtering instructions and images already delivered. Account for the complete input budget before transferring history; rejected requests leave the checkpoint and cursor intact.
- Add retained sampling that publishes the early score while collecting completed assistant output and encrypted reasoning for reuse. Preserve item IDs and input metadata, and discard unusable history without retracting an already published score.
- Keep the existing snapshot sampling path and share input preparation and execution with the new retained path. Retained sampling is not yet wired into the active backend.

## Testing

Add coverage for transcript and image deduplication, immutable history prefixes, budget boundaries, rejected preparation, WebSocket output retention, and retention failures that preserve the early score.

GitOrigin-RevId: 0fa33db8b8ea4483eb64d75e207690f1d349123b
This commit is contained in:
felixxia-oai
2026-10-01 01:11:10 +00:00
committed by copyberry
parent 83cf88306e
commit 5f300d3f74
11 changed files with 858 additions and 87 deletions
@@ -29,6 +29,7 @@ pub enum ContextPresentation<'a> {
SyncFull { session_id: &'a str },
SyncDelta { session_id: &'a str },
Async,
AsyncDelta,
}
/// Host-selected transcript entries and omission notice, before request admission.
@@ -39,6 +40,7 @@ pub struct RenderedTranscript {
}
/// Evidence collected successfully before host transcript selection.
#[derive(Clone)]
pub struct CollectedContext {
pub(crate) sections: Vec<ContextSection>,
}
@@ -108,6 +110,15 @@ impl CollectedContext {
">>> TRANSCRIPT END\n\n",
None,
),
ContextPresentation::AsyncDelta => (
ActionPresentation::Async,
Some(
"Continue the classification using the transcript added since your last assessment and the current action. Apply the same classifier policy to the whole conversation. Previous classifications are decisions, not authorization.\n",
),
">>> TRANSCRIPT DELTA START\n",
">>> TRANSCRIPT DELTA END\n\n",
None,
),
};
let mut sections = Vec::new();
let mut truncations = std::mem::take(&mut transcript.truncations);