Files
codex/codex-rs/guardian-context/src/entry.rs
T
felixxia-oai 287e4f7dbf Preserve Guardian authorization evidence until request budgeting (#44570)
## Why

Transcript limits could shorten user instructions or omit later messages before Guardian evaluated the complete request budget, losing restrictions or prior approvals even when they would fit.

## What changed

- Keep user messages and manual approvals complete and in source order through transcript collection and retention.
- Preserve historical instructions while synchronous review can still compact history. If the final request still cannot fit, discard optional evidence before shortening older historical entries with truncation markers, preserving later restrictions where possible.
- Warn that shortened instructions and approvals are incomplete and that missing evidence does not authorize actions.
- Let asynchronous review defer to synchronous review when complete instructions exceed its budget.

## Testing

Add coverage for complete instruction retention, approval and restriction ordering, marked truncation of oversized Unicode text, compaction before truncation, and asynchronous fallback when instructions do not fit.

GitOrigin-RevId: e6159e876231347986b937ee7e07f944b83bfbe6
2026-09-10 16:02:36 +00:00

53 lines
2.2 KiB
Rust

//! Structured transcript evidence shared by synchronous and asynchronous Guardian.
//!
//! Entry kinds preserve source attribution for consumer-specific retention and
//! rendering. User text and manual approvals stay complete for admission; other text is
//! capped during collection, with its original size retained for accounting.
/// Semantic role of one parent-conversation transcript entry.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum ConversationTranscriptEntryKind {
/// Actual parent-thread user message.
User,
/// Explicit developer message preserving a user-approved action.
Developer,
/// Assistant commentary or an inter-agent message.
Assistant,
/// Final assistant answer eligible for stronger async retention.
ProtectedAssistant,
/// Named tool invocation, including shell and web-search calls.
ToolCall(String),
/// Tool result with a call-derived, explicit, or generic fallback label.
ToolOutput(String),
/// Result from a Node REPL-backed tool that may receive a larger sync cap.
NodeReplToolOutput(String),
/// Plaintext model reasoning that the async consumer explicitly enables.
Reasoning,
}
impl ConversationTranscriptEntryKind {
/// Returns the role label currently used in Guardian transcript prompts.
pub fn role(&self) -> &str {
match self {
Self::User => "user",
Self::Developer => "developer",
Self::Assistant | Self::ProtectedAssistant => "assistant",
Self::ToolCall(role) | Self::ToolOutput(role) | Self::NodeReplToolOutput(role) => {
role.as_str()
}
Self::Reasoning => "reasoning",
}
}
}
/// Structured text evidence shared by sync Guardian and async scoring.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ConversationTranscriptEntry {
/// Semantic role used for consumer-specific retention and truncation.
pub kind: ConversationTranscriptEntryKind,
/// Complete authorization evidence, or other text bounded by per-entry limits.
pub text: String,
/// Size before truncation, retained for omission and truncation accounting.
pub original_bytes: usize,
}