A branch cannot undo an email

An agent's branch keeps its code apart. In this invented example, one changed line still emails a real customer. What to work out before the first run.

By Homayoon Behroozian, , 8 min read

Picture a checkout test that has been failing since Tuesday. You hand it to a coding agent. The agent makes its own branch and finds the cause: the test signs in as a customer that has gone missing from staging, the test copy of the app your whole team shares. So the agent changes one line. The test now signs in as a customer that does exist, the first one it found in staging. Checkout still fails further on, so the agent keeps working, and by lunch it has run the test nine times.

None of this worries you, and that's fair. The agent is on a branch, its own line of changes, kept apart from everyone else's code. Nothing it wrote has reached main. If the fix turns out wrong, you delete the branch and you're back where you started.

That one line also changed who the test's orders are for. Say staging's customers were copied from production a while ago, addresses and all. The old test placed its orders for a made-up customer, and its emails went to a test address that staging catches. The changed test places each order for a real person, and the app sends that person a confirmation email. This example is invented.

A branch keeps an agent's code apart, while the data and application state its fix can change stay shared. So before the first run, work out what trying the fix can change. Where a change can't be undone, a person approves it first.

Each thing the runs left needs its own undo

Nobody has built this checkout or run it. Start with one run of the changed test. The edit, one line, sits on the agent's branch. The test signs in as the customer the agent picked, fills a basket and places an order on staging. Staging saves that order on the customer's record. This customer is a copy of a real person, so the confirmation email goes to that person's address.

After nine runs there are three kinds of thing in three places. The agent's edits are on its branch. Nine orders are in staging's database. The app has sent nine emails, all addressed to the same person.

Before you look at the checkout again, try it with a board you have to cut to fit a gap, and see what you can take back.

Measure twice, cut once

A board lies on a bench below a gap in a bookcase. The reader draws a pencil line on the board and can erase it as often as they like. A tape can measure the gap. A saw cut takes the end of the board off for good. Cut too long and the board can be cut again. Cut too short and no eraser puts the wood back. The count of cuts taken back stays at zero.

A carpenter's version of the same question: the pencil line is the branch, and the cut is the email. Move the line, erase it, then cut the board to fit the gap.

In the checkout, delete the branch and the agent's edits are out of the project. The edits are all the branch ever held, and deleting it reaches nothing outside the repository. The nine orders are still on the customer's record, in staging's database. Say your team has a script that resets staging's test data: run it and the orders are taken back. That leaves the emails, and what happened to them depends on how your staging is set up.

Your staging may catch all outgoing mail. If it does, these nine emails stopped at the mail catcher, the part of staging that holds outgoing mail before it leaves, and nobody received anything. Someone built that on purpose, before any agent arrived.

The staging in this example does not. Say its mail catcher holds only the mail that goes to the team's test addresses. That is why the old test's mail never reached anyone. The customer the agent picked has a real address, which the mail catcher was never set up to hold, so the nine emails are in someone else's inbox.

Either way, the branch did not decide where the mail went. Deleting the branch takes the edits out of the project, the reset takes back the orders, and nothing the team runs takes back an email in someone else's inbox.

An undo exists only where someone built one

In the example, three things take a change back or hold it: the branch, the reset and the mail catcher. Each covers one place, and each is there because someone built it. A place has an undo only if someone built one there, and a place outside your own systems has only the undo its owner offers you.

An acrobat lets go of a trapeze above an orange safety net strung between two poles.
A net catches a fall only where someone has hung one.

Use that on two changes this example doesn't have. Take a test that makes a payment through a real payment service. The service may offer a refund. That is an undo someone built, it is the merchant's to ask for and the service's to give, and it may not put everything back. Then take a test that sends an SMS to a phone number. Once it is delivered, nothing you run takes that message back.

The email in the example sorts like the SMS. Recall exists inside one company's own mail, or between companies that have set it up, and it does not reach a customer, so an email in a customer's inbox has none.

The time to ask is before the first run

You find out which changes have no undo before the first run, because in the example the first run of the changed test is the one that sends the first email.

My position is that an agent may test the fix it proposes. First it has to work out what trying the fix can change in data and application state. Where a change doesn't revert, the agent gets approval before it touches that state.

In the example, before the first run of its changed test, the agent would follow one run to the last thing it causes and bring a note, leaving open any row it can't answer.

One runWhere it landsWhat takes it back
Edits one lineThe test, on the agent's branchDeleting the branch
Adds an orderA customer copied from production, in staging's databaseThe reset script
Sends an emailThat customer's real inboxNothing. The mail catcher holds test addresses only
An example of the note, for the invented checkout: the third row is the one a person has to answer.

Two rows have an undo, and the third is for a person.

A person could also let it run, knowing the mail will go, or keep the run off staging. Which it is depends on the situation, and the team has to keep control. The answer can't wait for review, because the pull request would show one changed line and none of the nine emails.

Where every change has an undo, a branch is enough

A person answers a row that has no undo. My position is that where trying the fix creates no change that needs approval first, the agent develops and tests it on a separate branch, brings it to a person for approval, and then follows the pull request and merge process. That approval comes after the work, for the finished fix. Where every change the fix can make has an undo, the agent goes ahead on its branch without asking.

Take the same checkout. Say the agent's fix had instead put the missing test customer back and left the test signing in as before. Nine runs would leave nine orders for a made-up customer, which the reset takes back, and nine emails to a test address, which the mail catcher holds. Every row of that note has an undo, so the agent goes ahead.

The fair objection is that an agent that stops to ask is slow, and a person asked every time stops reading. Writing about their own coding agent, Anthropic's engineers say that constantly clicking approve "can lead to 'approval fatigue', where users might not pay close attention to what they're approving" 1. That is about a tool asking permission for each step, and it is right. In the example the note would be written once, before the first run. It would have three rows, one of them for a person, and one decision made then would cover every run after it.

A yawning clerk with closed eyes brings a stamp down beside a towering pile of paper.
Asked at every step, a person stops reading what they approve.

The next time a failing test goes to an agent, ask it for the note first: what one run of its changed test will change, and what takes each change back. A row with no answer is yours to decide. Delete the branch and you are back where you started in the code, and nowhere else.

Sources

  1. Beyond permission prompts: making Claude Code more secure and autonomous, David Dworken and Oliver Weller-Davies, Anthropic, 2025-10-20