Skip to content

[#179]: Add v0.144.0 regression guards for paste-corrupted session entries#186

Merged
delexw merged 3 commits into
mainfrom
fix-issue-179
Jul 14, 2026
Merged

[#179]: Add v0.144.0 regression guards for paste-corrupted session entries#186
delexw merged 3 commits into
mainfrom
fix-issue-179

Conversation

@delexw

@delexw delexw commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #179

Summary

Codex v0.144.0 (upstream PR #31494) fixed a TUI-level bug where pasting terminal control sequences into the Codex prompt window corrupted resumed conversation history written to JSONL session files. This PR adds regression tests confirming that codex-trace's parser already handles both corruption forms gracefully.

Root cause (upstream)

When a user pasted text containing ANSI escape sequences into the Codex TUI before v0.144.0, the sequences were written into the JSONL session file in one of two forms:

  • Invalid JSON — raw ESC bytes (0x1b) embedded mid-value break the JSON structure, making the line unparseable.
  • Valid JSON, garbled content — the ESC character JSON-encoded as inside a string value. The line is technically valid JSON but the content is garbled display text.

Parser behaviour (already correct)

RawEntry::parse() in entry.rs is the entry point for every JSONL line:

let v: Value = serde_json::from_str(line).ok()?;
  • Case 1 (invalid JSON): serde_json::from_str returns Err, .ok()? short-circuits to None, and filter_map in session.rs silently drops the line. No panic.
  • Case 2 (valid JSON, garbled string): The line parses normally. The garbled content is stored as-is in the payload field; downstream code never inspects the raw string bytes. No panic.

No functional code change is needed — the parser already handles both cases.

Changes

Added four tests that document and lock in the existing behaviour:

File Test What it verifies
entry.rs v0144_paste_corrupted_invalid_json_line_is_silently_skipped Raw ESC bytes → parse() returns None
entry.rs v0144_response_item_with_unicode_escaped_control_sequences_does_not_panic -encoded sequences → parses correctly, no panic
entry.rs v0144_all_standard_entry_types_parse_correctly All four v0.144.0 entry types round-trip
turn.rs v0144_paste_corrupted_resumed_history_response_item_does_not_crash_turn_building Garbled history entry → turn building completes, status Complete

Verification

cargo test --lib   ->  325 passed; 0 failed
cargo clippy -D warnings  ->  clean
npm test  ->  exit 0

delexw added 2 commits July 12, 2026 11:06
…ion entries

Codex v0.144.0 (PR #31494) fixed a TUI-level bug where pasting terminal
control sequences corrupted resumed conversation history in JSONL session
files. Sessions captured before the fix may contain two corruption forms:

- Raw ESC bytes in a line (invalid JSON) — already silently skipped by
  serde_json::from_str(...).ok()? in RawEntry::parse()
- Unicode-escaped control sequences (�[1m) in string values (valid
  JSON, garbled content) — already parsed without panicking

Add four tests that explicitly document and lock in this behavior:
- entry.rs: invalid JSON line is silently skipped
- entry.rs: response_item with \u001b-encoded sequences parses correctly
- entry.rs: all four standard v0.144.0 entry types round-trip correctly
- turn.rs: turn building completes without panic when history contains
  garbled response_item content

No functional code changes — the parser already handles both cases.
…L corruption

Codex v0.144.0 (PR #31494) fixed paste-triggered corruption of
conversation history where terminal control sequences (ESC = U+001B)
could be embedded unescaped inside JSON strings, producing syntactically
invalid JSON lines in session JSONL files.

The parser already handled this gracefully:
- entry.rs: RawEntry::parse uses serde_json::from_str(...).ok()? which
  returns None for any invalid JSON line
- session.rs: parse_session_inner uses filter_map(RawEntry::parse) which
  silently skips None results
- discover.rs: scan_session_file uses Err(_) => continue to skip
  unparseable lines during the discovery scan

Add regression tests to document and lock in this behavior:
- entry.rs: verify corrupted line returns None; adjacent valid line still
  parses correctly
- session.rs: verify a full session with a corrupted line produces the
  correct turns from surrounding valid entries
- discover.rs: verify discover_sessions still returns the correct
  turn_count when a JSONL file contains a corrupted line

Fixes #179
@delexw
delexw merged commit ab4d8d5 into main Jul 14, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Compat] Codex v0.144.0: paste-triggered corruption of resumed conversation history fixed

2 participants