Conversation
An update hunk that contained a bare empty line (a blank context line without its leading space, or an empty line separating two file sections) failed with "Invalid hunk line". Codex reads such a line as an empty context line, and retries a match without a trailing empty context line because it stands for the final newline. Do the same. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When an agent edits a file with the built-in
apply_patchtool and one of its@@hunks contains a blank line written as a truly empty line (no leading space), the whole patch is rejected withInvalid hunk line (expected space, "+", or "-"):and nothing is written. Models produce this shape often: a blank context line between two statements, or an empty line separating two*** Update File:sections. The tool description tells the model it applies "the Codex patch format", and Codex accepts both.The Codex reference (
codex-rs/apply-patch) handles this in two places, mirrored here:streaming_parser.rs: "The normal parser treats a bare empty line in an update hunk as an empty context line").file_update.rs).Non-blank lines without a diff marker are still rejected.
Validation
bun test packages/runtime/tests/tools/built-in/apply-patch.test.tsBefore the fix (new tests added, source unchanged): 8 pass, 1 fail.
After the fix: 9 pass, 0 fail.
still rejects non-blank hunk lines without a diff markerpasses both before and after, which shows the parser is not widened beyond bare empty lines. The 7 existing tests are unchanged and pass.bun test packages/runtime/tests/tools/built-in/built-in-tools-module.test.ts: 5 pass / 1 fail on bothmainand this branch. The failure (runs bash commands from the workspace root) is pre-existing locally because that test spawnsbash.--max-warnings 0) on both touched files: clean onmainand on this branch.tsc --noEmit -p packages/runtime/tsconfig.json: clean onmainand on this branch.main(16 and 6); this change adds none.🤖 Generated with Claude Code