Skip to content

fix(diff-edit): reject conflicting blocks during validation - #2248

Merged
akramcodez merged 1 commit into
Nano-Collective:mainfrom
aliberk1:fix/diff-edit-validation-2235
Nov 18, 2026
Merged

akramcodez merged 1 commit into
Nano-Collective:mainfrom
aliberk1:fix/diff-edit-validation-2235

Conversation

@aliberk1

@aliberk1 aliberk1 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

Closes #2235.

validateBlocks checked each SEARCH against the original file, while applyBlocks checked the content after each earlier replacement. The reported one -> two, two -> THREE edit therefore passed validation but failed during execution: the second search had become ambiguous.

Validation now also dry-runs applyBlocks and returns the prepared content. Execution and the VS Code preview use that returned content instead of applying the blocks a second time. An edit that removes or duplicates a later search now fails validation with the same block-numbered error as execution, before any write.

This takes the issue's rejection option: the existing distinct-original-range contract stays in place, rather than introducing chained-edit semantics that would also require changing original-range preview and visibility handling.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Changeset

  • Added a patch changeset for @nanocollective/nanocoder.

Testing

Automated Tests

  • Added regression cases for the reported chain, the X=1 / Y=2 swap, and an earlier edit that removes a later search. Each checks validation, execution, and unchanged file contents.
  • Extended the independent multi-block case to check validation succeeds without writing before execution.
  • Tests cover both success and error scenarios.
  • Full pnpm test:all suite (not run; followed AGENTS.md's preference for focused specs).

Checks run on Linux, Node 24.22.3, pnpm 11.0.9:

pnpm run test:ava source/tools/file-ops/diff-edit.spec.tsx source/tools/file-ops/edit-recovery.spec.ts source/tools/file-ops/literal-replace.spec.ts
  58 tests passed
pnpm run test:types
  passed
pnpm run test:format
  passed
pnpm run test:lint
  passed
git diff --check
  passed

Biome reported only the existing informational schema-version mismatch (2.5.0 config vs 2.5.13 CLI). I also ran the original validation/application helpers against all three regression inputs to confirm validation accepted them while application threw, then verified the corrected helpers reject them during validation.

Manual Testing

No live model/provider or VS Code session was exercised; this is shared file-edit validation logic covered by local tests.

Checklist

  • Assigned to the issue (unassigned; approach posted in the issue before implementation).
  • Code follows project style guidelines.
  • Implementation reviewed against validation, execution, and preview call sites.
  • Changeset added; no public API change.
  • No breaking changes.
  • Existing error reporting retained; no new logging needed.

AI assistance: implemented and tested with OpenCode using OpenAI GPT-6 Astra.

@github-actions github-actions Bot added the area:tools Tool implementations and tool-calling label Nov 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

nc-review could not produce a verdict this run (agent exit 1). This is a problem with the review agent, not with your pull request. A maintainer can retry with /re-review.

@akramcodez
akramcodez merged commit ee800df into Nano-Collective:main Nov 18, 2026
18 of 19 checks passed
@akramcodez

Copy link
Copy Markdown
Member

Thanks @aliberk1, merged! Appreciate the clean fix and the regression specs.

Mahdi-Hasan added a commit to Mahdi-Hasan/nanocoder that referenced this pull request Nov 26, 2026
Block 2 is matched in block 1's output, so block 1's fitted lines must be
CRLF. A second test checks that a fitted replacement which repeats block 2's
search is rejected by the ordered dry run from Nano-Collective#2248.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:tools Tool implementations and tool-calling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants