Repository navigation
Conversation
…rmed revokes are retried Fixes #3164.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 30 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Review record (CodeRabbit skipped: review limit reached)This PR touches authentication, so the code-review agents' findings and their resolution are recorded here. Round 1 (omo BLOCK, Codex request changes at 36fe1ab): 5 HIGH + 5 MEDIUM, all reproduced with the fake account service. Fixed in 22456cf: desktop sign-in epoch taken before the loopback opens; a pre-update pending sign-in without an epoch is not kept; Round 2 (Codex at 22456cf): one HIGH introduced by round 1 (an in-flight request's 401 retry could run with another account's sign-in after the replaced one was ended). Fixed in 034269e: Final (034269e): omo CLEAR (no HIGH/MEDIUM); Codex targeted check PASS (HIGH closed, no new HIGH). Remaining LOWs (no follow-up issue):
|
…ever redeem or retry across a sign-out
Review record, round 3 (merge pass HOLD at 034269e -> ead7c40)CodeRabbit still skipped (review limit). Fixed, each with a test that fails at 034269e:
omo at ead7c40: CLEAR, no HIGH/MEDIUM. Remaining LOWs (no follow-up issue):
|
|
Parked as draft after the round limit. What this PR fixes (#3164): a sign-out wins over any sign-in, re-authentication or link still on its way (sign-out epoch), and revocations the service did not confirm are kept and retried, including through a closed page and leaving the account. The merge pass's delta review at ead7c40 reproduced:
These are tracked in #3198. The work resumes as one design pass across the client and the account service. |
|
Closing (owner decision): a rare two-window race; #3164 stays open to revisit when account use grows. |
Fixes #3164.
Problem
Two sign-out races in the account client, both reproduced with the fake account service:
POST /v1/signoutignored the answer: a 429 (or 5xx, or a network error) left the store empty while the discarded refresh token still redeemed.Fix
epochthat every sign-out replaces in the same transaction that removes the session. Every sign-in remembers the epoch when it starts (beginSignInputs it in the pending record; the device flow and native Apple sign-in capture it before they start) and is stored only while the epoch is unchanged (keepSignIn). One that finishes after a sign-out is ended at the service and throwsSignedOutError, sosignInAgainnever repeats the method change.clear()drops the epoch, so it counts as a sign-out too.endAtServicerefreshes an expired access token first, then treats only 204 (or 401, already over) as ended.endSignInkeeps a sign-in it could not end in the store (ending, capped at 16) andAccountService.endLeftovers()ends those again; it runs at every sign-out and whenever the account screen (Settings, or the hosted shell's list) loads.signOut()uses the same path, so a sign-out the service did not confirm is retried later too, and still throws so the caller can log it.No new UI or setting. Existing behaviour for a sign-in that finishes normally is unchanged. A sign-in started by an earlier build and finished after the update (no epoch) is not kept: that person signs in once more.
Validation
src/lib/account/methods.test.tsfail onorigin/main(the source changes stashed) and pass with the fix.endLeftovers()once the limit window passes (its refresh token no longer redeems).bun test src/lib/account/ src/lib/relay/: 277 pass. One existing test (takes back the session of a sign-in cancelled while it was being written) now hooksupdateMany, which the device flow writes through.bun run check fast: green (typecheck, build, unit 12800 pass).Review round (omo + Codex at 36fe1ab)
Fixed, each with a test that fails at 36fe1ab where noted:
bridge.start()(and redirect sign-ins after the PKCE digest): the epoch is now taken first (test).ending:clear()keepsendingand moves the session it forgets into it (test)./v1/signoutcounted as ended: it is retried with the refresh token, and only a refused refresh counts as over (test).addMethodcould report success after sign-out + new sign-in of the same account: it now checks the epoch.signOut()waited behind the lock before changing the epoch, and leftovers were ended under the lock: the epoch changes at once, andendLeftovers()runs outside the lock.(The 16-entry cap on
endingmentioned in round 1 was removed in round 3.)Review round 2 (Codex + omo at 22456cf)
call()now repeats a request only for the account it was made for, otherwiseSignedOutError(test; it also closes the older trigger of the same retry).addMethodthrowsSignedOutErrorinstead of returning a revoked session when a sign-out lands during its cleanup.Review round 3 (merge pass HOLD at 034269e)
Each fix has a test that fails at 034269e:
signOut()put the session on the list to end only after the revoke failed, so a page closed while/v1/signoutwas pending lost it. It now goes ontoendingin the same transaction that drops the session and changes the epoch, and leaves it only once the service confirms;endSignIndoes the same.call()'s 401 retry checked only the account. It now also refuses to repeat after a sign-out (epoch changed), so a method removal queued before a sign-out never runs with the next sign-in of the same account./v1/token(a link could add the identity when the revoke had failed).finishSignInnow checks the epoch before redeeming.endingis no longer capped: an unconfirmed revocation is never dropped.Remaining LOW: the IndexedDB
clear()path is exercised only through the memory store in unit tests.