Lightweight coding agent that runs in your terminal
Rust
Use `mem::take` to drain unified exec output buffers (#39515)
Tamir Duberstein18937b226524
diff --git a/codex-rs/core/src/unified_exec/head_tail_buffer.rs b/codex-rs/core/src/unified_exec/head_tail_buffer.rsindex 9bebfdcaf8..8515beef26 100644--- a/codex-rs/core/src/unified_exec/head_tail_buffer.rs+++ b/codex-rs/core/src/unified_exec/head_tail_buffer.rs@@ -93,16 +93,6 @@ impl<const MAX_BYTES: usize> HeadTailBuffer<MAX_BYTES> {out}- /// Drain the retained output and omission metadata, resetting this buffer's- /// contents while preserving its configured capacity.- pub(crate) fn drain(&mut self) -> Self {- Self {- head: std::mem::take(&mut self.head),- tail: std::mem::take(&mut self.tail),- omitted_bytes: std::mem::take(&mut self.omitted_bytes),- }- }-/// Append a later buffer with the same budget. This preserves the summary/// of the original concatenated output, including its omission count.pub(crate) fn push_buffer(&mut self, mut buffer: Self) {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.rsindex 7110cddea7..b8e78dc812 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@@ -42,24 +42,6 @@ fn head_budget_zero_keeps_only_last_byte_in_tail() {assert_eq!(buf.to_bytes(), b"c".to_vec());}-#[test]-fn draining_resets_state_and_push_buffer_preserves_omissions() {- let mut buf = HeadTailBuffer::<10>::default();- buf.push_chunk(b"0123456789".to_vec());- buf.push_chunk(b"ab".to_vec());-- let drained = buf.drain();- let mut collected = HeadTailBuffer::<10>::default();- collected.push_buffer(drained);-- assert_eq!(buf.retained_bytes(), 0);- assert_eq!(buf.omitted_bytes(), 0);- assert_eq!(buf.to_bytes(), b"".to_vec());- assert_eq!(collected.to_bytes(), b"01234789ab".to_vec());- assert_eq!(collected.omitted_bytes(), 2);- assert_eq!(collected.total_bytes(), 12);-}-#[test]fn chunk_larger_than_tail_budget_keeps_only_tail_end() {let mut buf = HeadTailBuffer::<10>::default();diff --git a/codex-rs/core/src/unified_exec/process_manager.rs b/codex-rs/core/src/unified_exec/process_manager.rsindex 70601f9b9d..9fd8b08a74 100644--- a/codex-rs/core/src/unified_exec/process_manager.rs+++ b/codex-rs/core/src/unified_exec/process_manager.rs@@ -1344,7 +1344,7 @@ impl UnifiedExecProcessManager {let mut wait_for_output = None;{let mut guard = output_buffer.lock().await;- drained_output = guard.drain();+ drained_output = std::mem::take(&mut *guard);has_drained_output =drained_output.retained_bytes() > 0 || drained_output.omitted_bytes() > 0;if !has_drained_output {