Checking pull requests an AI coding agent wrote: four layers before a person merges
Much of the code in our repositories is written by an AI coding agent from a GitHub issue, so we had to decide what has to be true before a person merges what it wrote. This log describes the four layers every pull request now passes, why each one was added, and what they caught. The counts come from the pull requests and review comments in our repositories, as of November 10, 2026; the references at the end name the records.
Background
Our setup is an issue-driven "factory". A person writes an issue with the decisions, the scope and the done criteria. Labelling it starts Claude Code in GitHub Actions, which implements the change on a branch and opens a pull request. A watcher process on the maintainer's machine then moves each pull request one step at a time: asks the agent to fix a failing check, asks for a review, and finally hands it to the owner with a merge command. The question is what that hand-off should be based on, when the author of the code also writes the description of what it did.
Options we weighed
- A person reads every diff. Safe, but the reading becomes the bottleneck and gets shallower as the volume grows.
- Trust the tests the agent ran. The agent can change the tests in the same pull request, and a green run only proves the tests that exist.
- Layers that do not depend on the agent's own account. Machine checks that compare against the base branch, a review by a different model, and merge rules that fail closed. We built this, one layer at a time, each after a concrete gap.
The four layers
1. Machine checks on every pull request.
- Quality: the repository's own lint, type check and tests.
- Secret scan of the commits the pull request adds, with a pinned scanner. A finding is never silenced in the repository: only the owner accepts it.
- Tests kept: the test IDs collected on the base branch and on the head are compared. A test that disappears does not fail the check (renames are common), but it blocks automatic merging and shows up in the review.
- Outcome: an issue can list machine checks of its done criteria (a file exists, a command answers a certain way). The check runs them on the head of the pull request, so "done" is decided by the result, not by the agent's summary.
2. A review by a different model. Once the checks pass, Codex reviews the pull request read-only and posts its verdict as a comment. Each finding carries a weight (blocking, major, minor) and who could cause the problem: someone outside, or only the owner on their own machine. Only blocking and major findings that someone outside can cause ask for changes; the rest come with an approval and are collected for a later retrospective.
3. A final advisory review. After Codex approves, Claude reviews the pull request once more. It does not block anything; its verdict is shown to the owner with the merge command.
4. Rules for merging without a person. Small changes from issues the owner has marked for it can be merged by the watcher, but only when every rule passes: the commits are the agent's, both reviews approve the latest commit, the outcome check passed on the issue as it is now, the change is within a size limit (200 lines in 10 files at the first stage), it touches no workflow, dependency or security file, and no test was removed, skipped or lost assertions. Anything the rules cannot read means "ask the owner".
Why each layer exists
- The second review was made mandatory for pull requests we write by hand on October 26, after a review of one change (running the implementing agent in a sandbox) found four blocking security problems that the tests had not.
- The outcome check came from noticing that nothing checked the done criteria themselves: the quality check runs the existing tests, and a reviewer can take the pull request's description at its word.
- Weighing findings replaced a fixed limit of two review rounds. On one pull request the reviewer raised a different serious problem in each of three rounds; stopping at two would have meant merging with a known major problem. Counting only rounds with serious findings keeps minor back-and-forth from going on forever.
- Not failing on a lost test came from the opposite problem: intended renames showed up as red failures, and a check that is red for intended changes stops being read.
Results
| What we counted | Count |
|---|---|
| Pull requests with a Codex review (7 repositories) | 303 |
| Reviews posted on them | 480 |
| Reviews that asked for changes | 153 |
| Pull requests whose first review asked for changes | 72 |
| Merged pull requests (9 product and factory repositories) | 460 |
| Of those, merged by the rules without a person | 48 |
About one review in three asked for changes, and roughly one pull request in four did not pass its first review. We did not measure how many of those findings would have caused a real failure, so these numbers show how often the second look disagreed, not how much it prevented. Automatic merging stayed a small share: most changes still touch a workflow, a dependency, or more lines than the limit.
Lessons learned
- The agent's report is not evidence. Checks that compare against the base branch and run the issue's own criteria give the reviewer and the owner something that does not depend on the author.
- A different model finds different things. The reviewer regularly flags tests that were weakened along with the change, including in our own hand-written pull requests.
- Weight beats count. A cap on rounds either stops too early or invites endless minor fixes. Asking for changes only on serious findings that an outsider can trigger is the rule we use now; we will see whether it holds as the volume grows.
- Fail closed everywhere. Every rule that cannot read its input says "a person decides". That keeps the automatic path narrow, which is the point.
Next steps
We plan to record, for each finding, whether it was fixed and whether it was right, so that the next version of this log can say how much the reviews prevented rather than how often they disagreed.
References
Our own records (private repositories, named here so the claims above can be traced):
- ziv-labs/agentic-factory-vnext CLAUDE.md, docs/overview.md — the issue-driven process, the checks, the reviews and the merge rules
- ziv-labs/agentic-factory-vnext PR #47 — the review that found four blocking security problems; second reviews mandatory from October 26
- ziv-labs/agentic-factory-vnext #28 — running the issue's done criteria on the pull request head (outcome)
- ziv-labs/agentic-factory-vnext #74, scripts/auto_merge.py — the rules for merging without a person, and their limits
- ziv-labs/agentic-factory-vnext #138 — a lost test blocks automatic merging but does not fail the check
- ziv-labs/agentic-factory-vnext #189 — review rounds by the weight of findings instead of a fixed count
- seven ziv-labs repositories Codex review comments — the counts in the table, as of November 10, 2026
Related notes
- Testing AI-generated code against the spec — Claude Code and Codex each wrote a semver comparison and its tests, five runs each. All matched a spec oracle; only Claude Code's tests missed an injected bug.
- Claude Code or Codex: which permission setup fits the task? — Four harmless steps run through Claude Code and Codex in two setups each: what was done, stopped or refused, with the test's limits stated and no ranking.