From 645c392924e39502aae6c1537d8ed167acbc4081 Mon Sep 17 00:00:00 2001 From: jif-oai Date: Thu, 9 Jul 2026 18:40:08 +0100 Subject: [PATCH] Surface unified exec output omissions --- .../core/src/unified_exec/async_watcher.rs | 2 +- .../core/src/unified_exec/head_tail_buffer.rs | 20 +++++++++++++++++++ .../unified_exec/head_tail_buffer_tests.rs | 4 ++++ .../core/src/unified_exec/process_manager.rs | 2 +- .../src/unified_exec/process_manager_tests.rs | 4 +++- 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/codex-rs/core/src/unified_exec/async_watcher.rs b/codex-rs/core/src/unified_exec/async_watcher.rs index 38010754e9..c1d61ebdce 100644 --- a/codex-rs/core/src/unified_exec/async_watcher.rs +++ b/codex-rs/core/src/unified_exec/async_watcher.rs @@ -326,7 +326,7 @@ async fn resolve_aggregated_output( return fallback; } - String::from_utf8_lossy(&guard.to_bytes()).to_string() + String::from_utf8_lossy(&guard.to_bytes_with_omission_marker()).to_string() } #[cfg(test)] diff --git a/codex-rs/core/src/unified_exec/head_tail_buffer.rs b/codex-rs/core/src/unified_exec/head_tail_buffer.rs index 52039e1495..2af9168c11 100644 --- a/codex-rs/core/src/unified_exec/head_tail_buffer.rs +++ b/codex-rs/core/src/unified_exec/head_tail_buffer.rs @@ -116,6 +116,26 @@ impl HeadTailBuffer { out } + /// Return the retained output with an explicit marker between the head and + /// tail when bytes were omitted. + pub(crate) fn to_bytes_with_omission_marker(&self) -> Vec { + if self.omitted_bytes == 0 { + return self.to_bytes(); + } + + let omitted_bytes = self.omitted_bytes; + let marker = format!("\n... {omitted_bytes} bytes omitted ...\n"); + let mut out = Vec::with_capacity(self.retained_bytes().saturating_add(marker.len())); + for chunk in self.head.iter() { + out.extend_from_slice(chunk); + } + out.extend_from_slice(marker.as_bytes()); + for chunk in self.tail.iter() { + out.extend_from_slice(chunk); + } + out + } + /// Drain all retained chunks from the buffer and reset its state. /// /// The drained chunks are returned in head-then-tail order. Omitted bytes diff --git a/codex-rs/core/src/unified_exec/head_tail_buffer_tests.rs b/codex-rs/core/src/unified_exec/head_tail_buffer_tests.rs index 34da5be5f9..41caaa8919 100644 --- a/codex-rs/core/src/unified_exec/head_tail_buffer_tests.rs +++ b/codex-rs/core/src/unified_exec/head_tail_buffer_tests.rs @@ -16,6 +16,10 @@ fn keeps_prefix_and_suffix_when_over_budget() { let rendered = String::from_utf8_lossy(&buf.to_bytes()).to_string(); assert!(rendered.starts_with("01234")); assert!(rendered.ends_with("89ab")); + assert_eq!( + String::from_utf8_lossy(&buf.to_bytes_with_omission_marker()), + "01234\n... 2 bytes omitted ...\n789ab" + ); } #[test] diff --git a/codex-rs/core/src/unified_exec/process_manager.rs b/codex-rs/core/src/unified_exec/process_manager.rs index 4730265af5..a7c5f5e670 100644 --- a/codex-rs/core/src/unified_exec/process_manager.rs +++ b/codex-rs/core/src/unified_exec/process_manager.rs @@ -1285,7 +1285,7 @@ impl UnifiedExecProcessManager { } } - collected.to_bytes() + collected.to_bytes_with_omission_marker() } async fn extend_deadlines_while_paused( diff --git a/codex-rs/core/src/unified_exec/process_manager_tests.rs b/codex-rs/core/src/unified_exec/process_manager_tests.rs index a076e50348..010aed26c4 100644 --- a/codex-rs/core/src/unified_exec/process_manager_tests.rs +++ b/codex-rs/core/src/unified_exec/process_manager_tests.rs @@ -278,8 +278,10 @@ async fn output_collection_stays_bounded_across_repeated_drains() { let (collected, ()) = tokio::join!(collect, produce); let head_bytes = crate::unified_exec::UNIFIED_EXEC_OUTPUT_MAX_BYTES / 2; let tail_bytes = crate::unified_exec::UNIFIED_EXEC_OUTPUT_MAX_BYTES - head_bytes; + let omitted_bytes = 2 * crate::unified_exec::UNIFIED_EXEC_OUTPUT_MAX_BYTES; let mut expected = vec![b'a'; head_bytes]; - expected.resize(head_bytes + tail_bytes, b'c'); + expected.extend_from_slice(format!("\n... {omitted_bytes} bytes omitted ...\n").as_bytes()); + expected.resize(expected.len() + tail_bytes, b'c'); assert_eq!(collected, expected); }