Repository navigation
Description
Split off #5249 (board task TALE-349). Its fix rides train as fix(platform): keep a single sign-on session in use signed in (branch fix/sso-session-idle-refresh, head ba64dedf41d6df73c741632786be89d92ac814d5).
What that fix does
resolveSessionAuthority (services/platform/backend/auth/session-authority.ts) runs on every authorization and now records the use on each browser session it accepts. When the row's updatedAt is min(updateAge, 60) seconds old or older, one conditional UPDATE moves updatedAt to now (services/platform/backend/auth/session-use.ts). The idle sweep reads updatedAt as the last use. Better Auth's own refresh writes it weeks late for a 30-day single sign-on row and never for a "don't remember me" row.
What it costs
On the stable line with SESSION_IDLE_TIMEOUT_MINUTES unset, updateAge is 60 seconds. Better Auth refreshes a regular row no later than the stamp would write it, so the stamp adds no write. It does add writes in two cases:
- The cookie cache is on. With
SESSION_COOKIE_CACHE_SECONDSset, requests the cache serves skip Better Auth's refresh, so the stamp writes a regular row between refreshes, at most once a minute. - The feature line. perf(platform): every active session is written once a minute #5164 refreshes a session that no organization window covers every 5 minutes (
updateAge300), which cuts those writes to a fifth. Once the fix of fix(platform): an organization's idle timeout signs SSO sessions out while they are in use #5249 reachesrelease/0.6with the rebase ontomain, the stamp writes every active session once a minute again and undoes that saving.
Proposal
Stamp only a row whose use Better Auth's refresh will not record in time. Let slideAt = expiresAt - (expiresIn - updateAge) be the moment Better Auth's refresh of the row is first due. Better Auth records the use in time when both of these hold:
slideAt <= updatedAt + updateAge + 1s: the refresh is due no later than a stamp would be.slideAt >= now - cookieCacheSeconds - 1s: the refresh is not overdue. It always is for a "don't remember me" row, which Better Auth never refreshes.
Otherwise, stamp as today:
- a 30-day single sign-on row fails the first condition;
- a "don't remember me" row fails the second;
- a regular row passes both and gets no extra write.
Done means
- Under an organization's idle window, a single sign-on session and a "don't remember me" session in use stay signed in. The integration lane
checkSessionUseUnderIdleWindowand the[SSO-R23]unit tests stay green. - A regular session that Better Auth refreshes gets no write from the stamp, on both lines, with or without the cookie cache. A unit test counts the writes.
This applies once the fix of #5249 has reached release/0.6.
Activity