G-12Diff Application Strategies

/coding-agents/diff-application

How an edit actually reaches the file — reprint the whole thing, or emit an anchored block the harness has to match.

Step-by-step walkthrough2 variants · 12 steps

Whole file

  1. The simplest strategy: ask for the whole file back.
  2. It always applies. There is no matching step, so there is nothing to fail.
  3. The write is a plain overwrite.
  4. But a three-line fix costs nine hundred lines of output — every time, on every retry.
  5. And whatever the model quietly failed to reprint is now gone — no conflict, no error, just missing code.
  1. The model emits only what changes, wrapped in enough surrounding lines to locate it.
  2. Output is proportional to the edit, not to the file. A three-line fix costs three lines.
  3. The harness has to find that anchor in the real file, byte for byte.
  4. Matched → applied in place, and everything the model never mentioned is untouched by construction.
  5. No match. The file moved on, or the model reproduced the whitespace wrong.
  6. This is the good failure: it stops, says so, and nothing was written.
  7. Re-read the file, re-anchor, retry. A loud failure beats a silent overwrite every time.
Key insight

This is the most consequential mechanism in coding agents and the least discussed. Whole-file rewrites can never fail to apply and can silently delete; anchored edits can fail to apply and never silently delete. Prefer the failure you can see.

Failure mode

Treating a failed match as a bug in the strategy. A no-match is the mechanism doing its job — the file moved, and the right response is to re-read and re-anchor, not to fall back to overwriting.

Elsewhere in the atlas