- Status: Accepted
- Date: 2026-05-11
- Updated: 2026-08-19
- Related: ADR-027: Instance/Space/Server Consolidation, ADR-029: Rename
Instance→Server, ADR-015: DMs as a hidden space
Context
ADR-027 collapsed the historical three-tier model (Instance → Space → Room) into two tiers (Server → Room) at the conceptual and user-facing layers. ADR-029 finished the cosmetic rename of Instance → Server across identifiers, public API surfaces, NATS subjects, frontend modules, and docs.
The Space tier is therefore behaviourally retired, but its mechanical residue is still load-bearing in four places:
-
A vestigial primary-space record with stale readers. Every deployment has one
Spaceproto stored inINSTANCEKV at keyspace.{spaceId}with fieldsid,name,description. The branding (logo, banner) and the canonical server name/description already live inINSTANCE_CONFIG(ServerConfigproto + separateinstance.logo/instance.bannerkeys). Four code paths still read from the Space record anyway (line numbers omitted — these files have since shifted):cli/internal/core/dm.go— bootstrap creates a synthetic DM Space record- the then-current API mutation path — explicit "until PR(c)" dual-write of name/description
cli/internal/http_server/opengraph.go— OG metadata readsspace.Name/space.Description(stale;ServerConfigis the right source)- the thin Space API wrapper
These are dead-end reads of stale data. Once they're removed, the persisted
space.{spaceId}KV record becomes an orphan and can be left alone — one tiny entry per server, zero functional impact.
-
spaceIDplumbing on the core API. Roughly 80 functions acrosscli/internal/core/*.gostill take aspaceID stringparameter. Every one of them either ignores the value or feeds it into a legacy compatibility mapping, which exists only to map the legacy wire valuespace_id = "DM"to"dm"and everything else to"channel". The parameter is a one-bit DM flag dressed up as an ID. -
DMs still have legacy hidden-space residue at the wire boundary. ADR-015's "hidden DM space" predates the room-
kinddiscriminator. With thekindfield now baked into KV keys and NATS subjects, the DM scope is determined bykind == "dm"directly; the oldspace_id = "DM"value only survives where persisted payloads or compatibility APIs still carry aspace_idfield. -
Proto layer is partially renamed. The durable server-membership deletion event has been corrected to
ServerMemberDeletedEventwhile preserving field 320. Live deployment-scoped config changes useServerUpdatedEvent; unusedServerCreatedEvent/ServerDeletedEventlive proto messages were removed during the 0.1 protobuf cleanup. The bareSpace/SpaceMembershipmessages and the legacySpaceUserPreferencesnotification shape share the remaining naming residue. Notifications 2.0 no longer reads or writes that legacy preference model; see ADR-076.
The cost of leaving this in place is paid every time someone reads the code: a new contributor sees a spaceID parameter and assumes the codebase is multi-space, which it isn't. The cost of removing it is one focused refactor.
The full per-space KV bucket family (SPACE_{spaceId}_BODIES, SPACE_{spaceId}_REACTIONS, etc.) referenced in some proto comments does not exist in current code — those buckets were already collapsed into SERVER_* by the Phase-4 migration (#354). So this ADR is not gated on a data migration.
Decision
Retire the Space tier as a code-level concept. The persisted space.{spaceId} KV record stays where it is as an orphan (one tiny entry per deployment — nothing reads it after this ADR's Phase 1).
Naming rule
When a function previously took spaceID and the only thing it actually needed was the room's kind, the new signature drops spaceID and either:
- takes a
kind RoomKind(orkind stringfor now, pending a typed enum), if the kind is what the caller wants to express; or - drops the parameter entirely if the function only needs the room ID (the kind is derivable from the room record).
The DM sentinel is retired as a product/storage concept in favour of an explicit kind == "dm" check at call sites. A small RoomKindFromLegacySpaceID / LegacySpaceIDForRoomKind mapping may remain only at wire-format boundaries where persisted payloads or compatibility APIs still expose space_id.
Scope
In-scope for this ADR:
- Drop the four readers of the
space.{spaceId}KV record. Replace each with the canonicalServerConfigread (server name / description) or eliminate the call:dm.go— DM bootstrap no longer needs a Space record.- the API mutation path — the explicit "dual-write until PR(c)" comment is now PR(c); drop the dual-write.
opengraph.go— readConfigManager().GetEffectiveInstanceName/GetEffectiveDescriptioninstead.- the Space API wrapper — delete with the rest of the surface.
- Collapse
spaceID→kind(or drop) acrosscli/internal/core/*.go. Mechanical refactor; behaviour-preserving. Tests update at the same time. - Delete
cli/internal/core/spaces.go, theSpaceGo type,SpaceMembershipproto message, andServer.primarySpaceIdAPI bridge field once nothing reads them. The 1070-linespaces.godisappears. - Retire legacy live deployment-scoped proto residue. Durable
evtv1.Eventtags 1030–1032 are reserved as retired live-only variants; the current live envelope keeps only the emittedServerUpdatedEventand reserves removed lifecycle names/tags. - Rename
live.server.space.{spaceId}.>NATS subjects tolive.server.{eventType}(or another deployment-scoped pattern — to be decided in Phase 1). Live subjects have no persistence; rename freely. - Rename
SpaceUserPreferences→UserPreferencesin proto + storage key naming. Same wire-format-safe argument (preferences are a small KV-stored proto, not in JetStream). - Frontend rename
$lib/state/space/*→$lib/state/server/*(or merge in). Cosmetic; the store is "the active server's room/permissions state", not "a space's". - Update
docs/fdr/,docs/ARCHITECTURE.md, and the relevantAGENTS.mdfiles to drop residual "space" prose that survived ADR-029's docs sweep (those described what the code looked like at the time; this ADR makes them stale).
Out of scope (deferred):
space.{spaceId}KV record: stays as orphan. One small entry per deployment, no readers post-Phase-1.ServerMemberDeletedEventproto message (evtv1.Eventfield 320): renamed during the 0.1 protobuf cleanup while preserving the field number. No 0.1 servers had been deployed yet, and 0.0 import remains field-number based, so the source name could still be corrected before beta.space_idfields on other persisted event payloads (e.g. message events): stay for the same reason — wire format must decode existing stored events.KV_INSTANCE*bucket names,instance.logo/instance.bannerKV keys,/api/instanceREST endpoint: stay. Already covered by ADR-029. The public LiveKit config key was later renamed fromlivekit.instance_idtolivekit.server_id, with the old name retained as a deprecated alias for existing configs.
Phases (PR boundaries)
| Phase | Scope | Risk | Approx. size |
|---|---|---|---|
| 1 | Drop the four readers of space.{spaceId} KV (opengraph, mutation dual-write, dm init, API wrapper). Replace with ServerConfig reads where needed. |
Low | ~4 files |
| 2 | Collapse spaceID → kind (or drop) across core + tests. |
Medium (mechanical but wide) | ~80 signatures, ~15 files |
| 3 | Delete spaces.go, Space / SpaceMembership proto messages, Server.primarySpaceId API field. Retire legacy live deployment-scoped proto residue and rename SpaceUserPreferences to its un-prefixed counterpart. Rename live.server.space.> subjects. |
Low-medium | ~1100 line net deletion + targeted proto/subject renames |
| 4 | Frontend $lib/state/space/ → $lib/state/server/ import sweep. |
Low | ~5 files + ~15 importers |
| 5 | Docs and rules cleanup (stale "space" prose). | Trivial | Small targeted edits |
Each phase is shippable independently. Phases 1 and 2 are good candidates to combine. Phase 3 is the biggest single landing because deleting spaces.go cascades into the proto + subject renames cleanly.
Consequences
Positive
- The core Go API stops lying about its shape: signatures reflect what data they actually depend on.
- New contributors don't have to learn the Space tier just to find it's not real.
spaces.go(1070 lines) goes away. TheSpaceGo type andServer.primarySpaceIdAPI bridge field go away.- The DM mechanism gets simpler: normal room code uses
kind == "dm"directly, while the legacyspace_idconversion is boxed into explicitly named compatibility helpers. - ADR-015 ("DMs as a hidden space") was already marked superseded by ADR-027 at the storage layer. This ADR finishes the job at the API layer.
Negative / risks
- Phase 2 touches ~80 function signatures in core. Mechanical, but caller fan-out is wide; the PR will be large. Mitigated by holding the diff to one mechanical pattern per call site (rename or drop, no semantic changes).
- The persisted
space.{spaceId}KV record remains as orphan data on every deployment. Cost: ~a hundred bytes per server. Accepted. - Tests that construct primary spaces via
CreateSpace(...)need to be migrated to the new bootstrap path. Risk of test churn proportional to the spread of the helper. - Retiring live event proto residue is safe at the wire level, but every Go callsite that constructs the event needs updating in the same PR. The emitted set is small (
ServerUpdatedEventpublishers inserver_branding.go).
Deferred
- Persisted shapes that can't be renamed without a JetStream migration:
space_idfields on persisted event payloads and the orphanspace.{spaceId}KV record. Same reasoning as ADR-029: cosmetic gain not worth a stream rewrite. The event variant name was corrected toServerMemberDeletedEventbefore 0.1 deployment while keeping proto field 320 stable; unused server lifecycle messages were removed from the then-current live-event envelope.
Alternatives considered
- Leave it alone. Defensible — nothing is actively broken. Rejected because the gap between "what the code shape suggests" and "what the code actually does" is the largest remaining one in the codebase, and every contributor pays the translation tax.
- Rip out the persisted Space record too. Rejected: requires a data migration with no functional payoff. The orphaned KV record is one tiny entry per server.
- Rename
space_idproto fields andlive.server.space.>subjects. Rejected: persisted bytes are stored under those names. Field-number stability and subject naming are documented carve-outs from ADR-029. - Keep
spaceIDin signatures, rename to_legacySpaceIDwith a comment. Rejected as worst of both worlds — same translation tax, more visible eyesore.