Change:
<!-- Do Not Delete This! bugreporttemplate --<!-- Please read our Rules of Conduct: --<!-- Read our guide about submitting issues: --<!-- Search existing issues to avoid creating duplicates. --<!-- Test using the latest Insiders build to see if your issue has already been fixed: --<!-- Instead of creating your report here, use 'Report Issue' from the 'Help' menu in VS Code to pre-fill useful information. --<!-- Launch with to check. --Does this issue occur when all extensions are disabled?: Yes/No <!-- If you answered No above, use 'Help: Start Extension Bisect' from Command Palette to try to identify the cause. --<!-- Issues caused by an extension need to be reported directly to the extension publisher. The 'Help Report Issue' dialog can assist with this. --- VS Code Version: OS Version: Steps to Reproduce: an extension that does this: 'll notice that is though it should exist because we created it on line 1. This is because we cache the session id based on the provider id & extension name but really we should be caching them based on provider id, extension name, AND SCOPES. This will allow the 3rd time to find the session created in the first line.
Verification steps: The code session3 should not be undefined.
is your solution to this issue the reason that the Insiders builds have started bugging me at least once a day to sign into GitHub? With four windows open, each with two extensions that want a GitHub token (GitLens and GitHub Issues and Pull Requests), I have to generate 8 tokens to make VS Code stop bugging me... at which point it almost always discovers a VS Code update, and often we do the dance again after it restarts.
(And never mind, I see it was, and I see you fixed it!)
Reopening this because I reverted the change that fixed it.
just checking to see if there were any updates on this issue?
haven't had a chance to revisit this. You can take a look at my commit if you'd like. The problem I needed to address is migrating from the old storage keys to the new storage keys and my commit didn't handle that. Unfortunately, I have some other work I'm working on at the moment so I won't be able to look at this this month.
This appears to be fixed. Closing now
verification: original steps to repro. Instead, session3 should be defined.

Discussion:
return choice === 0; } <del> private async setTrustedExtensionAndAccountPreference(providerId: string, accountName: string, extensionId: string, extensionName: string, sessionId: string): Promise<void> { this.authenticationService.updatedAllowedExtension(providerId, accountName, extensionId, extensionName, true); this.storageService.store(`${extensionName}-${providerId}`, sessionId, StorageScope.GLOBAL, StorageTarget.MACHINE); } </del> private async selectSession(providerId: string, extensionId: string, extensionName: string, scopes: string[], potentialSessions: readonly modes.AuthenticationSession[], clearSessionPreference: boolean, silent: boolean): Promise<modes.AuthenticationSession | undefined> { if (!potentialSessions.length) { throw new Error('No potential sessions found'); } if (clearSessionPreference) { <del> this.storageService.remove(`${extensionName}-${providerId}`, StorageScope.GLOBAL); </del> <ins> this.storageService.remove(`${extensionName}-${providerId}-${scopes.join('-')}`, StorageScope.GLOBAL); </ins> } else { <del> const existingSessionPreference = this.storageService.get(`${extensionName}-${providerId}`, StorageScope.GLOBAL); </del> <ins> const existingSessionPreference = this.storageService.get(`${extensionName}-${providerId}-${scopes.join('-')}`, StorageScope.GLOBAL); </ins> if (existingSessionPreference) { const matchingSession = potentialSessions.find(session => session.id === existingSessionPreference); if (matchingSession) {

} session = await this.authenticationService.createSession(providerId, scopes, true); <del> await this.setTrustedExtensionAndAccountPreference(providerId, session.account.label, extensionId, extensionName, session.id); </del> <ins> await this.authenticationService.updatedAllowedExtension(providerId, session.account.label, extensionId, extensionName, true); this.storageService.store(`${extensionName}-${providerId}-${scopes.join('-')}`, session.id, StorageScope.GLOBAL, StorageTarget.MACHINE); </ins> } else { await this.authenticationService.requestNewSession(providerId, scopes, extensionId, extensionName); }

this._inFlightRequests.set(extensionId, inFlightRequests); try { <del> await session; </del> <ins> const s = await session; return s; </ins> } finally { const requestIndex = inFlightRequests.findIndex(request => request.scopes === sortedScopes); if (requestIndex > -1) {

this._inFlightRequests.set(extensionId, inFlightRequests); } } <del> return session; </del> } }

this.updatedAllowedExtension(providerId, accountName, extensionId, extensionName, true); this.removeAccessRequest(providerId, extensionId); <del> this.storageService.store(`${extensionName}-${providerId}`, session.id, StorageScope.GLOBAL, StorageTarget.MACHINE); </del> <ins> this.storageService.store(`${extensionName}-${providerId}-${scopes.join('-')}`, session.id, StorageScope.GLOBAL, StorageTarget.MACHINE); </ins> quickPick.dispose(); resolve(session);

this.updatedAllowedExtension(providerId, session.account.label, extensionId, extensionName, true); // And also set it as the preferred account for the extension <del> storageService.store(`${extensionName}-${providerId}`, session.id, StorageScope.GLOBAL, StorageTarget.MACHINE); </del> <ins> storageService.store(`${extensionName}-${providerId}-${scopes.join('-')}`, session.id, StorageScope.GLOBAL, StorageTarget.MACHINE); </ins> } });

<ins> /*--------------------------------------------------------------------------------------------- *  Copyright (c) Microsoft Corporation. All rights reserved. *  Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import * as assert from 'assert'; import { AuthenticationProviderInformation } from 'vs/editor/common/modes'; import { IDialogService } from 'vs/platform/dialogs/common/dialogs'; import { TestDialogService } from 'vs/platform/dialogs/test/common/testDialogService'; import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService'; import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; import { INotificationService } from 'vs/platform/notification/common/notification'; import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService'; import { IQuickInputHideEvent, IQuickInputService, IQuickPickDidAcceptEvent } from 'vs/platform/quickinput/common/quickInput'; import { IStorageService } from 'vs/platform/storage/common/storage'; import { MainThreadAuthentication } from 'vs/workbench/api/browser/mainThreadAuthentication'; import { IExtHostContext } from 'vs/workbench/api/common/extHost.protocol'; import { IActivityService } from 'vs/workbench/services/activity/common/activity'; import { AuthenticationService, IAuthenticationService } from 'vs/workbench/services/authentication/browser/authenticationService'; import { ExtensionHostKind, IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService'; import { TestRemoteAgentService } from 'vs/workbench/services/remote/test/common/testServices'; import { TestQuickInputService } from 'vs/workbench/test/browser/workbenchTestServices'; import { TestActivityService, TestExtensionService, TestStorageService } from 'vs/workbench/test/common/workbenchTestServices'; function createSession(id: string = '1234', scope: string[] = []) { return { accessToken: '1234', account: { id: 'test@test.com', label: 'Test Person' }, id: id, scopes: scope }; } class AuthQuickPick { private listener: ((e: IQuickPickDidAcceptEvent) => any) | undefined; public items = []; public get selectedItems(): string[] { return this.items; } onDidAccept(listener: (e: IQuickPickDidAcceptEvent) => any) { this.listener = listener; } onDidHide(listener: (e: IQuickInputHideEvent) => any) { } dispose() { } show() { this.listener!({ inBackground: false }); } } class AuthTestQuickInputService extends TestQuickInputService { override createQuickPick() { return <any>new AuthQuickPick(); } } suite('MainThreadAuthentication', () => { let mainThreadAuthentication: MainThreadAuthentication; suiteSetup(async () => { // extHostContext: IExtHostContext, const services = new ServiceCollection(); const dialogService = new TestDialogService(); const storageService = new TestStorageService(); const quickInputService = new AuthTestQuickInputService(); const extensionService = new TestExtensionService(); const activityService = new TestActivityService(); const remoteAgentService = new TestRemoteAgentService(); services.set(IDialogService, dialogService); services.set(IStorageService, storageService); services.set(INotificationService, new TestNotificationService()); services.set(IQuickInputService, quickInputService); services.set(IExtensionService, extensionService); services.set(IActivityService, activityService); services.set(IRemoteAgentService, remoteAgentService); const instaService = new InstantiationService(services); services.set(IAuthenticationService, instaService.createInstance(AuthenticationService)); mainThreadAuthentication = instaService.createInstance(MainThreadAuthentication, new class implements IExtHostContext { remoteAuthority = ''; extensionHostKind = ExtensionHostKind.LocalProcess; assertRegistered() { } set(v: any): any { return null; } getProxy(): any { return { $getSessions(id: string, scopes: string[]) { return Promise.resolve([createSession(id, scopes)]); }, $createSession(id: string, scopes: string[]) { return Promise.resolve(createSession(id, scopes)); }, $removeSession(id: string, sessionId: string) { return Promise.resolve(); }, $onDidChangeAuthenticationSessions(id: string, label: string) { return Promise.resolve(); }, $onDidChangeAuthenticationProviders(added: AuthenticationProviderInformation[], removed: AuthenticationProviderInformation[]) { return Promise.resolve(); }, $setProviders(providers: AuthenticationProviderInformation[]) { return Promise.resolve(); } }; } drain(): any { return null; } }); await mainThreadAuthentication.$registerAuthenticationProvider('test', 'test provider', true); }); suiteTeardown(() => { mainThreadAuthentication.$unregisterAuthenticationProvider('test'); }); test('Can get a session', async () => { const session = await mainThreadAuthentication.$getSession('test', ['foo'], 'testextension', 'test extension', { createIfNone: true, clearSessionPreference: false }); assert.strictEqual(session?.id, 'test'); assert.strictEqual(session?.scopes[0], 'foo'); }); test('Can get multiple sessions (with different scopes) in one extension', async () => { let session = await mainThreadAuthentication.$getSession('test', ['foo'], 'testextension', 'test extension', { createIfNone: true, clearSessionPreference: false }); session = await mainThreadAuthentication.$getSession('test', ['bar'], 'testextension', 'test extension', { createIfNone: true, clearSessionPreference: false }); assert.strictEqual(session?.id, 'test'); assert.strictEqual(session?.scopes[0], 'bar'); session = await mainThreadAuthentication.$getSession('test', ['foo'], 'testextension', 'test extension', { createIfNone: false, clearSessionPreference: false }); assert.strictEqual(session?.id, 'test'); assert.strictEqual(session?.scopes[0], 'foo'); }); }); </ins>

import { ISaveOptions, IRevertOptions } from 'vs/workbench/common/editor'; import { CancellationToken } from 'vs/base/common/cancellation'; import product from 'vs/platform/product/common/product'; <ins> import { IActivity, IActivityService } from 'vs/workbench/services/activity/common/activity'; </ins> export class TestTextResourcePropertiesService implements ITextResourcePropertiesService {

export class TestExtensionService extends NullExtensionService { } export const TestProductService = { _serviceBrand: undefined, ...product }; <ins> export class TestActivityService implements IActivityService { _serviceBrand: undefined; showViewContainerActivity(viewContainerId: string, badge: IActivity): IDisposable { return this; } showViewActivity(viewId: string, badge: IActivity): IDisposable { return this; } showAccountsActivity(activity: IActivity): IDisposable { return this; } showGlobalActivity(activity: IActivity): IDisposable { return this; } dispose() { } } </ins>