# Undo and the trash

> Deleting an app or a resource moves it to the trash for 30 days, a reversible write records its undo, and a dict, a secret or a setting keeps what it held. Only purging is permanent.

NoClick is reversible by default. Deleting an app, database, bucket, dict, queue, repo, volume, inbox or agent doesn't destroy it: it goes to the **trash**, where it stays restorable for 30 days and is then purged. A write that can be taken back records how, so its operation can be undone, and a dict, a bucket's files, a secret or a setting keeps what it held before. Only what truly can't be undone (purging the trash, money leaving the account, a message reaching a person) waits for a person when an agent does it.

## The trash

`delete()` on a trashable resource returns its `TrashItem`:

```python
import noclick

item = noclick.Database.from_name("orders").delete()
print(item.kind, item.name, item.purge_after)   # database orders 2026-11-14 ...

item.restore()   # back under its name, every table and row with it
```

```ts
import { Database } from "noclick";

const item = await Database.fromName("orders").delete();
console.log(item.kind, item.name, item.purgeAfter);   // database orders 2026-11-14 ...

await item.restore();   // back under its name, every table and row with it
```

While it's in the trash:

- it's gone from every list and read, and its name is free for something new;
- what it holds is kept, and its storage is billed at the storage rate as before (a database's connection URLs stop working, and nothing reads or writes it; an app serves nothing, and what it keeps, its releases and build outputs, is billed as they were);
- restoring it is free.

| Kind | In the trash | Restoring brings back |
| --- | --- | --- |
| App | offline: its releases, deployments, settings, secrets, bindings and schedules, and the domains it was served at | the app, served again from the same release with no build, at its address and domains, its schedules firing (not while its repo is in the trash) |
| App NoClick publishes (unpublished) | offline: its releases, its address (no other app takes it) and its page's key, which stops working | the page at its address with the same key; publishing its automation's interface again does too |
| Database | its tables and rows, and its branches deleted before it | the database under its name (a branch only beside its source) |
| Bucket | its files | the bucket and every file |
| Dict | its keys | the dict and its keys, expiries kept |
| Queue | its messages | the queue and its messages |
| Repo | its history | the repo, every branch and commit |
| Volume | its files | the volume and its files |
| Inbox | its mail; its address takes no mail | the inbox at its address, taken back from an inbox made there since once that one is deleted (while it's live, the restore is refused with its id as `existing_id`) |
| Agent | its sub-agents, conversations and memory | the agent and its sub-agents; wake-ups and jobs that ended stay ended |
| Database copy | what a database held just before a restore rewound it (it lands here by itself) | that back in its database, with a restore that keeps what the database held then as a copy of its own |

List what's there, newest first, and put something back or purge it now:

```python
for item in noclick.TrashItem.list(kind="bucket"):
    print(item.name, item.trashed_at, item.purge_after)

stale = noclick.TrashItem.list(kind="volume")
for item in stale:
    item.purge()   # gone for good: this one can't be undone
```

```ts
import { TrashItem } from "noclick";

for (const item of await TrashItem.list({ kind: "bucket" })) {
  console.log(item.name, item.trashedAt, item.purgeAfter);
}

const stale = await TrashItem.list({ kind: "volume" });
for (const item of stale) {
  await item.purge();   // gone for good: this one can't be undone
}
```

Restoring is refused with `noclick.Conflict` when something new has taken the name since: rename or delete that one first, then restore. An app's address is held for it against every other account; a new app of yours with its name can take it, and the old one's restore then says so. An unpublished app's address is held against your own apps too, so the page comes back where it was. Purging a repo purges the apps in the trash that deploy it, which can't come back without it.

## Undo an operation

A reversible write records an operation that knows how to take it back. `undo()` runs that once:

```python
seen = noclick.Dict.from_name("processed-orders")
cleared = seen.clear()
cleared.undo()   # every key it removed that nothing has written since is back

item = noclick.Queue.from_name("invoices").delete()
noclick.Operation.from_id(item.operation_id).undo()   # the same as item.restore()
```

```ts
import { Dict, Operation, Queue } from "noclick";

const seen = Dict.fromName("processed-orders");
const cleared = await seen.clear();
await cleared.undo();   // every key it removed that nothing has written since is back

const item = await Queue.fromName("invoices").delete();
await Operation.fromId(item.operationId!).undo();   // the same as item.restore()
```

| Write | Its undo |
| --- | --- |
| Deleting a trashable resource | restores it from the trash |
| Clearing a dict | puts back the keys it removed, leaving newer writes as they are |
| A database migration | restores the database to the moment before it ran (`bookmark` on the result) |
| Restoring a database to a moment | puts back what it held just before, kept in the trash as a database copy (`kept_copy_id` on the operation) |
| Promoting a deployment | restores each database the app binds to the moment before production switched, and puts the release before back in production |

Every promote bookmarks the app's databases just before production switches, so a release that wrote bad data comes back out with its data:

```python
app = noclick.Project.from_name("booking")
promoted = app.deployments(branch="new-checkout")[0].promote()
promoted.wait()
# ... it charged the wrong prices ...
promoted.undo()   # the orders table as it was, and the previous release live again
```

```ts
import { Project } from "noclick";

const app = Project.fromName("booking");
const [latest] = await app.deployments({ branch: "new-checkout" });
const promoted = await latest.promote();
await promoted.wait();
// ... it charged the wrong prices ...
await promoted.undo();   // the orders table as it was, and the previous release live again
```

A database keeps 30 days of history on SQLite and 7 on Postgres, so a promote can be undone that long after. Undoing it takes back what was written to those databases since the promote, good writes included, so the promote's operation says which databases it would take back, to when, before you undo it (`undo_rewinds`, `undoRewinds` in TypeScript), and the undo's result says it again (`warning`).

Nothing a restore takes back is gone for good. Each one, yours or a promote's undo's (an operation of its own per database), keeps what the database held just before in the trash for 30 days as a database copy, on either engine: undoing the restore's operation, or restoring the copy from the trash, puts it back. That's a restore too, so it keeps what it replaces the same way. An undone promote's result names each database's copy and how it goes back (`copies`):

```python
undone = promoted.undo()
for copy in undone["copies"]:
    noclick.Operation.from_id(copy["operation_id"]).undo()   # the writes since the promote, back
```

```ts
import { Operation, Project, type JsonObject } from "noclick";

const [latest] = await Project.fromName("booking").deployments({ branch: "new-checkout" });
const promoted = await latest.promote();
const undone = await promoted.undo();
for (const copy of undone.copies as JsonObject[]) {
  await Operation.fromId(String(copy.operation_id)).undo();   // the writes since the promote, back
}
```

A copy goes back only into its database while that's live (not in the trash) and no other operation works on it; one that can't go back now stays in the trash with the days it had. A Postgres copy is a branch of the database, and its storage is charged at the database's rate while it's kept; putting it back moves the database onto that branch, at the same address and with the same login. A database made with `branch()` grows from the copy its own restore keeps, so once that copy's 30 days are over it leaves the trash but stays, charged with the database, until the database is deleted.

An operation's `undoable` says whether `undo()` can take it back now. Undoing twice, or undoing what reached the world (an email sent, a call placed, a payment), raises `noclick.Conflict`. Over HTTP it's `POST /v1/operations/{id}/undo`.

## A dict's history

Every write to a dict is logged for 30 days with the value it replaced, so a single key can be put back:

```python
prefs = noclick.Dict.from_name("prefs")
for change in prefs.history("theme"):
    print(change.at, change.op, change.previous)   # changed, deleted or created

prefs.restore_change(prefs.history("theme")[0])   # the value it had before that write
```

```ts
import { Dict } from "noclick";

const prefs = Dict.fromName("prefs");
for (const change of await prefs.history("theme")) {
  console.log(change.at, change.op, change.previous);   // changed, deleted or created
}

await prefs.restoreChange((await prefs.history("theme"))[0]);   // the value it had before that write
```

A key changed again within a minute of its last entry adds none, so a busy counter keeps one restore point a minute.

## A file's earlier versions

A bucket keeps what a file held before each write through NoClick replaced or removed it, for 30 days:

```python
bucket = noclick.Bucket.from_name("uploads")
for version in bucket.versions("menu.pdf"):
    print(version.replaced_at, version.op, version.size)   # changed or deleted

bucket.restore_version("menu.pdf", bucket.versions("menu.pdf")[0])
```

```ts
import { Bucket } from "noclick";

const bucket = Bucket.fromName("uploads");
for (const version of await bucket.versions("menu.pdf")) {
  console.log(version.replacedAt, version.op, version.size);   // changed or deleted
}

await bucket.restoreVersion("menu.pdf", (await bucket.versions("menu.pdf"))[0]);
```

Versions are kept in the bucket itself, copied in place and deleted by its own lifecycle when their days are up, so they're stored (and billed) like its files but never listed as files or served at a public URL. An upload through a signed link or S3 credentials goes straight to the store and keeps none.

## Earlier values of secrets and settings

A secret keeps the values it held before each change for 30 days, sealed: its versions say when each was replaced and which keys it held, never a value, and restoring one puts the sealed values back without showing them.

```python
stripe = noclick.Secret.from_name("stripe")
print([v.keys for v in stripe.versions()])
stripe.restore_version(stripe.versions()[0])

app = noclick.Project.from_name("booking")
app.secrets.delete("MAPS_API_KEY")
app.secrets.restore("MAPS_API_KEY", app.secrets.versions("MAPS_API_KEY")[0])
app.settings.restore("PUBLIC_BASE_URL", app.settings.versions("PUBLIC_BASE_URL")[0])
```

```ts
import { Project, Secret } from "noclick";

const stripe = Secret.fromName("stripe");
console.log((await stripe.versions()).map((v) => v.keys));
await stripe.restoreVersion((await stripe.versions())[0]);

const app = Project.fromName("booking");
await app.secrets.delete("MAPS_API_KEY");
await app.secrets.restore("MAPS_API_KEY", (await app.secrets.versions("MAPS_API_KEY"))[0]);
await app.settings.restore("PUBLIC_BASE_URL", (await app.settings.versions("PUBLIC_BASE_URL"))[0]);
```

An app's secrets and settings keep their deletions too, so a deleted one comes back the same way; the app sees it at its next deployment. Deleting a `noclick.Secret` is for good: its versions go with it.

## What waits for a person

Because deletes, migrations, database restores (an undone promote's included) and config changes can be undone, an agent acting through NoClick (an MCP connection, a hosted agent's `noclick` tool, the account's assistant) does them without asking. The [policy](https://www.noclick.com/docs/guide/policy.md) can still hold any of them. What can't be undone keeps waiting for a person:

- purging the trash;
- deleting what has no trash: a secret, a phone number, a domain, a user, a key;
- money leaving the account, and consent to terms;
- a message to a real person outside the account.
