Defer Guardian Node REPL output truncation until prompt preparation (#57176)

## What changed

Preserve complete Node REPL tool outputs during synchronous transcript collection and apply the configured output token limit during prompt preparation, after full or delta transcript selection.

## Testing

Update transcript assertions to verify that oversized Node REPL outputs remain intact during collection and are truncated to the selected token cap when rendered.

GitOrigin-RevId: 30ced935c04db456a277f7e58281d45e0e2047dd
This commit is contained in:
ioanbudea-OAI
2026-10-26 18:15:37 +00:00
committed by copyberry
parent ec513795a6
commit 83a9600acb
4 changed files with 21 additions and 14 deletions
+7 -4
View File
@@ -215,6 +215,7 @@ pub(crate) async fn build_guardian_prompt_items_with_parent_turn(
Some(context) => context.turn().config.guardian_transcript_mode,
None => session.get_config().await.guardian_transcript_mode,
};
profile.transcript.entry_limits.node_repl_output_tokens = node_repl_result_token_limit;
let mut transcript = profile.prepare_transcript(transcript_entries, offset);
if transcript_entries.is_empty() {
transcript.items.push(Budgeted::required(
@@ -233,9 +234,11 @@ pub(crate) async fn build_guardian_prompt_items_with_parent_turn(
#[cfg(test)]
pub(crate) fn render_guardian_transcript_entries(
entries: &[ConversationTranscriptEntry],
node_repl_result_token_limit: usize,
) -> (Vec<String>, Option<String>) {
let mut transcript =
ContextProfile::synchronous().prepare_transcript(entries, /*entry_number_offset*/ 0);
let mut profile = ContextProfile::synchronous();
profile.transcript.entry_limits.node_repl_output_tokens = node_repl_result_token_limit;
let mut transcript = profile.prepare_transcript(entries, /*entry_number_offset*/ 0);
if entries.is_empty() {
transcript.items.push(Budgeted::required(
codex_guardian_context::TranscriptContent::Text(
@@ -267,8 +270,8 @@ pub(crate) fn render_guardian_transcript_entries(
/// Keep both tool calls and tool results here. The reviewer often needs the
/// agent's exact queried path / arguments as well as the returned evidence to
/// decide whether the pending approval is justified.
/// Tool-call and output truncation happen in sync preparation; other caps still apply
/// during collection. The cursor counts every non-empty evidence entry.
/// Per-entry truncation happens in sync preparation after cursor selection.
/// The cursor counts every non-empty evidence entry.
pub(super) fn collect_guardian_context(
history: &dyn SectionHistory,
node_repl_result_token_limit: usize,
+6 -6
View File
@@ -1186,16 +1186,14 @@ fn collect_guardian_transcript_entries_includes_recent_tool_calls_and_output() {
kind: ConversationTranscriptEntryKind::NodeReplToolOutput(
"tool read_file result".to_string()
),
content: codex_guardian_context::TranscriptContent::Text(
guardian_truncate_text(&oversized_result, token_cap).0
),
content: codex_guardian_context::TranscriptContent::Text(oversized_result.clone()),
original_bytes: oversized_result.len(),
retained_source: None,
}
);
assert_eq!(entries.len(), 4);
assert_eq!(
render_guardian_transcript_entries(&entries),
render_guardian_transcript_entries(&entries, token_cap),
(
vec![
"[1] user: check the repo".to_string(),
@@ -1829,7 +1827,8 @@ fn build_guardian_transcript_reserves_separate_budget_for_tool_evidence() {
}));
let entries = collect_guardian_transcript_entries(&items, GUARDIAN_MAX_TOOL_ENTRY_TOKENS);
let (transcript, omission) = render_guardian_transcript_entries(&entries);
let (transcript, omission) =
render_guardian_transcript_entries(&entries, GUARDIAN_MAX_TOOL_ENTRY_TOKENS);
assert!(
transcript
@@ -1902,7 +1901,8 @@ fn build_guardian_transcript_preserves_recent_tool_context_when_user_history_is_
]);
let entries = collect_guardian_transcript_entries(&items, GUARDIAN_MAX_TOOL_ENTRY_TOKENS);
let (transcript, omission) = render_guardian_transcript_entries(&entries);
let (transcript, omission) =
render_guardian_transcript_entries(&entries, GUARDIAN_MAX_TOOL_ENTRY_TOKENS);
assert_eq!(
transcript[..8],