Deduplicate retained instructions against Guardian transcripts (#48109)

## Why

Synchronous Guardian reviews can include the same user instruction in both the retained instructions section and the conversation transcript. Avoid this duplication while preserving complete authorization evidence and its original acceptance order.

## What changed

- Carry retained source metadata into transcript rendering. Omit a retained instruction when the transcript delivers its complete matching source revision.
- Label qualifying transcript entries with retained source order and protect them from budget truncation. Keep separate retained instructions when source metadata is missing or incomplete.
- Track delivery of source-order guidance so it remains available even when all retained instructions are delivered through the transcript. Invalidate that delivery proof when messages are shortened.

## Testing

Add coverage for complete-source deduplication, missing or incomplete metadata, budget protection, guidance redelivery, and source metadata preservation across resume. Update Guardian review assertions and snapshots to verify instructions are delivered once.

GitOrigin-RevId: 20ad0304501fa49f1596c4cfaf3ef89d64815753
This commit is contained in:
felixxia-oai
2026-09-25 14:54:51 +00:00
committed by copyberry
parent e75b36efde
commit d5cbfe1455
25 changed files with 528 additions and 164 deletions
@@ -44,6 +44,15 @@ pub trait ConversationHistorySnapshot: Send + Sync {
self.items()
}
/// Original source metadata stays attached to the exact unshortened history item.
/// Legacy providers cannot establish completeness from a message ID alone.
fn review_items_with_sources(
&self,
) -> Box<dyn Iterator<Item = (&ResponseItem, Option<&codex_history::RetainedSource>)> + Send + '_>
{
Box::new(self.review_items().map(|item| (item, None)))
}
/// Changes whenever offsets into the retained review evidence become invalid.
fn review_history_version(&self) -> u64 {
self.history_version()