Human approval gates for AI coding agents
Sometimes you want a person to say yes before an agent's change lands. This pattern pauses the Run at a human gate, shows the reviewer what they're approving, gives the wait a timeout with a safe default, and pins the merge to the exact commit that was approved.
Part of the Patterns for a software factory series.
The problem: approvals that stall, or approve the wrong thing
Most teams that run coding agents end up with the same rule somewhere: "a human has to approve this before it merges." Maybe it's anything touching auth, maybe it's database migrations, maybe it's everything for the first month while you build trust.
The rule is easy to say. It's harder to make work, and it usually breaks in one of two ways.
The approval stalls. The agent opens a PR, someone is supposed to look at it, and nobody does. A week later there are fifteen of these, all slightly out of date, and the factory has quietly turned into a queue.
The approval lands on a moving target. Someone looks at the change, says "looks good", and then a new commit gets pushed. Maybe the agent kept going, maybe someone fixed a test. The "yes" was for one version of the code, and a different version merges. Nobody did anything wrong, and the approval still meant very little.
A human approval gate is the pattern that fixes both: the factory waits for a person in a way that's visible, bounded, and tied to one specific commit.
The pattern
Four moves:
- A pull request arrives and the factory does whatever automatic work comes first: classify the risk, summarize the change, run a reviewer.
- The Run pauses at a gate. The gate shows the person what they're deciding on (the PR, the commit, the agent's summary) and a small form to fill in.
- The wait has a deadline. If nobody answers in time, a default applies, and the default is the safe answer: not approved.
- The merge is pinned to the reviewed commit. If the branch moved while the person was looking, the merge refuses, and the new commit goes through its own Run.
The idea underneath is the same one as the rest of the series: the agent can do the work, but the decision about what lands is held by the factory, and here, by a person.
How it looks in dotFactory
In dotFactory this is a human gate, a step with kind: gate. It doesn't run anything. It suspends the Run until a person answers a form, and the form is just the step's out: ports. An enum becomes a select, a ? makes a field optional. The in: values are the context the reviewer sees.
Here's a version that starts from the PR with the kind: github trigger (it fires on opened, synchronize, and reopened), has an OpenCode agent write a short summary for the reviewer, waits at a gate, and then either merges with github_merge or leaves a review with github_comment. The agent's key comes from credential and the GitHub calls use a scoped github_token:
type PullRequest = { number: int, url: text }
type AgentCall = { token: secret, prompt: text }
type Summary = { what: text, risks: text }
type Verdict = enum { approved, rejected }
type GithubAccess = enum { read, write, admin }
type GithubScope = map(text, GithubAccess)
external port credential(key: text) -> secret
external port github_token(repo: text, scope: GithubScope) -> secret
runner agent:
kind: opencode
in: AgentCall
out: open
trigger on_pr:
kind: github
config: {
path: "/api/github/webhook"
target: { one: { repo: "acme/app" } }
event: pull_request
actions: ["opened", "synchronize", "reopened"]
}
out: { pr: PullRequest, commit: text }
step summarize:
runner: agent
in:
token: credential(key: "agent")
prompt: "Summarize this change for a reviewer: what it does, and what could go wrong."
pr: on_pr.pr
commit: on_pr.commit
out: { summary: Summary }
step approve:
kind: gate
config: { timeout: "1d", default: { verdict: rejected } }
in:
pr: on_pr.pr
commit: on_pr.commit
summary: summarize.summary
out:
verdict: Verdict
note: text?
step merge:
kind: github_merge
when: approve.verdict == "approved"
config: { method: "squash" }
in:
token: github_token(
repo: "acme/app"
scope: {
"contents": "write"
"pull_requests": "write"
"checks": "read"
"statuses": "read"
}
)
repo: "acme/app"
number: on_pr.pr.number
sha: on_pr.commit
body: summarize.summary.what
step push_back:
kind: github_comment
when: approve.verdict == "rejected"
config: { event: "REQUEST_CHANGES" }
in:
token: github_token(
repo: "acme/app"
scope: { "pull_requests": "write" }
)
repo: "acme/app"
number: on_pr.pr.number
body: "Not approved at the gate (or the gate timed out). Have a look at the Run for the reviewer's note."
A few things worth pointing out.
The reviewer sees what they're approving. The gate's in: carries the PR, the commit, and the agent's summary. If you want the reviewer to see the full description and discussion too, the pr_context port fetches the PR's body, comments, and changed files, and you can hand that to the summary step.
Nobody has to go hunting. While the gate is pending, the Run shows as waiting and the run page shows the form. There's also a pending-gates list across all your factories, so a reviewer has one place to look.
The timeout never invents a yes. timeout: "1d" bounds the wait and default: { verdict: rejected } is what applies when it runs out. The rejection path posts a "request changes" review, so the PR doesn't just sit there silently. If you leave out the default, the gate keeps waiting past the deadline instead, which is honest but brings the stall problem back.
The approval is pinned. The merge gets sha: on_pr.commit, the commit the reviewer was shown. github_merge re-reads the PR and refuses if the head moved, if CI on that commit isn't green, or if a review of that commit carries a :hold. A new push fires the trigger again as synchronize, so the new commit gets its own Run and its own gate. An old "yes" can't carry over to new code.
One answer, final. A gate resolves once. If two reviewers click at the same moment, the second submission is refused. No double merges, no flip-flopping.
When to use it, and when to skip it
Use it when:
- The change is something you'd never want landing unseen: auth, payments, migrations, infra.
- You're early with agents and want a person on every merge while you learn how the agent behaves.
- You want the approval recorded next to the Run, not lost in a chat thread.
Skip it (or narrow it) when:
- Most PRs are small and boring. Gating everything trains people to click "approve" without reading, which is worse than no gate. Put risk-based review routing in front, so only the risky ones reach a person.
- Your reviewers already live on GitHub and are happy reviewing there. Then a comment that leaves the PR open may be enough, and you don't need the factory to wait.
- Nobody has time to answer. A gate with no one behind it is just a slower "no". Fix the staffing before adding the step.
A gate also pairs well with an adversarial reviewer in front of it: let a second agent try to break the change first, and give the person its findings along with the summary. And if you need to stop things fast without answering forms, that's the hold and kill switch pattern. Stopping a Run cancels the gates it was waiting on.
For the bigger picture of who should sign off on agent code, see Who signs off on code an agent wrote?, and for why the rules belong in a file rather than a prompt, Put your software factory in a file.
Frequently asked questions
What is a human approval gate for AI coding agents?
It's a step in the workflow that pauses until a person approves or rejects, before the agent's change can merge. In dotFactory it's a kind: gate step: the Run waits, the reviewer fills in a small form, and their answer decides what happens next.
What happens if nobody approves?
You choose. With a timeout and a default, the default applies when time runs out, and it should be the safe answer, like rejected. Without a default, the gate just keeps waiting until someone answers or the Run is stopped.
What if new commits are pushed after I approve?
They don't ride on your approval. The merge is pinned to the commit you were shown, so github_merge refuses if the branch moved. The new push starts its own Run, with its own gate.
Can the gate ask for more than yes or no?
Yes. The form is the gate's out: ports, so you can add an optional note, a choice between merge strategies, or anything else typed. Downstream steps read the answers like any other step's outputs.
Is a gate the same as a GitHub required review?
Not quite. A required review is a GitHub rule about who must approve. A gate is part of the factory's workflow: it can show the agent's summary or a reviewer's findings, it has a timeout with a default, and its answer feeds the next steps. You can use both.
Written by
Simone has spent more than 10 years building software, from research at CERN to big tech at AWS and fast-growing startups like Rippling. These days he's building dotFactory, because he thinks writing software should feel a lot more like running a well-oiled factory.