AI coding

A Fixed Review Order for Ten Finished Agent Branches

Antonio Evans10 min read

A flat overhead view of a review desk: ten finished agent branches drawn as ten short parallel tracks feeding into a single conveyor belt.
Key points

Key points

  1. 1Parallel git worktrees give each agent an isolated directory, which moves the constraint from merge conflicts to the human review queue.
  2. 2Apply four gates in a fixed order: automated checks pass, diff size within a set limit, touched paths inside an allowed set, then a human logic read.
  3. 3Reject or send back at the first failing gate, so a branch that fails checks never costs a logic review.
  4. 4Batch the survivors by shared path and review one batch at a time, so total review time grows with failing gates, not with agent count.

Why parallel worktrees make review the constraint

A git worktree is an additional working directory attached to the same repository and the same history, so several branches can be checked out at once in separate folders the git-worktree documentation. The Nx team documents the pattern that agents made routine: create a worktree per issue, start the agent there, and keep editing your own checkout while it works in the background the Nx blog on worktrees. Laurent Kempé records the scale change that follows, from three worktrees kept for development and review to running one agent per worktree across projects the account of moving from three worktrees to N.

Isolation also protects correctness. A very common setup is one bare repository with a hidden metadata folder and a sibling directory per branch, so each task has its own checkout while sharing one history a practical bare-clone worktree setup. Espressif's workshop adds the agent-side discipline: a single request can change several files, and every changed file must belong to the task the Espressif agent Git workflow.

What worktrees do not fix is the last step. Ten agents finish, and one person has ten diffs to read. Attention does not parallelize the way directories do. The queue becomes the constraint, and the only way to keep review time flat is to stop paying full attention to branches that fail cheap checks.

The cost curve is documented. An analysis of more than 50,000 pull requests across more than 200 engineering teams reports 40 percent fewer defects in changes of 200 to 400 lines than in larger ones, about 25 extra minutes of review per additional 100 lines, and 70 percent lower defect detection above 1,000 lines the PR size data study. The same source reports 87 percent detection for 1 to 100 lines, 65 percent for 301 to 600, and 28 percent above 1,000, with meaningful comments falling from 3.2 per change to 1.8 as size grows.

Treat those as that study's findings rather than universal constants, but the shape gives you the decision rule: reading a big diff carefully costs hours and finds less. A gate that stops large diffs before the logic read protects the scarce resource you have.

Gate 1: automated checks pass before a human looks

The first gate is the cheapest and should be fully automated: build, tests, linters, type checks, secret scanning. If a branch fails, it goes back to the agent and no human opens the diff.

This is the largest saving in the order. Ten branches that each fail a test suite cost zero reviewer minutes instead of ten partial reads. The reviewer's first action is to sort the branch list by check status and discard the red ones.

Two conditions make the gate trustworthy. Checks must run on the branch as submitted, in the environment the merge target uses, not on the agent's local assumption. And the agent must be able to read the failure output, or it will resubmit the same broken branch. Espressif's guidance points the same way: build and test the affected project before committing the Espressif agent Git workflow.

You can script the sort. Commands differ by forge, but the logic is universal: check out each branch, run checks, print one line with the outcome.

#!/usr/bin/env bash
# Gate 1 triage: one line per agent branch, checks first
set -uo pipefail
BASE="${BASE:-origin/main}"
for branch in $(git for-each-ref --format='%(refname:short)' refs/heads/agent/); do
  git switch --quiet "$branch" || { echo "SKIP $branch (checkout failed)"; continue; }
  if ./ci/check.sh >/dev/null 2>&1; then
    status="PASS"
  else
    status="FAIL"
  fi
  lines=$(git diff --shortstat "$BASE"...HEAD | awk '{print $4+$6}')
  echo "$status ${lines:-0} $branch"
done

Sort the output and ignore every FAIL line for the rest of the session. The list you carry forward is shorter, and nothing on it has a known broken build.

Gate 2: diff size within a set limit

The second gate is a number. Pick a maximum changed-line count for a branch that gets a human read and send anything above it back to be split. The 400-line ceiling is a defensible starting point, because the 200 to 400 band is where the size study found the best reported mix of detection, review time and engagement the PR size data study. The same source suggests tighter limits by change type: under 100 lines for bug fixes, 200 to 400 for one cohesive feature, 300 to 500 for one logical refactor, under 50 for configuration.

Measure from the merge base to the branch head, count additions and deletions, and exclude generated or vendored files so agents cannot pad a diff with formatting. Be explicit about what does not count.

Change typeSuggested ceilingReason
Bug fix100 linesForces a surgical change and a regression test
New feature, one slice400 linesInside the band with the best reported detection
Refactor, one pattern500 linesA repeated transformation reads faster than raw size implies
Config or dependency change50 linesHigh blast radius, low reviewability
Docs onlyNo hard limitLow production risk, still gate on paths

The Karpathy guidelines skill states the principle behind the ceiling: minimum code that solves the problem, nothing speculative, and if you write 200 lines and it could be 50, rewrite it the skill source. A branch that blows past the ceiling is usually an agent adding flexibility nobody asked for. Returning it with the line count and the ceiling is a complete, unambiguous instruction.

Allow one documented exception: a mechanical rename or format change across many files, where the diff is a single repeated transformation. Review the pattern once rather than line by line. Make the agent state the pattern in one sentence; if it cannot, the gate stands. Skills are portable Markdown instructions rather than provider-specific code, so the same guideline text can be installed in any agent that reads SKILL.md the skill listing.

Gate 3: touched paths inside an allowed set

The third gate checks where the branch went, not how far. A 120-line diff that edits a migration, a lockfile and a CI workflow is riskier than a 400-line diff confined to one feature folder. Path review is fast because it is a set comparison, not a reading task.

Path stateExamplesVerdict
AllowedFeature directories, tests beside them, docs for the same featurePass to Gate 4
Allowed with labelShared utilities, public interfacesPass, tag for extra care
ForbiddenMigrations, lockfiles, secret or env files, CI config, unrelated top-level foldersSend back
SuspiciousDeletions of files the task never named, new dependency manifestsSend back with a question

Espressif's checklist is the same test in other words: every changed file belongs to the task, generated files are intentional, and no credentials or build artifacts were added the Espressif agent Git workflow. The Karpathy guidelines call it surgical changes: touch only what you must, do not improve adjacent code, do not delete pre-existing dead code unless asked the skill source. A related project documents guarding agent edits against scope creep, in the spirit of the same rule a scope-guard plugin.

Generate the path list mechanically, not by eye:

BASE=origin/main
git diff --name-only "$BASE"...HEAD \
  | sed 's#/[^/]*$##' | sort -u

Read the folder list, not the diff. If a folder appears that the task description did not name, the branch stops here. A bare-repository layout makes this cheap, because every branch already sits in its own worktree and you can run the command without disturbing your own checkout a practical bare-clone worktree setup.

Gate 4: the human logic read, batched by shared path

Only branches that pass three gates reach a human reading logic. The read covers four things: does the change do what the task asked, is control flow correct at the edges, do the tests exercise the behavior, and will the names or comments mislead the next reader.

Two rules keep this gate from expanding. Read the diff, not the whole file, unless a changed line calls something the diff does not show. And stop at the first substantive concern, sending the branch back with the concern named. One pass with a clear rejection beats a full reading plus ten minor notes.

Batching is what keeps total time flat as branch count grows. Group survivors by the folders they touch and review one group per sitting, so you load each file's context once instead of once per branch. Six branches touching three shared modules become three batches, not six sessions. Espressif's practice of small, coherent commits supports this: commit after each verified state rather than at the end of a large task, which keeps each reviewable unit small the Espressif agent Git workflow.

The evidence supports batching for a second reason: attention decays inside a session. The size study found fewer meaningful comments on larger changes despite longer review time, and attributes it to cognitive overload and approval bias the PR size data study. A batch of small diffs in one area keeps each change inside the range where scrutiny stays high.

Know the limit of automation here. An empirical study of pull request acceptance found that static-analysis quality flaws did not influence whether a maintainer accepted or rejected a change, with only a few rules considered at all the study on code quality and pull request acceptance. Automated findings are a filter in front of the logic read, not a substitute for it. That is exactly the role Gates 1 to 3 play: they decide what gets read, not whether reading happens. A research overview maps the wider literature on how change size, ordering, tests and explanations affect reviewers the code review research overview, which is a better guide than intuition if you want to tune the limits beyond the starting values.

A worked example with ten branches

Ten agents finish, each with a task description, a diff and a check status. Apply the gates in order and count reviewer minutes, using illustrative per-branch costs: check triage 2 minutes, size check 1 minute, path check 2 minutes, logic read 25 minutes for an accepted diff.

BranchGate 1 checksChanged linesPathsOutcomeReviewer minutes
a1FAILnot measurednot checkedBack to agent2
a2PASS1,240feature A onlyBack: split3
a3PASS180feature A, testsGate 428
a4PASS340feature BGate 428
a5PASS90migrationBack: forbidden path5
a6PASS260feature B, shared utilsGate 4, extra care30
a7FAILnot measurednot checkedBack to agent2
a8PASS410feature CBack: over ceiling3
a9PASS150docsGate 4, quick15
a10PASS220feature AGate 428

Six branches fail a gate before any logic read, at 15 reviewer minutes. Four reach Gate 4, batched by path into feature A (a3, a10), feature B (a4, a6) and docs (a9), at 101 minutes. The session costs about 116 minutes, and the largest block is the batched logic read.

Compare that with reading all ten diffs without gates. Using the size study's figures as an illustration, 4.2 hours for an oversized change and 1.5 hours for a mid-sized one turn the same ten branches into a queue measured in days the PR size data study. The gates do not make reading faster. They make most branches cheap to reject, so reading time goes only where a read can change the outcome. Review time now scales with the number of branches that fail their first gate, which you can reduce by improving agent instructions, not with the number of agents you run.

Instrumenting the queue so it stays flat

A fixed order stays flat only if you can see which gate does the work. Log three numbers per branch: the gate that stopped it, the changed-line count, and the number of touched folders. After a few batches you will know whether the ceiling is right and whether path failures cluster on one folder.

Agent session capture helps when a branch fails a gate for a reason the diff does not explain. A command-line tool that hooks into your Git workflow to record agent sessions makes it possible to reconstruct what an agent did the Entire CLI. If you build your own harness, the branch prefixes and checkpoints in Espressif's workflow are a reasonable model the Espressif agent Git workflow, and the bare-clone layout keeps one folder per branch a practical bare-clone worktree setup.

Two metrics belong on a dashboard: median reviewer minutes per passed branch, and the share of branches stopped at Gate 1. If the first climbs, your ceiling or batching groups are wrong. If the second falls, agents are shipping broken builds, and the fix belongs in their instructions or their test access, not in review.

For teams that want the triage commentary generated by a model, one endpoint for several model kinds keeps the script simple: Quanta Inference serves text, image, video, audio and embedding models through one OpenAI-compatible API key (https://quantaintelligence.ai/inference). The per-branch cost of a summarizer is the point of the gate, so route it through something predictable.

FAQ

FAQ

Why is the order fixed instead of reviewing the most interesting branch first?

The order runs from cheapest and most objective to most expensive and most subjective. Automated checks and line counts take seconds and return a clear verdict; a logic read takes tens of minutes and is the only step that does not scale. Reversing the order means paying the expensive step on branches that would have failed a cheap one.

What if a branch is large but genuinely correct?

Send it back anyway, or invoke a documented exception. The size study found that larger changes get longer review and fewer meaningful comments, so a large correct diff still consumes attention you need for the next branch the PR size data study. If the change is one repeated mechanical transformation, allow it and review the pattern once.

Should the same person run all four gates?

Gates 1 to 3 should be scripted where possible and can be run by anyone, including the person who launched the agents. Gate 4 is where a second reviewer adds value, especially for branches tagged at Gate 3 for touching shared interfaces. Keep one owner for the queue so batching by path stays consistent.

How does batching by path interact with a stack of dependent branches?

Treat a dependent stack as one batch unit if the branches touch the same files, and review in dependency order so each read builds on the previous one. If the stack crosses folders at Gate 3, split it and review the foundational branch first. Stacks are the normal way under the ceiling: a 1,200-line feature becomes three 400-line branches.

Does this order work for non-code artifacts such as docs or configuration?

Yes, with different gates. For docs, Gate 1 is a link and spell check, Gate 2 can be waived, and Gate 3 checks that no unrelated page was rewritten. For configuration, keep a very low ceiling and treat any change to deployment paths as a Gate 3 stop, because the blast radius is high and the diff is easy to read too quickly.

Sources

Sources

  1. Git - git-worktree Documentation
  2. How Git Worktrees Changed My AI Agent Workflow | Nx Blog
  3. Laurent Kempé - From 3 Worktrees to N: How AI Agents ...
  4. Set up a local repository in which every branch is checked ...
  5. AI agent coding for ESP-IDF workshop - Optional: Git workflow for agent ...
  6. The Impact of PR Size on Code Review Quality: What Data ...
  7. skills - karpathy-guidelines - GitHub
  8. Karpathy Guidelines by multica-ai, AI Skill for Any LLM | TypingMind
  9. GitHub - atoolz/scope-guard: Stop AI scope creep. A Claude Code plugin ...
  10. Does code quality affect pull request acceptance? An ...
  11. Overview of Code Review Research
  12. GitHub - entireio/cli: Entire CLI hooks into your Git workflow to capture AI ...
About the author

About the author

Antonio Evans
Antonio Evans

Antonio Evans is the founder of Quanta Intelligence and a fractional CTO who builds HIPAA-ready AI systems for health and life-science companies. Before that he was technical co-founder of FriendsEAT for twenty years, CEO of Socialdraft, and a data engineer at IBM. Antonio lives with his dog Santino in Lisbon, Portugal.

All articles