Amended 2026-11-30: Section 8 adds the replica proof. When no record is in the window, a replica proves one time that its projections are current for all users, and does not run a strict check for each user. The guarantee and the window of 60 seconds do not change. The cost of the window no longer increases with the number of users.
Amended 2026-11-30: Section 5 is replaced. The realtime credential timer now uses the same check as request validation, and sends no request to the stream leader for each connection. Connection setup uses the same check. A realtime connection on a replica that is behind can stay open for approximately two minutes after a revocation.
Summary
Today a replica accepts a runtime credential only after it has confirmed, with
the EVT stream leader, that its User Auth projection is current for that
user. This is the strict auth generation check. It runs on every request.
We propose that a replica remembers a strict check that accepted a user for 60 seconds. During that time, request validation for that user reads the local projection and sends nothing to the stream leader.
The changed guarantee: a replica can accept a revoked credential for a maximum of 60 seconds after the revocation, and only while its User Auth projection has not applied the revoking event. Today that time is zero. In usual operation the projection applies the event in milliseconds.
The window is the guarantee. Two gates end it early when the replica detects that it has no NATS connection or that its projector failed. They are a small improvement for those clear cases. They do not make the worst case shorter.
Context
Chatto runs as multiple replicas. Each replica keeps its projections in
memory and feeds them from the EVT stream
(ADR-033). A projection on
one replica can lag a write that a different replica made.
Each validation of a runtime credential (cookie session, access token,
renewable session) compares the auth generation that the credential stores
with the current auth generation of the user. RequireAuthenticationAllowed
and CurrentAuthGeneration in cli/internal/core/auth_generation.go do this
check. The generation and the active state come from
UserAuthProjection.AuthGeneration.
So that a replica never decides from a projection that lags, the check first
reads from the stream leader the newest position of each subject that can
change the result. Then it waits until the projection has applied that
position. #3778 decreased
this cost from approximately 25 sequential leader reads to seven concurrent
position reads and one or two reads that validate the wait. It also added
userAuthGenerationSubjects, a list of subjects that maintainers must keep
complete by hand.
The cost of the strict check increases with the number of requests, not with the number of revocations. Measurements from November 2026:
- On the largest production deployment (approximately 25 replicas on one shared NATS cluster of three nodes), each NATS server used 60% to 67% of one CPU. The stream leader served approximately 141 JetStream API requests each second. All streams together received approximately 1.4 writes each second.
- In process, after #3778, one check costs 8 leader reads and 143 µs. Before, it cost 24 reads and 690 µs.
Almost all of these reads confirm that nothing changed.
Two existing rules already accept a bounded delay for revocation:
- Request validation reads
RUNTIME_STATEfrom any replica first. That read can accept a credential but cannot reject one (ADR-079). - A realtime connection validates its credential again on a timer
(
realtimeCredentialCheckInterval, one minute). A process-local watcher also closes it when a deactivation fact reaches the replica (WatchAccountAccessInvalidated).
Decision
Accept bounded staleness when a replica validates an existing runtime credential. The window is 60 seconds.
1. A replica remembers strict checks that accept
When a strict check accepts a credential of a user, the replica records the time for that user. For the next 60 seconds, request validation for that user on that replica does not read from the stream leader. It reads the local User Auth projection directly. This is the fast check.
There is no background probe. A replica without requests sends nothing.
Why 60 seconds:
- The window does not make revocation fast or slow. The fast check reads the live projection, which usually applies an event in milliseconds. The window only limits how long a replica that is behind, and does not know it, can stay wrong.
- 60 seconds is the interval that realtime connections already use for their credential timer.
- 5 seconds helps only during a burst of requests. A client that sends one request each 15 or 30 seconds gets no benefit. 60 seconds includes those clients.
2. Only a "valid" answer can be stale
The fast check can only accept. When the local projection gives a different answer (unknown user, deleted or deactivated account, or a generation that is not the stored generation), the replica runs the strict check and uses that result.
A stale negative answer rejects a valid user, for example an account that a different replica created or reactivated. Some paths also delete the stored credential on that answer. Thus no path acts on a negative answer that did not come from a strict check.
3. Issuance and credential changes stay strict
The fast check applies only to the read-only pass of request validation. That
is the pass that already reads RUNTIME_STATE from any replica. Each pass
that reads through the stream leader keeps the strict check on every call.
| Path today | Type | Check after this decision |
|---|---|---|
ValidatePresentedRuntimeCredential, first pass (cookie and bearer) |
Validation | Fast check permitted |
ValidatePresentedRuntimeCredential, second pass after a rejection |
Validation, deletes | Strict |
revalidateRealtimeCredential (realtime timer, see section 5) |
Validation | Fast check permitted |
RenewCookieSession |
Change, deletes | Strict |
MarkCookieSessionFresh, MarkBearerTokenFresh |
Change, deletes | Strict |
requireFreshCredential |
Validation | Strict |
SetCookiePrivilegedMode, setRenewableSessionPrivilegedMode |
Change, deletes | Strict |
RevokePresentedRuntimeCredentialWithReason (logout) |
Revocation, deletes | Strict |
RevokeRefreshTokenWithReasonResult (logout) |
Revocation, deletes | Strict |
refreshBearerSessionAt (refresh rotation) |
Issuance | Strict |
verifyUserPassword |
Issuance | Strict |
CreateCookieSession, NewCookieSessionData and their variants |
Issuance | Strict |
CreateBearerSessionWithSource, createBearerSessionForGrant |
Issuance | Strict |
CreateAuthCode and its variants |
Issuance | Strict |
ExchangeAuthCodeForClientResourceSession |
Issuance | Strict |
Requests are the large majority of all checks, so the strict rows cost little.
4. Two gates end the window early
A replica uses the fast check only while it has reason to believe that its User Auth projection is fed. Each auth generation check, fast or strict, samples both gates. When a sample finds a gate closed, the window ends for all users on that replica, and the next validation of each user is strict. A strict check that finds a gate closed at its start or end starts no window. A gate that closes and opens again between two samples is not seen. The NATS reconnect count fences connection gaps between samples. For a stall between samples, the window stays the bound.
- The NATS connection is not connected, or the recovery after a reconnect is not complete. The strict check then fails and the replica rejects the request, as it does today.
- The User Auth projector reports that it failed or is stalled.
A replica can be behind in three ways:
- It has no connection to NATS. It also cannot read from the stream leader. Gate 1 applies, and the behavior is the same as today. Without this gate, a partitioned replica accepts recently checked users for the full window, which is worse than today.
- It has a connection, but its projection is behind. Examples are a blocked or slow apply, an event consumer that stopped or that the SDK creates again, and a slow NATS server that feeds the consumer while the stream leader answers normally. The strict check finds a revocation in this condition. The fast check does not. Gate 2 applies to the part that the replica can detect. The part that it cannot detect is the residual risk, and the full window applies to it.
- Usual delivery delay of some milliseconds. The strict check closes this interval today. The fast check does not. This delay does not depend on the length of the window.
What the current code can detect, and how fast:
| Signal | Source today | Detection time |
|---|---|---|
| Connection closed or reset | nats.Conn status events and IsConnected, which runNATSRecovery and chatto_nats_connected use |
Immediate. runNATSRecovery also polls each 250 ms |
| Recovery after a reconnect is not complete | natsRecoveryState, which ChattoCore.Ready reads |
Immediate. It stays set until all projections are current again |
| Connection lost without a reset | The NATS client ping. Chatto uses the defaults: 2 minutes, 2 pings | 4 to 6 minutes. Longer than the window |
| Projector failed | Projector.Err(), Status().Err |
Immediate |
| Projector stalled | Status().Stalled |
After 5 minutes of pending work without a commit (DefaultProjectorStallAfter). Longer than the window |
| Consumer receives no heartbeat | The SDK reports it to handleConsumeErr after approximately 10 seconds and creates the consumer again |
Not visible to core. The projector only writes a log line |
The gates are thus weaker than the window in two cases, and the full window of 60 seconds applies to both:
- A network partition that does not reset the connection. The replica accepts recently checked users from its projection until each window ends. Then each strict check fails. Today the replica rejects those requests immediately.
- A projection that stopped less than 5 minutes ago. The stalled state does not end a window that is in progress. It only prevents new windows on a replica that has been stalled for 5 minutes or longer.
Faster signals are an open point. This record does not design them.
5. The realtime timer uses the same check as request validation
The realtime credential timer validates through
ValidatePresentedRuntimeCredential, for cookie and for bearer credentials.
It is the read-only first pass of section 3, so the fast check is permitted.
The timer sends no request to the stream leader for each connection. Its
cost does not increase with the number of connections.
The setup of a realtime connection uses the same check. On a replica that is behind, a new connection can thus start with a revoked credential inside the window, as a request can. The timer then closes it. Many clients that connect again at the same time, for example after a deployment, send no burst of requests to the stream leader.
A connection on a replica that is behind, and whose gates have not detected it, can stay open for approximately two minutes after a revocation: one timer interval and one window. This is accepted. On a replica that is current, the timer reads a projection that has applied the revocation, and the connection closes at the next timer run. The account-access watcher and the termination signal of a global sign-out close connections sooner and do not change.
The first decision kept the strict check for the timer, to hold the worst case at one timer interval. The cost was one strict check each minute for each connection, which increased with the number of connections.
6. Validation fails closed after the window
When the window has passed, the next validation runs the strict check. If NATS is not reachable, that check fails as it does today. A replica that a network partition isolates cannot accept credentials for longer than the window.
7. The record is process-local acceleration state
The time of the last strict check is process-local. A replica never persists it and never shares it. A replica that restarts has no records and starts with strict checks. The implementation must limit the size of this state. A record that is older than the window has no value and can be removed.
8. A replica proof serves all users
Added 2026-11-30.
Sections 1 to 7 give each user a window, and each window starts with a strict check for that user. The cost thus increases with the number of active users. A measurement on the largest production instance on 2026-11-30 showed this: approximately 38 active users caused approximately 13 position reads each second on the stream leader, and 86% of all JetStream API requests of that instance were position reads that found nothing.
A strict check proves that the projections are current for one user. A replica proof proves the same for all users:
- The replica reads, from the stream leader, the newest position of each
event type in
userAuthGenerationEventTypes, with a subject filter for all users (evt.user.*.{type}). This is the same number of reads as one strict check. - It waits until its Users and User Auth projections have applied those positions.
- It records the time at which the proof started.
While a replica proof is less than 60 seconds old, the read-only first pass of request validation uses the fast check for every user. The rules of sections 2, 3, 4, 6, and 7 apply without change:
- The fast check can only accept. A mismatch in the local projection runs the strict check for that user, and that result is final.
- Issuance, credential changes, revocation, and the authoritative second pass stay strict for each user. A replica proof does not apply to them.
- A closed gate ends the proof, as it ends the records of the users. A proof is valid only for the NATS reconnect count at its start.
- A strict check that does not accept a user ends the proof for that user. A proof applies to a user only if it started after the last such check. That check is newer evidence than the proof: for example, it can fail because the replica is behind for that user. The table of user records has a size limit. When it is full and cannot store such a check, the replica ends the proof for all users, also a proof that is in progress. While the table stays full and such checks continue, the replica keeps no proof. Each request without a record then pays for the proof reads and for its strict check. This is safe, but it is slower than no proof.
- The window starts when the proof starts, not when its wait ends.
- The proof is process-local acceleration state.
A proof starts only when a request finds no record in the window. A replica without requests sends nothing, so this is not the background probe that the alternatives reject. Requests that need a proof at the same time share one proof. A proof that fails, for example because NATS is not reachable, gives no acceptance. The request then runs the strict check, which fails closed.
A replica usually takes one proof in each window. It takes one more when a request finds that the proof does not apply to its user.
A user without a record gets the window too. Before section 8, the first validation of a user on a replica was always strict, because only a strict check started a window. A proof now starts the window for all users. A user whom the replica has not validated before can thus get an acceptance that is stale by one window at most. The maximum time does not change.
The proof waits for the events of all users. When a replica is behind for one user, a proof also makes the requests of other users wait. Three rules bound that cost:
- A request leaves the proof when its own deadline ends or its caller cancels it. The proof continues for the other requests.
- A proof ends after 2 seconds (
replicaProofTimeout). - After a failed proof, the replica starts no proof for 5 seconds
(
replicaProofRetryDelay).
In each case the request runs the strict check for its user, as before section 8. That check waits only for the events of that user. A failed proof thus adds the reads of one proof, one time in 5 seconds, to the reads of the strict checks.
The guarantee does not change. A replica that is behind, and does not know it, can accept a revoked credential for a maximum of 60 seconds after the start of its last proof, and only while its User Auth projection has not applied the revoking event.
Why not one broad subject filter. The alternative "One shared currency check for each replica" needs a User Auth projection that reads all user events. The User Auth projection is replayed from the start of the stream at each process start, and two tests keep its subject filters narrow for that reason. On the largest production instance, 14% of the user events are events that the projection reads. The other events are mostly sign-in and token audit facts, and their number increases with each sign-in. The replica proof gets the shared check with the narrow filters.
Consequences
- The security guarantee changes. Today every replica sees a revocation before it accepts the credential. Revocations are password changes, account deletion, deactivation, key shredding, and identity unlinks that do not preserve credentials. After this decision, a replica can accept a revoked credential for a maximum of 60 seconds, and only if its User Auth projection has not applied the event.
- The usual exposure is the projection lag, not the window. The fast check reads the projection, and the projection usually applies an event in milliseconds. The window is the worst case, for a replica that is behind and whose gates have not detected it.
- Cost. With the replica proof of section 8, a replica that serves requests usually takes one proof in each 60-second window, for all users. Before section 8, it ran one strict check for each active user in each window. Concurrent requests that find no valid window each run a strict check, and each strict path of section 3 runs one on each call. Today it runs one for each request.
- Availability does not change. Gate 1 ends all windows when the replica detects that it has no NATS connection. It then rejects requests as it does today. Before the detection, it accepts recently checked users until their windows end.
- The gates depend on existing signals. The stall signal and the default ping are slower than the window. The residual risk in section 4 stays until faster signals exist.
- New process-local state. It needs a size limit and tests for the window boundaries.
userAuthGenerationSubjectsstays. The strict check continues to use the list, and maintainers must continue to keep it complete.- Realtime connections have a longer worst case. They keep their watchers. Their timer uses the fast check (section 5), so the worst case on a replica that is behind is approximately two minutes.
Statements that the implementation must update
This record does not change other records. The change that implements it must update these statements:
-
FDR-023, "Password and account lifecycle revocation": validation "waits the user projection to the current auth-generation events". Also the bearer decision: "opaque tokens give instant revocation", and "deleting the stable authority rejects every access generation on its next API request".
-
ADR-024: "Instant revocation", and the statement that the revocation guarantee comes from the comparison with the current auth generation. Each must say "within one minute in the worst case".
-
ADR-079: auth-generation changes reject "all overlap at its next validation". The paragraph on fast reads must also name the window.
-
docs/architecture/projections.md: "Each validation of a runtime credential checks the auth generation. Before the check reads the projection, it waits…". -
docs/architecture/runtime-state.md: "Authentication checks the account’s durable auth generation before cleanup finishes." The inventory also needs an entry for the new process-local state.The inventory no longer holds these two sentences, because it records only what exists. This record and the comment on
auth_generation.gostate the rule. The entry for the process-local state is inruntime-state.md. -
FDR-018: deactivation "invalidates cookie and bearer sessions". The statement stays true but must name the window.
-
proto/chatto/admin/v1/members.protoand the generated API reference: "Deactivation immediately invalidates existing sessions" becomes "within one minute in the worst case". -
The glossary entry "Auth generation check window", which names this proposal.
ADR-033, ADR-036, ADR-046, and ADR-114 contain no statement that this decision contradicts. No persisted contract changes.
Alternatives
- Keep the strict check on every request. This is the state after #3778. It is correct, but the cost increases with the number of requests.
- One shared currency check for each replica. Give the User Auth
projection one broad subject filter. Currency is then one position read, and
concurrent requests can share that read. This keeps the strict guarantee and
removes the hand-maintained list. It needs changes to the shared projector
in
pkg/events. It is not rejected. It can complement this decision later: it makes the strict checks that remain cheaper. - A background probe that confirms the projection is at the end of the stream. Replicas without requests also pay for the probe. At the current traffic, the probe costs more reads than it saves.
- Different subjects, or an auth record for each user in key-value storage. The first changes persisted contracts (ADR-114). The second needs two stores to agree.
Open Points
- Constant or configuration. We recommend a constant of 60 seconds first. The window is a security property. A setting lets one deployment weaken it silently, and replicas with different values make the guarantee hard to state. Add a setting only when an operator shows a need.
- Bot credentials. Bot API key authentication and bot incoming webhook authentication also read from the stream leader on each request. A separate change makes those reads narrower. Whether and how this policy applies to them is not decided here.
- The benefit is not measured. There is no measurement of the time between requests of one user in production. Thus the share of strict checks that the window removes is not known.
- Faster gate signals. Three candidates:
Status().PendingForexists today and shows pending work before the stall threshold. When the consumer is silent, it changes only after the next source check (projectionSourceCheckInterval, 30 seconds). Gate 2 could use it with a short threshold and no framework change.- A signal for consumer heartbeat loss needs a change in
pkg/events. - A shorter NATS ping interval makes gate 1 detect a silent partition faster. It is a connection option, and it changes the reconnect behavior of all NATS clients in the process.
- A proof without reads. Each projector already reads the newest position
of its subject filters from the stream leader at an interval
(
projectionSourceCheckInterval, 30 seconds). If the projector status gave the start time and the result of the last successful source check, a replica could use that check as its proof and send no additional reads. This needs a new status field inpkg/events. - Measurements after rollout. Confirm the effect with the JetStream API
request rate on the stream leader, the number of strict checks each second,
the number of replica proofs each second
(
chatto_auth_generation_replica_proofs_total), and the ratio of fast checks to strict checks.