How to revert an AI agent's change after a bad deploy
Quick answer: To revert an AI agent's change after a bad deploy, find the merge commit that the failing deploy built. Open a revert pull request against that commit with GitHub's Revert button or git revert, let the checks pass, and merge it. Then record a finding on that commit and move the agent down one level of autonomy. Its next changes go through a person until its record earns the level back.
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.
How do you revert an AI agent's change after a bad deploy?
To revert an AI agent's change after a bad deploy, find the exact merge commit that shipped it, open a revert pull request against that commit, let your checks run and merge it. Then record the finding against the change and move the agent down one level of autonomy. Do it in that order: restore service first, deal with the agent second, and never skip either step. A bad deploy from an agent isn't a special kind of incident. It's an ordinary regression with one extra question attached: how much should this author be trusted to merge next time? Teams that treat it as a pure engineering incident get service back but learn nothing about the agent. Teams that treat it as a pure AI problem tend to argue about models while production stays broken.
Here's the sequence written out as events. A deploy fails at commit a1b2c3d, or an error-rate alert fires twenty minutes after it went live. Whoever is on call matches the alert to the deploy, and the deploy to a merged pull request. A Bug Fixer agent opened that pull request, and it was merged under the repository's merge policy. A person clicks Revert on the merged pull request, which opens a new pull request that undoes it. CI runs on the revert, passes, and the revert is merged. The pipeline ships the previous behavior. Then the change gets a finding: what broke, at which commit and how it was noticed. The agent drops one level, and the drop is recorded with the reason.
None of this needs a new process. If you already have an incident runbook, the agent-specific part is two lines long: record the finding at the commit, and adjust the agent's level. Both lines are mechanical, not judgment calls. Nobody holds a meeting to decide whether the agent 'deserves' to lose merge rights. The rule says a problem traced to one of its merged changes costs it a level, and it applies whether the damage was large or small. That predictability is the point, and it's the core of a software factory that adjusts each agent's autonomy from its record. Engineers will accept automation that merges code if they know exactly what happens the first time it goes wrong.
How do you trace a failed deploy after merge to the exact commit?
To trace a failed deploy after merge, match the commit SHA the deploy recorded to the merge commit on your default branch, then follow that commit back to its pull request. Most hosting platforms and CI systems stamp every deploy with the commit it built, so start by reading that value instead of guessing from timestamps. If you deploy on every merge, each deploy maps to one merge and the culprit is obvious. If you batch several merges into one release, you have a range of commits, and you'll need to check what each change touched. The stack trace, the file that throws and the time the alert started usually narrow a batch of five merges down to one within minutes.
How the pull request was merged decides how you undo it. A squash merge leaves a single ordinary commit, so a plain git revert of that SHA does the job. A true merge commit has two parents, and Git needs to know which side is the mainline. git revert -m 1 keeps the default branch and undoes the feature side. A rebase or fast-forward merge leaves a run of commits that you revert as a range. GitHub's Revert button on a merged pull request handles the common cases by opening a new pull request that undoes the original. It needs write access, and it isn't offered for commits pushed straight to the default branch. Agents that publish each change as one commit on its own branch make all of this simpler.
One trap catches teams the first time they revert a merge commit. Git treats the revert as a statement that you don't want those changes again. If the agent later fixes its work and you try to merge the same branch, the original commits won't come back in. The clean options are to revert the revert or to land the corrected change on a fresh branch. For an agent's change, a fresh branch is almost always better. The agent reads the finding, starts a new run and opens a new pull request that goes through review and checks from scratch. Your history ends up with three separate, readable entries: the bad change, its revert and the corrected attempt.
| How it was merged | How to revert it | What to watch for |
|---|---|---|
| Squash merge | git revert <sha> | A single ordinary commit, so no -m flag is needed |
| Merge commit | git revert -m 1 <sha> | Parent 1 is the default branch side; check parents with git show first |
| Rebase or fast-forward | git revert --no-commit OLDEST^..NEWEST, then commit | Reverts a range of commits as one change |
| GitHub Revert button | Opens a new revert pull request | Needs write access; not offered for direct pushes to the default branch |
Should you roll back AI-generated code or fix forward when it breaks production?
When AI code breaks production, revert first, and fix forward only when the revert itself is riskier than the bug. That's the right default for any change, and it matters even more for an agent's change, because the agent isn't on the incident call and can't explain what it meant to do. A revert is a known quantity: it returns the code to a state that already ran in production. A forward fix is new code written under pressure, often by someone who didn't write the original. The standard industry measure of recovery time runs from the failed deployment until service is restored, not until the root cause is fixed. That's the right framing. Users feel the outage, not the root cause. The root cause can wait an hour.
There are real exceptions, and you should know them before you need them. A change that ran a database migration may not revert safely, because rolling the code back while the schema stays on the new version can break things in a new way. A change that sent emails, charged cards or published data has side effects no revert can undo. A change that later merges have built on may revert with conflicts. This is why a sensible merge policy lists migrations, payment code, deploy files and secrets as protected paths that always wait for a person. If an agent's change touched one of those areas, a human approved it. The person who approved it is the right one to choose between reverting and patching.
Who should open the revert pull request? Almost always a person, the one on call. The Revert button takes seconds, and nobody should wait for an agent to wake up, read logs and reason about a fix while users are seeing errors. Once service is back, the agent becomes useful again. You can hand a Bug Fixer or Software Engineer the finding and ask it to find the real cause, write a failing test that reproduces it, and open a fresh pull request. That second attempt goes through the same review and checks as any other change. Our view is simple: an agent shouldn't be in the critical path of its own rollback. People get service back, and agents repair the change afterward with the evidence in hand.
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.
What should you record after a revert of an AI agent's change?
After rolling back AI-generated code, record a finding tied to the exact merged commit: what failed, how it was noticed, when, and who confirmed it. The finding connects the incident to the agent's future behavior. Without it, the revert sits in git history as an anonymous undo, and the agent that wrote the change has no idea anything went wrong. In Factorik, several events record a finding on their own. They include CI or a deploy failing at the merged commit and a revert of the change. A person can also press 'Report a problem with this change' on the run and fill in 'What went wrong'. Each of these records the finding against the change, tells the team and costs the agent a level, so nobody has to remember the paperwork mid-incident.
Not every regression shows up as a red deploy. Some show up as errors creeping upward, a checkout step that converts worse, or a page that renders blank in one browser. That's where watching changes after merge earns its keep. A person can press 'Watch in production' on a run to mark its change. After the merge, a Change Watcher agent checks production a set number of minutes later, using tools such as Sentry or Datadog if they've been granted to it. The watcher changes no code. Its suspicions also don't count against anyone until a person confirms them in the Inbox, so a noisy alert can't cost an agent a level unfairly. There's more on watching AI-generated code once it's live if you want the full setup.
A finding also feeds into the agent's next run. Every run reads the team's standing rules, its goals, recent feedback and the findings on its past changes. The agent that broke the build last week starts this week knowing it did. That's the difference between a revert and a lesson. You can make the lesson explicit, too: rate the failed run, answer 'What should it do differently?', and press 'Make this a standing rule' if the point applies beyond this one change. 'Never change retry logic without a test that simulates a timeout' is the kind of rule that earns its place. Keep rules specific and tied to what actually went wrong. A vague rule such as 'be more careful' teaches the agent nothing it can act on.
Why demote AI agent autonomy instead of switching the agent off?
When a problem is traced to one of an agent's merged changes, move its autonomy down one level instead of switching it off. Dropping a level shrinks what it may merge without a person, and its useful work keeps coming as pull requests someone reviews. In Factorik, every agent works at one of three levels. At the first, it opens pull requests a person merges. At the second, it merges low-risk changes by itself when the merge policy allows. At the third, it merges whatever the merge policy allows. A problem on a merged change moves the agent down a level at once. Factorik records the change along with who or what made it and why, and nobody has to act on it during the incident.
The instinct after a bad deploy is to switch the agent off entirely. Resist it. Pausing throws away the record, stops the routine fixes the agent was getting right, and swaps a measured response for an emotional one. A one-level drop fits the problem. An agent at the top level loses the right to merge whatever the policy allows and goes back to merging only small changes that touch nothing sensitive. An agent at the middle level goes back to opening pull requests for a person to merge. Its work keeps flowing, but it passes through a person again. If an agent keeps producing findings at the bottom level, pause it and rewrite its instructions. That's a different signal, and it calls for a different response.
Climbing back is slower than falling, on purpose. An agent earns a level again only when its record of merged changes clears the bar: enough merged changes, a high merge rate and no problems. The setting 'How agents are promoted' decides how that happens. Either a person presses 'Promote' when the offer appears, or the promotion happens automatically. The asymmetry is the whole design. One bad change costs trust at once, and only a run of good ones earns it back, much as it would for a new engineer. To see the full loop, read how autonomous coding agents earn the right to merge. When you're ready to try it on a repository of your own, you can start a free 7-day trial of the Team plan with no payment details needed.
Frequently asked questions
Does reverting an AI agent's change automatically demote it?
Yes. In Factorik, a revert of an agent's merged change records a finding and moves that agent down one level at once. The same happens when CI or a deploy fails at the merged commit, or when a person reports a problem with the change. A watcher agent's suspicion works differently: it only counts once a person confirms it in the Inbox. Every level change is recorded with who or what made it and why, so the history stays auditable.
Can an AI agent revert its own change after a failed deploy?
It can be asked to, but it shouldn't be the first responder. A person can revert in seconds with GitHub's Revert button or git revert, and during an incident, getting service back matters more than automating the fix. Once things are stable, an agent such as a Bug Fixer can take the finding, reproduce the failure with a test and open a corrected pull request. That pull request then goes through the usual review and checks.
What if an AI agent's change can't be reverted cleanly?
Changes that ran migrations, touched payment flows or triggered external side effects may not roll back safely, and later merges can make a revert conflict. In those cases, a person decides between a partial revert and a forward fix. The better prevention comes earlier: list migrations, deploy files, secrets and money-handling code as protected paths in the merge policy. Then changes there always wait for a person's approval before they merge.
How does an agent win back its level after a bad deploy?
By building a fresh record. It climbs one level when enough of its merged changes land, with a high merge rate and no problems traced to them. Depending on the organization's setting, either a person presses 'Promote' when the offer appears or the promotion happens automatically. Until then, its changes go through the stricter path of its lower level. The team keeps getting the useful work while trust is rebuilt.
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.