earendil-works/pi · error · Error
edits[ ] and edits[ ] overlap in . Merge them into one edit…
Error message
edits[${previous.editIndex}] and edits[${current.editIndex}] overlap in ${path}. Merge them into one edit or target disjoint regions. What it means
After sorting edits by match position in applyEditsToNormalizedContent, adjacent edits are checked for overlap; if the previous edit's range extends into the current one, the two edits touch the same bytes and cannot both be applied deterministically. The message tells the model to merge the edits or target disjoint regions.
Solutions
- Merge the overlapping edits into one edit, or adjust their ranges to target disjoint regions.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at packages/agent/src/harness/tools/edit-diff.ts:346 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of earendil-works/pi@4af9d21d3b (2026-08-24).
Data as JSON: /api/errors/52a84a33134ef993.
Report an issue: GitHub.
Appendix: source
Thrown at packages/agent/src/harness/tools/edit-diff.ts:346
const occurrences = countOccurrences(replacementBaseContent, edit.oldText);
if (occurrences > 1) {
throw getDuplicateError(path, i, normalizedEdits.length, occurrences);
}
matchedEdits.push({
editIndex: i,
matchIndex: matchResult.index,
matchLength: matchResult.matchLength,
newText: edit.newText,
});
}
matchedEdits.sort((a, b) => a.matchIndex - b.matchIndex);
for (let i = 1; i < matchedEdits.length; i++) {
const previous = matchedEdits[i - 1];
const current = matchedEdits[i];
if (previous.matchIndex + previous.matchLength > current.matchIndex) {
throw new Error(
`edits[${previous.editIndex}] and edits[${current.editIndex}] overlap in ${path}. Merge them into one edit or target disjoint regions.`,
);
}
}
const baseContent = normalizedContent;
const newContent = usedFuzzyMatch
? applyReplacementsPreservingUnchangedLines(normalizedContent, replacementBaseContent, matchedEdits)
: applyReplacements(replacementBaseContent, matchedEdits);
if (baseContent === newContent) {
throw getNoChangeError(path, normalizedEdits.length);
}
return { baseContent, newContent };
}
View on GitHub (pinned to 4af9d21d3b)