Skip syntax highlighting for lines over 4 KiB (#34796)

## Why

Very long individual lines can make syntax highlighting consume excessive CPU or memory even when the overall input remains below the existing size and line-count limits.

## What changed

- Fall back to plain, unstyled text when any input line exceeds 4 KiB.
- Keep the existing 512 KiB total-size and 10,000-line guardrails.

## Testing

- Cover highlighting fallback and text preservation for a long single-line Bash command.
- Snapshot rendering of a command that exceeds the per-line limit.

GitOrigin-RevId: ba02997331a294d8a32ca89ee06acb12dd3bbd83
This commit is contained in:
Eric Traut authored and copyberry committed 2026-07-22 17:38:11 +00:00
1 parent 2c49493b5b
commit 5381edb133
3 files changed
+59 -4

No files matched your search

@@ -0,0 +1,9 @@
---
source: tui/src/history_cell/tests.rs
expression: rendered
---
• Ran AAAAAAAAAAAAAAAAAA
│ AAAAAAAAAAAAAAAAAA
│ AAAAAAAAAAAAAAAAAA
│ … +225 lines
└ (no output)
+25
View File
@@ -7,6 +7,7 @@ use crate::exec_cell::ExecCell;
use crate::legacy_core::config::Config;
use crate::legacy_core::config::ConfigBuilder;
use crate::line_truncation::line_width;
use crate::render::highlight::MAX_HIGHLIGHT_LINE_BYTES;
use crate::session_state::ThreadSessionState;
use crate::wrapping::word_wrap_lines;
use codex_app_server_protocol::AskForApproval;
@@ -1861,6 +1862,30 @@ fn single_line_command_wraps_with_four_space_continuation() {
insta::assert_snapshot!(rendered);
}
#[test]
fn single_line_command_over_highlight_limit_uses_plain_text_fallback() {
let call_id = "c1".to_string();
let base64_like = "A".repeat(MAX_HIGHLIGHT_LINE_BYTES + 1);
let mut cell = ExecCell::new(
ExecCall {
call_id: call_id.clone(),
command: vec!["bash".into(), "-lc".into(), base64_like],
parsed: Vec::new(),
output: None,
source: ExecCommandSource::Agent,
start_time: Some(Instant::now()),
duration: None,
interaction_input: None,
},
/*animations_enabled*/ true,
);
cell.complete_call(&call_id, CommandOutput::default(), Duration::from_millis(1));
let rendered = render_lines(&cell.display_lines(/*width*/ 24)).join("\n");
insta::assert_snapshot!(rendered);
}
#[test]
fn multiline_command_without_wrap_uses_branch_then_eight_spaces() {
let call_id = "c1".to_string();