fix(dashboard): an expired sign-in goes to the login, and the evidence pack says why it failed #418

Merged
sharang merged 2 commits from fix/dashboard-token-refresh into main 2026-09-28 20:40:02 +00:00
Owner

What happened on staging (2026-09-28)

Every page said "Die Prüfobjekte konnten nicht geladen werden", so it looked as if the projects were gone. The data was intact, which the infra session confirmed read-only:

  • the MongoDB volume is unchanged;
  • the tenant is intact, with no purge or delete.

The agent rejected each request with JWT validation failed: ExpiredSignature. The dashboard logged Token refresh failed: refresh rejected (400 Bad Request): invalid_grant, and it kept sending the stale token.

Change

  • One refresh at a time per session. A page's parallel requests all refreshed with the same refresh token. Keycloak rotates refresh tokens, so it rejects every refresh after the first.
    • A per-session lock serialises the refresh.
    • A request that waited re-reads the session and uses the token the other request obtained.
    • Unused locks are dropped.
  • A refused refresh ends the sign-in.
    • The session's user is removed, and the server function answers session_expired.
    • check_auth uses the same current_user, so a sign-in that can't be refreshed counts as signed out.
    • The app shell re-checks every minute and sends the browser to the login.
  • Other failures say why. The targets page shows the reason and an "Erneut versuchen" button, instead of a bare "konnten nicht geladen werden". An expired sign-in goes to the login instead.
  • A Keycloak that can't be reached (network error, 5xx) doesn't end the sign-in. The stale token is sent, as before, and the next request tries again.

Checks

  • fmt, and clippy with the CI flags on both dashboard feature sets.
  • Tests: dashboard 63 + 46.
  • New tests:
    • one lock per session, and unused locks are dropped;
    • an expired sign-in is recognised in a server error.

Also worth checking

If invalid_grant shows up again after this, the next suspect is the stage realm's SSO Session Idle / Max limits: Keycloak's defaults are 30 minutes idle and 10 hours max. Even then, the user now lands on the login instead of a broken page.

Also: the evidence pack (G4)

The .html files in the user's Downloads are the dashboard's own page (the target page's "Wird geladen …"), saved under the target's id. Both attempts happened while the agent was refusing requests: at 15:33 UTC during the Mongo outage, and at 20:25 UTC with the expired token. The download was a plain link, so an error answer from the route became a saved HTML file.

  • "Nachweispaket herunterladen" is now a button that fetches the pack in the page (EvidencePackButton, used on the target page and the CRA status page).
  • A application/zip response is saved under the server's file name.
  • Anything else shows a toast, "Das Nachweispaket konnte nicht erstellt werden", with the reason when the server gave one as plain text.
  • A 401 or an expired sign-in goes to the login.
  • Also: the file picker's "Browse…" button uses the dashboard's button style.

Checks: clippy on both feature sets is clean; tests 63 + 46.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p

## What happened on staging (2026-09-28) Every page said *"Die Prüfobjekte konnten nicht geladen werden"*, so it looked as if the projects were gone. **The data was intact**, which the infra session confirmed read-only: - the MongoDB volume is unchanged; - the tenant is intact, with no purge or delete. The agent rejected each request with `JWT validation failed: ExpiredSignature`. The dashboard logged `Token refresh failed: refresh rejected (400 Bad Request): invalid_grant`, and it kept sending the stale token. ## Change - **One refresh at a time per session.** A page's parallel requests all refreshed with the same refresh token. Keycloak rotates refresh tokens, so it rejects every refresh after the first. - A per-session lock serialises the refresh. - A request that waited re-reads the session and uses the token the other request obtained. - Unused locks are dropped. - **A refused refresh ends the sign-in.** - The session's user is removed, and the server function answers `session_expired`. - `check_auth` uses the same `current_user`, so a sign-in that can't be refreshed counts as signed out. - The app shell re-checks every minute and sends the browser to the login. - **Other failures say why.** The targets page shows the reason and an "Erneut versuchen" button, instead of a bare "konnten nicht geladen werden". An expired sign-in goes to the login instead. - **A Keycloak that can't be reached** (network error, 5xx) doesn't end the sign-in. The stale token is sent, as before, and the next request tries again. ## Checks - fmt, and clippy with the CI flags on both dashboard feature sets. - Tests: dashboard 63 + 46. - New tests: - one lock per session, and unused locks are dropped; - an expired sign-in is recognised in a server error. ## Also worth checking If `invalid_grant` shows up again after this, the next suspect is the stage realm's **SSO Session Idle / Max** limits: Keycloak's defaults are 30 minutes idle and 10 hours max. Even then, the user now lands on the login instead of a broken page. ## Also: the evidence pack (G4) The `.html` files in the user's Downloads are the dashboard's own page (the target page's "Wird geladen …"), saved under the target's id. Both attempts happened while the agent was refusing requests: at 15:33 UTC during the Mongo outage, and at 20:25 UTC with the expired token. The download was a plain link, so an error answer from the route became a saved HTML file. - "Nachweispaket herunterladen" is now a button that fetches the pack in the page (`EvidencePackButton`, used on the target page and the CRA status page). - A `application/zip` response is saved under the server's file name. - Anything else shows a toast, *"Das Nachweispaket konnte nicht erstellt werden"*, with the reason when the server gave one as plain text. - A 401 or an expired sign-in goes to the login. - **Also:** the file picker's "Browse…" button uses the dashboard's button style. Checks: clippy on both feature sets is clean; tests 63 + 46. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang added 1 commit 2026-09-28 20:27:48 +00:00
fix(dashboard): an expired sign-in sends you to the login instead of failing every page
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Canceled after 4m51s
ecee3b5b50
On staging every page said "konnten nicht geladen werden" while the data
was intact: the agent rejected each request with an expired token, because
the dashboard's token refresh was refused by Keycloak (invalid_grant) and it
kept sending the stale token.

- One refresh at a time per session. A page's parallel requests all
  refreshed with the same refresh token, and Keycloak, which rotates it,
  rejects every one after the first. A request that waited uses the token
  the other one got.
- A refused refresh ends the sign-in: the session's user is removed and the
  server function answers session_expired. The app shell checks the sign-in
  every minute and on such an answer goes to the login; the auth check itself
  counts an unrefreshable sign-in as signed out.
- A failure that is not about the sign-in shows its reason and a retry on
  the targets page, instead of a bare "could not be loaded".

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang changed title from fix(dashboard): an expired sign-in sends you to the login instead of failing every page to fix(dashboard): an expired sign-in goes to the login, and the evidence pack says why it failed 2026-09-28 20:32:37 +00:00
sharang added 1 commit 2026-09-28 20:32:38 +00:00
fix(dashboard): the evidence pack downloads a ZIP or says why not
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 6m54s
1a28a80d83
The download was a plain link. When the agent refused (an expired token,
the Mongo outage), the route answered with the app's own page, and the
browser saved that as <target id>.html: an empty white page. The button
now fetches the pack in the page: a ZIP is saved under the server's file
name; anything else shows "Das Nachweispaket konnte nicht erstellt werden"
(with the server's reason when it gave one in words), and an expired
sign-in goes to the login.

The file picker's own button uses the dashboard's button style.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang merged commit 420ce241cd into main 2026-09-28 20:40:02 +00:00
Sign in to join this conversation.