Skip to content

perf(platform): record a session's use only where Better Auth does not #5264

Open

Description

@tale-code-bot

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:

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 checkSessionUseUnderIdleWindow and 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

  1. added
    perf
    agent-ready
    on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyperf

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions