mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Simplify unified exec output snapshots (#39259)
## What changed - Return retained unified-exec output as one contiguous byte buffer. - Use the buffer directly for sandbox-denial checks, removing intermediate chunk aggregation and an unnecessary owned string conversion. - Update the output-retention test to assert the flattened snapshot. GitOrigin-RevId: 84eacee0166b86d3cb2d6a37e96125977fad0267
This commit is contained in:
1 parent
ecb8013dfa
commit
3006151ad4
4 files changed
+10
-33
No files matched your search
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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]
|
||||
|
||||
@@ -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(())
|
||||
|
||||
Reference in new issue
Block a user