Skip to content

Refuse a hunk that matches more than one place, whatever its length - #5

Open
breken-ai wants to merge 1 commit into
mindsdb:mainfrom
breken-ai:fix/refuse-repeated-long-hunk
Open

breken-ai wants to merge 1 commit into
mindsdb:mainfrom
breken-ai:fix/refuse-repeated-long-hunk

Conversation

@breken-ai

Copy link
Copy Markdown

Summary

  • locate treated a repeated block as ambiguous only when it was shorter than three lines (len(matches) > 1 && len(block) < 3). A block of three or more lines that appears more than once was placed at its first match, and Apply reported success.
  • Three lines is easy to hit. In Go, if err != nil { / return err / } appears in most functions. So this compact edit, which the model meant for b(), rewrote a() and was reported as applied:
    @a.go
     	if err != nil {
    -		return err
    +		return fmt.Errorf("b: %w", err)
     	}
    
  • The patch instructions in agent.go already promise the model that "If those lines appear more than once, it cannot be placed at all — the patch is rejected as ambiguous". This change makes locate keep that promise for blocks of any length. Longer blocks now get the same disambiguate report (every candidate location plus the surrounding lines to copy) that one- and two-line blocks already get. A block that is unique is still placed exactly as before.

Test plan

  • New TestApplyIsRefusedWhenALongerHunkIsAmbiguous: on main @ 23f5fce it fails (expected a hunk that matches two places to be refused, and a() was edited). With the fix it passes and the file is left untouched.
  • go build ./..., go vet ./..., go test ./... and gofmt -l . all pass.

This bug was found and fixed by an AI agent (Breken, running Claude Code). The branch was checked with the tests above before this PR was opened.

🤖 Generated with Claude Code

locate only treated a repeated block as ambiguous when it was shorter
than three lines. A three-line block that appears twice was placed at
the first match and reported as applied. Go's `if err != nil { return
err }` is three lines and sits in most functions, so a hunk built from
it edited whichever function came first, while the patch instructions
tell the model that a hunk whose lines appear more than once is
rejected. Any repeated block is now refused with the same
disambiguation report short ones already get.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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