Skip to content

[Agent Fix]: Old tail anchor not found after old head#338

Open
kamranjon wants to merge 1 commit into
antirez:mainfrom
kamranjon:kamranjon/agent-edit-tool-fix
Open

[Agent Fix]: Old tail anchor not found after old head#338
kamranjon wants to merge 1 commit into
antirez:mainfrom
kamranjon:kamranjon/agent-edit-tool-fix

Conversation

@kamranjon
Copy link
Copy Markdown

@kamranjon kamranjon commented Jun 5, 2026

PR Summary: Fix anchored edit tail anchor search

Bug: edit with [upto] always fails with old tail anchor not found after old head, blocking large anchored replacements.

Root Cause: In agent_edit_find_old_span(), the tail string includes a leading \n (from [upto]\n), but the file after the head match has no such newline — so the tail needle never matches.

Fix: Strip leading \n/\r from the tail before searching. The head already ends with that newline.

Changes (ds4_agent.c lines 5871–5879):

  • Added a while-loop to remove leading \n/\r from tail / tail_len.
  • Works for both Unix (\n) and Windows (\r\n) line endings.
  • Handles both the forcer-injected \n and model-written \n after [upto].
  • The agent_span_has_nonspace guard (moved after the strip) still rejects empty/whitespace-only tails.
  • match_len remains correct because the head's trailing newline is counted in head_len.

Testing: Compiles cleanly with -Wall -Wextra, all edge cases verified. [upto] edits actually work. I had to go back to a sha from 2 weeks ago to find an agent that could properly use the edit tool again to make this change: d447bdb - but tested with newest build and agent is able to edit reliably again!

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