Verify manual approval provenance in Guardian transcripts (#64160)

## Why

Guardian identified manual approvals by the opening text of a developer
message. Hook output could use the same opening text, and unrelated
content in the same message could be included with an approval.

## What changed

Check each developer text part before joining it into the transcript.
Require the manual approval prefix, the `guardian.approved_action` content
kind, and provenance from the harness outside of hooks.

## Testing

Transcript tests cover missing provenance and same-prefix text with hook
provenance or a different content kind. The context budget test checks
that the full manual approval stays ahead of a later user restriction
and that adjacent hook text is excluded.

GitOrigin-RevId: 64fafc3a429ce1e21eb5233c8223228947d1c20b
This commit is contained in:
ioanbudea-OAI
2026-11-26 14:29:37 +00:00
committed by copyberry
parent 7ca4eada90
commit 61369c4e95
7 changed files with 117 additions and 68 deletions
@@ -4,6 +4,11 @@ use crate::async_scorer::conversation::ConversationBackend;
use super::*;
use crate::async_scorer::authorization::ScoreAuthorization;
use codex_context_fragments::AnnotatedContent;
use codex_context_fragments::message_from_parts;
use codex_guardian_context::MANUAL_APPROVAL_CONTENT_KIND;
use codex_protocol::models::ContentItemKind;
use codex_protocol::models::ContentItemMetadata;
use codex_protocol::models::ImageReference;
use pretty_assertions::assert_eq;
@@ -155,17 +160,14 @@ async fn assert_catalog_budget(evidence: BudgetEvidence) -> Result<()> {
let mut history = checkpoint.iter().cloned().collect::<Vec<_>>();
history.push(user);
if matches!(evidence, BudgetEvidence::UserInstructions) {
history.push(ResponseItem::Message {
status: None,
encrypted_content: None,
id: None,
role: "developer".to_owned(),
content: vec![ContentItem::InputText {
text: approval.clone(),
}],
phase: None,
internal_chat_message_metadata_passthrough: None,
});
history.push(message_from_parts(
"developer",
vec![AnnotatedContent::text(
&approval,
ContentItemKind(MANUAL_APPROVAL_CONTENT_KIND.to_owned()),
ContentItemMetadata::harness(),
)],
));
history.push(user_instruction(restriction));
}
history.extend(commentary.into_iter().map(|text| ResponseItem::Message {
@@ -1,12 +1,17 @@
use super::ContextInput;
use codex_context_fragments::AnnotatedContent;
use codex_context_fragments::message_from_parts;
use codex_extension_api::ConversationHistorySnapshot;
use codex_extension_api::ResponseItem;
use codex_guardian_context::ContextTarget;
use codex_guardian_context::MANUAL_APPROVAL_CONTENT_KIND;
use codex_protocol::AgentPath;
use codex_protocol::ResponseItemId;
use codex_protocol::models::AgentMessageInputContent;
use codex_protocol::models::AudioReference;
use codex_protocol::models::ContentItem;
use codex_protocol::models::ContentItemKind;
use codex_protocol::models::ContentItemMetadata;
use codex_protocol::models::FunctionCallOutputContentItem;
use codex_protocol::models::FunctionCallOutputPayload;
use codex_protocol::models::ImageReference;
@@ -901,17 +906,14 @@ fn transcript_preserves_newest_manual_approval_when_message_budget_overflows() {
phase: None,
internal_chat_message_metadata_passthrough: None,
},
ResponseItem::Message {
status: None,
encrypted_content: None,
id: None,
role: "developer".to_string(),
content: vec![ContentItem::InputText {
text: approval_text,
}],
phase: None,
internal_chat_message_metadata_passthrough: None,
},
message_from_parts(
"developer",
vec![AnnotatedContent::text(
approval_text,
ContentItemKind(MANUAL_APPROVAL_CONTENT_KIND.to_owned()),
ContentItemMetadata::harness(),
)],
),
];
let transcript = TranscriptConfig {