Factorik Factorik Start free trial
← See all articles

How to Set Up a Merge Policy for AI Agent Pull Requests

Quick answer: A merge policy for AI agent pull requests is a short list of rules a pull request must meet before it merges without a person: auto-merge switched on for the repository, every check passing, no protected path touched, and the change under a size limit. Start with auto-merge off, require checks, protect the paths where a mistake is expensive (CI config, migrations, secrets, auth, billing), keep the size caps small, and only then let agents that have earned it merge inside those rules.

Let an agent earn its place on your team

Define a Factorik agent once and it wakes on an issue, a failed build or a schedule, works in an isolated sandbox and ships a pull request. It starts with a person merging its work and earns more autonomy on its record. Try it free for 7 days, no payment details needed.

Start your free trial

What is a merge policy for AI agent pull requests?

A merge policy is the set of conditions under which a pull request may merge without a person pressing the button. For human-written code, most teams express this with branch protection: a required review, required status checks, perhaps a code owner for some folders. For pull requests written by agents, the question is sharper, because the author can open many more of them and there is no person behind each one who will notice a mistake and stop.

A good merge policy for agent pull requests is made of facts the server can check, not opinions. Did every check pass on the commit being merged? Does the change touch a path the team marked as sensitive? How many files and lines does it change? Is auto-merge allowed in this repository at all? Each answer is yes or no, and a pull request that fails any of them waits for a person.

The merge policy is one half of the decision. The other half is the agent: how much it has earned the right to merge. In Factorik the two are separate on purpose. The repository's merge policy says what may ever merge by itself there. The agent's level says how much of that this agent may use. A new agent opens pull requests that a person merges, whatever the policy says; an agent that earned more autonomy on its record may merge inside the policy, never outside it.

RuleQuestion it answersSafe starting point
Auto-merge switchMay anything merge here without a person?Off
Required checksDid every check pass on this exact commit?On
Merging with no checksIs a repository without CI allowed to merge?Off if the repository has tests
Protected pathsDoes the change touch something expensive to get wrong?CI config, migrations, secrets, auth, billing, payments
Size capsIs the change small enough to have been reviewed well?Small
Merge methodHow does the change land on the default branch?Whatever the team already uses
The rules of a merge policy, and the question each one answers.

Should auto-merge be on or off at the start?

Off. Turn it on only once you have watched an agent's pull requests for a while and can say, from what you saw, which of them you would have merged without reading closely. Auto-merge that is on before anyone has looked at the agent's work is trust given on a promise.

In Factorik, open Repositories, find the repository and press "Merge policy". The first switch is "Merge automatically". When it is off, every agent pull request in that repository waits for a person, whatever the agent's level. It is off by default, so a repository you have just connected never merges an agent's change by itself.

Off does not mean slow. Agents still wake on their triggers, work in their sandboxes and open pull requests; they appear in the Inbox with "Approve and merge" for a person. What you gain in this period is a record: how many of the agent's pull requests were merged, how many needed changes, and whether any merged change later caused a problem. That record is what makes turning the switch on a decision rather than a guess.

Which checks should an agent's pull request pass before it merges?

All of them, on the exact commit that would merge. "Require all checks to pass" means every check your git host reports on the head commit of the pull request must have succeeded. A check that is still running is not a pass, and a check that failed blocks the merge for a person too: in Factorik a person cannot approve past a failed check.

The exact commit matters more for agents than for people. An agent may push a second commit after a review asks for changes, or after CI failed on its first attempt. A pass on the earlier commit says nothing about the later one. The policy should only ever be read against the commit that is about to land.

"Allow merging when there are no checks" is the exception for repositories without CI, such as a documentation site or a small configuration repository. Leave it off for any repository that has tests that should run. If a workflow fails to start, a repository with this switch on would see no checks and could merge an untested change; with it off, the change waits.

Checks are also where a review fits. If an agent on the repository reviews pull requests, a merge waits for its approval of the current commit as well, and after a few rounds of changes a person decides. A person's approval can override the reviewer's. That makes an AI review one more gate rather than one more comment; how an AI review should gate a merge covers it in detail.

Which paths should be protected from AI agents?

Protect the paths where a small change can do large damage, or where a change runs with more power than the code around it. "Protected paths" takes glob patterns, such as src/payments/** or **/*.sql. A pull request that touches any file matching one of them waits for a person, at every level, however small it is.

A reasonable first list for most web applications: CI and automation configuration (.github/), database migrations (/migrations/), environment and secret files (/.env*), authentication and permissions (/auth/), and anything to do with money (/billing/, /payments/). Factorik's starting policy for a new repository already protects paths of these kinds, and you adjust the list to your layout.

CI configuration deserves a sentence of its own. A workflow on a pull request's branch can run on the host with the repository's secrets before anyone merges it. That is why changes under .github/ stay protected and are never treated as low-risk in Factorik, and why the app can only publish a workflow change where the account owner granted it permission to. Where it has no such permission, the agent hands that part to a person instead of losing the change.

Then add your own. Look at your incident history and your CODEOWNERS file: the folders that caused the worst incidents, and the ones where only a few people are trusted to review, are the ones to protect. Infrastructure as code, feature flag defaults, pricing tables, data retention jobs and public API contracts are common additions.

How large should an agent's change be allowed to be?

Small enough that a reviewer would have read every line. "Largest change, in files" and "Largest change, in lines" cap the size of a pull request that may merge by itself; a larger one waits for a person. Agents are good at producing large, plausible diffs, and a large diff is exactly where a review becomes a skim.

Set the caps from your own history. Look at the agent's merged pull requests during the period when auto-merge was off, and at the kind of change you want to flow: a dependency bump in one manifest and one lock file, a one-function bug fix with its test, a documentation correction. The caps should let those through and stop a refactor across a dozen modules.

Size caps in the policy are separate from what Factorik calls a low-risk change. An agent at the middle level merges by itself only changes that are low-risk by facts about the change: small, removing little, and touching nothing sensitive, such as dependencies, build and deploy, secrets and permissions, migrations or money. The policy's caps apply on top of that to every agent in the repository. What counts as a low-risk change explains the facts behind it.

Let an agent earn its place on your team

Define a Factorik agent once and it wakes on an issue, a failed build or a schedule, works in an isolated sandbox and ships a pull request. It starts with a person merging its work and earns more autonomy on its record. Try it free for 7 days, no payment details needed.

Start your free trial

How does a pull request move through the policy, step by step?

Take a made-up repository, acme/api, with "Merge automatically" on, "Require all checks to pass" on, the default protected paths, and small size caps. A Dependency Updater on it has earned the middle level: it may merge low-risk changes by itself.

On Monday its schedule wakes it. In its sandbox it finds a patch release of a logging library with a fix for a known vulnerability, updates the manifest and the lock file, runs the tests, and finishes. The server publishes the change as one commit on a new branch and opens a pull request. Because a dependency change is a sensitive kind of change, it is not low-risk, so it waits in the Inbox for a person, with the reason shown on the run. An engineer reads it, presses "Approve and merge", and it lands as a squash commit.

On Wednesday the Bug Fixer on the same repository, at the top level, fixes a date parsing bug: one source file, one test file, a few lines. The checks pass on the head commit, no protected path is touched, and the change is under both caps. The run page says "Decided by the merge policy", and the pull request merges with no one pressing anything.

On Thursday the same Bug Fixer fixes a bug that turns out to live in src/auth/session.ts. The checks pass and the change is small, but it matches /auth/, so it waits for a person. The agent's level did not change and neither did the policy: the path decided.

What should I change in the policy as agents earn trust?

Change one thing at a time, and change it because of something you saw. A policy that gets wider every week regardless of what happened is a calendar, not a policy.

Turning "Merge automatically" on is the first widening, and usually the most important. Leave the caps small and the protected list long when you do it. Raising the caps comes later, when you see small, well-tested pull requests waiting for a person only because they changed one file too many. Removing a protected path should be rare and deliberate; most teams never remove the ones for CI, migrations and secrets.

Widening also works in the other direction. In Factorik, any problem traced to one of an agent's merged changes (CI or a deploy failing at its merge commit, a revert, a person reporting a problem) moves that agent down a level at once. The policy does not have to be tightened by hand to make an agent stop merging; its level drops, and what it may merge drops with it. Watching changes after they merge explains how those problems are tied to a change.

"How to merge" ("Squash and merge", "Merge commit" or "Rebase and merge") is not about trust. Pick the one your team already uses, so an agent's change looks like everyone else's in the history. A new policy applies to the next pull request, not to the ones already open.

How do I try this on one of my repositories?

Whatever tool you use, the order holds: auto-merge off, checks required, sensitive paths protected, small size caps, a record built while a person merges, and only then a wider policy for the agents that earned it.

In Factorik that takes a few minutes. Connect GitHub, add your AI credential, create an agent from a preset such as the Bug Fixer or the CI Fixer, and open "Merge policy" on the repository before its first run. You can start a free 7-day trial of the Team plan with no payment details needed, let the agent open pull requests for a person to merge, and decide from its record when the policy should open up.

Frequently asked questions

Should AI agents be allowed to auto-merge pull requests?

Only inside rules the server can check, and only after a record of their work shows it. Start with auto-merge off, require every check to pass, protect sensitive paths and cap change size. Then let agents that have earned it merge the changes that meet every rule.

Which files should never be auto-merged?

Start with CI and automation configuration, database migrations, environment and secret files, authentication and permissions, and billing and payments. Add the folders behind your worst incidents and the ones only a few people are trusted to review.

Does a protected path block an agent from changing a file?

No. The agent can still change it and open a pull request. A protected path only means that pull request waits for a person to merge it, at every level.

Does a merge policy replace GitHub branch protection?

No. Keep your branch protection. Factorik's merge policy decides when Factorik may merge an agent's pull request by itself; the git host's own rules still apply on top of it.

When does a change to the merge policy take effect?

It applies to the next pull request. Pull requests already open are not re-decided by a policy saved after them.

Let an agent earn its place on your team

Define a Factorik agent once and it wakes on an issue, a failed build or a schedule, works in an isolated sandbox and ships a pull request. It starts with a person merging its work and earns more autonomy on its record. Try it free for 7 days, no payment details needed.

Start your free trial

How helpful was this article?

Articles by Factorik →