Skip to content
The AI Agent Factory

35.7 Tenants, connectors and deletion

Approved by
Panaversity ·
11 min read

In everyday life. A storage company gives each customer a locked unit and a key that opens only that unit. When a customer leaves, the company empties the unit, and the customer can check that it is empty.

What you will learn. Every place a company's data lives on this platform, how to keep companies apart in each, how connectors fit, and how to delete one conversation everywhere.

Why it matters. A data leak between two clients ends a business. So does a client asking you to delete their data, and you not knowing where it is.

Every store, one rule

On this platform, one client's data can be in all of these:

StoreWhat it holdsHow companies are kept apart
Neon PostgresWorkers, assignments, usage, decisions, process recordstenant_id on every row, every query filtered by the trusted tenant
Conversation Durable ObjectsPi transcripts and run stateOne object per assignment; its name includes the tenant
Coordinator objectsBudgets, locks, the stop switchOne per worker, and a worker belongs to one tenant
Workflow stateStep results of each processProcess IDs include the tenant; inputs are IDs, not documents
R2 file storageInvoice PDFs, reportsOne prefix per tenant, and code that builds the prefix from the trusted tenant
Vector searchMemory and skill search, later in this partA tenant filter on every query, or one index per tenant
Logs, traces, AI Gateway logsCalls, prompts, resultsRedaction, retention limits, access by role

The rule is the same for every row: the tenant is decided by trusted code, from who is signed in or from the assignment. A tenant ID that the model writes can never, on its own, reach a company's data. Nor is a process ID, a worker ID or an event signal.

Step 7. Write the tenant test: sign in as an Acme user and, through every route the platform has (control plane, conversation, tool, Workflow start, file download, search), try to reach one Lahore Foods invoice. Every attempt must be refused and recorded. Then add a test where the model's tool call names Lahore Foods' tenant: it must be refused by authorize.

Environments and connectors

Each role gets only the environment it needs. The AP worker needs typed business tools and its connectors. It does not need a code sandbox or a browser, so it does not get one. A worker that cannot run code cannot be tricked into running it.

The worker reaches the client's accounting system through a connector, as in Chapter 18. On a platform with many clients:

  • Each company signs in to its own accounting system with its own OAuth approval. The platform stores each company's tokens apart, encrypted, and refreshes and rotates them.
  • A worker gets a connection to its own company's system, through the platform's code, at the moment it calls a tool.
  • Neither a worker nor a Workflow holds a platform-wide credential. No single secret opens every client's ledger. If one did, one bug would expose them all.

Deletion, with proof

A client asks you to delete one conversation: say, an assignment about a supplier who has since left. You must remove it from every store above, and show that it is gone.

The paper's rule: keep lineage. When data is copied, into a summary, a memory, a report, an evaluation set, record where it went. Deletion then follows the lineage.

For a conversation, the steps are:

  1. Postgres: delete or anonymise the assignment's rows, keeping only what the law requires (for example, that a payment happened), without the content.
  2. R2: delete the files under the assignment's prefix.
  3. Workflow state: processes keep state only for a limited time. Delete the instances that hold the assignment with the Workflow binding's deleteBatch, and check that none remains.
  4. Logs and gateway logs: delete by correlation ID where the store allows, or rely on a short retention set in advance.
  5. Memories and evaluation sets: follow the lineage, and delete or rebuild what came from this conversation. This matters most later in this part.
  6. The conversation's Durable Object.

Step 6 needs care. Pi Durable 1.6 has no call to delete a conversation. Because each conversation has its own Durable Object, you delete the whole object's storage instead, in this order (Lifecycle is the part from Chapter 33 that wakes the object with its alarm, for deadlines and jobs):

  1. lifecycle.dispose(), which releases live resources.
  2. lifecycle.disableAlarms(), so no deadline or job wakes the object again.
  3. ctx.storage.deleteAll(), which removes Pi's tables, its saved runs and your own rows.
  4. ctx.storage.deleteAlarm(), to be sure no alarm is left.

We tested this on Wrangler's local runtime on 30 November 2026. A conversation waiting for an approval, with a three-day deadline and a Lifecycle job, was deleted this way. Afterwards its object had no entries, submissions or tasks, and no alarm. After a full restart, Pi did not bring the run back: the conversation started empty. We have not yet repeated this on a deployed account, so the lab's proof script checks it on yours.

Two cautions remain. The order matters: if the alarm survives, Lifecycle wakes the object and rebuilds empty tables, which looks like a failure in the proof. And deletion removes the whole conversation, never one message in it. So the paper's advice still applies: keep sensitive content out of Pi transcripts where you can, and refer to documents by ID instead of pasting them in.

Step 8. Write scripts/delete-conversation.ts and scripts/prove-deleted.ts. The first follows the lineage and deletes the assignment from every store in the table. The second searches every store for the assignment's ID, correlation ID and three distinctive strings from its content, and fails if any is found. Run both on a test conversation.

What to check. Is every store in the table in the delete script? Does the proof script search the stores independently, rather than trusting the delete script's own log? What does it report for the Durable Object, and have you confirmed that report by hand?

The invariant. Each company's data is kept apart in every store by a tenant decided in code. Deletion follows the lineage to every copy, and a separate check proves it.

Check yourself. The delete script removes the assignment from Postgres, R2 and the Durable Object, and the proof script finds nothing. A month later the worker's memory still mentions the supplier. What was missed? (The lineage into memory. The conversation's facts were copied into a memory record, and neither script followed that copy. Add memory stores to the lineage and to the proof.)

  • Building Affordable, Self-Improving AI Workers (Panaversity, 29 November 2026), section 11.4, and companion appendices A7 and A8
Owner
Panaversity