Skip to content

[Bug] diff_edit validator accepts a multi-block diff whose later block depends on an earlier one, then execute fails #2235

Closed

Description

@addyCooks

Description

diff_edit checks every SEARCH block against the original file, but applies the blocks one after another. If block 2 searches for text that block 1 produces or removes, the validator says the diff is valid and execute then throws. The file stays unchanged.

Environment

  • OS: Windows 11 Home 10.0.26300
  • Node version: v22.22.3
  • Nanocoder version: 1.32.0 (built from main at 5df35b3)
  • Provider: Not provider-specific
  • Model: Not model-specific

Steps to Reproduce

  1. Create chain.txt containing one\ntwo\n and read it with read_file.

  2. Call diff_edit with this diff:

     <<<<<<< SEARCH
     one
     =======
     two
     >>>>>>> REPLACE
     <<<<<<< SEARCH
     two
     =======
     THREE
     >>>>>>> REPLACE
    

Expected Behavior

Either the validator rejects the diff with a clear message, or the blocks are applied in order.

Actual Behavior

The validator returns valid, then execute throws.

Logs/Screenshots

validator: {valid: true}
execute:   Search block 2 could not be applied cleanly after earlier edits.

(X=1 -> Y=2 followed by Y=2 -> X=1 fails the same way.)

Additional Context

  • I have searched existing issues to ensure this is not a duplicate
  • I can reproduce this issue consistently
  • This issue occurs with the latest version of nanocoder (main)

Suggested fix:

  • source/tools/file-ops/diff-edit.tsx (validateBlocks, using countOccurrences at line 141): check each block against the content after the previous blocks were applied, so validator and execute agree. Return the block number in the error.
  • Add a test for a chained diff and a swap.

Activity

  1. added
    bug
    on Nov 16, 2026
  2. added theissue type on Nov 16, 2026
  3. added
    area:tools
    on Nov 16, 2026
  4. added
    needs-triage
    on Nov 16, 2026
  5. aliberk1 commented on Nov 16, 2026

    @aliberk1
    Contributor

    I am working on this with AI assistance. The tool currently requires distinct original-file ranges (including duplicate-search rejection), and its preview/visibility checks use those original ranges. I plan to preserve that contract and have validation also dry-run the ordered replacements using the same helper as execution, so a later block made ambiguous or removed by an earlier block is rejected before approval, with the block number. I will add regression cases for the reported chain, a swap, and an overlapping edit that removes a later search, check that failed edits leave the file unchanged, and retain successful independent multi-block coverage.

  6. removed
    needs-triage
    on Nov 16, 2026
  7. addyCooks commented on Nov 16, 2026

    @addyCooks
    CollaboratorAuthor

    Hi @aliberk1, I’m assigning this one to you. I’ll review your PR this time. Going forward, please comment on the issue first and wait until you’re assigned before you start working on it. That way we avoid duplicate work and keep things fair for everyone.
    Thanks for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:toolsbug

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions