Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions codex-rs/.config/nextest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ slow-timeout = { period = "1m", terminate-after = 4 }
[[profile.default.overrides]]
filter = 'test(approval_matrix_covers_all_modes)'
slow-timeout = { period = "30s", terminate-after = 2 }

[[profile.default.overrides]]
filter = 'test(windows_unified_exec)'
slow-timeout = { period = "30s", terminate-after = 4 }
1 change: 1 addition & 0 deletions codex-rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions codex-rs/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ shlex = { workspace = true }
similar = { workspace = true }
strum_macros = { workspace = true }
url = { workspace = true }
vt100 = { workspace = true }
once_cell = { workspace = true }
regex = { workspace = true }
tempfile = { workspace = true }
Expand Down
5 changes: 2 additions & 3 deletions codex-rs/core/src/unified_exec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,12 @@ mod tests {

assert_eq!(buffer.total_bytes, UNIFIED_EXEC_OUTPUT_MAX_BYTES);
let snapshot = buffer.snapshot();
assert_eq!(snapshot.len(), 3);
assert_eq!(snapshot.len(), 2);
assert_eq!(
snapshot.first().unwrap().len(),
UNIFIED_EXEC_OUTPUT_MAX_BYTES - 2
);
assert_eq!(snapshot.get(2).unwrap(), &vec![b'c']);
assert_eq!(snapshot.get(1).unwrap(), &vec![b'b']);
assert_eq!(snapshot.get(1).unwrap(), &vec![b'b', b'c']);
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
Expand Down
21 changes: 19 additions & 2 deletions codex-rs/core/src/unified_exec/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,25 @@ pub(crate) struct OutputBufferState {

impl OutputBufferState {
pub(super) fn push_chunk(&mut self, chunk: Vec<u8>) {
self.total_bytes = self.total_bytes.saturating_add(chunk.len());
self.chunks.push_back(chunk);
if chunk.is_empty() {
return;
}

// On Windows (especially with ConPTY) output can arrive in many tiny chunks.
// Coalesce them to avoid pathological behavior in drain/collect paths.
const MAX_COALESCED_CHUNK_BYTES: usize = 8_192;

let mut chunk = chunk;
let chunk_len = chunk.len();
self.total_bytes = self.total_bytes.saturating_add(chunk_len);

if let Some(tail) = self.chunks.back_mut()
&& tail.len().saturating_add(chunk_len) <= MAX_COALESCED_CHUNK_BYTES
{
tail.append(&mut chunk);
} else {
self.chunks.push_back(chunk);
}

let mut excess = self
.total_bytes
Expand Down
17 changes: 15 additions & 2 deletions codex-rs/core/src/unified_exec/session_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ const UNIFIED_EXEC_ENV: [(&str, &str); 8] = [
("GIT_PAGER", "cat"),
];

fn normalize_unified_exec_text(raw: &str) -> String {
if cfg!(target_os = "windows") {
let mut parser = vt100::Parser::new(40, 120, 1_024);
parser.process(raw.as_bytes());
parser.screen_mut().set_scrollback(usize::MAX);
return parser.screen().contents();
Comment on lines +66 to +70
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Windows normalization drops output beyond 1024 lines

On Windows we now pass unified-exec output through a fresh vt100::Parser with a scrollback of only 1 024 lines (Parser::new(40, 120, 1_024)) and only set scrollback to usize::MAX after processing. Any command that emits more than 1 024 lines will therefore have all earlier lines discarded before token truncation and before being sent back to the user, whereas other platforms still preserve everything up to UNIFIED_EXEC_OUTPUT_MAX_BYTES/max_output_tokens. This is a regression for long-running commands on Windows because their output is silently chopped to the last ~1 024 lines even when higher limits are configured.

Useful? React with 👍 / 👎.

}

raw.to_string()
}

fn apply_unified_exec_env(mut env: HashMap<String, String>) -> HashMap<String, String> {
for (key, value) in UNIFIED_EXEC_ENV {
env.insert(key.to_string(), value.to_string());
Expand Down Expand Up @@ -163,7 +174,8 @@ impl UnifiedExecSessionManager {
.await;
let wall_time = Instant::now().saturating_duration_since(start);

let text = String::from_utf8_lossy(&collected).to_string();
let raw_text = String::from_utf8_lossy(&collected).to_string();
let text = normalize_unified_exec_text(&raw_text);
let output = formatted_truncate_text(&text, TruncationPolicy::Tokens(max_tokens));
let has_exited = session.has_exited();
let exit_code = session.exit_code();
Expand Down Expand Up @@ -285,7 +297,8 @@ impl UnifiedExecSessionManager {
.await;
let wall_time = Instant::now().saturating_duration_since(start);

let text = String::from_utf8_lossy(&collected).to_string();
let raw_text = String::from_utf8_lossy(&collected).to_string();
let text = normalize_unified_exec_text(&raw_text);
let output = formatted_truncate_text(&text, TruncationPolicy::Tokens(max_tokens));
let original_token_count = approx_token_count(&text);
let chunk_id = generate_chunk_id();
Expand Down
Loading
Loading