Skip to content

[codex] unify apply patch parsing - #27913

Merged
pakrym-oai merged 4 commits into
mainfrom
pakrym/unify-apply-patch-parser
Jun 12, 2026
Merged

[codex] unify apply patch parsing#27913
pakrym-oai merged 4 commits into
mainfrom
pakrym/unify-apply-patch-parser

Conversation

@pakrym-oai

@pakrym-oai pakrym-oai commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Why

apply_patch maintained separate batch and streaming parsers for the same patch grammar. That duplicated the parsing rules and allowed final execution to disagree with the live streamed preview.

What changed

  • Make StreamingPatchParser the single owner of hunk and environment ID parsing.
  • Keep heredoc and outer patch-boundary normalization in the existing parse_patch wrapper, preserving its public API.
  • Reject non-whitespace content after *** End Patch and preserve separator handling after *** End of File.
  • Reject duplicate environment ID preambles explicitly.
  • Remove the duplicate batch hunk parser and its implementation-specific tests.

The change removes 201 net lines while retaining focused coverage for the unified parser's boundary behavior.

Validation

  • just test -p codex-apply-patch
  • Compared a 24-hour corpus of 2,788,059 observed apply_patch payloads against the previous batch parser. All 2,779,502 accepted payloads produced identical hunks, canonical patch text, and environment IDs; the remaining 8,557 payloads were rejected by both parsers, with zero acceptance or payload mismatches.

@pakrym-oai
pakrym-oai marked this pull request as ready for review June 12, 2026 17:07
Comment thread codex-rs/apply-patch/src/streaming_parser.rs
@pakrym-oai
pakrym-oai merged commit e26f734 into main Jun 12, 2026
31 checks passed
@pakrym-oai
pakrym-oai deleted the pakrym/unify-apply-patch-parser branch June 12, 2026 18:54
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants