Skip to content

fix(core): refuse an edit whose new text mixes read_file line numbers - #505

Merged
lg2m merged 1 commit into
mainfrom
fix/edit-gutter-mixed-new
Oct 30, 2026
Merged

lg2m merged 1 commit into
mainfrom
fix/edit-gutter-mixed-new

Conversation

@lg2m

@lg2m lg2m commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

What changed

old sometimes matches only after read_file's N<TAB> gutter is stripped from it. Before this change, a new that had line numbers on some lines and not others was written as-is, so the file got lines like 2 BETA. Now:

  • If every non-blank line of new has the gutter, it is stripped (same as before).
  • If no line of new has the gutter, new is used as-is (same as before).
  • If new mixes the two, the edit is refused. Nothing is written, and the model gets this message:
    edit N: invalid_edit: old matched only without its read_file line numbers, but new mixes numbered and unnumbered lines; remove the N<TAB> line-number prefixes from new

The invalid_edit: prefix is already classified as ToolErrorKind::Correction, the same as the other edit argument errors. No protocol change was needed.

Verification

  • New tests in matching.rs: the mixed case is refused (failed on origin/main with Ok(... replacement: " 2\tBETA\nadded\n 3\tgamma\n")); an all-gutter new is still stripped; a plain new still applies as-is; content that really starts with digits and a tab still matches exactly.
  • A new end-to-end test through edit_file checks the exact refusal text, the Correction classification, and that the file is unchanged.
  • cargo xtask check passed.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T23:50:47.711255Z 7ef7784 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@lg2m
lg2m merged commit 9420863 into main Oct 30, 2026
8 checks passed
@lg2m
lg2m deleted the fix/edit-gutter-mixed-new branch October 30, 2026 00:08
@lg2m lg2m mentioned this pull request Oct 30, 2026
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.

1 participant