# Delete by id, not by filter: three cleanups that went wide

> A search for 'probe' purged a profile called 'asd'. An empty body purged 586. A loop revoked a key nobody named. Delete by the ids you were given.

Source: https://mosaicbrowser.com/blog/widened-cleanup

## A cleanup scoped by a search string is not scoped

A search for 'probe' purged a profile called 'asd'. An empty body purged 586. A loop revoked a key nobody named. Delete by the ids you were given.

![586: Profiles lost to one empty request body, beside a screenshot: mosaic API keys: one per script or tool, each revocable on its own](https://mosaicbrowser.com/covers/widened-cleanup.webp)

Delete by id, never by filter, and build the id list from what you were asked to remove or from what you created yourself, at the moment you created it. We learned that rule three times before the end of September 2026, on three different things. One of the three cost 586 profiles that never came back.

## A search for "probe" took a profile called "asd"

After a round of measurements we had a pile of test profiles, all with "probe" in the name. The tidy-up looked like this:

```
const l = await ipc('profiles.list', { search: 'probe', limit: 50 })
for (const r of l.ok.rows) { /* delete, then purge */ }

```

It purged five profiles that were not ours to purge. One was called `asd`, a name with no part of the word "probe" in it. Mosaic's profile search matches more than the name; the search box says "Search name, note or tag", and a note or a tag had matched.

The rule was already written down: delete by id. It had been read as a rule about the *absence* of a scope. It is about anything that is not an id. A search string looks precise and is a pattern match over fields nobody enumerated, and purging is irreversible.

All five came back, and only because a purge takes a safety snapshot of the library before it destroys anything. We restored them by id from the snapshot taken that morning. A sixth, lost to the same search in an earlier call, turned up when we previewed the snapshot against the live library: the preview's `missing` list is exactly "in the snapshot, not here now".

Mosaic is a desktop app

Email yourself the link and open it on your computer.

[How it works: REST API](https://mosaicbrowser.com/features/rest-api)

## An empty body purged 586 profiles

The one that did not come back happened earlier, and it was four words in a check script. The script creates test fixtures and removes them, and a new block ended:

```
await call('DELETE', `/profiles/${id}`)
await call('POST', '/trash/empty', {})     // meant "tidy up after myself"

```

`POST /trash/empty` with no body was documented as emptying the whole trash, and it did exactly that. The route, its validator and its docs were all correct. The fault was the default: whoever wrote the script read "empty the trash" as "empty the trash I filled". At that point purging deleted folders outright, there were no backups, and the machine had no local Time Machine snapshots. 586 profiles were gone.

Four changes followed, and only the last one really holds:

- The script purges by id, with `DELETE /trash/profiles/<id>`.
- An empty body on `POST /trash/empty` is a `400` now. You name a `projectId`, an `os` list, or send `{"all": true}`. That is one word longer to type and impossible to type by accident.
- The MCP tool `empty_trash` refuses the same way, because a model that leaves out every argument would otherwise have emptied everything.
- `store.emptyTrash` has no default and throws. That is the method every door goes through, including the window's own IPC, so it is the one place the rule cannot be skipped.

We proved it by making the call that caused it:

```
POST /trash/empty {}          400  "...it will not guess how much you meant."
POST /trash/empty {all:true}  200  {"purged": 3}
empty_trash, no arguments     Error: ...Name a projectId, an os list, or all: true.

```

On an update, an absent field means "leave it alone". On a route that destroys data, absent has to mean "refuse", never "everything".

## A loop revoked a key nobody named

On 20 September we were asked to revoke six API keys named "engine measurement". The loop went over `apiKeys.list()` and revoked every row it returned. One of those rows was called Arche and belonged to the operator's own tool. Key secrets are stored hashed, so it could not be given back, only replaced and reconfigured by hand.

![Mosaic API keys, each named after what uses it](https://mosaicbrowser.com/shots/api-keys.png)
*One key per tool, so one can be revoked alone*

The instruction named a set; the code took the whole collection. The correct loop differs by one filter:

```
for (const k of keys.filter((k) => k.name === 'engine measurement'))

```

A listing is a superset of the target by definition. Iterating it unfiltered is a decision to act on everything, written as if it were a decision to act on something. Ten minutes earlier in the same session, two other keys had been revoked correctly, by id, one call each. The habit did not carry over, because the written rule lived under a heading about profiles and this was keys.

## Delete by id, not by filter: what we do now

- Collect ids when you create the thing, and delete only those. Do not re-derive the set from a query later.
- Before an irreversible loop, print what it is about to act on, by name, with a count. The window does this for free: revoking a key shows its name beside the button. A script shows nothing until it is done.
- Make the wide version of a destructive route ask for itself by name. `{"all": true}` is a sentence; `{}` is not.
- Keep a way back. The safety snapshot is why the first story is a near miss and the second is a loss.

Purging itself is quicker now too; [emptying the trash used to stop the whole application](https://mosaicbrowser.com/blog/empty-trash-freeze). The routes involved are in the [local REST API](https://mosaicbrowser.com/features/rest-api), and the same refusals hold on the [MCP server](https://mosaicbrowser.com/features/mcp-server). Trashing, as opposed to purging, closes the profile's browser first, as [trashing a profile closes its browser](https://mosaicbrowser.com/blog/trash-closes-the-browser) explains.

## Questions

### Why delete by id instead of by a search or filter?

A filter is a pattern match over fields you did not list, run against data that changes. An id names one row. On anything that cannot be undone, the set should be the ids you were asked about or the ids you created, collected at that moment.

### What does Mosaic's POST /trash/empty do with an empty body?

It refuses with a 400. You have to name a projectId, an os list, or send all: true. The MCP tool empty_trash refuses the same way, and so does the store method underneath both.

### Can a purged Mosaic profile be recovered?

Often, yes. Every purge takes a safety snapshot of the library first, and restoring from it brings back the profile's fingerprint, proxy, locale, notes and tags. It does not bring back cookies, so the profile comes back logged out.

### How do I find what a cleanup removed?

Preview a snapshot against the live library. Its missing list is every profile that is in the snapshot and not in the library now, which turns 'something may be gone' into names.

## Related

[Emptying the trash stopped the whole application](https://mosaicbrowser.com/blog/empty-trash-freeze): rmSync on twenty Chromium profile folders stopped Mosaic for 0.70 s, and the API answered one request. A rename plus fs.promises.rm took 0.06 s.

[Trashing a profile closes its browser, at every door](https://mosaicbrowser.com/blog/trash-closes-the-browser): Delete a running profile in Mosaic and its browser closes first. If the browser will not close, the profile stays on the list, with its Stop button.

[Anti-detect browser REST API: profiles from your scripts](https://mosaicbrowser.com/features/rest-api): Mosaic's anti-detect browser REST API runs on 127.0.0.1 with API keys. Create and start profiles, then attach Puppeteer or Playwright over CDP.

[An anti-detect browser MCP server for your AI assistant](https://mosaicbrowser.com/features/mcp-server): Mosaic's anti-detect browser MCP server lets Claude or any MCP client create, launch and drive your profiles. 150+ tools, off by default, key-gated.

[A silently ignored flag looks exactly like a working one](https://mosaicbrowser.com/blog/silently-ignored-flags): Chromium accepts an unknown command line switch without a word. Two of our WebRTC flags never existed, and a renamed feature did nothing for months.







[The companion held a full-power API key](https://mosaicbrowser.com/blog/companion-api-key): Our in-browser extension used a full API key kept in a file. Now each launch gives it a token in memory that reaches its own profile and nothing else.

## Mosaic, on your own computer

The browser this blog is about: its own Chromium, fingerprints from real machines and a proxy IP per profile. Free covers 3 profiles with no card, and Pro is $25 a month for any number of them.

Mosaic is a desktop app

Email yourself the link and open it on your computer.
