Repository navigation
fix(dash0): keep valid sessions when a token refresh fails transiently - #782
Merged
Merged
Conversation
A 500, 502 or 429 from /auth/refresh counted as "rejected": the dashboard cleared both tokens and sent the user to login?session_expired=true. A network error during the refresh did the same through apiFetch's 401 path. The server answers 401 for every dead session, so only a 401 now ends it. Any other failure is "unavailable": the request fails as a NetworkError and the tokens stay. The cold-load /auth/me check retries twice before giving up. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #782 +/- ##
==========================================
- Coverage 89.23% 89.22% -0.02%
==========================================
Files 1320 1320
Lines 135152 135152
==========================================
- Hits 120609 120595 -14
- Misses 14534 14548 +14
Partials 9 9 🚀 New features to boost your workflow:
|
fclairamb
enabled auto-merge (squash)
November 6, 2026 17:56
Merged
fclairamb
added a commit
that referenced
this pull request
Nov 7, 2026
🤖 I have created a release *beep* *boop* --- ## [0.44.1](v0.44.0...v0.44.1) (2026-11-07) ### Bug Fixes * **dash0:** keep valid sessions when a token refresh fails transiently ([#782](#782)) ([8e77846](8e77846)) * **deps:** update module github.com/crewjam/saml to v0.5.2 ([#786](#786)) ([9d370fe](9d370fe)) * **deps:** update module github.com/posthog/posthog-go to v1.40.1 ([#775](#775)) ([37ada84](37ada84)) * **deps:** update module github.com/posthog/posthog-go to v1.41.1 ([#785](#785)) ([8684c71](8684c71)) * **docs:** plain markdown for the API reference .md pages ([#784](#784)) ([3270ac6](3270ac6)) * **security:** normalize trailing-dot custom status domains ([#778](#778)) ([8b2a7ca](8b2a7ca)) * **slack:** resolve check and incident link unfurls ([#779](#779)) ([930f18e](930f18e)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Over 30 days, 16 of 87 PostHog replays of logged-in users include a
/login?session_expired=trueredirect, across 11 users. Several of those users still held a valid refresh token at the time of the redirect.4c18f13a(orga8cb119a), 2026-10-10 17:02: their open dashboard tab unloaded itself with no user action and went tosession_expired=true. That was 8 minutes after a successful refresh. The refresh token was valid until 10-17, with an active owner membership.d8dfb730(orga6b8a965), 2026-10-30 07:07: a cold load went tosession_expired=truewith a refresh token valid until 11-06, and no refresh was recorded on the server./auth/me401, then/auth/refresh500, console[auth] token refresh failed: rejected, tokens wiped, redirect tologin?session_expired=true.Token lifetimes are not the cause. Access tokens last 1h, and refresh tokens use a 7-day sliding idle window that the server slides correctly. Two of the redirects (org
87ca1191, 10-16 and 10-27) were real 7-day idle expiries, which is intended.Cause
token-refresh.tstreated any non-OK answer from/auth/refreshas "rejected": a 500 from a DB hiccup, a 502 from the ingress during a pod restart, or a 429. It then cleared both tokens and redirected. The server only answers 401 for a dead session (handleRefreshError).apiFetchhandled a refresh that failed on a network error the same way.refreshAccessToken()returned null, the original 401 went tohandleResponse, and that cleared the session and redirected. This contradicted the module's own rule that a network blip must never clear the session.Fix
/auth/refreshisrejected. Any other failure is nowunavailable(renamed fromnetwork-error, which now also covers non-401 server answers). It keeps the tokens and logs a warning.apiFetchthrows aNetworkErrorwhen the refresh isunavailable, instead of logging the user out./auth/meis retried twice (after 1s, then 3s) on a transient failure. Before, such a failure left the user signed out on the login page.Tests
token-refresh.test.ts: 500, 502, 503 and 429 giveunavailablewith no clear and no redirect. A 401 still clears and redirects.client.test.ts: anapiFetchwhose refresh hits a 500 or a network error rejects withNetworkError, keeps both tokens and does not navigate.mainand pass here. Full unit suite: 182 files, 2795 tests passing.tsc -bpasses.🤖 Generated with Claude Code