Fix repeated silent authentication failures caused by stale refresh tokens - #335641
Open
GaspardRuan (gaspardruan) wants to merge 1 commit into
Open
Conversation
Copilot started reviewing on behalf of
GaspardRuan (gaspardruan)
September 11, 2026 07:56
View session
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: TylerLeonhardtMatched files:
|
Author
|
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused implementation matches the described failure mode and has comprehensive regression coverage.
Pull request overview
Fixes repeated Microsoft authentication failures by persisting MSAL’s rejected refresh-token removal before a bounded retry.
Changes:
- Adds cache-aware silent token acquisition with one retry.
- Preserves concurrent SecretStorage updates.
- Adds regression and concurrency coverage.
File summaries
| File | Description |
|---|---|
common/cachePlugin.ts |
Handles cache persistence after authentication failures. |
node/tokenCache.ts |
Implements invalidation and bounded retry logic. |
node/cachedPublicClientApplication.ts |
Integrates recovery into non-broker silent authentication. |
node/test/tokenCache.test.ts |
Tests recovery, persistence, errors, and concurrent updates. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Fixes #335639
Problem
I investigated this after Settings Sync continued to show “Sign in to Sync Settings” following a successful Microsoft sign-in on macOS. Logs showed
createSessionreturning a session, followed bygetSessionsreturning no sessions afterAADSTS700082. I can no longer reproduce the original sign-in failure with my real account. Instead, the tests use a simulated account, synthetic tokens, and simulated identity-server responses with the real MSAL library and VS Code authentication code to reproduce the token-cache defect described below. The same regression tests fail on the original code and pass with the proposed fix.The Microsoft authentication extension's current MSAL dependency can repeatedly reload a rejected refresh token from persisted storage. MSAL removes the token from memory on an
invalid_grant/bad_tokenresponse, but does not call the persistence callback on that failure path.When a rejected family refresh token coexists with a fresh application refresh token for the same account, repeated silent requests keep submitting the family token and failing despite the fresh credential being available.
Reproduction
See #335639 for the reproduction steps, expected results before and after the fix, and an auxiliary standalone MSAL reproduction.
Fix
Persist MSAL's removal of the rejected token before retrying silent authentication once, within the existing PCA sequencer. Apply this to ordinary silent acquisition and ID-token refresh. Broker authentication and unrelated errors keep their existing behavior.
If the persisted cache changed while the request was in flight, reload it instead of writing the failed request's snapshot. This check is not atomic with the subsequent write, so a concurrent update between them can still be overwritten. A concurrent cache change can also exhaust the retry, requiring a subsequent session request.