Quickback Docs
Database per Tenant

Tenant Database Limits

Every configuration the compiler refuses with tenancy.isolation durable-object, with its error code and the fence that replaces it.

Configurations the compiler refuses for a project with tenancy.isolation: 'durable-object', each with its compile error and what to do instead. Start at Database per Tenant for the model.

What the compiler refuses

CodeCause
TENANT_ORGANIZATION_UNKNOWN / TENANT_TARGET_MISMATCH / TENANT_PURGEDRuntime: provision of an id Better Auth does not know; a partition name the registry attributes to another organization; a normal operation on a purged row (recovery uses resolveRecoveryTarget).
TENANT_OPERATION_ID_CONFLICT / TENANT_OPERATION_PENDINGRuntime: a repeated operation id with different parameters; a repeated id whose receipt is not yet settled (reconcile it with GET /tenants/operations/:id).
TENANT_INVALID_TRANSITION / TENANT_CONFIRM_REQUIRED / TENANT_OPERATION_ID_INVALIDRuntime, not compile: a lifecycle operation refused by the state machine, without its confirmation, or with a malformed operation id. See Lifecycle operations.
TENANCY_OPERATOR_AUTHtenancy.operator.http.allow names a mutation route but auth.cloudflareAccess is not configured. Configure Access, allow only backups / bookmark / outbox-receipts, or set http: false.
TENANCY_OPERATOR_HTTPtenancy.operator.http is neither false nor { allow: [...] } naming at least one known route, or it is set beside the deprecated tenancy.operator.purge. See Operator routes.
TENANCY_RUNTIME / TENANCY_PROVIDERThe runtime is not Cloudflare, or the database is not cloudflare-d1. Postgres schemas, RLS and migrations do not port to Durable Object SQLite.
TENANCY_ORGANIZATIONSThe Better Auth organization plugin is off.
TENANCY_PLACEMENT_CROSS_TENANTAn organization-scoped table declares placement: 'platform'. Use { platform: true, crossTenant: true }.
TENANCY_PLACEMENT_UNSCOPEDA table declares placement: 'tenant' but no arm of its firewall — top level, all:, any: or optional — binds an organization column. The tenant pin needs one.
TENANCY_PLACEMENT_UNCONFIRMEDThe build carries no deployed-schema facts (an older CLI, or an unreadable latest snapshot), and a table derives tenant from an any: / optional organization arm. Declare its placement.
TENANCY_ORG_COLUMNSA tenant table's firewall binds more than one organization column. Keep it on the platform ({ platform: true, crossTenant: true }).
TENANCY_PLACEMENT_MOVEDA table in the deployed features D1 derives tenant from its firewall (a shared project switching to 'durable-object', or an any: / optional organization arm). Declare placement: 'tenant' after copying its rows, or { platform: true, crossTenant: true }. See Placement changes on deployed tables.
TENANCY_PLACEMENT_MIXED_FEATUREOne feature mixes tenant and platform tables.
TENANCY_FK_TENANT_TO_PLATFORMA tenant table references a platform table. References to Better Auth tables (user) are ids without a foreign key and are allowed.
TENANCY_FK_PLATFORM_TO_TENANTA platform table references a tenant table.
TENANCY_ASYNC_TRANSACTIONA tenant action, a helper it reaches, or a JS trigger handler passes an async or Promise-returning callback to transaction() on a db / tx handle.
TENANCY_BATCH_ASYNCA tenant table's create / update / upsert access, or its guards, is a function.
TENANCY_UNSAFE_RECREATEA new tenant migration recreates a referenced table or copies into an unsafe NOT NULL column.
TENANCY_UNSAFE_ACTION / TENANCY_ROOT_ACTION / TENANCY_CTX_UNAVAILABLEA tenant action is cross-tenant unsafe (unsafe: true, or an object without crossTenant: false) or sets unsafe.authWrites, mounts outside its feature's path (and outside its tables' routes and every tenant namespace prefix; see Actions at a table route), or reads ctx.auth, ctx.tenancy or ctx.seal — or ctx.fga when the project declares no authz.fga — by property access or destructuring, including the auth execute param. They exist only on the edge. The ctx check also covers helpers tenant code imports and JS trigger handlers on tenant tables. Keep cross-tenant unsafe and root-path ingress in a platform feature and call a result job. unsafe: { reason, crossTenant: false } is allowed: see Same-tenant unsafe actions.
TENANCY_QUEUE_BINDINGTenant code (an action, a tenant job, a JS trigger handler or a helper they import) enqueues to a binding that is not one of the edge Worker's queues, or one the build cannot read. See Platform queues.
TENANCY_ENV_UNAVAILABLEA tenant action, a tenant job's body, a helper either imports, or a JS trigger handler on a tenant table reads an env binding (env.DB, c.env.AUTH_DB, const { BUCKET } = env, …). The tenant Worker has no D1, R2, KV, queue, var or secret bindings.
TENANCY_HELPER_UNRESOLVEDA module tenant code loads imports a relative or alias path that names no file in the build, or uses a computed import() / require(). See Helpers run where their caller runs.
TENANCY_TRIGGER_UNVERIFIABLEA JS handler: trigger on a tenant table has a source that can't be extracted as one arrow function or function expression.
TENANCY_JOB_CALL_TENANT_SOURCEcallTenantJob's tenant argument (or a target helper's organizationId) is not visibly server-verified (ctx.activeOrgId / ctx.tenantId, a resolveTenant / resolvePrincipalTenant result, a forEachTenant callback's tenant). Opt out with // quickback-allow-tenant-source: <reason>. See Result jobs.
TENANCY_JOB_RESULT_SCHEMA / TENANCY_JOB_RESULT_PRODUCERA result job without resultSchema (or a resultSchema without result: true), a resultSchema that is not a stripping or strict z.object, a result that is not the literal true, a result job that is not a tenant job or a project without isolation: 'durable-object'; or a result-job message built anywhere but callTenantJob's message argument. See Result jobs.
TENANCY_ADMISSION_DEPENDENCYEdge code reads a tenant-placed table: a scope kind, namespace, ws-ticket, live view, platform feature's authorization, derived JSON key, or a platform action's anchor, refs or operator target. Also a platform action, feature lib/ file, schedule, non-tenant queue handler, or edge-loaded quickback/lib helper or auth hook naming a tenant table, an edge module importing a tenant feature's module or using a computed import() / require(), an ambiguous scope instance, or an unresolved instance on a kind that is also a lookup. At runtime, an edge query on a tenant table throws TENANT_TABLE_ON_EDGE. See Admission tables stay on the platform.
TENANCY_ADMISSION_MIXED_PLACEMENT, _PARTITIONED, _UNRESOLVED_INSTANCE, _TENANT_COLUMN, _LOOKUP, _SQL_HELPER, _SELF, _HOPSA scope kind reads a tenant table but can't be tenant-backed. See Which kinds can be tenant-backed.
TENANCY_LEGACY_SCOPE_ENTERA scope kind reading a tenant table has no oauth. Tenant-backed kinds are admitted only through instance-bound OAuth: add oauth to the kind.
TENANCY_NAMESPACE_SPLIT, _PARTITIONED, _UNROUTEDSee Tenant namespaces.
TENANCY_EDGE_ACTION_PLACEMENT, _NAMESPACE, _CTXAn edge: true action is in a tenant feature, is not under a tenant namespace prefix, or reads ctx.<exposeAs>. See Edge namespace actions.
TENANCY_TICKET_GATE_UNSUPPORTEDA realtime.wsTicket session gate on a tenant room isn't the tenant-backed kind's own admission, plus at most one { roles } lane of plain organization roles. See Durable Objects → Tenant rooms.
TENANCY_ROOM_LOOKUPA resource-backed realtime room (bindings.durableObjects[].access.resource) on a tenant table has no tenancy.lookups entry on its room key column. See Durable Objects → Tenant rooms.
TENANCY_ROOM_UNSUPPORTEDA realtime room on a tenant table uses a form the tenant gate can't run: multi-resource access.resources, a partitioned table, or an inherited read.access with a record: predicate.
TENANCY_ADMISSION_ID_STRATEGYA tenant-backed scope kind's instance or proving table has generateId: false | 'short' | 'serial', allowClientIds: true, or a numeric primary key (see Tenant-backed scope kinds). Or tenant code (an action, a helper it reaches, or a trigger handler) inserts into a scope instance or proving table with an explicit id, a spread that may carry one, or a row it can't inspect. Omit id; // quickback-allow-id is honored only for crypto.randomUUID() / generateId(…).
TENANCY_REALTIME_PLATFORM_ROOMWith a tenant-backed scope kind, a tenant table's CRUD broadcasts (realtime.scopeTable / scopeKeyFrom) target a room that is not on a tenant table, or the ws-ticket's bound kind is tenant-backed but its scopeTable is a platform table. A tenant object can address only rooms on its own tables.
TENANCY_REALTIME_TAG_AMBIGUOUSA tenant-backed kind proves subjects from more than one table, and a recipients resolver calls recipient.scope({ kind, subjectId }) for it (or with a kind the compiler can't read) without provingTable, so the tenant tag can't name the proving table. The error lists each call's file and line. Pass provingTable.
REALTIME_RECIPIENT_PROVING_TABLEA recipients resolver's recipient.scope names a literal provingTable that is not one of the kind's proving tables (a relationship from of its roles). Any tenancy mode.
TENANCY_REALTIME_VIEW_ROOMA live view is rooted on a tenant table while a scope kind is tenant-backed. View rooms are not tenant-qualified yet.
TENANCY_UNSUPPORTEDA tenant table declares namespace, afterCommit, or a .sealed() column; embeddings without tenancy.bridges.embeddings, or on a partition table; a q.storageKey() column without tenancy.bridges.files, or on a partition table. .encrypted() and q.secret() are supported: see Encrypted columns; storage keys: Managed files; embeddings: Embeddings.
TENANCY_OWNS_CROSS_OBJECTA table's owns names a table in another placement (a platform table, another partition). A changeset writes root and children in one transaction in the root's database: keep owned tables in the root's placement.
TENANCY_FILES_BRIDGEtenancy.bridges.files without isolation: 'durable-object'.
TENANCY_EMBEDDINGS_BRIDGE / _VECTORIZE / _AUDITtenancy.bridges.embeddings without isolation: 'durable-object'; embedded tenant tables without providers.database.config.vectorizeIndexName; or auditFields: false, which removes the write chokepoint intents are recorded at.
TENANCY_EMBEDDINGS_SOURCE / _PROTECTED_SOURCEAn embedded tenant table's fields is empty or names a column the table does not have, or names a masked, .encrypted(), .sealed(), q.secret(), q.vaultRef() or q.storageKey() column.
TENANCY_EMBEDDINGS_SCOPEAn embedded tenant table's firewall binds anything besides its organization column, or its read access authorizes per row (owner, record predicates, relationships, FGA, a function). See Embeddings.
TENANCY_EMBEDDINGS_SERVICEA defineEmbedding search helper uses the Vectorize binding tenant vectors live in. Its helper queries without an organization namespace and returns raw ids and scores. Search tenant tables with ?similar=, or point the definition at another index.
TENANCY_EMBEDDINGS_MODEL / _COLUMN / _METADATAA model the bridge cannot size an index for, or embedded tenant tables of different dimensions; embeddingColumn or metadata on an embedded tenant table.
TENANCY_TRIGGER_CROSS_OBJECTA tenant table's sql: trigger (body or when:) names a table outside its own object — a platform table, another partition kind, or a table no feature declares — or uses SQL the compiler does not model (a schema-qualified name, a CTE, a table-valued function other than json_each / json_tree, a statement keyword such as DROP / PRAGMA, unbalanced parentheses). Also a platform table's trigger that names a tenant table. Every violation is listed.
TENANCY_BACKUPtenancy.backup.bucket is not an UPPER_SNAKE binding name, or every is not <n>m / <n>h / <n>d of at least 15 minutes.
TENANCY_BACKUP_ENCRYPTtenancy.backup.encrypt is true in a project with no .encrypted() or q.secret() column, so it has no per-organization keys to seal dumps with. See Encrypted dumps.
TENANCY_LOOKUPA lookup's table is not a tenant table, or its column is not a column of that table.
TENANCY_PARTITION / TENANCY_PARTITION_UNSCOPED / TENANCY_PARTITION_KEY / TENANCY_PARTITION_KINDSA partition name is not a lowercase identifier, the table has no organization arm, the key is not a column (or differs within the feature), or the project declares more than one partition kind.
TENANCY_FK_CROSS_PARTITION / TENANCY_CROSS_PARTITIONA foreign key, or an action (or a helper it reaches, or a trigger handler), spans two objects.
TENANCY_QUEUE_PARTITION / TENANCY_QUEUE_MIXED_PLACEMENTA queue handler imports a partitioned feature without placement: { partition }, or mixes database placements. See Partition jobs.
TENANCY_JOB_PLACEMENT / TENANCY_QUEUE_PARTITION_KEYA placement that is not a literal, names an undeclared kind or conflicts with tenant: true; a partition-job message literal without partitionKey. See Partition jobs.
TENANCY_QUEUE_TENANT_ID / TENANCY_QUEUE_RESERVEDA platform action, queue handler or schedule builds a tenant-job message without tenantId, or a handler uses the reserved type qb:backup.
TENANCY_NAMESPACE_DELETIONSee Deleting the namespace.
TENANCY_JURISDICTION_CHANGED / TENANCY_JURISDICTION_UNKNOWNtenancy.jurisdiction differs from the deployed wrangler.toml's # quickback:tenancy.jurisdiction= line, or wrangler.toml binds QuickbackTenant without that line. Add it with the jurisdiction the objects were created in. A build without wrangler.toml only warns.
TENANCY_ROUTE_RESERVED / TENANCY_ADMIN_NOT_BEHIND_ACCESSA feature mounts at /tenants, or Access is configured and no application covers the operator routes.
TENANCY_TENANT_WORKER_UNKNOWNThe existing wrangler.toml references QuickbackTenant in a form the build cannot resolve to an edge and tenant Worker. Rewrite it as plain [[durable_objects.bindings]] tables under a named edge table.
TENANCY_TENANT_WORKER_CHANGEDA deployed edge (per the existing wrangler.toml) would bind a different tenant Worker than it does now. See Two Workers.
TENANCY_ENVIRONMENT_WORKER / TENANCY_ENVIRONMENT_SHARED / TENANCY_ENVIRONMENT_BACKUPA named environment has no tenantWorker.name, shares a tenant Worker or backup bucket with another target, or names a tenant Worker like an edge or files Worker. A target that does not deploy as the project name reuses the single-target tenant Worker or bucket. A Worker takes a reserved <name>-unselected, <name>-files-unselected or <name>-tenant-unselected placeholder name. backupBucketName is missing while tenancy.backup is set, or set while it is not. See Named environments.
TENANCY_PURGE_DO / TENANCY_FGAtenancy.purge, or a top-level fga block (declare it at authz.fga), together with isolation: 'durable-object'.
TENANCY_FGA_SHARING / TENANCY_FGA_MEMBERSHIP / TENANCY_FGA_ACCESS_ARM / TENANCY_FGA_MIXEDAn FGA shape that would reach tuples from outside the organization object: sharing without link subjects, derived membership, an fga arm off a tenant table, ctx.fga off the organization object. See FGA.

Fence a result job to an authorization epoch

callTenantJob(env, tenantId, message, runId, { expectedAuthorizationEpoch }) optionally requires a safe nonnegative integer epoch. The tenant compares it with its live admission permit before executing or replaying a result. A mismatch returns { status: 'unavailable', code: 'TENANT_AUTHORIZATION_EPOCH_CHANGED' }. The expected epoch also participates in the durable run hash: reusing a run ID with a different fence produces TENANT_JOB_RUN_CONFLICT once admitted.

Result handlers receive readonly authorizationEpoch?: number from that same permit, including ordinary four-argument calls. This value never comes from the message. Preserve it in a server-owned proof when subsequent work must be invalidated by restore. Other queue handlers may omit it. This does not change archive, restore or purge admission. RPC version 8 is required; deploy the tenant worker before the edge worker. Older workers fail closed on the new contract.

Fence purge to a retained backup

Operators retaining records before erasure can use purgeTenant(env, tenantId, tenantId, { expectedBackup: { key, generation, bytes } }). Pass the completed archived backup receipt whose contents were retained. The options and receipt accept exactly those keys. The receipt must name this organization's backup and contain a positive safe integer byte count. This fence does not download bytes and has no backup-download size cap.

Under exclusive control admission, before permanent purge marking, the tenant requires that receipt to match its latest completed archived backup, current generation and clean state. A completed restore, subsequent writes after unarchive, or a replacement backup refuse with TENANT_PURGE_BACKUP_STALE. Nothing is erased and a known rejected fence is released. In-flight work or restore continues to refuse under the existing maintenance contract.

The permanent purge marker retains the receipt identity outside erased tenant storage. A retry with that same receipt can finish after an interrupted erase; a different receipt, or a fenced retry of an originally unfenced purge, refuses. The original three-argument trusted-operator API remains available, including finishing an already marked purge without supplying a receipt. It cannot alter the permanent receipt or re-enable the tenant. Applications requiring retention must consistently supply the fourth argument before their first irreversible purge. RPC version 9 is required: deploy the tenant worker before the edge worker; older workers fail closed. No room-deletion callback or general maintenance callback is exposed by this API.

Hold admission through a resource room's native commit

Result jobs and outbox delivery do not keep a permit around their consumer's later native Durable Object commit. For a declared, locally authored room on a non-partitioned tenant resource, call acquireTenantRoomPermit inside the actual room operation, while holding its own work gate:

import { tenantRoomSession } from "../../../lib/tenant-room-session";
import { acquireTenantRoomPermit, releaseTenantRoomPermit } from "../../../lib/tenants";

// Method on the existing room class. No FIFO, admission, name initialization,
// or native storage I/O here: control calls back while this actor awaits it.
getTenantRoomSession(version: number) {
  return tenantRoomSession(this.ctx, version);
}

// Inside the actual authorized room operation, after taking its work gate:
const permit = await acquireTenantRoomPermit(this.env, verifiedTenantId, this.ctx, {
  binding: "PAGE_ROOM",
  key: roomKey,
  operationId, // stable server-owned id for THIS operation's exact retries
  expectedAuthorizationEpoch,
});
// All SQL authority reads, binary checks and native transaction retries must
// settle here. Keep the existing resource-pointer/native CAS checks.
await commitNativeCheckpoint();
await this.ctx.storage.sync();
await releaseTenantRoomPermit(this.env, this.ctx, permit);

Do not put release in an unconditional finally: a timeout, failed sync or unsettled continuation is not proof that no native commit can still happen. An ambiguous acquire/release retains quarantine; retry that exact operation or prove the actual room actor was replaced. A new operation must have its own ID. Released/denied identities remain terminal in individual durable records; the shared index contains only active operations. Delayed acquisition cannot resurrect them. Exact concurrent retries share the final ownership outcome; late failed cleanup cannot release a grant another retry already received. Duplicate requests wait on their own bounded timer, never another request's I/O promise. Timing out does not release admission.

The tenant verifies the live actor session through the declared existing room namespace, the current epoch/generation, and exactly one undeleted resource row using its parsed organization/key/deletion columns. It returns captured authorizationEpoch, generation and the permit token. This is ownership and restore admission, not user authorization: keep the application's operator/user checks and resource-pointer CAS. Ordinary admitted jobs can still change a resource while this permit is held; the permit blocks exclusive restore, purge and backup maintenance, not ordinary application edits.

The public helper takes the actual native DurableObjectState and derives its private session; it does not accept a supplied session string. An edge caller with a made-up object gets a different UUID and cannot borrow the live room session merely by reading the callback. Release also requires that same actual state/session. A session is private to that actor instance, never persisted or a module-wide UUID shared by rooms. tenantRoomSession uses a WeakMap keyed by its actual DurableObjectState and performs no I/O. Pruning compares the live room session, not the tenant actor's session. Tenant/control restart, elapsed time, a missing method or a probe error never retire a live room permit. An actual room replacement proves that its old continuation cannot access native storage. It may still finish external I/O; immutable R2/artifact safety remains a separate application protocol. See DO shutdown semantics and storage sync/output gates.

Room records and an armed compatibility guard are stored atomically outside the tenant's restored database. Older control code sees a non-purge operation with an unknown recovery kind and refuses restore, purge and recovery. It cannot prune the separate room records. Only the room-aware release or a proven room restart clears the last active record and its guard together. Unknown or inconsistent state blocks admission and exclusive maintenance. RPC version 10 is required; room permit calls never fall back to an older protocol. Rolling back while a room permit is held intentionally retains quarantine.

The compiler adds private tenant-worker bindings to existing edge room classes, with the matching edge script for each named environment. It adds no room class, namespace or migration. External-script rooms, partitioned resource rooms and rooms without a provable parsed organization column cannot use this API. Authored tenant handlers still cannot read the private bindings. Deploying a tenant that references a previously undeployed edge class may require the existing edge class to be deployed first. For an upgrade, a compatibility phase can add the zero-I/O getTenantRoomSession method using a private per-instance UUID to the already existing edge room class before introducing the tenant's reverse binding or the full room-permit configuration. Then the room-aware tenant can bind that existing class, followed by the full edge configuration. The full room class must then use the same generated WeakMap helper for both its callback and acquisition; a compatibility-only private UUID must not remain a different identity source. This is an artifact/rollout plan, not a deployment performed by compilation.

A completely fresh pair has circular edge TENANT and tenant ROOM references. Its account bootstrap/provisioning order needs a separate account-stage drill; local generation and Wrangler dry-run do not prove that one deployment creates such a pair without extra setup. Named-environment bindings must target that specific environment's existing edge Worker/class, and the deployment must verify those physical namespaces before enabling room commits. No raw SQL opener or arbitrary callback bridge is added. Local fault-adapter tests can drop an RPC reply before helper validation or reject an application acknowledgement after native storage.sync() completed. Those seams do not establish physical network loss or a native storage engine failure; the corresponding native/account failure drills remain open.

On this page