Context
ADR-033 moves Chatto's
content and domain state to EVT, with projections derived from that event
history. Not every durable value belongs in that log. Some state is operational
or user-runtime state: it needs to survive process restarts, but it is a
latest-value cursor, token, job status, cache marker, or runtime preference
rather than reconstructable Chatto content.
Historically these values have lived in a mix of buckets:
SERVER_RUNTIMEfor read cursors, mention flags, per-room runtime indexes, and legacy video processing state.AUTH_TOKENSfor bearer tokens.- Feature-specific KV buckets or object stores for caches and processing metadata.
That spread makes the event-sourcing boundary fuzzy. It also keeps
SERVER_RUNTIME as an architectural name even though "server" is a
user-facing product concept, not a useful storage category.
Decision
Persist all non-content runtime state in one JetStream KV bucket named
RUNTIME_STATE.
The storage boundary is:
- If a value is needed to reconstruct Chatto content or domain state, it belongs
in
EVT. - If a value is durable latest-value runtime/user/operational state, it belongs
in
RUNTIME_STATE. - If a value is purely transient process state, it can remain in memory or a
memory-backed KV bucket. Shared volatile cache state that must be visible
across Chatto processes belongs in
MEMORY_CACHE. - If a value is binary/object data, it belongs in the appropriate object store.
- Administrator-managed configuration stays in the existing configuration buckets because it is configuration, not runtime state.
- KMS KEK material stays in
ENCRYPTION_KEYSbecause its backup and security rules are intentionally different from ordinary runtime state. App-owned wrapped DEK records live inRUNTIME_STATE; they are backed up with the encrypted data they describe, but are unusable without the excluded KEKs.
RUNTIME_STATE is persisted and configured for latest-value use:
- File storage.
- One version per key (
History: 1). - Replicated with the deployment's configured replica count.
- Compression enabled.
- Per-key TTL support enabled via a limit-marker TTL; no global TTL is applied.
Current occupants include:
- Room read cursors:
read.room.{userId}.{roomId}. - Thread read cursors:
read.thread.{userId}.{roomId}.{threadRootEventId}. - Bounded notification read-boundary and visibility-boundary records used to
coordinate read reconciliation and persistent privacy boundaries between
EVTand the separateNOTIFICATIONSevent stream. Notification derivation work, occurrences, and lifecycle facts do not live inRUNTIME_STATE; see ADR-076. - Web Push subscriptions:
push_subscription.{userId}.{endpointHash}. - Runtime credential verifiers:
session.{hmac}. Cookie-presentation records carry a fixed explicitauth.token_ttlexpiry and rotate in the final quarter of that lifetime. Human bearer access records use fixedauth.access_token_ttlexpiry and point to a stablerenewable_session.{hmac}authority with an explicitauth.token_ttlrenewal window. Values include credential kind (first_party_sessionoroauth_access_token), presentation (bearerorcookie), source, safe request metadata, fresh-auth metadata, and the user auth generation they were issued against. User-wide cleanup scans these records and deletes entries whose stored user ID matches. - Renewable human bearer-session authorities:
renewable_session.{hmac}with user/client binding, current window expiry, auth generation, current refresh generation, last refresh-request verifier/time, and fresh-auth metadata. The verifier is a purpose-separated HMAC of a raw UUID version 4 recovery nonce. Rotation uses KV revision OCC across replicas and advances the window in its final quarter. The raw refresh credential and recovery nonce are never stored; deleting this key invalidates every access generation. - Mutable human sessions:
session.{hmac}cookie records andrenewable_session.{hmac}bearer authorities store explicit expiry. Each changed revision uses revision-checked JetStream publish with a per-message TTL equal to its remaining explicit lifetime. See ADR-081. - OAuth authorization-code verifiers:
grant.{hmac}, with per-key 5-minute TTL. Values include the user auth generation they were issued against. - Account workflow credential verifiers:
email_otp.{hmac(subject)}.{hmac(code)},email_otp.{hmac(subject)}.challenge,registration_completion.{hmac},password_reset.{hmac}, andaccount_deletion_token.{hmac}, with per-key TTLs appropriate to each workflow. - Link-preview cache entries:
link_preview.{urlHash}, with per-key 24-hour TTL for successful previews and 1-hour TTL for failed fetches. - App-owned wrapped DEK records:
dek.{contentKeyRef}, one protobufUserDataEncryptionKeyper purpose-scoped user DEK epoch. These records have no TTL and are shredded on account deletion.
ReadStateModel mirrors the room and thread cursor keyspaces into memory with
one filtered watcher per Chatto process. The watcher supplies both its initial
latest-value snapshot and ongoing changes; core startup does not complete until
that snapshot is applied. KV remains authoritative, writes retain revision OCC,
and write paths wait for the watcher to observe their successful revision when
they require local read-your-writes.
NotificationBoundaryIndex applies the same process-wide filtered-watcher
pattern to notification read and visibility boundaries. Core startup waits for
its initial snapshot. Writes retain KV revision OCC and wait for the successful
revision to reach the index when local read-your-writes matters. One owning
model therefore serves all requests and background repair without creating a
watcher per request, user, or WebSocket.
The HMAC keys for runtime credential handles, renewable sessions, OAuth codes,
and account workflow tokens are derived with [core].secret_key from opaque
credential material plus a per-flow scope string. RUNTIME_STATE is included
in backups, so active sessions and pending flows survive restore when the same
secret is used; restoring with a different secret intentionally invalidates
those credentials. Backup archives do not contain raw cookie credential
handles, bearer access or refresh credentials, links, or OAuth codes.
Attachment declarations and video derivative manifests are not a RUNTIME_STATE
target. Uploaded assets are content and are declared with AssetCreatedEvent;
generated video thumbnails and variants are content metadata, so completed/failed
outcomes live in durable room EVT events that reference the created asset ID.
The current video processor does not write new runtime progress or claim state;
legacy SERVER_RUNTIME video.* records are historical pre-0.1 state and are
not written by current code.
Mention flags are not a target runtime-state model. Attention indicators derive
from exact unread notification occurrences instead of preserving
room_mention_status.* as canonical state.
Consequences
EVTremains focused on reconstructable content and domain history.- Runtime state has one persisted operational home with uniform backup, TTL, and history semantics.
- Hot read-state assembly avoids one KV round trip per room or thread, at the cost of process memory proportional to the persisted marker count and one process-wide filtered watcher per replica.
- Notification read and visibility reconciliation gets the same bounded, process-wide watcher and startup/read-your-writes guarantees.
- The old
SERVER_RUNTIMEbucket is historical pre-0.1 storage, not a place for new state. - Runtime values in
RUNTIME_STATEare not replayable fromEVT; backup and restore procedures must include this bucket when preserving user/runtime continuity matters. - Runtime credential records can be backed up without storing redeemable raw
tokens, because their keys are HMAC-derived from
[core].secret_key. - Per-key TTL becomes available for tokens and similar runtime values without splitting each feature into its own bucket.
- Mutable human-session revisions use per-message TTL. Explicit record expiry remains the authorization boundary.
- Security-sensitive exceptions remain explicit. In particular, KMS KEKs in
ENCRYPTION_KEYSare not folded into this bucket; only app-owned wrapped DEK records live inRUNTIME_STATE. MEMORY_CACHEis the companion non-durable bucket for cross-process volatile state. It uses memory storage, one version per key, the deployment's replica count, no global TTL, and a limit-marker TTL for expiring presence sessions. It is excluded from backups and is expected to clear on a full JetStream restart. Current occupants are user presence recordspresence.{userId}with per-key TTL. Active voice call participants are projection-backed durable room facts, notMEMORY_CACHEstate. LiveKit E2EE call keys are stored behind the KMS boundary inENCRYPTION_KEYSundercall.e2ee.{callId}refs and shredded when the corresponding call ends. The retiredUSER_PRESENCEandCALL_STATEbuckets are historical pre-0.1 shapes; fresh boots do not provision or import them.
Related
- ADR-033 — defines the event-sourced content/domain boundary.
- ADR-081 — separates mutable human-session state from immutable cleanup deadlines.
- ADR-028 — defines the read-cursor
shape that now lives in
RUNTIME_STATE. - ADR-076 — defines the bounded notification log and its cross-log runtime boundaries.