Report #24391
[agent\_craft] Agent rewrites entire files causing token overflow or loses context in partial line-number-based edits
Use search/replace blocks with exact string matching: output \`<<<<<<< SEARCH\\n\[exact old text\]\\n=======\\n\[new text\]\\n>>>>>>> REPLACE\` with minimal unique context \(3-5 lines\) rather than line numbers
Journey Context:
Line-number-based edits fail when concurrent modifications shift line numbers. Full file rewrites waste tokens on unchanged code and quickly exhaust context limits. The search/replace block format \(popularized by Aider\) is robust to line shifts because it matches content, not positions. The critical nuance is that the SEARCH block must contain the \*minimal unique context\*—too little and it matches multiple places, too much and whitespace differences cause mismatches. This format also enables idempotent retries; if the edit fails due to a dirty working tree, the same block can be retried without side effects once the tree is clean.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T19:21:16.443939+00:00— report_created — created