# 35.7 Tenants, connectors and deletion (/affordable-self-improving-ai-workers/the-worker-platform/tenants-connectors-and-deletion)

---
type: Document
title: "35.7 Tenants, connectors and deletion"
description: "Keep each company's data apart in every store, give each role only the environment and connectors it needs with each company's own sign-in, and delete a conversation from every store with proof, including the part Pi Durable cannot do yet."
status: stable
order: 435.07
ksor:
  owner: team:panaversity
  audience: [ public ]
  approval:
    by: process:panaversity
    at: 2026-11-30T08:18:55Z
chapter: "35"
part: IV
expert_status: manager
concepts: [ "35.7" ]
last_verified: 2026-11-29
sources:
  - id: paper
    title: "Building Affordable, Self-Improving AI Workers (Panaversity, 29 November 2026), section 11.4, and companion appendices A7 and A8"
    resource: "Panaversity paper, version 1.0, 29 November 2026 (not yet published)"
generated:
  at: 2026-11-30T08:18:55Z
  by: human:zia
trust_tier: unverified
build_id: sha256:d6ce3f28a2cf8e492a60bae1b426b7cc6466e35e83d70c3b9763db2c55009f4b
dirty: true
ksor_version: 0.0.60
---

**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:

| Store | What it holds | How companies are kept apart |
| --- | --- | --- |
| Neon Postgres | Workers, assignments, usage, decisions, process records | `tenant_id` on every row, every query filtered by the trusted tenant |
| Conversation Durable Objects | Pi transcripts and run state | One object per assignment; its name includes the tenant |
| Coordinator objects | Budgets, locks, the stop switch | One per worker, and a worker belongs to one tenant |
| Workflow state | Step results of each process | Process IDs include the tenant; inputs are IDs, not documents |
| R2 file storage | Invoice PDFs, reports | One prefix per tenant, and code that builds the prefix from the trusted tenant |
| Vector search | Memory and skill search, later in this part | A tenant filter on every query, or one index per tenant |
| Logs, traces, AI Gateway logs | Calls, prompts, results | Redaction, 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.)*
