Repository navigation
perf(auth): cut round trips in native refresh-token rotation - #8010
Merged
Merged
Conversation
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Reviewed the single joined pre-read in Key checks:
Files Reviewed (1 file)
Reviewed by deepseek-v4.1-flash · Input: 48.9K · Output: 11.9K · Cached: 435.8K Review guidance: REVIEW.md from base branch |
pandemicsyn
approved these changes
Oct 20, 2026
This was referenced Oct 22, 2026
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.
bot: In
apps/web/src/lib/auth/device-sessions.ts(rotateRefreshToken), the three sequential pre-transaction selects — the refresh-token row, the parent device session, and the user's blocked status — are now one joined query that returns the token row, the full session, and the full user. The inner joins keep every refusal outcome and error code exactly as before: a token whose session or user no longer exists refuses the same way as an unknown token, and revoked-session and blocked-user refusals are unchanged.Token generation inside the transaction now uses the pre-read user row, so the user row is fetched once per rotation instead of twice. The in-transaction
FOR UPDATEsession lock, the token re-read under it, and the consume and replacement issuance are unchanged.Happy-path database statements drop from eight to six: one joined lookup, the session lock re-read, the token re-read, the consume, the
last_seen_atupdate, and the replacement-token insert. The unconditionallast_seen_atupdate is kept on purpose so the mobile device list keeps showing a fresh last-seen value on every rotation.End-to-end verification
pnpm --filter web run test -- --testPathPattern device-sessions— 16/16 pass (happy path, unknown token, replay, lost rotation, retired pair, stale request, lock-order recovery, grace expiry, revoked session, concurrent revocation, blocked user, unblock retry, 30-day expiry, issuance rollback).pnpm --filter web run typecheckandpnpm --filter web run lintpass.POST /api/auth/native/refresh, got 200 with a new one-hour pair, confirmed the old token consumed and the new one live, rotated the new token again — 200. Postgres statement logging during one rotation shows exactly six auth statements, the first being the single joined select with both inner joins.Proxy answers
The owner's proxy gave these answers in the owner's place.
Answer: Keep unconditional write (Recommended)
Confidence: 0.65 · Precedent: Speed and least work: 'do the least amount of work possible, with no drop in quality' (session 7f3470e0ba6f). The step is optional, a stale 'Last seen' would lower quality, and with roughly hourly rotations a short threshold would rarely skip a write.