Skip to content

microsoft-authentication: evict dead accounts from the cache instead of retrying them forever - #333638

Open
Tom Harvey (tombuildsstuff) wants to merge 1 commit into
microsoft:mainfrom
tombuildsstuff:b/evicting-dead-accounts-from-the-cache
Open

microsoft-authentication: evict dead accounts from the cache instead of retrying them forever#333638
Tom Harvey (tombuildsstuff) wants to merge 1 commit into
microsoft:mainfrom
tombuildsstuff:b/evicting-dead-accounts-from-the-cache

Conversation

@tombuildsstuff

Copy link
Copy Markdown

This commit fixes an issue where a credential that is permanently invalid sitting in the cache would be continually retried (which will never succeed), rather than being cleaned-up.

Instead this commit changes this so that when a credential is permanently invalid (e.g. revoked/expired/deleted — detected via MSAL's bad_token/refresh_token_expired codes on an InteractionRequiredAuthError) - that the account gets evicted from the account cache instead of retrying it indefinitely.

This doesn’t interrupt the regular recoverable flow (when consent is required, conditional access, plain interaction prompts) - but does handle when an account has been removed, a credential deleted etc.

…d of retrying them forever

This commit fixes an issue where a credential that is permanently invalid sitting in the cache would be continually retried (which will never succeed), rather than being cleaned-up.

Instead this commit changes this so that when a credential is permanently invalid (e.g. revoked/expired/deleted — detected via MSAL's bad_token/refresh_token_expired codes on an InteractionRequiredAuthError) - that the account gets evicted from the account cache instead of retrying it indefinitely.

This doesn’t interrupt the regular recoverable flow (when consent is required, conditional access, plain interaction prompts) - but does handle when an account has been removed, a credential deleted etc.
Copilot AI balanced review requested due to automatic review settings August 31, 2026 20:52
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

TylerLeonhardt

Matched files:

  • extensions/microsoft-authentication/src/node/authProvider.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Evicts permanently invalid Microsoft authentication accounts instead of repeatedly retrying silent authentication.

Changes:

  • Detects MSAL bad_token and refresh_token_expired errors.
  • Removes affected cached accounts while retaining recoverable accounts.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

if (isPermanentlyInvalidAccountError(e)) {
this._logger.info(`[getAllSessionsForPca] [${scopeData.scopeStr}] [${account.username}] refresh token is permanently invalid, removing account`);
try {
await cachedPca.removeAccount(account);
try {
await cachedPca.removeAccount(account);
} catch (removeError) {
this._logger.error(`[getAllSessionsForPca] [${scopeData.scopeStr}] [${account.username}] failed to remove account`, JSON.stringify(removeError));
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.

3 participants