Skip to content

fix: show the implementer the repository it is patching - #136

Merged
thedancingdeveloper merged 1 commit into
mainfrom
fix/show-the-implementer-the-repo
Aug 3, 2026
Merged

fix: show the implementer the repository it is patching#136
thedancingdeveloper merged 1 commit into
mainfrom
fix/show-the-implementer-the-repo

Conversation

@thedancingdeveloper

Copy link
Copy Markdown
Contributor

Closes #135. Substantially mitigates #133.

The bug

IMPLEMENT_PROMPT asks for a diff that "applies cleanly at the repository
root". context_provider defaulted to lambda _record: "", and
agent-harness run never passed one — so Repository context: was always
empty and the model was asked to patch files it had never seen.

It cannot write context lines it does not know, so it wrote hunks with none:

--- a/calc.py
+++ b/calc.py
@@ -0,0 +1,4 @@
+def multiply(a, b):
+    return a * b

git apply refuses that against a non-empty file. --unidiff-zero accepts it
and inserts at line 1 — which is how multiply ended up above the module
docstring, and two tests above from calc import add, subtract, with pytest
green throughout.

Two parts to the fix

Show it the repository. A default context_provider giving the tracked
file listing, files the brief names in full, then the rest smallest-first
within a 60k budget. Binary files are listed, never read.

Read from the base ref, not the working tree. This one is subtle and was
found by the first fix not working. The tree still holds the previous item's
branch when the implementer is called — the branch for this item is not cut
until the apply step — so the model was shown a file its patch would never
meet, and every patch failed to apply. The base is now resolved before the
implementer runs and read via git show <base>:<path>. Correct by
construction, and it touches no checkout.

Live result

Same three-item backlog, same endpoint, across the three fixes in this series:

outcome
before #132 0/3 — all rejected on a plumbing artefact
after #132 1/3 — the other two rejected, correctly, for misplacement
after this 3/3 completed

Each item on its own branch, tests passing on each independently (3, 4 and 4
tests), the stacked item correctly based on its dependency, and calc.py
ending up exactly as a human would write it — docstring first, functions in
order.

On #133

Not closed. With real context the model produces proper diffs and the first
rung of the ladder succeeds, so --unidiff-zero stops being reached in
practice. The rung can still misplace a zero-context hunk if one arrives; that
remains worth addressing on its own terms.

Tests: four new, covering the listing reaching the implementer, a named file
being included whole under a tight budget, an empty repository, and binary
files being listed but not read. Suite, ruff and mypy . green.

The prompt asks for a unified diff that "applies cleanly at the repository
root". `context_provider` defaulted to `lambda _record: ""` and the CLI never
passed one, so it asked for that while showing the model nothing at all.

A model cannot write context lines for a file it has not seen. So it wrote
hunks with none, declaring `@@ -0,0` against files that were not empty; git
apply refuses those, --unidiff-zero accepts them and inserts at line one, and
code landed above module docstrings and imports with every check still green.
That is the root cause behind #133, and it explains the shape of every diff
this path has ever produced.

Two parts:

**Context.** A default provider that supplies the tracked file listing, the
files the brief names in full, and as much of the rest as a byte budget
allows, smallest first. Binary files are listed but not read.

**Read it from the base, not the tree.** The working tree still holds the
previous item's branch when the implementer is called -- the branch for this
item is not cut until the apply step -- so reading the tree showed the model a
file its patch would never meet. The base ref is now resolved before the
implementer runs and the context is read from it with `git show`, which is
correct by construction and touches no checkout.

Live, on a three-item backlog with a real endpoint: 0/3 completed before,
**3/3 after**, each on its own branch with its tests passing, the stacked item
correctly based on its dependency, and the module docstring still the first
thing in the file.
@thedancingdeveloper
thedancingdeveloper merged commit cdf6a00 into main Aug 3, 2026
2 checks passed
@thedancingdeveloper
thedancingdeveloper deleted the fix/show-the-implementer-the-repo branch August 3, 2026 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: the implementer is asked for a diff against a repository it is never shown, so it emits context-free hunks

1 participant