Skip to content

agent: reject edit calls whose new= text contains [upto]#421

Open
aledesogusbusiness-hue wants to merge 1 commit into
antirez:mainfrom
aledesogusbusiness-hue:fix/agent-upto-in-new-text
Open

agent: reject edit calls whose new= text contains [upto]#421
aledesogusbusiness-hue wants to merge 1 commit into
antirez:mainfrom
aledesogusbusiness-hue:fix/agent-upto-in-new-text

Conversation

@aledesogusbusiness-hue

Copy link
Copy Markdown

Problem

[upto] is an anchor marker that belongs only in the old= parameter of an edit tool call, where it acts as a range wildcard between a unique head and tail.

If the model accidentally emits [upto] inside the new= parameter, agent_tool_edit() passes new_text straight to agent_apply_file_splice(), which splices the literal string — including [upto] — into the file. The resulting file corruption triggers the system to retry the patch, which fails again with the same outcome, looping.

Fix

Add a guard in agent_tool_edit() that returns a Tool error immediately when new_text contains "[upto]". This gives the model corrective feedback on the next turn rather than writing the marker to disk.

if (strstr(new_text, "[upto]"))
    return xstrdup("Tool error: new text must not contain the [upto] anchor marker\n");

Test plan

  • Craft an edit call where new= includes [upto]; verify the tool returns the error string and leaves the file unchanged.
  • Normal edits with [upto] only in old= are unaffected.

Fixes #408

🤖 Generated with Claude Code

[upto] is an anchor marker that belongs only in the old= parameter of
an edit tool call.  If the model accidentally emits it in the new=
parameter the literal string gets spliced into the file, leaving
obvious corruption that triggers the system to retry the same patch,
which fails again with the same outcome.

Guard agent_tool_edit() against this: return a Tool error immediately
when new_text contains "[upto]" so the model gets corrective feedback
instead of writing the marker to disk.

Fixes: antirez#408

Co-Authored-By: Claude Sonnet 4.6 <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.

[upto] tag left if the code

1 participant