# Undo what an agent changed

Source: https://molted.email/docs/undo-agent-changes

Stop an agent key and put back every settings change it made since a time. A person's action, from Settings > Access.

If you let your agent run everything, undo is your safety net. An agent that
was tricked into a "block everything" rule, or that loosened your spam filter,
can be rolled back in one go: Molted stops the key, then puts back each setting
the key changed since the time you pick.

Undo uses the change history Molted records for every setting that controls
mail: who changed it, with which key, and the value before and after.

## Who can undo

- Only an **admin** or the **workspace owner**, signed in to the [portal](https://molted.email/docs/portal.md). An agent can never
  undo anything, its own changes or a person's fix. The routes answer
  `403 human_required` to an agent's session, and an API key has no session
  there at all (`401`).
- Undoing needs a **password sign-in from the last 10 minutes**. If yours is
  older, the panel asks you to sign in again, then brings you back to it.
  Looking at the list doesn't need that.

## Open it

Go to **Settings > Access** (`/app/settings#access`). Each key has
**Undo changes…** next to **Revoke**, and so does each key revoked in the last
30 days (listed under the live keys) and each suspended key. The panel shows
what the key changed since a time you choose: the last hour, the last 24 hours
(the default), the last 7 days, or a custom time (up to 90 days back).

One undo puts back at most 200 changes, the newest first. If the key made more
in that time, undo still stops the key first, then walks the newest 200 and
says how many it didn't reach. The key can't change anything more, so run undo
again for the same time: it walks past what the first run settled and puts back
the rest.

## Keys the key created

An agent can create keys with its key. Those keys are the agent's too: the
panel names them, lists their changes with the key's (marked with the key that
made each one), undoes them in the same run, and stopping the key stops them
as well, including keys they created in turn.

Each change is one plain line, the same wording as Home's activity. Some are
marked:

- **To review**: a suppression. Undo lists these and never removes them (see
  [Suppressions are never removed](#suppressions-are-never-removed)).
- **Can't be undone**: with the reason, for example an incident the agent
  acknowledged.

## What it covers

Every settings change the key made:

- mailbox rules (added, changed, reordered, deleted);
- the spam filter (threshold, link limit, unauthenticated mail, blocked
  keywords, allowed senders) and the other safety settings;
- workspace settings (cooldown, postal address, marketing consent);
- a mailbox's address, display name, pause, catch-all and settings, its
  approval rule, and the default mailbox;
- a domain's sending limits and warmup;
- account-wide pauses and resumes, and a lifted reputation pause;
- the humanizer;
- the sender allowlist, and labels: a rename, a new color or a move, and a
  deleted label (with the conversations it was on);
- suppressions and suppressed domains (for review only, see below).

## How undo stops the key first

Before it puts anything back, undo stops the key, and every key it created, so
none of them can change things while undo runs. You choose how:

- **Revoke the key** (the default). It stops working at once, for good: create
  a new key to connect the agent again.
- **Suspend the key**. It stops working at once, everywhere (the API, the
  mailbox host, the MCP server and OAuth tokens made from it all answer `401`),
  until you **Reactivate** it in Settings > Access. Only an admin or the owner can
  reactivate a key, never an agent, and each key is reactivated on its own.

A key that is revoked already stays revoked: undo only puts back its changes. A
suspended key can be revoked from the panel, or left suspended.

A suspended key is yours to decide on. No agent key can revoke or rescope it,
not even the key that created it (`403 key_suspended`), and it still holds the
agent it was bound to: no other key can act as that agent or take its leases
until you reactivate or revoke it.

Undo always stops first, before it looks at anything else, so nothing an agent
did can keep its keys running. It stops the whole family in one step, however
deep, then looks again. A key minted at that moment is either stopped with the
rest or not created at all (the minting key is checked while the key is
created). If one still runs, the result names it, so you can revoke it.

A key can mint keys at most 20 generations deep (`422 key_chain_too_deep`
beyond that). For an older family deeper than that, undo still stops every key
in it, but lists and puts back none of their changes: the panel says so.

## How a change is put back

Undo walks the key's changes newest first and puts each one back only while
nobody else touched it since, and the value is still the one the agent wrote:

- **A field someone changed since is skipped, whatever its value now.** If you,
  or anyone else, changed the spam threshold after the agent did, undo leaves
  your value and says who changed it ("Changed since by Alice"), even if you set
  it back to what the agent had chosen. The agent's other fields in the same
  change are still put back.
- **A pause or resume of yours wins.** If the agent paused a mailbox or the
  whole account and you then paused or resumed it yourself (or pressed Pause
  while it was already paused), undo leaves it as you left it. Undo only lifts a
  pause that is still the agent's own: the change that paused the mailbox was
  made with the key, or a key it created. Another agent's pause is left, and the
  line names who paused it.
- **Paused, then resumed, ends paused.** If the key paused a mailbox and later
  resumed it, undo puts the resume back first (the mailbox is paused again,
  with you as who paused it), and then leaves that pause in place. The line
  says "Left paused: it was paused by this key earlier". Resume it yourself if
  it should send.
- **Lists revert as a set difference.** For blocked keywords and allowed
  senders, undo takes out the entries the agent added and puts back the ones it
  removed. An entry added since stays, and so does any entry someone else added
  or removed since.
- **Deleted things come back, created things go.** A rule, label, allowlist
  entry or suppression the agent deleted is re-created as it was, with the same
  id, unless the key had created it itself, and a rule only into a mailbox that
  is still live. (Labels record who created them, so a label the key made and
  then deleted stays deleted.) A rule or allowlist entry it created is deleted, and a mailbox
  it cloned is deleted (archived, so you can restore it for 14 days) unless
  someone else set it up since, made it the default, or mail arrived on it.
- **A renamed or recolored label gets its old name and color back**, field by
  field, like any other setting. If someone renamed it since, the name stays
  theirs; if another label took the old name meanwhile, the rename is left and
  the line says why. A label the key created stays.
- **A pause comes back as a pause.** If the agent resumed sending, or lifted a
  reputation pause, undo pauses again. A lifted reputation pause comes back as a
  pause of that mailbox; its reputation counters stay reset.

Running undo again on the same window puts back nothing new: everything already
reads as it did before the agent. Undo's own writes are marked as undo's, so a
second run is never blocked by the first: if the first stopped before the
oldest changes (it ran out of time, or more changes landed than one run reads),
the second run puts those back too.

## Suppressions are never removed

A suppression the agent added may be a real opt-out, and honouring opt-outs is
the law. So undo never removes suppressions in bulk. It lists the ones the agent
added or changed under **To review**, and you lift any yourself
([Suppressions](https://molted.email/docs/suppressions.md)).

Some of those are not the agent's at all. When a bounce, complaint or
unsubscribe suppressed the same address at the same moment as the agent's add,
the record says so, and undo explains it on that line. A suppression the agent
**removed** is put back.

## What undo can't put back

The panel says this up front:

- **Conversations a rule already archived** stay archived: the archive doesn't
  record which rule did it. Find them in Archived.
- **Mail held for approval meanwhile** stays held. Decide it on Home.
- **Sends a setting blocked meanwhile** aren't sent again.
- **Some of a deleted label's conversations.** A delete records the first 500
  conversations the label was on. A label on more comes back on those 500, and
  the line says how many more it was on: add the label to those yourself.
- **The revocation itself**. Create a new key to connect the agent again. A
  suspended key can be reactivated.

## Changes the agent made while signed in

An agent that signed up through the CLI can also change settings through its own
sign-in, without the key. Those changes carry no key, so undo finds them by the
agent's account instead and counts them in the panel. Undo doesn't revert them,
and revoking or suspending the key doesn't end that sign-in. If no agent account is
linked to the key (a person created it and no agent sign-in used it), the panel
says so.

## The result

After undo runs, the panel shows how the key (and the keys it created) was
stopped, then three groups:

- **Restored**: each change put back, in the timeline's wording.
- **Skipped**: each change left alone, with why (changed since by whom, already
  as it was, or can't be undone).
- **To review**: the suppressions, and any change whose result isn't known (the
  mailbox service didn't answer in time, or the run reached its time limit).
  If there were more than 200 changes, it says how many were not reached. Check
  those, or run undo again for the same time: it only puts back what is still
  as the agent left it.

If the key's family was too deep to walk, the result says nothing was put back,
and why; the keys are stopped all the same.

Home's activity gets one line for the whole undo ("Undid 12 changes of the key
"sales-bot" and revoked the key"), and every setting it put back has its own
line, with you as the one who changed it.
