GitHub returned a 422 and refused to open the pull request. The branch had no commits on it. Yet the AI that produced that branch had just reported: "Added one line." And when our system ran git in the working copy, git agreed: M docs/README.md 1 insertion.
Both were true. The line existed. It just never left the working copy.
The AI was not lazy, and it was not joking. Trace what it did step by step and it turns out to have followed the rule to delegate almost too faithfully. This is the story of where that one line went.
The short version
- The repo's rules said implementation must be delegated to a subagent called implementer. The AI did exactly that, and said it would wait for the completion notice
- The README in the working copy did gain one line. Nobody committed it
- In an unattended, one-shot run, the AI's turn ends the moment it answers. With nothing committed, the system pushed the branch anyway
- A push only carries commits. The line stayed behind, the branch matched main, and GitHub's 422 said zero
The task: one line in a README
We build a system that hands work to AI agents. A local LLM decides which agent gets a job, and Claude Code does the implementing. The system clones the target repo, creates a work branch, starts Claude Code with no person attached, and lets it work. When the AI has finished and committed its work, the system pushes the branch and opens a pull request on GitHub. The goal is that a person only has to look at the finished pull request and decide whether to merge it.
On our other repos, this loop already worked end to end. So we tried the next step: asking the system to work on itself.
The first task was deliberately tiny, just enough to see the loop go all the way around:
Add one line to docs/README.md linking DOGFOODING-LOG.md
DOGFOODING-LOG.md is the trial-run log for the system: every run, what we asked, what broke, how we fixed it, and whether it passed. The task was to link it from the docs README. It was hard to imagine a way to fail.
The AI followed the repo's rules
The repo has a CLAUDE.md, the rules file Claude Code reads before it starts working. The rule was headed "main session = coordinator". Translated from the original Japanese, it said the main session launches specialist agents (task-decomposer, implementer, qa, reporter and so on) directly and in series through the Task tool; delegation is mandatory, and the main session must not bypass implementer and implement the work itself.
implementer is the name of the subagent that does the editing. The parent conversation sorts the work by type and coordinates, and specialist child AIs edit the files.
The rule was thorough. It even covered small fixes: a LIGHT_EDIT is delegated to a single implementer.
LIGHT_EDIT is the work type for a light edit. Adding one line to a README is exactly that. Even for a one-line change, the parent does not write it; it calls one implementer.
The AI that picked up the task read the rule first, and obeyed it. Its own words, from the log:
Delegating to implementer... waiting for the completion notice
It did not write the README itself. It handed the work to a child AI. Up to that point, it did what the rule asked. Waiting for a notice, though, was not something the rule said.
Its turn ended while it waited
The catch: this AI was running unattended, one shot.
In an interactive Claude Code session, the conversation keeps going after the parent hands work to a child. When the child finishes, a notice arrives, and the parent picks up from there.
A one-shot run (claude --print) does not work like that. The AI answers once, and that is the end. The moment it wrote "waiting for the completion notice" and returned its answer, its turn was over. Nobody was left to wait, and nobody was left to receive the notice.
When the parent's turn ends, whatever was supposed to come next, "look at the result, then commit", never happens. In an unattended run, committing the change in the working copy is part of the AI's job. It never got that far, and the system moved on to its next step.
"Added one line" was not a lie
This is the strange part. The AI reported "Added one line."
When the AI's turn ends, our system runs git status --porcelain and git diff --stat HEAD in the working copy itself, and records the output as the change summary. The AI does not write it; git counts it. And git said M docs/README.md and 1 insertion.
M marks a file that has been modified in the working copy and not yet committed. 1 insertion is one added line. So docs/README.md in the working copy really did have one new line. The report and git's summary were both telling the truth about the working copy.
The only thing missing was a commit.
GitHub said zero
Next, the system pushed the work branch. A push sends commits to GitHub. Changes still sitting in the working copy stay on the machine.
Getting a change to GitHub with git takes three steps. Edit the file in the working copy. Turn that edit into a commit on the branch with git add and git commit. Send the commit to GitHub with git push. Our one line had stopped at step one. The system ran step three as usual. With no commit to send, what reached GitHub was a branch identical to main.
The branch pointed at the same commit as main: zero commits ahead. When the system tried to open the pull request, GitHub answered 422: there are no commits between main and this branch.
The AI said one line. Git's summary said one line. GitHub said zero. All three were right. The line was in the working copy and not on the branch. They were simply looking at different places.
The other funny part: every step on the system's side worked. Cloning its own repo with a token, creating the work branch, pushing: all of that succeeded in this run. It proved the system could reach its own repo. The branch it delivered just happened to be empty.
Delegating was not the mistake
At this point we could have decided "no subagents in unattended runs". But when we checked, that was not the problem.
Even in a one-shot run, a subagent works correctly if the parent waits for it on the spot. The child works in its own context, its file changes stay in the working copy, and its result comes back to the parent. We ran it on the machine that does the work and confirmed exactly that. The hunch that "delegating should be fine" was right.
The rule itself said "in series". What tripped was not the delegating; it was the waiting. This AI chose to run the child in the background and wait for a notice, inside a run where no notice could ever arrive.
Why it never happened on other repos
On other repos, the same system had never stalled this way. The reason is simple: their CLAUDE.md files had no "delegate" rule, so the AI opened the files and edited them itself.
Only when it worked on this repo did it read this repo's rules, and carry a rule written for interactive sessions into an unattended run. The rule and the AI that followed it lived in the same repo. It tripped over its own rules exactly when we asked it to improve itself.
While the system worked on other repos, this mismatch stayed hidden; it surfaced only when the system worked on itself. The trial-run log records it as the eighth mismatch found (Gap#8), with what happened, why, and the fix. Most facts in this post are quoted from that log.
Every AI that works in a repo reads its CLAUDE.md: the one chatting with a person and the one running alone, without distinction. From the reader's side, a rule is a rule.
How it ended
The fix had two parts. When starting the AI unattended, we add one sentence saying, in effect, that it may delegate to subagents but must wait for their result before moving on. And if the branch has zero commits ahead of main, the system does not push or open a pull request; it skips delivery and records in words what happened. Delegation itself was not banned. Only the waiting was fixed.
The first sentence is not an edit to the repo's CLAUDE.md. It is appended to the instructions only when the AI is started unattended. Its key parts read "you MUST run any sub-agent SYNCHRONOUSLY" and "NEVER run a sub-agent in the background or 'wait for a completion notification'", and it also asks the AI to check that every change is committed before finishing. The CLAUDE.md rule stayed as it was; we only added how to wait in an unattended run.
The second lets the system notice zero lines before GitHub has to say so. Until then, the only signal of an empty branch was GitHub's 422, and that 422 told us only that a pull request could not be opened. After the fix, the system counts the commits ahead of main before pushing, and if there are none it skips opening the pull request and records a message saying the actor (the AI working inside the system) did not commit any change, with the branch identical to its base.
Two pull requests after the fix
Then we asked for the same task again. This time the AI added exactly one line to the README, committed it, the branch had a diff, and a pull request was opened: #1, the first pull request in that repo. The diff was exactly one line.
The second-run AI committed its line itself. Working copy to branch, branch to GitHub: the line that stopped at step one the first time made it through all three steps.
We asked for the same task once more in the next check, and got PR #2. That AI did not touch the docs README; it appended the link to the end of an existing sentence in the top-level README.md. The "one line" that never left the working copy the first time had now arrived in two places.
Each pull request carries a short English summary of the task that the system writes before the work starts. The request said "docs/README.md", but the first sentence of both summaries said "the README.md file": the docs/ had dropped out. In the second-run pull request, the steps and limits still said docs/README.md, and the AI wrote to the docs README. In the third-run pull request, the docs/ was missing from the steps and limits too, and the AI wrote to the top-level README.
Both pull requests were then closed without being merged. The task had only ever been a way to see the loop go all the way around.
So today, neither README on main links to DOGFOODING-LOG.md. Counting from the day the AI reported "Added one line", the number of link lines that made it into the README is still zero.
First in a working copy, then in two closed pull requests. That one link has been written three times, and it has yet to reach main once.
Terms
- Subagent: another AI that a Claude Code conversation hands work to. It runs in its own context and returns a result to the parent
- CLAUDE.md: a rules file in the repo that Claude Code reads before it starts working
-
Unattended one-shot run: starting an AI with no person in the conversation; it answers once and exits. In Claude Code,
claude --printworks this way - Working copy: the folder where the system clones the repo and lets the AI work. Changes made there do not reach the branch until they are committed
- 422: the status code GitHub's API returns when it cannot process what it received. Here, it was a request to open a pull request from a branch with no changes




Top comments (12)
The 'all three were right' framing is what makes this stick — the AI, git status, and GitHub each told the truth about a different layer, and the bug was in the handoff between them. The part I'd steal is the trial-run log: without DOGFOODING-LOG.md recording each run, this would have stayed a shrug instead of a diagnosis. And the third run writing to the wrong README is a useful second lesson — the same pipeline can fail on the path, not just the commit.
This isn't a model failure, it's a completion contract failure — the parent delegated, waited for a notice, and its turn ended while the line sat uncommitted in the working copy. 'Added one line' was true and useless at the same time, and a push only carries commits, so GitHub's 422 was the honest one in the room. Where does the fix belong — in the coordinator, verifying a commit exists before it reports done, or in the system, refusing to push a branch with zero commits ahead of main?
One cheap check that covers this and the half-done case: fail the run if
git status --porcelainisn't empty after the agent finishes. A has-commits check catches run 1, but not a run that commits some files and leaves the rest in the working copy.This clicked for me as a mode mismatch: CLAUDE.md assumes an interactive coordinator that can wait for the implementer, but a
claude --printrun ends as soon as the parent answers. For unattended jobs I now keep a repo rule that LIGHT_EDIT shouldn't be delegated at all — the parent edits, commits, then exits. I'd also have the orchestrator refuse to push unlessgit log origin/main..HEADshows a commit andgit status --porcelainis empty, so a dirty working copy can't look like success."Both were true" is the hard part of this story. Coming from construction, it's the cabinet that got built in the shop and never loaded on the truck. The shop says it's done, the site says it isn't there, and neither one is lying. The work lived in the handoff between them, and nobody owned the handoff. A one-shot run that ends the moment the coordinator answers is the foreman clocking out before the delivery shows up. Checking whether the change is on the branch, and not whether the agent said so, puts the inspection where the house is. Three writes and zero arrivals on main is an honest number to publish.
The part I'd take from this beyond the fix: the AI's report and your own git summary agreed because they were reading the same place. Two checks that look at the same source aren't two checks, they're one check run twice. The only signal that was actually independent was GitHub's, and that's exactly why it was the one that caught it.
So when I design a "done" check now, I start from where the result has to exist for the work to count (here: the remote branch, compared against main, with the requested path in the diff) and check there, not wherever the agent happened to be working. Your zero-commits gate before push is that idea moved one step earlier, which is the right direction.
The third run is the detail that stayed with me — the summary dropping "docs/" and the agent faithfully writing to the wrong README is such a quiet failure mode, nothing errors, nothing looks wrong, and the work lands in the wrong place. And the punchline that the link has now been written three times and still hasn't reached main once is painfully funny. The bit I'd steal is the zero-commits-ahead check before push — GitHub's 422 was doing your validation for you until then. Do you run that check as part of the agent's own finish step now, or is it the system counting before it pushes?
Uehara, the detail that stayed with me is not the empty branch — it is that the same task produced three different outcomes across three runs: a 422 with zero commits, a PR that touched docs/README.md, and a PR that touched the top-level README because "docs/" had dropped out of the steps and limits. Your fix solves the first failure, the waiting one, but the third run shows a second failure hiding behind it: the instructions themselves drifted between runs, and nothing in the loop noticed.
The concrete step I would take: record the exact instructions hash next to each run's diff in DOGFOODING-LOG.md, so a failure can be traced to "the prompt changed" versus "the agent behaved differently on the same prompt." Right now the log records what was asked, but if the asking itself drifts run to run, the log cannot tell those two apart.
And since the system already runs git status --porcelain and git diff --stat HEAD to write the change summary, the zero-line check you added could be a hard gate before push — fail the run if the reported "1 insertion" is still uncommitted, instead of letting GitHub's 422 be the first signal. One question: in run 3, did "docs/" drop out because the system regenerated the steps from the previous run's output, or because the instructions were edited between runs?
The third run suggests a separate delivery check: keep the original requested path outside the generated summary, then compare it with the files in the committed diff before opening the PR. A nonempty branch proves something was committed; it doesn't prove the requested file was changed. Flag unexpected paths for review rather than silently accepting the summary as the specification.
We hit a cousin of this. A long job I started from a session died with the session, and its last message still said "running". Like your "added one line", it was true when it was written. Since then I trust the state, not the report: git log before I believe "done", the process list before I believe "running".