ADR 0015: graph runtime and registry
Status: Accepted on 2026-11-29 (knotrel/knotrel#224). Scope decisions Q1, Q2 and Q4 approved by the maintainer on 2026-11-29. Issues: #154 (contracts), #156 (runtime), #155 (graph resources). The “no public item” clause of decision 2 is superseded by ADR 0018 (additive core API in 1.x).
Related: ADR 0016 (authority, snapshots and restore), ADR 0017 (authentication and trust boundary).
Context
Knotrel 1.2 serves one graph per process. knotrel-server keeps that graph in
a single GraphState behind one read-write lock, together with everything that
belongs to it: revision, generation, the synchronization state of
source-managed mode, the feeder session and lease, the deduplication window, the
readiness word and the fail-stop flag. The admission lanes and the B2 query
limiter are process-wide.
v1.3.0 adds several independent graphs per process, each owned by a tenant (#153). Graph rules (single writer, readiness, fencing, fail-stop) must then hold per graph, and one tenant must not be able to exhaust the process. The existing single-graph routes and configuration must keep their documented meaning.
Decision
- A new crate,
knotrel-runtime, owns the graphs. It holds a registry keyed by tenant and graph ID and, for each graph, the state thatGraphStateholds today. It owns the graph lifecycle (creation, loading, draining, deletion), pinning of in-use graphs, per-graph fail-stop and admission. It exposes typed operations, not HTTP. A lookup with the wrong tenant is indistinguishable from a missing graph. - Dependency direction: the server depends on the runtime, the runtime on
knotrel-core(and optionally onknotrel-storage, ADR 0016). The core gains no dependency and no public item in v1.3.0; a missing core capability is a change request to this ADR. Q2: the runtime may depend ontokiowith thesyncfeature only, for synchronization primitives; HTTP and networking stay in the server. - Q1: the existing routes also go through the registry, on an internal
default graph created at startup from today’s configuration
(
KNOTREL_MODE, engine, limits) and owned by the local default tenant. The server keeps a direct handle to it, so these routes do no registry lookup. The existing HTTP contract is unchanged. -
Q4: limits are split by what they protect.
Scope Limits Process Connections, maximum request body size, import permits Tenant Quotas on graphs, pending jobs and concurrently executing jobs Graph Admission lanes (shared, feeder data, feeder control), graph limits, the B2 query limiter re-expressed per graph Creating more graphs therefore does not multiply the imports the server allows at once, and one tenant’s load cannot take another tenant’s capacity.
- A worker panic fails only its graph. Other graphs keep serving. This narrows the 1.x fail-stop rule (threat model T1.15) to one graph.
- Graph IDs are opaque and server-generated; their format is part of the API contract (graph resources). The stability class of the runtime’s public API is in stability.
Alternatives considered
- Keep the 1.2 code path for the existing routes and add the registry beside it. Avoids touching the request path of existing routes, so fewer cells in the release qualification, but leaves two implementations of every graph rule (readiness, fencing, fail-stop, admission) that can drift apart. Rejected (Q1).
- Registry inside
knotrel-server, no new crate. Smaller change, but ties graph lifecycle to HTTP and prevents embedders from running several graphs without the server. Rejected. - Process-wide admission only, as in 1.x. Simple, but one busy graph or tenant starves every other. Rejected.
- Per-graph import permits. Would let the number of concurrent imports, and their memory, grow with the number of graphs. Rejected (Q4).
- Public engine traits in the core, so the runtime is generic over engines. Out of scope for v1.3.0; evaluated separately in #222.
Consequences
- The largest refactor of v1.3.0: graph state, lifecycle and admission move
out of the server’s
service.rsintoknotrel-runtime. - The request path of every existing route changes. Its cost is measured once, in the v1.3.0 qualification #187 (single-graph regression against v1.2.0, Q3 and the carried lifecycle results), not during development.
- Metrics keep bounded labels: no graph or tenant ID as a Prometheus label by default; per-graph detail is available through the API.
- The future of
KNOTREL_MAX_CONCURRENT_QUERIES(keep per graph, fold into tenant quotas, or deprecate) is decided with #87. - Single-graph users see no change in behavior or configuration.