Records Architecture decision

ADR-096

Require Session-Scoped Privileged Mode

Accepted Decided 2026-09-03 Source file

Amended 2026-11-19. Role grants now require activation only when the role is protected. Sessions activate the selected roles. The owner override requires selection of owner. Direct user grants apply with Shield Mode on or off. See FDR-046.

Amended 2026-09-25: ADR-105 also gates the effective-owner override with privileged mode. Realtime fan-out and notification decisions use the privileged-mode state of the receiving session instead of entitlement semantics.

Context

A user can have ordinary permissions and administrative permissions at the same time. Before this decision, all assigned permissions were always active. The bundled client therefore showed edit, delete, and administration actions during ordinary chat use. A user could select one of these actions by mistake.

Roles are reusable permission containers. A custom role or a direct user grant can give the same authority as a system role. A solution that activates role names would not cover these cases.

Chatto has one server session for each connected server. A global client state cannot safely represent authority on several independent servers.

Decision

Role protection determines which grants a human must activate. Direct user grants and unprotected role grants apply during ordinary use. Activation does not change RBAC state.

One activation applies to the protected roles the user selects on that server. It does not grant a new permission. A later role removal or deny takes effect during an active window.

The first activation flow uses an explicit user confirmation. An activation has a fixed 15-minute deadline. Permission use does not extend the deadline. The user can deactivate it at any time.

Activation belongs to one runtime credential session:

  • A same-origin cookie session stores the deadline in its mutable session.{hmac} record.
  • A bearer login stores the deadline in its stable renewable_session.{hmac} record. Access-token rotation reads the current deadline from that record.
  • Logout, session revocation, expiry, or deletion removes the activation with the session.
  • Bot API keys do not require and cannot activate privileged mode. The direct bot permission and owner-ceiling rules do not change.

The permission resolver keeps two concepts separate. Entitlement resolution describes assigned authority for administration, delegation ceilings, and UI discovery. Effective authorization applies the privileged-mode gate when the checked user is the human authenticated by the current request. Internal work without a public runtime credential keeps entitlement semantics.

ViewerService reports whether privileged mode is available, whether it is active, and its deadline. It also provides activate and deactivate RPCs. The effective permission grants in viewer and room state describe permissions that can be used now. The bundled client puts the control in the current-user area for the selected server. Each mutation response includes the new effective server capabilities and permissions, which the client applies immediately. It then keeps its realtime projection and resume cursor and reconnects. The client reads room and room-group resources through ConnectRPC before it completes catch-up. After an immediate reconnect from a caught-up live socket reports RESUMED, the client uses the mutation's viewer permissions. It reads only missing DM profiles and reloads only timelines whose message permissions changed. It does not refresh all cached users or unrelated current values for this permission change. A normal cursor resume contains only later EVT changes and cannot represent this runtime-state mutation. These resource updates change room-scoped permissions without unmounting the current interface.

Snapshots, expiry, network recovery, queued reconnects, and failed permission reads use full current-value recovery. Late permission reads cannot complete a newer authorization refresh. Explicit mutation responses run in call order. Deactivation can proceed while an earlier projection refresh is pending. A new mutation response replaces an in-progress transport immediately. The replacement uses full current-value recovery, and the old reads cannot fail the replacement socket, publish stale viewer authority, or complete its authorization generation. Ordinary reconnect requests still coalesce while a connection attempt is in progress. Validated small replay gaps use the general catch-up budget, so the audit facts from rapid changes do not exhaust the stricter large-replay budget. Both paths keep the same concurrency, authorization, and replay-work limits. The mutation handlers assemble only the viewer capabilities and permission fields that their responses return.

The realtime connection retains the privilege deadline accepted during its subscription. At that deadline, the server cancels authorized work and sends a reconnecting PRIVILEGED_MODE_EXPIRED close when possible. The replacement projection reports unprivileged effective permissions. The client also keeps a local deadline as a prompt fallback.

Privileged-mode authority stays in runtime state. Chatto writes minimal PrivilegedModeActivatedEvent and PrivilegedModeDeactivatedEvent facts to EVT for the event log. The activation fact records the selected role names and the deadline. Older activation facts omit the role names. Automatic expiry does not require a scheduled event because the activation fact already records the deadline. These facts are audit-only and do not change runtime authority during replay. If the runtime-state mutation succeeds but its audit append fails, Chatto keeps the runtime result and logs the failure. This prevents an audit outage from keeping privilege active.

Compatibility

The protobuf additions use new fields and RPCs. An older server ignores the new client feature because its viewer response cannot report availability. An older client on a newer server cannot activate elevated permissions. This is an intentional Chatto 0.5 authorization behavior change.

The realtime subscription message has no privileged-mode field. The client tracks the pending authorization refresh itself. It reads current resources through ConnectRPC before it completes catch-up. No released client and server pair depends on the temporary cursor-reset behavior that existed during development.

A deployment must update all replicas before it relies on this boundary. An old replica does not apply the new request-time gate.

Consequences

  • Ordinary chat use does not expose assigned administrative authority.
  • The rule follows permissions, including custom roles and direct grants.
  • Session revocation also revokes active elevated authority.
  • The runtime-state records have one more mutable deadline.
  • Clients must refresh effective permission state after activation, deactivation, or expiry.
  • The event log records user-driven privileged-mode transitions without making EVT the authorization source.
  • A future MFA step can be added to the activation RPC without changing the RBAC model.

Records that name this record

Esc