# Tenancy

Run several customers or business units on one instance with server-enforced separation, per-tenant settings and optional per-tenant keys.

## How separation works

- A tenant owns **sources**. A ticket belongs to the tenant of the source it arrived through. A ticket filed in the console belongs to the caller's selected tenant.
- Users are granted specific tenants, or `*`. Owners see every tenant.
- Reads and writes are scoped by tenant on the server, over one shared database. Cedar policies can also test the tenant.
- Budgets, the semantic cache, the learned taxonomy, retention windows and data residency can differ per tenant.
- On a multi-tenant instance, channels with no signed-in person (Teams, the answer API) must be bound to one tenant, and refuse to answer until they are.

## Create a tenant

1. Open **Tenants** and add one (`PUT /api/tenants/{tenant_id}`).

   | Field | Notes |
   | --- | --- |
   | name | Display name |
   | about | Description |
   | region | A free-text note of where its data lives. It is not enforced |
   | residency_region | Enforced: an ISO code such as `DE`, or `EU`. Model calls and embeddings for the tenant stay in that geography or are refused |
   | no_cross_geo | Also refuse cross-region routing inside the geography |
   | environment | For example `production` (the default) or `test` |
   | retention | Per-store retention windows for this tenant |
   | sources | Source ids this tenant owns |
   | owns_unsourced | Whether tickets with no source land here |

2. Bind other resources, such as agents or triggers, with `PUT /api/tenants/bindings/{kind}/{name}`.
3. Grant users with `PUT /api/tenants/grants/{username}`.
4. Users switch tenant from the console header (`POST /api/tenants/select/{id}`).

## Regions on the hosted service

On the hosted service, each region we offer is a separate deployment, and a workspace bought through the Microsoft marketplace is placed in one of them. The [sub-processors page](/subprocessors#where) lists the regions we offer today, who is placed in which, and where each keeps a workspace's data and its backup copies. A region is listed there before any workspace is placed in it. The organisation's country is taken from its Microsoft sign-in, never from where it connects from. While any placement rule is set and the sign-in states no country, no workspace is set up.

In an EU-hosted workspace, model calls and embeddings stay in the EU. Its agents call Google Vertex AI's EU multi-region endpoint, the embedding model runs inside the EU deployment in Frankfurt, and a call that cannot be shown to stay in the EU is refused, never sent elsewhere.

## Isolation tiers

Each tenant has an isolation tier. Every tenant starts on **shared**, and nothing changes for it until you move it.

| Tier | Where the tenant's rows live | Cost |
| --- | --- | --- |
| `shared` (default) | The instance's tables, beside other tenants', kept apart by the tenant column and row-level security | None |
| `schema` | A Postgres schema of the tenant's own (`t_<tenant>_<hash>`) in the same database. Connections working for the tenant read and write it; no other tenant's connection can see it | None: same database |
| `dedicated` | A database of its own, served by a separate Liyagent instance (a cell). This instance sends the tenant's requests there with `421` and the cell's address | Only once you provision the cell |

The tier covers every table with a tenant column that row-level security covers. Instance-wide settings and accounts stay in the shared tables. Tickets, and what is drafted from them such as Scribe articles, belong to a tenant by their source, not by a tenant column, so they stay in the shared tables on every tier.

### Move a tenant

1. Check what would move: `GET /api/admin/platform/tenant-tiers/{tenant}/plan` lists the tenant's row count per table and its own settings records. Add `?to=dedicated&target_db_env=TICKETIQ_CELL_<NAME>` and the plan also lists `blockers`: every reason the move would be refused, in the words the move itself uses.
2. Move it: `POST /api/admin/platform/tenant-tiers/{tenant}/migrate` with `{"to": "schema"}`. The rows move in one transaction with the tier change, so a move happens whole or not at all.
3. For `dedicated`, see the next section.

Moving to a less isolated tier (`schema` or `dedicated` back to `shared`) loosens isolation, so it needs `governance.weaken` and a reason. Move between `schema` and `dedicated` through `shared`.

A request another replica handled in the seconds before it saw the new tier can leave a row in the shared tables. `POST /api/admin/platform/tenant-tiers/{tenant}/drain` moves any such rows into the tenant's schema, and every start of the instance does the same, adding any table or column an upgrade brought.

> [!NOTE]
> Instance-wide background jobs read the shared tables. A job that should cover a schema-tier tenant runs for that tenant. Keep a tenant on `shared` if it relies on instance-wide sweeps over its tenant-column tables.

Every move writes `tenant.tier.migrate` (or `tenant.tier.migrate.failed`), and a drain writes `tenant.tier.drain`.

### Move a tenant to a dedicated cell

Place a tenant on its cell when you create it, or move it while it holds nothing but its settings. A move to a cell carries the tenant's rows in the tenant tables and its own settings records, and it is refused, before anything is written, while the tenant owns anything a move does not carry.

Before you move:

1. Start a Liyagent instance of the same release on the cell's database. A database no instance has started, or one last started by another release, is refused.
2. On this instance, set `TICKETIQ_CELL_<NAME>` to the cell's database URL. The URL is never sent in a request.
3. Create the tenant's people on the cell. Accounts belong to an instance and are not carried; the plan shows how many accounts hold a grant on the tenant here (`people_here`).

Then send `{"to": "dedicated", "target_db_env": "TICKETIQ_CELL_<NAME>", "endpoint": "https://<cell host>"}`. Run it through the API, not a script: the move counts the tenant's vector points, and refuses where no vector store is bound.

| The move is refused when | What clears it |
| --- | --- |
| The tenant owns tickets, sources, transcripts, sessions, meetings, archived recordings, files, chat files, computer-use runs, approvals, voice lines, usage records, secrets, bound agents or MCP servers, vector points, trace spans, model weights, or rows in instance-wide tables such as role bindings | Move before the tenant is used, or delete those first. The refusal names each kind with its count |
| A legal hold names the tenant | Release the hold |
| The cell's database lacks a table or column the tenant's rows need | Bring the cell to the same release and use that feature there once |
| The cell already lists a tenant with this ID as its own | Delete that tenant on the cell. `replace_on_cell` never deletes a tenant the cell holds as its own |
| The cell holds a copy an earlier, failed move left | Send `"replace_on_cell": true`. The copy is deleted on the cell before the new one is written |
| The cell's address is not `https://host[:port]` | Send the address with no path, query, user name or fragment. `http://` is accepted only for `localhost` |

How a move behaves:

- Each side changes in one transaction. The rows are copied to the cell and committed there, then deleted here in the same transaction that changes the tier. If anything fails in between, the copy on the cell is removed and the tenant stays here, whole.
- A row written for the tenant during the move stops it: nothing is moved, and you try again.
- If a failure arrives after this instance committed, the move stands and the response carries `sender_error`. If it cannot be established whether this instance committed, nothing more is deleted on either side and the error tells you to check the tenant's tier before any retry.
- Moving back (`{"to": "shared", "target_db_env": ...}`) copies the rows here, switches the tier, then deletes them on the cell. If that last delete fails, the response carries `cell_left`: the tenant is served here, and its copy on the cell is cleared by deleting the tenant there.
- People of a moved tenant are sent to the cell with `421` and its address. Only an address that passes the check above is ever sent.

### Your default tenant

A person with no saved tenant choice lands in the instance's own home (the tenant the legacy, unscoped records were adopted into) when they can see it. Otherwise they land in the first tenant they can see whose environment is not a rehearsal one (`demo`, `sandbox`, `test`, `staging`, `dev`, `qa`, `trial`), not in whichever tenant sorts first alphabetically.

## Delete a tenant

`DELETE /api/tenants/{tenant_id}` deletes a tenant and purges its customer data in the same request. It needs `access.write` and access to the tenant. What goes:

- the rows of every table stamped with the tenant, in the shared tables and in a schema-tier tenant's own schema, including its LLM gateway request log, entitlement grants and model registry records (versions, stage history, experiments, runs, fine-tunes, and the weights no other version uses)
- the tickets that came in through its sources and its direct intake, open or closed, with their runs, attachments, inbox mail, case audits and their auditor overrides, and working memory, and the knowledge articles Scribe drafted from them
- its transcripts, agent sessions, meetings (with their recall entries and raw archive objects), onboarding journeys, memory (with the record of what each memory was learnt from) and its own settings
- its agent trace spans, hand-offs and run event log, Playground chat files, computer-use runs with their screenshots, approvals with their cards, approval-triage rules, voice-desk calls and phone lines, agent avatars, per-person usage, and its entries in the lists features share between tenants (knowledge gaps, retros, trigger runs, template installs, canaries)
- its sources, the credentials stored for the tenant, and any instance-wide credential that only its sources used
- its vectors, the knowledge collections of its sources and its blobs

Only what a billing or tax law needs, or a control still in force, is kept, with nothing in it that names a person:

- the hourly spend ledger: amounts, counters, the agent, model and provider. The person, the ticket and the tags are removed and the rows merged, so no amount can be traced back to a person.
- its budgets: the limit, period and the agent each caps. Recipients, names, tags and authors are blanked.
- agent-level usage counters that the spend ledger has not yet absorbed: agent, provider, model and counts, with no person.

A source that another tenant has listed by the time the purge runs stays with that tenant. Until the purge has finished, no tenant can add the deleted tenant's sources. The audit log is kept. Each purge writes `tenant.purge` with counts per store and no content.

Records a legal hold covers are kept. A hold on the tenant, or holds that can't be read, keep everything. A ticket, requester, conversation or agent hold keeps the records it names. The daily retention job removes what was kept once the hold is released. Until then the tenant id can't be used for a new tenant, because that tenant would see the old records.

The purge stays pending, and the daily retention job carries on with it, until every store is done:

- **Vectors.** A process with no vector store (a worker or a command-line run) records the vectors it couldn't remove. The tenant stays pending until a process with the store removes them.
- **Dedicated tier.** The instance orders the purge on the tenant's cell, through the `TICKETIQ_CELL_<NAME>` variable recorded when the tenant moved there. The cell deletes the tenant on its next daily pass and purges it with its own vector store and blobs. The instance's purge finishes only once the cell holds neither the tenant nor a pending purge of it. If that variable isn't set on this instance, the purge stays pending as `cell:unreachable`. For a tenant moved before the variable was recorded, the purge looks for it: of the `TICKETIQ_CELL_<NAME>` variables set on this instance, if exactly one names a database that holds the tenant (and none can't be read), it's recorded and audited as `tenant.tier.cell_env` by `system`, and the purge goes on. If none or several do, the purge stays pending as `cell:unreachable`, and the pending entry's `reasons.cell` names the variables it checked. Then name the right one with `POST /api/admin/platform/tenant-tiers/<tenant>/cell-env` and `{"db_env": "TICKETIQ_CELL_<NAME>"}`. The variable must be set on this instance and its database must hold the tenant.

Rows stamped with no tenant, and the unsourced intake (web, email and API tickets with no source), belong to the instance, not to a tenant. A tenant given the unsourced intake only has access to it, so those tickets stay when that tenant is deleted.

Copies in backups go as the backups are replaced. On a self-hosted stack, `deploy/backup.sh` prunes snapshots older than `BACKUP_RETENTION_DAYS` (14 by default). Each WAL-G base backup deletes those older than the newest `WALG_RETAIN_FULL` (7 by default). Setting either to `0` keeps every backup, and with it every deleted tenant's rows.

### When a marketplace subscription ends

A workspace opened by a marketplace subscription is deleted, with its data as above, by the daily retention job once every subscription for it has ended and `TICKETIQ_MARKETPLACE_ENDED_PURGE_DAYS` have passed (14 by default, at most 28). That window is for exporting. Each deletion writes `commerce.workspace.deleted`.

A workspace an operator attached a subscription to is kept, with the rest of its data, after the same window. Only what was provisioned for the subscription goes: the agents its plan installed and the buyer's account, with every record in the tenant stamped with them (memory, runs, transcripts and sessions). If a subscription still running for another workspace uses the account, the account stays and loses only this tenant. Records a legal hold covers, and the agents and accounts, stay until the hold is released. It happens once and writes `commerce.workspace.purged` with counts only.

The subscription records themselves stay, because the marketplace's payouts are reconciled against them: subscription ids, offer, plan, quantity, terms and states. The marketplace is the merchant of record and invoices the buyer, so no invoice of ours needs the buyer's details. Once a subscription has ended and its workspace's data is purged (or, for a subscription that never got a workspace, once the same window has passed), the name the buyer gave the subscription is blanked and the buyer's and purchaser's emails and Microsoft object ids are replaced by keyed pseudonyms: an HMAC under a key derived from the vault key, so the database alone can't be used to test a guess, while the same person buying again still matches. A later report from the marketplace doesn't bring them back. The accounts made for a deleted workspace go with their sign-in links, unless a running subscription or a live tenant's grant still uses them. A subscription still running keeps its buyer until it ends. Each pass writes `commerce.people.forgotten` with subscription ids and counts.

## Retire a tenant

`POST /api/tenants/{tenant_id}/retire` retires a tenant by crypto-shredding: it writes an erasure receipt, deletes the tenant, destroys its data keys (making everything sealed under them unreadable, in backups too) and removes its blobs. It needs `access.write` and `admin.write`, access to every tenant (`*`), a reason and the tenant id repeated as confirmation. It is refused unless per-tenant keys (`TICKETIQ_TENANT_KEYS`) and content sealing (`TICKETIQ_SEAL_CONTENT`) are both on and nothing the tenant owns is left outside its key, and while a legal hold covers the tenant. Each retirement's receipt is listed at `GET /api/tenants/retirements`.

> [!WARNING]
> Retirement can't be undone. Export what you need first.

## Next steps

- [Identity and roles](/docs/govern/identity-roles)
