Skip to content

A dashboard session that outlives its token says so and signs in again without losing the page - #210

Merged
zlareb1 merged 26 commits into
mainfrom
fix/dashboard-token-refresh
Nov 3, 2026
Merged

zlareb1 merged 26 commits into
mainfrom
fix/dashboard-token-refresh

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in a release)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

When the dashboard's sign-in token expires or is revoked mid-session, a card now says so over the page and any open dialog, instead of each page showing "Sign-in rejected: token expired"; signing in again in a new tab lets the page carry on as it was. With SSO on, a page loaded after a sign-in session expired starts the sign-in again by itself and returns to that page.

Why

The dashboard's SSO token lives oauth_access_token_ttl_seconds (one hour by default) and has no refresh. Only the boot-time whoami check sent a dead token to the sign-in screen. A tab open past the token's expiry kept the token, so every read afterwards answered 401 AUTH_INVALID: token expired: Signature has expired, and each view showed that as its own error ("Couldn't load collections", "Couldn't load documents"). No view refreshed the token: none could, because this token has no refresh path. collection.list validates the same token as every other op.

Reproduced against a local server with a token that expires a few seconds after it is minted (past the 30 s leeway): the Library shows "Couldn't load documents · Sign-in rejected: token expired: Signature has expired".

The fix:

  • One request path. api.ts::request is the path every authenticated call takes. A 401 for the token the request carried calls the handler App registers.
  • Mid-session, a card. The handler forgets the token and pins a card (its chunk is fetched as the app loads, so a deploy that removes chunks cannot leave it unloadable; should that fetch fail, no card shows rather than an error page) in the toast viewport: "Your session ended. This page stays as it is.", with Sign in in a new tab (straight to the identity provider when SSO is on) and Reload. The toast viewport sits above every dialog, stays a live region while a modal hides the page, and the memory inspector already ignores presses on it. Modal and the task sheet now ignore them too, through one shared check (keepOpenOnToasts), so pressing the card never dismisses a dialog. Nothing else changes: an open dialog keeps what was typed (checked in a browser with the Add document dialog), and the view underneath stays mounted. The gate, the card and a view's own error for such a call (an expired, revoked or missing token) all say "Your session ended — sign in again." instead of "Sign-in rejected: …". Behind a proxy it keeps the server's words, since there is no session there and a missing header is the proxy's fault.
  • Every tab follows. Each tab listens for storage events on the token and the sign-out mark from the moment the app loads, so no change before the first render is lost.
    • When another tab drops the token after a refusal, this tab's session ends too. Its tokenless calls would otherwise show their errors one by one.
    • When the person signs out in another tab, this tab reloads to the plain sign-in screen, also when its own session had already ended. Sign-out leaves a marker in local storage that lasts until the next sign-in. That screen has no expired reason, so SSO does not sign them straight back in, even on a reload much later.
    • When another tab stores a token whose claims name another person or org, this tab reloads as soon as it hears of it, so nothing the previous person read stays on screen. Every call, the ui.vitals row, sign-out (which leaves another person's token alone entirely, and says another account is signed in) and the error page's health read also check the stored token's claims against the person whose page it is, kept in step with whoami, so nothing of this page goes out under someone else's token, not even in the moment before the tab hears of the change. With auth off there is no person to match, and the check stays off.
    • When another tab stores the same person's token, this tab asks whoami with it, retrying on 503. The answer counts only if that token is still the stored one. If the server confirms it, the card goes away and list_mine is read again, so changed roles take effect. If the server refuses it, this tab's session ends and the page stays. If whoami cannot answer, a healthy tab stays as it was, and an ended one keeps its card and asks again 30 s later while that token is still the stored one.
  • During boot, the gate. Before boot has an identity there is no page to keep. A refusal then only drops the token, and boot shows the sign-in gate once whoami answers, with the reason it alone knows: "refused" for a token a sign-in link brought, "expired" for a sign-in session's token (it carries sid), "ended" for any other, such as a minted one. This includes the case where the early list_mine read is refused while whoami is still answering, even if whoami then says yes. A session-storage note keeps that reason across a Reload, even though the token is already gone. Boot ignores the note right after a sign-out, so signing out from a page that shows the card lands on a plain sign-in, and when boot fails it names the reason only if this boot itself lost the token, so a Reload during an outage starts no sign-in by itself. With SSO on, the gate then starts the sign-in by itself for "expired" only, at most once in five minutes per tab, and returns to the page through the existing return-to-start path. A token that a #token= link brought and the server refused shows "The token this sign-in brought was refused" and waits for a click, and so does a minted token once it expires, so neither a provider that returns refused tokens nor a break-glass token used while the provider is down can loop or send the person to a provider that is down. If another tab stores a different token while boot waits for whoami, including while whoami keeps answering 503, boot starts again with that token.
  • Auth-off installs. There is no sign-in, so a 401 drops the stored token, and every call it refused, concurrent ones included, goes again without it. The view keeps the server's words: there is no session to sign in to.
  • whoami errors. whoami throws on any status other than 200; behind a proxy, a 401 or 403 still means signed out. While the server answers 503, boot retries up to five times a second apart (the server's own Retry-After is 5 s), stopping if the stored token changes, and if it is still 503 the sign-in screen shows with the existing toast ("Loom is unavailable right now — try again in a moment"), and the token is kept for the next load. A replica whose keyring is still loading answers 503 on purpose so the client keeps its token, but the client used to read it as "signed out" and clear a good token.

Scope and risk

  • Only a 401 counts, and only when the request carried the token still stored. A 401 for a token another tab replaced while the call was out is not re-sent under a token this tab has not checked. When the new token is the same person's, it says "Signed in elsewhere — retry", and the view's Retry sends it; anyone else's reads as the ended session while the tab reloads. A 403 (no grant) stays the view's own error. Concurrent 401s end the session once. A token stored while a request was in flight is not cleared by that request's 401.
  • While the card shows, views whose reads fail show their own errors under it. After signing in again, the card goes away and each view keeps its own Retry.
  • Modal ignores a press on the toast viewport, so a press on an ordinary toast no longer dismisses a dialog either.
  • While a dialog is open, its focus trap keeps the keyboard inside it, so the card's buttons take a pointer. A keyboard user saves or copies the draft, closes the dialog, then reaches the card. Letting focus out to the card would break the trap every dialog relies on. Screen readers announce the card, because it sits in the toasts' live region, which a modal leaves readable.
  • The shell's index chunk stays within its 120 kB budget (118.6 kB): the cross-tab token handler ships in the session card's chunk, which the app fetches as it loads (should that fetch fail, a token change in another tab reloads the page instead), and the health problems banner, shown only on a degraded deployment, loads as its own chunk and shows nothing should that chunk fail to load.
  • A token whose claims the page cannot read names no one, so the page-owner check lets its calls go; the server's answer to that token decides.
  • Server unchanged; no new token or refresh endpoint.

Compatibility, rollout and rollback

  • Wire: none.
  • Operator steps: none.
  • Rollback: revert the commit. Nothing is stored except two session-storage entries (loom_sso_resumed_v1, loom_session_ended_v1) and the loom_signed_out_v1 stamp in local storage.

Tests

  • frontend/src/api.request.test.ts: a 401 for the stored token ends the session and still rejects the call. Three 401s in flight together end it once. A 403, a 401 that races a newly stored token, and a 401 for a request sent without a stored token do not end it.
  • frontend/src/flows/TokenGate.test.tsx: resumeSsoOnce allows one automatic sign-in per five minutes. An expired SSO gate remembers the page and calls goToSso; a first visit waits for a click.
  • frontend/src/App.boot.test.tsx, where whoami answers for the token it is sent:
    • a 401 mid-session pins the card in the toast viewport, clears the token and keeps the page;
    • the same person's token from another tab, once whoami confirms it, removes the card without a reload;
    • someone else's token reloads (reloadPage is asserted);
    • another tab dropping the token ends this tab's session, and a sign-out there reloads this one with no expired note, even on a reload long after;
    • another tab storing a token the server refuses ends this tab's session without a reload;
    • another person's token reloads at once, without waiting on whoami;
    • a newer drop that lands while whoami answers keeps the card;
    • a healthy tab that cannot confirm another tab's token stays as it is;
    • a reload after the session ended shows the gate with the expired reason, and with SSO on starts the sign-in by itself once; after a minted token ended it shows the gate and starts none;
    • an ended tab that cannot confirm another tab's token asks again 30 s later and then carries on;
    • a sign-out elsewhere reloads a tab whose session had already ended;
    • a list_mine 401 while whoami answers yes still shows the gate with the expired reason, and the app does not come up without a token;
    • signing out after the session ended shows the gate with no expired reason, and SSO does not start;
    • a refused #token= link shows the "refused" gate, and SSO does not start, even when the early list_mine read is refused first;
    • another tab storing a token while boot waits for whoami reloads, also while whoami answers 503;
    • a sign-in link that whoami alone refuses shows the "refused" gate and starts no SSO;
    • a Reload while the server is away starts no SSO;
    • a whoami 503 is retried and the token is kept.
  • frontend/src/lib/format.test.ts: an expired, revoked, ended or missing bearer reads as an ended session, except with auth off; a wrong password still reads "Sign-in rejected".
  • frontend/src/api.request.test.ts: signing out marks the browser until the next sign-in, which clears the mark, and leaves another person's token alone; ErrorBoundary.test.tsx: the health read sends no token naming someone else; a call refused for a token another tab replaced meanwhile is not sent again and says to retry; a call under a token naming someone other than the page's person is never sent, and neither is the ui.vitals row (lib/vitals.test.ts); with auth off, every concurrent refused call goes again without the token.
  • The full frontend suite (210 files, 1,698 tests), the unit suite, the Playwright suite (485 passed, 6 skipped; the three INP budgets that missed under a full parallel run pass on their own, as on main), npm run build, npm run budget and make lint pass on the head rebased on main.
  • Manual, against a local server with auth on, in the dark theme (the dashboard's only theme):
    • Before: the Library shows "Couldn't load documents · Sign-in rejected: token expired".
    • After: with the Add document dialog open and a draft typed, Upload past the token's expiry shows the card over the dialog. Pressing Sign in in a new tab opens the new tab, and the dialog stays open with the draft.

🤖 Generated with Claude Code

@zlareb1 zlareb1 changed the title A refused sign-in token returns every dashboard view to sign-in A dashboard session that outlives its token says so and signs in again without losing the page Nov 3, 2026
@zlareb1
zlareb1 force-pushed the fix/dashboard-token-refresh branch from 9bdfa96 to 81b64d8 Compare November 3, 2026 20:46
zlareb1 and others added 26 commits November 3, 2026 21:07
The dashboard's SSO token lives an hour with no refresh, and only boot's
whoami check sent a dead token to the gate: past expiry every view showed
the 401 as its own error. The shared request path now ends the session on
a 401 for the stored token, and the SSO gate starts sign-in again by
itself once in five minutes, returning to the same page.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
A mid-session refusal puts the sign-in gate over the page instead of
unmounting it, and never leaves for SSO by itself, so nothing typed is
lost; the same person signing in again carries on there. An auth-off
install drops a stale stored token instead of showing a gate. whoami
answering anything but 200 throws, so a replica still loading keys no
longer clears a good token.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The overlay could not take input under an open modal, let shortcuts act
under it, and lost the page on an SSO click. A bar over the page now says
the session expired; signing in happens in a new tab, whose token this
tab takes through the storage event (the same person carries on with the
identity read again, anyone else reloads). A refusal before boot has an
identity shows the gate with the expired reason, and boot asks whoami
again while a replica answers 503.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Every signed-in tab hears another tab store or drop the token: dropped
ends its session too, stored carries on only once whoami confirms the
same person (anyone else reloads). The card is pinned in the toast
viewport, so it stays above and audible over a modal, and Modal ignores
a press there as the inspector already did. A reload after the session
ended keeps the expired reason through a session-storage note. An
expired token reads "Your session expired — sign in again." in a view's
error.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…nly once confirmed

Signing out marks the browser, so another tab that loses the token
reloads to a plain sign-in instead of an expired-session gate whose SSO
would sign the person back in. A token stored elsewhere is taken only if
it is still the stored one when whoami answers, and a healthy tab that
cannot confirm it stays as it is. Boot treats a token dropped while whoami
answered as refused, and tries the page again when whoami stays 503. A
revoked token reads as an ended session too, except behind a proxy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…er reloads at most three times

Boot ignores the session-ended note once the person signed out, so the
gate is a plain sign-in. A whoami that stays 503 reloads the page at most
three times, never in proxy mode. Auth-off keeps a stored token again.
The task sheet, like Modal and the inspector, stays open on a press on
the toasts (one shared check). The gate, the card and the views all say
"Your session ended". The card loads with its first use.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…or a click

The card is imported eagerly: a lazy chunk removed by a deploy would
reload the long-lived tab it is there to keep. A token a #token= link
brought that the server refuses shows its own notice and starts no SSO,
so a break-glass link stays put while the identity provider is down.
Boot starts again when another tab stores a token while whoami answers,
and a token another tab dropped then reads as an ended session. With
auth off a view keeps the server's words. The reload after a lasting 503
is gone: the toast says why, and the token stays.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The early list_mine read could be refused before whoami answered and set
the gate to "expired", whose SSO starts by itself, ahead of boot's
"refused" for a sign-in link's token. Before boot has an identity a
refusal now only drops the token and notes it; boot shows the gate with
the reason. The boot test refuses the early read too, first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… at once

A token stored elsewhere that the server refuses ends this tab's session
and keeps its page; one whose claims name someone else reloads before
whoami is asked. The sign-out mark lasts until the next sign-in, and boot
also catches a token stored while a tab with none waited for whoami. A
refusal that ended the session reads as an ended session whatever its
words. A refused sign-in link leaves no note when boot then fails.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…gain after a 503

A 401 for a token the call carried reads as the ended session also when
another refusal ended it a moment before, so the wording no longer
depends on the server's words. An ended tab that could not confirm
another tab's token asks again after 30 s. A sign-in link's token is
compared as stored (no whitespace). The docs say a keyboard user closes
an open dialog to reach the card, and the card is one line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…aced by a new token goes again

The storage listener registers with the module, so no change between
boot and the first render is lost, and it hears a sign-out even when
this tab's token was already gone. A 401 for a token another tab
replaced meanwhile sends the call again, once, with the new token. The
30 s recheck is cancelled by the next change. With SSO on, the card's
new tab goes straight to the identity provider.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The one retry after a 401 now needs the new token to name the same
subject and org; any other token never carries this page's call, which
fails as the ended session instead. The retry is one logical call in the
view's count, a retried call refused again reads as ended too, and the
card is announced once by the viewport's live region. A sign-out mark
acts only once this tab's token is gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…nds without one

The same-person retry is gone: a call another tab's sign-in raced fails
as the ended session, and Retry sends it, so no call ever goes out under
a token this tab has not checked. With auth off, the call whose 401
dropped a stale token goes again without it. A refused sign-in link
keeps its reason when whoami then fails, reloadPage runs once however
many changes ask, and an empty org claim compares as "".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…n-in says to retry

Each call checks the stored token's claims against the person whose page
it is (kept in step with whoami) and goes out only under theirs, so the
moment before this tab hears of another tab's sign-in cannot send under
someone else. A call raced by the same person's sign-in elsewhere says
"You signed in again in another tab — retry". With auth off every
concurrent call a stale token got refused goes again without it. The
card's chunk is fetched as the app loads.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
An auth-off install's stand-in identity is no owner a token can match,
so the check would have refused every call under a leftover token: it
now passes with auth off, where the 401 path drops the token. The
ui.vitals row goes out only under the page's person's token too. "You
signed in again" is said only when the new token is the same person's;
anyone else's reads as the ended session while the tab reloads.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…retries stop on a new token

Should the session card's chunk fail as the app loads, the card renders
nothing, and each view's error still says the session ended. whoami's
retries stop once the stored token changes, so none carries another
tab's token, and boot waits about five seconds (the server's Retry-After)
before giving up on a 503. Two test assertions that could not fail are
gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ut and the error page send only the page's own

When the stored token changes while whoami is being retried, the retry
answers "not authenticated" for the old one and boot's own check starts
again with the new token, instead of leaving the gate. Sign out revokes
only the page's person's token, and the error page's health read sends
it only then; the listener uses the same check. Tests cover a sign-in
link that whoami alone refuses and the vitals row under the page's own
token.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…or path still names its reason

Sign out returns before marking or clearing anything when the stored
token is not the page's person's: another tab signed them in a moment
ago, and the reload that follows opens their page. When boot's whoami
fails after the early read refused the token, the gate still says the
session ended (or that the link's token was refused). Two comments name
the card and the "refused" reason.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… the token after its wait

Boot's error path names an ended session only when this boot itself
lost the token, so an earlier load's note does not send a Reload
during an outage to the identity provider. whoamiWhenReady checks the
stored token again after its one-second wait, before the next ask.
Signing out under another person's token says another account is signed
in. The page owner is boot's whoami answer itself.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The session-ended note now holds the gate's reason: a token with a
sign-in session (sid) is "expired" and the SSO gate starts the sign-in
again, while a minted token is "ended" and waits for a click, since it
may be the way in while the identity provider is down. The refused-token
notice fits a link and an SSO return alike, signOut has one doc comment,
and the error page's health test checks the read was made.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
When another tab drops or replaces the token, this tab's gate reason
comes from the token stored before (the storage event's old value), so
a sign-in session's token resumes SSO by itself in every tab. The
signed-in-elsewhere refusal no longer waits to read the response body.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
With main's latest additions the shell's index chunk passed its 120 kB
budget. The cross-tab token handler now ships in the session card's
chunk, which the app fetches as it loads (a chunk that cannot load
reloads the page, which decides on the stored token), and the health
problems banner, shown only on a degraded deployment, loads as its own
chunk and shows nothing when that chunk cannot load. The index chunk is
118.6 kB of its 120 kB.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The page-owner check refused every call under a stored token whose
claims it could not read, so the whole dashboard read as a session that
ended. Such a token names no one: the call goes, and the server's answer
to it decides.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…eloads

The cross-tab handler now runs after its chunk loads, so a change it
hears late that is no longer the stored token defers to the newer one
and never clears a token stored after it. A token the server confirms
for someone other than this page's person reloads the page, and a stale
chunk that the reload handler takes shows no card or banner.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the fix/dashboard-token-refresh branch from 3300318 to 8bec729 Compare November 3, 2026 21:34
@zlareb1
zlareb1 merged commit a9b4583 into main Nov 3, 2026
2 checks passed
@zlareb1
zlareb1 deleted the fix/dashboard-token-refresh branch November 3, 2026 21:35
@pufit pufit mentioned this pull request Nov 4, 2026
9 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant