From 3df178fffcb265e0c8857a7c92ce68fc98d631d6 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 16 Jun 2026 02:48:56 +0200 Subject: [PATCH] agent: reject edit calls whose new text contains [upto] [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: https://github.com/antirez/ds4/issues/408 Co-Authored-By: Claude Sonnet 4.6 --- ds4_agent.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ds4_agent.c b/ds4_agent.c index 1c5209154..917bd2909 100644 --- a/ds4_agent.c +++ b/ds4_agent.c @@ -6272,6 +6272,8 @@ static char *agent_tool_edit(agent_worker *w, const agent_tool_call *call) { const char *new_text = agent_tool_arg_value(call, "new"); if (!old || !old[0]) return xstrdup("Tool error: edit requires non-empty old text\n"); if (!new_text) return xstrdup("Tool error: edit requires new text\n"); + if (strstr(new_text, "[upto]")) + return xstrdup("Tool error: new text must not contain the [upto] anchor marker\n"); char err[256]; char *data = NULL;