JuliusBrussee/caveman · error
caveman-code: old_string and new_string are identical
Error message
caveman-code: old_string and new_string are identical
What it means
The edit/replace tool in packages/agent/src/code.ts rejects a no-op edit up front: if old_string exactly equals new_string, nothing would change, so it throws 'caveman-code: old_string and new_string are identical' before reading the file. This catches agent loops that re-emit the same replacement.
Solutions
- Change new_string to the desired different content — an edit must actually modify the text.
- If the edit was already applied, skip it instead of re-issuing the same call.
- If you only wanted to locate text, use the read or grep tool rather than edit.
- Trim or normalize the strings and confirm they truly differ (compare with ===) before calling.
- For regex-style transformations, compute the new text yourself and pass it as new_string.
Example fix
// before
edit({ path: "a.ts", old_string: "const x = 1;", new_string: "const x = 1;" })
// after
edit({ path: "a.ts", old_string: "const x = 1;", new_string: "const x = 2;" }) Defensive patterns
Strategy: validation
Validate before calling
if (input.old_string === input.new_string) {
throw new Error("old_string and new_string are identical; the edit is a no-op");
} Try / catch
try {
await edit(input);
} catch (e) {
if (e.message.includes("old_string and new_string are identical")) {
console.error("Skipping no-op edit.");
} else throw e;
} Prevention
- Assert old_string !== new_string before every edit call in generated tooling.
- After a successful edit, update the agent's file snapshot so it never replays the same edit.
- Use read/grep to inspect content instead of issuing zero-diff edits.
- Precompute regex transformations into a concrete new_string that differs.
When it happens
Trigger: Calling the edit tool where input.old_string === input.new_string byte-for-byte — e.g. re-running a previous successful edit, copy-pasting the same block into both fields, or attempting an 'edit' that only reformats via regex which the tool does not support.
Common situations: LLM retries replaying an identical edit after a failure elsewhere; generating edits programmatically without checking the strings differ; intending a regex replacement but passing literal identical strings; whitespace normalization silently making both sides equal.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- caveman-code: not a file
- caveman-code: old_string appears
- caveman-code: old_string not found in
- cave_execution_authorization_private
- objectstore: page size must be positive
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/d5fd6345a75e245e.
Report an issue: GitHub.
Appendix: source
Thrown at packages/agent/src/code.ts:343
});
const editTool = tool({
name: "edit_file",
description:
"Replace an exact string in a workspace file. The old string must appear exactly " +
"once unless replace_all is set. Writes to disk.",
input: schema.object({
path: schema.string(),
old_string: schema.string(),
new_string: schema.string(),
replace_all: schema.optional(schema.boolean()),
}),
effect: "write",
result: "inline",
timeoutMs: READ_TIMEOUT_MS,
async execute(input) {
if (input.old_string === input.new_string) {
throw new Error("caveman-code: old_string and new_string are identical");
}
const target = await contained(input.path);
const content = await readFile(target, "utf8");
const occurrences = content.split(input.old_string).length - 1;
if (occurrences === 0) {
throw new Error(`caveman-code: old_string not found in ${input.path}`);
}
if (occurrences > 1 && input.replace_all !== true) {
throw new Error(
`caveman-code: old_string appears ${occurrences} times in ${input.path}; ` +
"add surrounding context or pass replace_all",
);
}
// split/join UNCONDITIONALLY. String.prototype.replace
// interprets `$&`, `$\``, `$'`, `$$`, `$1`… in the REPLACEMENT even for a
// string pattern, so a new_string containing any of them would silently
// corrupt the file. The non-replace_all branch is guaranteed exactly one
// occurrence above, so joining replaces precisely that one.View on GitHub (pinned to 3ee70a1026)