Context
The client stored public profiles in its realtime projection, room-directory queries, and timeline summary cache. Each cache had different readers and invalidation rules. A user could appear in a room member list but remain absent from the quick finder. Joining the caches inside the finder made a navigation component responsible for profile precedence and deletion.
Decision
Use one in-memory UserStore for each server ID and connection scope. It owns
public user profiles keyed by user ID. The realtime projection uses this same
store. Directory and timeline API adapters hydrate it; render adapters derive
names, avatar URLs, bot metadata, and other public fields from it.
Keep room membership IDs, query pagination, permissions, and request status in their existing owners. Timeline rows can contain render snapshots, but they do not form another profile cache. Server-scoped profile views resolve current fields from the shared store. Private admin fields are outside this store.
The signed-in account has a separate owner: one CurrentUserState per server.
Only complete live viewer responses populate it. Public profiles and saved
chat text cannot supply account data, mark it loaded, or establish session
validity. Routes and recovery share its pending account request. The registry
checks account changes and clears the previous account's private state before
publishing a new account. Reset and disposal reject late account responses.
Route loaders and mounted transport components do not keep another account
cache or clear account data when they unmount.
Commands do not wait for realtime catch-up.
Account settings wait for this owner's data before they initialise edit buffers. A refresh preserves those buffers. A failed refresh can retain the complete account for display; an authentication rejection still disables private actions.
Profile contexts are read-only views of that owner. API adapters write directly to it; there are no separate summary caches or profile-priming hooks.
The shared owner enforces these rules:
- Concurrent missing-user reads share requests with at most 100 IDs per batch.
- A realtime update replaces a profile and prevents an older read from replacing it. List and detail reads use per-user revisions for the same guarantee.
- Incidental timeline includes only seed unknown users.
- Deletion leaves a tombstone. A profile-change invalidation permits a new read.
- Reset clears profiles and fences pending reads. Connection disposal also prevents retained readers from publishing new data.
- Opaque realtime cursors are not compared. If a shared read omits a user at a different cursor, the caller retries that missing user at its own boundary.
- Custom-status expiry belongs to the profile owner and ends on reset/disposal.
This refines ADR-062: TanStack Query still owns snapshot requests and pagination, but public identities have one shared owner across snapshot and realtime consumers. The change adds no server API or external connection. The client keeps this shared state in memory only; see ADR-107.
Complete directory load (amended 2026-11-30)
The original decision excluded a full-directory download. A host can now
enable one with the client option loadUserDirectory. The default is off,
because a bot usually needs only the users that it meets.
When the option is on, each live server store reads the complete user
directory after a full realtime catch-up. It reads UserService.ListUsers in
pages of 500 users, one page after another, and publishes each page to the
shared owner as a partial user resource. Thus the same fences, deletion
markers, and presence rules apply as for other user reads. A page has no
realtime cursor, so it does not replace a profile that changed after the page
request started. The store does not load the directory during the poll of an
inactive server. The server omits accounts without a readable profile. If a
page is empty before the end of the directory, the load cannot continue and
its state is failed.
The store exposes the state of the load as userDirectory.status. A
projection reset stops a load in progress, sets the state to idle, and the
next full catch-up starts the load again. A resumed stream does not start it
again: realtime events carry profile changes, new accounts, deletions, and
presence to every connected user.
A catch-up reads known users again, because replay does not carry presence. After a complete directory load, the known users are the whole server. The catch-up then reads only the users whose presence is on screen: the members of loaded member lists, direct message participants, and the viewer. It does not read the other users again. Their presence stays as it was until their next presence event, so it can be out of date after a reconnect.
A snapshot that keeps the current view also keeps the known users. The directory load that follows it finds the accounts that were deleted in the meantime: it reads by ID each user that was known before the load and that the load did not return. An ID that this read omits confirms the deletion. A load without a concurrent change has no such user and makes no such request. If the read fails, each later catch-up reads these users again until a read succeeds. This read has no realtime cursor, so it does not replace a profile that changed after the read started. The store makes the same check when the load after such a snapshot does not complete, for example because the directory is now above the limit. The catch-ups after that load read every known user again, as they do without a directory load.
The client does not load a directory with more than 20,000 users. The state
is then skipped, and the on-demand reads apply. The limit also bounds the
cost for a server release that reads every profile for each directory page.
There is no server version check: a development build and the release before
it report the same version.
The reason for the change is the cost of the alternative. On-demand reads left names and user search incomplete until a request finished, and each consumer had to start its own reads. The server now reads only the profiles of the requested page, so the complete directory of 10,000 users is approximately 0.8 MB compressed.
Consequences
- Users discovered through rooms, DMs, or timelines are available to local search without a separate merge or request.
- Profile changes and privacy boundaries apply to all profile readers.
- API adapters must publish through the shared owner's fenced read methods. A component must not install an old response directly as a current profile.
- Without the complete directory load, the known-user set is incomplete. With
it, the set is complete only while
userDirectory.statusiscomplete, and an account deletion during the load can still cause one user to be absent. On-demand reads stay available for a missing user. In both cases, the set lasts only for the connection's current authorized state.