Skip to content

0007 - Agent Code Review and Merge

Status

Accepted. Builds on ADR-0006.

Amended 2026-10-06 by ADR-0011 decision 6: decisions 2–3 of The loop now also require the reviewer to bring the pull request branch up to date with its base before it approves — update the branch with the latest base, wait for the checks and run the tests again. When that update conflicts, the reviewer now ends with the out of date verdict (below) if the content is approved, and asks for changes only when the content itself needs them. This catches conflicts between pull requests in the same repository that Gitea still reports as mergeable, such as two migrations given the same number, once a runner works on several tasks at once. Whether Gitea should also enforce it with "block merge on outdated branch" is a branch-protection decision left to the owner.

Amended 2026-10-10: a fourth verdict, out of date, for a pull request whose content is approved but whose branch conflicts with its base. It does not use up a review round and sends the task back for a merge-only run (decision 6 of The loop and Why out of date is its own verdict). Taskbase task #758, agent-runner task #759.

Amended 2026-10-12 by Taskbase task #874: the reviewed PR may be in another repository under the organization's gitea_org when that repository is linked to a project in the same Taskbase organization. The original task's project still controls review settings, verdicts and rounds.

Touched 2026-10-27 by ADR-0024 (accepted; task #1741). Review is still set per project by review_persona: routing review by the author's role (reviewer_role, ADR-0024 §7.2) is a later step behind this ADR's deferred "reviewer persona chosen per task" trigger, and is not built. What shipped in v1 that touches review: a paused organization holds its reviews too, and a review run that creates or reassigns tasks follows the review persona's role in the organization's team (the delegation rule).

Amended 2026-11-03 by decision #2421 and Taskbase task #2422: a fifth verdict, merge_handoff, for a drain-class pull request (label drain-before-merge). The reviewer approves without merging, and the implementer merges it in a merge run (decision 9 of The loop).

Date

2026-09-24

Context

With ADR-0006 an agent takes a task, works in a fresh clone and opens a pull request that closes the task's Gitea issue. A person then reviews and merges it; only then does the task reach Done. For routine work that person is the bottleneck.

We want a second agent to review that pull request and, when satisfied, merge it — and, when not, to send the work back to the developer agent with its feedback, without a person in the loop until the agents cannot agree.

Two constraints shape the design:

  • Gitea does not let a user approve or reject their own pull request, though an author may merge it when no branch protection requires approvals. A reviewer with the author's identity can only leave its verdict as a comment review.
  • Taskbase decides what runs; the repository decides what may merge. Branch protection, required checks and merge style stay in Gitea, as ADR-0005 intended. The reviewer works within them.

Decision

Review is opt-in per project

A project gets an agent review setting:

Field Meaning Default
review_persona persona that reviews; setting it turns review on none (off)
review_model model tier or id for reviews the runner's default
review_labels labels a runner must have to take reviews role=reviewer
review_max_rounds review rounds before the task goes to a person 3

The loop

sequenceDiagram
    participant Dev as Developer agent
    participant TB as Taskbase
    participant Rev as Reviewer agent
    participant Gitea

    Dev->>Gitea: push branch, open pull request closing the issue
    Dev->>TB: finish succeeded with the pull request link
    TB->>TB: task to Review, queue a review run on the same task
    Rev->>TB: claim the original task as a review run
    Rev->>Gitea: check out the branch, read the diff, run the tests
    alt approved
        Rev->>Gitea: approve and merge
        Gitea-->>TB: issue closed, task to Done
    else changes requested
        Rev->>Gitea: review with comments
        Rev->>TB: finish with verdict changes requested
        TB->>TB: requeue the task with the feedback
        Dev->>Gitea: push fixes to the same branch
    else blocked
        Rev->>Gitea: review as a comment, explaining the blocker
        Rev->>TB: finish with verdict blocked
        TB->>TB: task to Blocked, same round kept
    else out of date
        Rev->>Gitea: review as a comment naming the conflicting files
        Rev->>TB: finish with verdict out of date
        TB->>TB: requeue the task for a merge-only run, same round kept
        Dev->>Gitea: merge the base into the same branch, resolve conflicts
    end
  1. A review run is queued on the original task when an agent task enters the project's Review column and has an associated pull request. The run uses review_persona, review_model and review_labels; its role and round are stored on task_runs. No review task or Gitea issue is created. A successful implementation run moves the task to Review as before.
  2. The reviewer checks out the pull request's branch, compares the diff with the task, runs the repository's tests, and ends with a verdict line the runner reads: Verdict: approved, Verdict: changes requested, Verdict: blocked or Verdict: out of date (the runner also accepts out-of-date and out_of_date, and reports it as review_verdict: out_of_date).
  3. Approved: the reviewer approves and merges, but only if Gitea reports the pull request mergeable and its required checks pass, using the repository's merge style. The merge closes the issue and the Gitea sync moves the task to Done, as before. The verdict stays in the original task's run history.
  4. Changes requested: the reviewer submits a review with specific comments. Taskbase moves the original task back to In Progress and queues it for implementation; the claim carries the pull request link and review summary, and the developer agent pushes fixes to the same branch. Moving the task back to Review starts the next round.
  5. Blocked: the pull request is correct, but something outside it stops it merging — branch protection, a required approval the agent cannot give, broken CI infrastructure — and no code change can fix it. The reviewer leaves its verdict as a comment review explaining the blocker and who can clear it. Taskbase moves the original task to Blocked (needs_attention) without queuing a revision run, and does not advance the round: a requeue once the blocker is cleared claims the same round again. This is distinct from a reviewer merely commenting because Gitea refused its own APPROVED or REQUEST_CHANGES review (below) — that still reflects an approved or changes-requested verdict, just posted as a comment.
  6. Out of date: the content is approved, but the branch cannot be brought up to date with its base without resolving conflicts. (A branch that updates cleanly the reviewer updates itself, and approves.) The reviewer does not resolve the conflicts: it posts a comment review saying the content is approved and naming the conflicting files, and ends with Verdict: out of date. When the content itself needs changes, it ends with Verdict: changes requested instead and mentions the conflicts too.
  7. No round used: like blocked, the verdict is not counted as a review round, and it never moves the model tier.
  8. Merge-only run: like changes requested, Taskbase moves the task back to In Progress and queues an implementation run; its claim carries revision.verdict = "out_of_date". The runner then tells the agent only to git merge origin/<base> into the pull request's branch, resolve the conflicts keeping both sides' intent, re-run the build and tests, and push to the same branch without rebasing or force-pushing — changing nothing else — and to summarise which files conflicted and how it resolved each. The task then goes back to Review, and that review claims the same round as the one that found the branch out of date, even when it is the last.
  9. Loop guard: after 3 consecutive out of date verdicts on a task (no approved or changes requested in between), the task goes to Blocked (needs_attention) instead, with the reason "the pull request keeps falling behind its base; consider running related tasks one after another" and an attention event with reason review_out_of_date.
  10. Round limit: after review_max_rounds counted rounds — review runs other than blocked and out of date — the task goes to Blocked (needs_attention) for a person instead of another round. Requeue, the claim and moving a card into Review all count rounds this way.
  11. A review run with no verdict line is treated as failed: the original task needs attention.
  12. Merge hand-off (added 2026-11-03, decision #2421, Taskbase task #2422): a drain-class pull request, labelled drain-before-merge, takes a service every run needs offline, so the operator merges it around a drain. The reviewer approves it without merging and reports review_verdict: merge_handoff.
  13. No round used, and Taskbase queues an implementation run whose claim carries revision.verdict = "merge_handoff": a merge run. Its merge closes the task as usual.
  14. Loop guard: a second merge_handoff in a row means the merge run left the pull request open; the task goes to Blocked (needs_attention) with reason review_blocked and the detail "the merge run ended without merging the approved pull request".
  15. It counts as an approval in approval rates. Details: Merge hand-off.

Escalating the model tier

A revision does not always run on the task's own tier. Round 1's "changes requested" is often a small fix — a commit message, a missing comment — so its revision still runs on the task's own tier. From round 2, each "changes requested" whose revision is queued moves the task up one tier (small → medium → large, capped at large) before the revision is queued; review_max_rounds still caps the rounds, escalated or not.

A failed implementation or revision run (outcome failed, not reason usage_limit) is requeued once, one tier up, instead of going to Blocked — unless the run before it (ignoring lost and usage-limit runs) also failed, or the task is already at large, when it goes to Blocked as before.

Escalation reads only signals about the work's quality: a usage_limit failure, a cancelled or lost run, a person's requeue, a legacy review task, and a blocked or out of date verdict never move the tier — only changes_requested does. A task pinned to an explicit model id never escalates, since there is no tier to move. The persona assigned to the task is unchanged either way; escalating it too is deferred (see below).

A project turns this off with escalate_models (default on); see Runners and Runs.

Amended 2026-10-01: a revision or a retry can move a task up a model tier, as above.

Why out of date is its own verdict

In europehub (Emmalia), pull requests #113 and #141 ran out of review rounds although every reviewer approved their content. Three pull requests edited the same files, so each time one merged, the others no longer merged into main. Each review then said, in effect, "content fine, but resolve the conflicts with main" and returned changes requested, which counted as a round; after review_max_rounds the tasks were parked for a person. Rounds spent only on keeping a pull request mergeable should not use up the review budget, so that case gets its own verdict. The loop guard still stops a pull request that keeps falling behind, since running the related tasks one after another is then the better fix.

Amended 2026-10-10: added with the out of date verdict.

Who reviews: any runner with the label, under its own identity

A runner has one identity (ADR-0006). A runner that should review adds role=reviewer to its labels and then takes review runs alongside implementation work, one at a time — often reviewing pull requests its own account opened. The independence of the review comes from a fresh session with the reviewer persona, not from a second account: the verdict is recorded on the review run in Taskbase, and in Gitea the review is a real approval or, on its own pull request, a comment review followed by the merge.

Amended 2026-09-26: the first version required a separate reviewer runner with its own Keycloak and Gitea accounts, so that Gitea would record an approval from someone other than the author. That split one machine's identity in two for a record nothing depends on while no repository requires approvals.

Where a repository does require approvals, or reviews should run elsewhere, a runner may set a dedicated label: it then claims only tasks whose required labels include it. A runner with its own accounts dedicated to role=reviewer never takes implementation work, and gives Gitea an approval from someone other than the author.

Board

The original task stays in Review while it is being reviewed, goes back through In Progress when requeued for changes, and reaches Done on merge. Implementation and review runs both stay on the original task, with separate usage totals.

What we deferred (and what would trigger adding it)

Concept Trigger to add
Escalating the persona, not just the model tier Escalated runs still fall short because of the persona's scope rules
Review of pull requests opened by people People want agent review on their own pull requests
Several reviewers or a required human approval per change A class of change needs more than one pair of eyes
Reviewer persona chosen per task rather than per project Tasks in one project need different kinds of review
Automatic retry when merge is blocked by failing checks Flaky checks routinely block good pull requests
A separate reviewer identity by default A repository requires approvals from someone other than the author