Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Simplify unified exec output snapshots (#39259)

Tamir Duberstein3006151ad413
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 fb04f34f0b..27fa23472c 100644
--- a/codex-rs/core/src/unified_exec/head_tail_buffer.rs
+++ b/codex-rs/core/src/unified_exec/head_tail_buffer.rs
@@ -83,21 +83,6 @@ impl HeadTailBuffer {
self.push_to_tail(&chunk[head_len..]);
}
- /// Snapshot the retained output as a list of chunks.
- ///
- /// The returned chunks are ordered as: head chunks first, then tail chunks.
- /// Omitted bytes are not represented in the snapshot.
- pub(crate) fn snapshot_chunks(&self) -> Vec<Vec<u8>> {
- let mut out = Vec::with_capacity(2);
- if !self.head.is_empty() {
- out.push(self.head.clone());
- }
- if !self.tail.is_empty() {
- out.push(self.tail.iter().copied().collect());
- }
- out
- }
-
/// Return the retained output as a single byte vector.
///
/// The output is formed by concatenating head chunks, then tail chunks.
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 c086984d93..1fe97b26da 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
@@ -30,7 +30,6 @@ fn max_bytes_zero_drops_everything() {
assert_eq!(buf.retained_bytes(), 0);
assert_eq!(buf.omitted_bytes(), 3);
assert_eq!(buf.to_bytes(), b"".to_vec());
- assert_eq!(buf.snapshot_chunks(), Vec::<Vec<u8>>::new());
}
#[test]
@@ -105,10 +104,6 @@ fn empty_and_tiny_chunks_have_bounded_metadata() {
buf.push_chunk(vec![*byte]);
}
- assert_eq!(
- buf.snapshot_chunks(),
- vec![b"01234".to_vec(), b"789ab".to_vec()]
- );
assert_eq!(buf.retained_bytes(), 10);
assert_eq!(buf.omitted_bytes(), 2);
}
diff --git a/codex-rs/core/src/unified_exec/mod_tests.rs b/codex-rs/core/src/unified_exec/mod_tests.rs
index d097e783d9..d72ebb8f54 100644
--- a/codex-rs/core/src/unified_exec/mod_tests.rs
+++ b/codex-rs/core/src/unified_exec/mod_tests.rs
@@ -330,12 +330,13 @@ fn push_chunk_preserves_prefix_and_suffix() {
buffer.push_chunk(vec![b'c']);
assert_eq!(buffer.retained_bytes(), UNIFIED_EXEC_OUTPUT_MAX_BYTES);
- let snapshot = buffer.snapshot_chunks();
+ let snapshot = buffer.to_bytes();
let head_bytes = UNIFIED_EXEC_OUTPUT_MAX_BYTES / 2;
let tail_bytes = UNIFIED_EXEC_OUTPUT_MAX_BYTES - head_bytes;
- let mut expected_tail = vec![b'a'; tail_bytes - 2];
- expected_tail.extend_from_slice(b"bc");
- assert_eq!(snapshot, vec![vec![b'a'; head_bytes], expected_tail]);
+ let expected = std::iter::repeat_n(b'a', head_bytes + tail_bytes - 2)
+ .chain(b"bc".iter().copied())
+ .collect::<Vec<_>>();
+ assert_eq!(snapshot, expected);
}
#[test]
diff --git a/codex-rs/core/src/unified_exec/process.rs b/codex-rs/core/src/unified_exec/process.rs
index e8ec6b9882..fc93935ada 100644
--- a/codex-rs/core/src/unified_exec/process.rs
+++ b/codex-rs/core/src/unified_exec/process.rs
@@ -259,9 +259,9 @@ impl UnifiedExecProcess {
self.terminate();
}
- async fn snapshot_output(&self) -> Vec<Vec<u8>> {
+ async fn snapshot_output(&self) -> Vec<u8> {
let guard = self.output.output_buffer.lock().await;
- guard.snapshot_chunks()
+ guard.to_bytes()
}
pub(crate) fn sandbox_type(&self) -> SandboxType {
@@ -279,13 +279,9 @@ impl UnifiedExecProcess {
)
.await;
- let collected_chunks = self.snapshot_output().await;
- let mut aggregated: Vec<u8> = Vec::new();
- for chunk in collected_chunks {
- aggregated.extend_from_slice(&chunk);
- }
- let aggregated_text = String::from_utf8_lossy(&aggregated).to_string();
- self.check_for_sandbox_denial_with_text(&aggregated_text)
+ let aggregated = self.snapshot_output().await;
+ let aggregated_text = String::from_utf8_lossy(&aggregated);
+ self.check_for_sandbox_denial_with_text(aggregated_text.as_ref())
.await?;
Ok(())