You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] diff_edit validator accepts a multi-block diff whose later block depends on an earlier one, then execute fails #2235
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
Create chain.txt containing one\ntwo\n and read it with read_file.
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.
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.
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!
Activity
aliberk1 commentedon Nov 16, 2026
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.
addyCooks commentedon Nov 16, 2026
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!