Skip to content

Commit a90a58f

Browse files
authored
Trim double Total output lines (#4787)
1 parent b2d81a7 commit a90a58f

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

codex-rs/core/src/client_common.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,16 @@ fn build_structured_output(parsed: &ExecOutputJson) -> String {
159159
parsed.metadata.duration_seconds
160160
));
161161

162+
let mut output = parsed.output.clone();
162163
if let Some(total_lines) = extract_total_output_lines(&parsed.output) {
163164
sections.push(format!("Total output lines: {total_lines}"));
165+
if let Some(stripped) = strip_total_output_header(&output) {
166+
output = stripped.to_string();
167+
}
164168
}
165169

166170
sections.push("Output:".to_string());
167-
sections.push(parsed.output.clone());
171+
sections.push(output);
168172

169173
sections.join("\n")
170174
}
@@ -177,6 +181,13 @@ fn extract_total_output_lines(output: &str) -> Option<u32> {
177181
total_segment.parse::<u32>().ok()
178182
}
179183

184+
fn strip_total_output_header(output: &str) -> Option<&str> {
185+
let after_prefix = output.strip_prefix("Total output lines: ")?;
186+
let (_, remainder) = after_prefix.split_once('\n')?;
187+
let remainder = remainder.strip_prefix('\n').unwrap_or(remainder);
188+
Some(remainder)
189+
}
190+
180191
#[derive(Debug)]
181192
pub enum ResponseEvent {
182193
Created,

codex-rs/core/tests/suite/shell_serialization.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,17 +255,17 @@ async fn shell_output_reserializes_truncated_content() -> Result<()> {
255255
Wall time: [0-9]+(?:\.[0-9]+)? seconds
256256
Total output lines: 400
257257
Output:
258-
Total output lines: 400
259-
260258
1
261259
2
262260
3
263261
4
264262
5
265263
6
266-
.*\[\.{3} omitted \d+ of 400 lines \.{3}\]
264+
.*
265+
\[\.{3} omitted \d+ of 400 lines \.{3}\]
267266
268-
.*\n396
267+
.*
268+
396
269269
397
270270
398
271271
399

codex-rs/core/tests/suite/tools.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,6 @@ async fn shell_sandbox_denied_truncates_error_output() -> Result<()> {
516516
Wall time: [0-9]+(?:\.[0-9]+)? seconds
517517
Total output lines: \d+
518518
Output:
519-
Total output lines: \d+
520519
521520
failed in sandbox: .*?(?:Operation not permitted|Permission denied|Read-only file system).*?
522521
\[\.{3} omitted \d+ of \d+ lines \.{3}\]
@@ -601,7 +600,6 @@ execution error: .*$"#;
601600
Wall time: [0-9]+(?:\.[0-9]+)? seconds
602601
Total output lines: \d+
603602
Output:
604-
Total output lines: \d+
605603
606604
execution error: .*$"#;
607605
let spawn_error_regex = Regex::new(spawn_error_pattern)?;

0 commit comments

Comments
 (0)