{"record":{"id":"8e575138d51cadd2","repo":"Tencent/WeKnora","slug":"old-string-and-new-string-are-identical-no-change","errorCode":null,"errorMessage":"old_string and new_string are identical; no change would be made","messagePattern":"old_string and new_string are identical; no change would be made","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/tools/sandbox_edit.go","lineNumber":281,"sourceCode":"\t\t\t\"size\":         len(content),\n\t\t\t\"replacements\": replacements,\n\t\t},\n\t}, nil\n}\n\n// Cleanup releases any resources.\nfunc (t *EditSandboxFileTool) Cleanup(ctx context.Context) error {\n\treturn nil\n}\n\n// applySandboxEdit performs an exact string replacement. replaceAll=false\n// requires a unique match.\nfunc applySandboxEdit(content, oldString, newString string, replaceAll bool) (string, int, error) {\n\tif oldString == \"\" {\n\t\treturn \"\", 0, fmt.Errorf(\"old_string is required; copy the exact text to change, including whitespace\")\n\t}\n\tif oldString == newString {\n\t\treturn \"\", 0, fmt.Errorf(\"old_string and new_string are identical; no change would be made\")\n\t}\n\tn := strings.Count(content, oldString)\n\tif n == 0 {\n\t\treturn \"\", 0, fmt.Errorf(\"old_string was not found in the file. Copy the exact text (including whitespace) from the file\")\n\t}\n\tif n > 1 && !replaceAll {\n\t\treturn \"\", 0, fmt.Errorf(\n\t\t\t\"old_string matched %d times. Include more surrounding context so it is unique, or set replace_all=true\",\n\t\t\tn,\n\t\t)\n\t}\n\tif replaceAll {\n\t\treturn strings.ReplaceAll(content, oldString, newString), n, nil\n\t}\n\treturn strings.Replace(content, oldString, newString, 1), 1, nil\n}\n","sourceCodeStart":263,"sourceCodeEnd":298,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/agent/tools/sandbox_edit.go#L263-L298","documentation":"applySandboxEdit in internal/agent/tools/sandbox_edit.go validates a file-edit request before applying it. It throws this error when the caller passes an edit where old_string and newString are byte-for-byte identical, which would be a no-op. The tool rejects it early so the agent/user notices the mistake instead of silently doing nothing.","triggerScenarios":"Calling the sandbox edit tool (via Execute) with old_string equal to new_string, e.g. retrying an edit after it already succeeded so the target text now equals the replacement, or copy-pasting the same block into both fields.","commonSituations":"An LLM agent re-sends a previously applied edit; a developer constructs an edit programmatically with the same variable for both arguments; whitespace-only 'changes' that turn out identical; retry loops without re-reading the file.","solutions":["Re-read the current file content and diff it against your intended final state to see what actually still needs changing.","Make newString genuinely different from oldString, or skip the edit entirely if the file already has the desired content.","If many arguments were passed positionally, verify oldString and newString weren't swapped or duplicated."],"exampleFix":"// before\napplySandboxEdit(content, oldString, oldString, false)\n// after\nif oldString == newString {\n    return content // no-op; skip edit\n}\nnewContent, _, err := applySandboxEdit(content, oldString, newString, false)","handlingStrategy":"validation","validationCode":"if oldString == newString {\n    return fmt.Errorf(\"skipping edit: old_string equals new_string\")\n}","typeGuard":null,"tryCatchPattern":"newContent, n, err := applySandboxEdit(content, oldString, newString, replaceAll)\nif err != nil && strings.Contains(err.Error(), \"identical\") {\n    // treat as no-op: re-read file and confirm desired state already present\n    return content, nil\n}","preventionTips":["Re-read the file after every edit before constructing the next one.","Compare oldString vs newString before calling and skip no-op edits.","Track which edits have already been applied to avoid resending them."],"tags":["edit-tool","no-op","validation","go"],"backgroundTag":"identical-edit-arguments","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}