Design Record: Tenant-Bound Driver Facades
Status: implemented. Every driver kits use declares a tenantBinding, and the kernel refuses to hand kits a driver port without one.
Status: implemented. Every driver kits use declares a tenantBinding, and the kernel refuses to hand kits a driver port without one.
#Problem
Kit ports are context-first (ARCHITECTURE Invariant 4), and store@1 reaches kits only through handles.storeFor(ctx), which checks the context. Driver ports do not work that way. A kit gets a frozen facade of the driver's declared members (readMembers while a guard runs), but every method still takes a raw tenant:
| Port | Tenant in the call | What a kit can do today |
|---|---|---|
search-index@1 | get(tenantId, id), upsert(docs[].tenantId), search({ tenantId }), ... | read and write any tenant's documents |
queue@1 | enqueue({ tenantId }), getJob(tenantId, id); lease / listJobs cross tenants | enqueue into, or read, any tenant's jobs |
telemetry@1 | recordSpan(span.tenantId), ...; readSpans(query) | write or read any tenant's spans and costs |
notifier@1 | notify({ tenantId }); listNotices(filter?) and acknowledge(noticeId) take none | list and acknowledge every tenant's notices |
blobs@1 | none: content addressed by sha256 | read any tenant's blob given its digest; dedupe reveals that content exists |
A kit that forwards an unchecked tenant id, by mistake or by intent, crosses tenants, and the kernel never sees it.
#Decision
Kits get context-first driver facades. Every tenant-scoped method of a driver port is called by kits as method(ctx, ...args), with the arguments unchanged. The kernel's facade then:
- Checks
ctxthe waystoreFordoes (checkedContext: issued by this kernel, same tenant and actor as issued, capture and mode never widened). - Applies the guard-phase rule (
readMembers). - Binds the tenant. Every place the call names a tenant must equal
ctx.tenantId, otherwise the call fails withCONTEXT_TENANT_MISMATCH. A filter that names no tenant getsctx.tenantIdfilled in, so a kit can never list across tenants. - Calls the driver.
The host keeps the raw drivers (kernel.getPort).
Why verify rather than strip the tenant arguments: kits keep their argument shapes, so migrating a call means adding ctx in front of it. An argument naming another tenant then fails loudly instead of being rewritten silently.
Why not an ambient context (AsyncLocalStorage) check:
- Host-driven calls into kits and detached async work would run without one, or with a stale one.
- An explicit
ctxis typed, visible at every call site, and checked by the same code as the store.
#Binding spec
Each driver contract declares, per member, how the tenant is bound:
"tenantBinding": {
"get": { "arg": 0 },
"search": { "arg": 0, "field": "tenantId" },
"upsert": { "arg": 0, "field": "tenantId", "each": true },
"lease": "platform",
"propose": "none"
}{ "arg": n }: positional tenant id parameter, which must be the context's tenant.{ "arg": n, "field": "f" }: an object argument (absent counts as{}) whose fieldfmust be the context's tenant and is set to it when absent. This covers filters (listNotices,listJobs): a kit can never list across tenants.{ "arg": n, "field": "f", "each": true }: an array argument, every element bound that way."none": tenant-free (runner.exec,vault.*,identity.verify*). Called asmethod(ctx, ...args)all the same, so every kit-facing driver call carries a context.{ "ctx": n }: the member already takes the caller's context at argumentn(model.propose(request, ctx)). Its shape is unchanged, and the kernel checks that context in place."platform": crosses tenants by design (queue.lease,heartbeat,complete,fail, andlistAllJobs, added for worker-pool's sweep of jobs whose worker died). Only kits grantedcontextIssuerget these members. Those kits (worker-pool, scheduler) already act for every tenant, so no new grant is needed. Every other kit's facade omits them.
The SDK's KitDriverPort<T> type turns a driver interface into its context-first kit-facing form.
A member with no binding is left off the kit facade (fail closed), as a member missing from members is today.
#API changes needed first
Two drivers cannot be bound with their current methods. Both change in place (done), since the platform has not shipped @1 externally:
notifier@1:acknowledge(noticeId)becomesacknowledge(tenantId, noticeId), andlistNoticesrequires a tenant in its filter.blobs@1: storage becomes tenant-scoped:put(tenantId, data, options),get(tenantId, sha256),has,delete. Dedupe and existence checks then stay within a tenant.blobs-fsrefuses to start over blobs from before (BLOBS_LEGACY_UNSCOPED) untillegacyTenantIdnames their owner, then moves them there once.
#Phases
- Kernel and SDK (done). Add the
tenantBindingspec toPortContractand the loader. Build ctx-first facades for contracts that declare a binding. Add a confinement test: a mismatched tenant is refused, a filter is filled in, a platform member is reachable only withcontextIssuer. Contracts without a binding keep today's facade, so the migration is incremental. - One driver per commit. For each driver: annotate its contract, add a kit-facing interface to its contract package (for example
SearchIndexKitPort), and migrate its kits:search-index@1: ingestion, knowledge-graph, lineage, memory, memory-consolidation, search-graph, search-keyword;queue@1: resilience, scheduler, worker-pool (the last two holdcontextIssuerand get the platform members);telemetry@1: observability, workspace-ui;notifier@1: approvals (after its API change);blobs@1: artifacts, sandbox, simulation (after its API change);runner@1,vault@1:"none"bindings, call sites gainctx.model@1binds its context in place instead (proposeas{ "ctx": 1 },pricinganddescribeModelas{ "ctx": 0 }), so the kernel checks the context the driver receives (and onlyid,pricing, anddescribeModelare inreadMembers, forbidding liveproposecalls inside read-only Guard Phase 1).
- Flip the default. A driver contract without a
tenantBindingcan no longer be handed to kits (PORT_TENANT_BINDING_UNDECLARED). The raw-argument facades are removed, and ARCHITECTURE §7 Invariant 4 covers driver ports too.
#What stays out of scope
- Kit namespaces within a tenant, such as one kit's queue names or index kinds versus another's. That is confinement between kits, not between tenants, and can build on the same facade later.
- The host. It is trusted, and keeps raw drivers.