Skip to content

feat(gateway): probe the SSO session so a dead refresh token logs out - #343

Merged
quickbeard merged 1 commit into
mainfrom
feat/account-probe
Aug 28, 2026
Merged

quickbeard merged 1 commit into
mainfrom
feat/account-probe

Conversation

@quickbeard

Copy link
Copy Markdown
Owner

Summary

Follow-up to #341 (supersedes #342, which GitHub closed when its stacked base branch was deleted on merge). The sidebar avatar showed a signed-in identity even when the SSO wrapper had already rejected the session's refresh token — a state unknowable from disk alone. getAccount now verifies it with a bounded network probe.

  • @codev/gateway gains probeSession(): an unexpired access token is "live" with no network call; no refresh token is "dead"; otherwise it hits ${SSO_URL}/token with the refresh grant — a definite rejection (400/401/403) is "dead", a network failure or 5xx is "unknown", and a successful refresh persists the (possibly rotated) tokens before returning "live". The userinfo round-trip honors the injected fetchImpl; the stale user block stands in if it fails.
  • The desktop controller's getAccount() probes only when the access token has expired, capped at 2.5s (timeout counts as "unknown"), and only "dead" hides the avatar — an unreachable IdP never logs anyone out visually (same rule as ensureKey). The verdict is cached for 60s since getAccount refires on every state event; a live probe self-heals by persisting tokens, so later calls short-circuit on disk.
  • No renderer changes: AccountNav already renders whatever getAccount resolves.

Testing

  • bun typecheck clean in codev-gateway, desktop, app (re-run after the rebase onto main).
  • bun test: gateway 65 pass (new probeSession suite: live short-circuit, dead-on-rejection, unknown-on-network/5xx, rotation persistence), desktop 20 pass (new getAccount policy suite: probe skipped on live token, dead hides, unknown optimistic + cached, no probe without identity).

🤖 Generated with Claude Code

https://claude.ai/code/session_01BcADw33oD8qs5jvn5NWMJx

loadAccount stayed optimistic about a refresh token the wrapper had
already rejected — the avatar showed a session no silent refresh could
revive. getAccount now probes the token endpoint when the access token
has expired: only a definite rejection (400/401/403) hides the avatar,
a network failure or server error proves nothing, and the verdict is
cached for a minute since getAccount refetches on every state event. A
live probe persists the refreshed (possibly rotated) tokens, so later
calls short-circuit on the unexpired access token.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BcADw33oD8qs5jvn5NWMJx
@quickbeard
quickbeard merged commit 22e33c9 into main Aug 28, 2026
0 of 5 checks passed
@quickbeard
quickbeard deleted the feat/account-probe branch August 28, 2026 06:57
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