Designing Agent Rollback and Undo Strategies for GitHub PR Actions
Building a ledger system to track and reverse agent actions beyond git.

Git records only part of the work. For rollback to work, a run ledger must be in place before merge, link each side effect to a tested undo path, and show what cannot be reversed so the approval gate can enforce that boundary.
Why "revert the PR" fails as a rollback strategy for agents
The git graph records repository changes. An agent can edit files while also changing a feature flag, posting a comment, or running a migration. Those actions affect different stores of state. Reverting the merge commit can bring back the tracked code while leaving the flag flipped, the comment posted, and the migration applied.
The PR diff is therefore a partial receipt. It shows the repository-visible fraction of a wider operation, and treating it as the whole record creates a false restoration point. A successful revert proves that the repository change was reversed. It does not prove that the system returned to its previous state.
This gap is structural to multi-turn, tool-calling agents. A task that appears to involve three file edits can also involve an MCP server call, regenerated snapshots, and a retry of a flaky command. Rollback must address the actions actually taken. Any policy based only on the diff leaves the reviewer unable to judge whether recovery is complete.
The taxonomy of side effects that git cannot recover
For set_feature_flag, the undo path is restoring the previous flag value. For post_comment, it is delete_comment or supersede_comment. These are distinct operations against state outside the repository. Restoring the code that led to the original call does not undo either action on its own.
Infrastructure and database actions need more proof that recovery works. The inverse of create_cloud_resource is destroying the resource plus verifying cleanup. The inverse of run_migration is a validated down migration, unless the migration requires an explicit irreversible marker. Recovery must deal with the state that the forward action left behind.
Generated files shipped elsewhere and cache invalidations also fall outside git revert’s scope. Together, these categories show why there is no universal inverse operation for an agent run. The ledger needs a mapping from each tool call to its own undo path, rather than a single recovery command attached to the PR. Secret rotation, sent emails, and processed charges require a different treatment because an inverse may not exist. Those actions need an explicit approval boundary because rollback cannot be taken for granted.
What a run ledger captures and why it must be built before merge
A run ledger is the compact record that travels with an agent task. It records what the agent was allowed to do, what it actually did, which approvals changed the scope, what proof it collected, and how to undo the work. A reviewer needs enough information to connect an action to its permission, its evidence, and its recovery path.
The repository diff and an explicit external_side_effects field provide complementary parts of that record. The diff explains the tracked changes, while the side-effects field exposes work that git cannot recover. The ledger also needs the change class and the boundary of the work being recorded. Without those connections, a collection of logs may document activity without making rollback executable.
The ledger must exist before merge because an incident is the wrong moment to reconstruct actions omitted from a confident agent summary. It can live in a PR description, job record, markdown file, or trace viewer. The container is secondary to the record’s usability. Humans must be able to review it, and a governance system must be able to parse it.
Change classes: matching rollback ceremony to actual risk
Class 0 covers docs-only changes, with git revert as the rollback method and optional rehearsal. Class 1 covers code-only changes, with git revert plus tests and rehearsal required in CI. The distinction keeps a documentation edit from inheriting the ceremony required for a change with executable behavior.
Class 2 covers generated or config changes. Its rollback method is restoring the artifact or previous config, with rehearsal required and a diff receipt. Class 3 covers external side effects and requires inverse tool calls, rehearsal in a sandbox, and approval from a human. These classes distinguish restoring a known artifact from reversing an action in another system.
Class 4 addresses irreversible actions and requires a dry run and explicit human sign-off before the agent may proceed. This changes the control from recovery after execution to authorization before execution.
An agent given a Class 0 request to fix a typo that calls a migration tool has performed a Class 3 run. The ledger’s change class is therefore a post-action determination based on recorded behavior. That retrospective classification does not replace advance authorization for irreversible actions. A Class 4 tool call must still be stopped before it runs if the required sign-off is missing.

Rehearsing the undo path in a sandbox before merge gates are reached
A sandbox that checks only the forward path proves too little. Applying a change and running tests can establish that the new state works without establishing that the previous state is recoverable. A full rehearsal applies the change, runs the relevant checks, captures side effects, executes rollback, runs the checks again, and proves return to the expected baseline.
Two failures independently prevent the change from being ready. If rollback execution fails, the undo procedure is not usable. If rollback executes but baseline restoration fails, the procedure is incomplete. Merge depends on recovery evidence as well as evidence that the change works.
Stateful rehearsal makes that distinction testable in practice. A migration down must run against a fixture database containing the rows created by the up migration. A stateless stub that always returns “migration succeeded” cannot expose a broken down path. The same principle applies to a feature-flag reset or comment deletion. A stateful API simulator must track sequential calls so that the rollback is tested against the state produced by the original action.
The baseline must include the outputs that the change can affect. Tests, fixtures, generated artifacts, and traces provide the evidence required at review. A receipt showing only that the inverse tool returned successfully leaves the final question unanswered. The rehearsal must prove restoration.
The undo-unit problem in multi-turn agents: defining what one rollback step covers
In a conversational coding agent, one rollback unit could cover everything done between two user messages or one assistant turn that spans multiple tool-call batches. It could instead refer to a single tool call or an entire multi-step session. These choices change what recovery does, even when each inverse operation works as it should.
The ambiguity is unresolved in many codebases. An /undo command can therefore be surgical or blunt depending on a policy that may never have been made explicit. A ledger cannot resolve that policy by merely collecting more events. The team must first define which work belongs to one rollback step.
The change_id field makes the chosen boundary machine-readable. Assigning a stable identifier to the unit of work at the start of a session lets the ledger express what the rollback covers. The identifier gives the recovery procedure an explicit scope instead of leaving incident responders to interpret conversational turns.
Bounded autonomy, read-only planning, and once-per-PR limits can help with this. They constrain where actions can occur and how much work an agent can perform within a defined scope. The rollback policy still has to say whether one step reverses a call, a turn, or the broader unit of work.
What the merge-gate review checklist must require
The reviewer’s starting point must be evidence. The review must establish what changed in git, what changed outside git, and which tool calls were write-capable.
The review must then distinguish reversible from irreversible side effects. For reversible actions, it must establish whether rollback was rehearsed in the required environment and whether it returned tests, fixtures, generated artifacts, and traces to baseline. For irreversible actions, it must establish whether the required authorization preceded execution. The reviewer also needs the receipt itself. An assertion that recovery was tested is not a substitute for the ledger.
If the ledger is missing, block merge. If the required rollback rehearsal was not done, block merge. If the agent cannot explain its external side effects, block merge, preserving the proportionality of the change classes, including optional rehearsal for docs-only changes, while requiring evidence for higher-risk work.
The gate brings permissions, logs, and rollback into one decision. The permission profile defines the allowed scope before the run, the ledger records what happened, and the rehearsal receipt provides evidence that recovery works. Reviewing them together exposes the gap between permission to act and proof that an action can be undone. Treating them as separate documents would leave that connection for the reviewer to reconstruct.
This review adds checks that must be done before a change is accepted. Its value is not in slowing agents down. Fast execution followed by slow incidents is not sustainable agent velocity, particularly when failures could force a team to remove agent access entirely. The merge gate protects the conditions under which that access can remain useful.
The honest boundary: what the ledger cannot undo and why prevention is the correct strategy for irreversible actions
Secrets already rotated, emails already sent through an email API such as Resend, and charges already processed through Stripe or PayPal must not be given inverses that do not exist. The ledger must identify that boundary explicitly. “Cannot rollback” is valid metadata.
Secret rotation, for example, can require a rollback procedure, dependent service refresh, and an audit note without making the original action undoable. Recording those obligations is useful, but they must not be confused with proof that the prior state can be recovered. The ledger must describe the actual limit of recovery.
Even repository-based rollback has a narrower scope than it appears. A revert against a clean worktree does not recover .gitignore’d artifacts such as build output, .env, or scratch directories that may be important to the user. The ledger must account for them.
For Class 4 actions, prevention is the correct control. A dry run is required, explicit human sign-off is required, and the agent must be blocked without that sign-off. A merge-time review can inspect the record, but it cannot retroactively authorize an irreversible action safely.
Ledger-based recovery is achievable for code, config, branch, and feature-flag changes. For payments, messaging, and irreversible external state, its purpose is to expose the boundary early enough to prevent unauthorized execution. The design implication is direct. Build the approval gate so that irreversible actions require explicit human authorization before the agent calls the tool.


