Skip to content

Upgrade @microsoft/vscode-azext-azureauth to v6: ES module build, cached and faster subscription loading #990

Open

Description

Summary

Upgrade @microsoft/vscode-azext-azureauth from 4.1.1 to v6. This has three reasons:

  1. ES module build. Removes the @azure/arm-resources-subscriptions Vite alias that Modernize the build, bundling, and test stack #880 added (original scope of this issue, details below).
  2. Subscription loading is slow and repeated. 4.1.1 has no cache and lists every account × tenant one after another, on every call. v6 is a rewrite that adds caching, parallel listing, a public per-tenant lookup and cancellation.
  3. Deep links to Azure resources (Open Azure resources and the dashboard or shell from deep links (/connect/azure, open=) #1067) spend most of their time listing subscriptions. Part of that work in Open Azure resources and the dashboard or shell from deep links (/connect/azure, open=) #1067 was deferred to this upgrade (see Deep links below).

Blockers: #880 is merged. Start after #1067 is merged, because it adds new subscription call sites (src/deepLinks/azureSubscription.ts) that this upgrade must migrate.


Why subscription loading is slow today (measured)

From a /connect/azure trace in #1067:

15:25:03.256  Looking up the subscription node     ← 10.7 s: getSubscriptions() across all accounts × tenants
15:25:13.960  Looking up the cluster node          ←  4.4 s: databaseAccounts.list (RU)
  • VSCodeAzureSubscriptionProvider.getSubscriptions() (4.1.1) does for account → await getTenants(account) → for tenant → await getSubscriptionsForTenant(…), plus each account's home tenant. Every call does the full walk. There is no cache, and nothing runs in parallel.
  • The filter is applied after the full listing, so getSubscriptions(true) costs as much as getSubscriptions(false).
  • Each discovery plugin has its own provider instance (azure-mongo-vcore-discovery, azure-mongo-ru-discovery, azure-vm-discovery), so expanding all three lists three times.
  • A /connect/azure deep link lists twice: once in resolveAzureSubscription (unfiltered, to find the account and tenant) and again when the Discovery view's provider root expands (filtered).
  • getSubscriptionsForTenant is private in 4.1.1, so there is no public way to load one tenant except the getSubscriptions({ tenantId }) filter.

What v6 offers (checked against 6.1.0-alpha.2)

4.1.1 (today) v6
Listing sequential, full walk on every call cached (before filtering), parallel with a limiter
Cache control — noCache per call; automatic partial refill after sign-in; onRefreshSuggested (sessionChange, subscriptionFilterChange, cloudChange)
Per-tenant lookup private public getSubscriptionsForTenant({ tenantId, account })
Failing tenant aborts the listing skipped
Cancellation none CancellationToken on every call
Sovereign cloud change — watched, fires cloudChange
Step-up MFA — BearerChallengePolicy

v6 still has no "get subscription by ID". Loading a subscription still needs its tenant (see Deep links).

Breaking API changes to plan for (4.1.1 → v6)

  • getSubscriptions(filter) → getAvailableSubscriptions(options)
  • getTenants(account?) → getAccounts() + getTenantsForAccount(account), plus getUnauthenticatedTenantsForAccount
  • isSignedIn(tenantId?, account?) → removed; use getAccounts() / signIn(tenant, { promptIfNeeded: false })
  • signIn(tenantId?, account?) → signIn({ tenantId, account }?, options?)
  • onDidSignIn / onDidSignOut → onRefreshSuggested
  • Providers moved to providers/, with a new AzureSubscriptionProviderBase. Protected hooks still exist: getSubscriptionFilters, getTenantFilters, getAccountFilters.
  • Also read the intermediate 4.2.0 / 5.0.0 / 5.1.0 entries in the package CHANGELOG.md (auth challenges, CJS+ESM, onDidChangeSessions only subscribed when events are used).

Call sites (on the #1067 branch; re-check after merge)

File Uses
src/plugins/api-shared/azure/AzureSubscriptionProviderWithFilters.ts subclass; overrides getSubscriptionFilters (reads azureResourceGroups.selectedSubscriptions, globalState fallback azure-discovery.selectedSubscriptions)
src/plugins/service-azure-mongo-vcore/discovery-tree/AzureServiceRootItem.ts isSignedIn, getSubscriptions(true)
src/plugins/service-azure-mongo-ru/discovery-tree/AzureMongoRUServiceRootItem.ts same
src/plugins/service-azure-vm/discovery-tree/AzureServiceRootItem.ts same
src/plugins/api-shared/azure/wizard/SelectSubscriptionStep.ts getSubscriptions(false)
src/plugins/api-shared/azure/subscriptionFiltering/InitializeFilteringStep.ts getTenants, isSignedIn(tenant, account), getSubscriptions(false)
src/plugins/api-shared/azure/credentialsManagement/SelectAccountStep.ts, AccountTenantsStep.ts getTenants, isSignedIn, signIn
src/commands/newConnection/PromptTenantStep.ts, src/commands/updateCredentials/PromptTenantStep.ts isSignedIn, getTenants (wrapped in traceTenantLookup)
src/deepLinks/azureSubscription.ts (#1067) isSignedIn, signIn, signIn(tenantId), getSubscriptions(false)
src/documentdb/auth/documentdbTokenResource.ts getConfiguredAuthProviderId, getConfiguredAzureEnv (still exported in v6 from utils/configuredAzureEnv)

About 15 more files under src/plugins/api-shared/azure/ and src/plugins/service-azure-* import types only (AzureTenant, AzureSubscription, …).

Things to pay attention to

Version and bundle

  • Dedupe: @microsoft/vscode-azext-azureutils 4.2.0 depends on ^6.0.0-alpha.6 and installs 6.0.0-alpha.8. That range accepts 6.0.0-alpha.8 but not 6.1.0-alpha.2 (prerelease ranges don't cross minor versions; checked with semver). Picking 6.1.0-alpha.2 keeps two auth copies in the bundle. Pick 6.0.0-alpha.8, or bump azureutils to a version that accepts 6.1.x.
  • v6 is still alpha (first alpha 2025-12, latest 6.1.0-alpha.2 2026-06). The Azure Resources extension ships on ^6.1.0-alpha.2; vscode-cosmosdb is on ~5.1.1. 5.1.1 gives only the ESM build, none of the loading improvements.
  • engines.vscode: v6 needs ^1.106.0; we require ^1.109.0.
  • Dependency quarantine: no version published in the last 7 days (node .github/skills/flagging-fresh-dependencies/scripts/find-fresh-dependencies.mjs --fail-on-fresh).
  • l10n: l10n/scripts/constants.mjs merges a checked-in copy of the package's bundle at l10n/@microsoft/vscode-azext-azureauth/bundle.l10n.json. Refresh it from the new version, then npm run l10n and npm run l10n:check.

Filters and caching

  • v6 caches before filtering, so filter changes take effect without noCache. Check that our getSubscriptionFilters override, with its globalState fallback, is still called on every listing and that subscriptionFilterChange fires for our writes.
  • Our tenant filter is ours, stored in globalState (subscriptionFilteringHelpers.ts), and applied by callers through getTenantFilteredSubscriptions. v6 has a getTenantFilters hook. Decide whether to keep our filter as is or map it onto the hook; don't do both.
  • Open Azure resources and the dashboard or shell from deep links (/connect/azure, open=) #1067 writes filters from a deep link (D0011): showDiscoveryProvider, removeUnselectedTenant, setSelectedSubscriptionIds. After the upgrade, the Discovery view must show the newly selected subscription without a manual refresh.
  • One provider instance per plugin means one cache per plugin. Consider sharing one provider instance across the vCore, RU and VM plugins so they share a cache. Mind disposal: today each plugin disposes its own provider.
  • Use noCache: true wherever a stale list is wrong: the explicit Refresh on Discovery provider roots, and the deep link's retry after "subscription not found" (the user may just have been granted access).
  • The root items carry a comment that running getSubscriptions and getTenants in parallel once gave wrong results. Re-check that note with v6's own parallel listing, and drop it if it no longer applies.

Sign-in and events

  • isSignedIn is gone. Every "Sign in to Azure" prompt (discovery roots, wizards, deep link) needs a new check that doesn't prompt (signIn(…, { promptIfNeeded: false }) or getAccounts()).
  • Session changes: verify sign-out, sign-in and account switch refresh the Discovery view (onRefreshSuggested), and that cached AzureSubscription.credential objects from a signed-out session are not reused.
  • Sovereign clouds (docs/ai-and-plans/features/sovereign-clouds/): v6 watches the cloud setting. Check that switching clouds clears the cache and refreshes.
  • "Skip failing tenants": a tenant that needs re-authentication now silently drops its subscriptions instead of failing. Check that the Discovery view and the deep link's tenant sign-in offer still guide the user.

Deep links (#1067)

resolveAzureSubscription lists every subscription to find the account and tenant of one subscription ID. After the upgrade:

  1. Find the tenant first: the link's tenantId when present; otherwise the anonymous ARM challenge. An unauthenticated GET https://<ARM endpoint>/subscriptions/{id}?api-version=2022-12-01 returns 401 with WWW-Authenticate: Bearer authorization_uri="https://login.windows.net/<tenantId>" (verified). Use the configured cloud's ARM endpoint. Keep the full listing as a fallback.
  2. Load only that tenant: getSubscriptionsForTenant({ tenantId, account }) for each account from getAccounts(). Keep the existing rules: prefer an account whose tenant is not filtered out; offer "Sign in to tenant" when no account has it (now also possible without tenantId in the link).
  3. Cancellation: pass the progress notification's CancellationToken (the /connect/azure notification is already cancellable) so ✕ aborts the listing instead of only stopping between steps.
  4. With the cache, the Discovery view's "Loading subscriptions…" step after the link (Open Azure resources and the dashboard or shell from deep links (/connect/azure, open=) #1067 walks the tree through the view) should be served from the cache instead of listing again.

Expected: the first step of an Azure deep link goes from ~10 s to ~1–2 s, and the tree step becomes a cache hit.

Original scope (from #880): remove the bundler workaround

  • vite.config.ext.mjs aliases @azure/arm-resources-subscriptions to its CommonJS entry (TODO(#990)). 4.1.1's Promise.resolve().then(() => require('@azure/arm-resources-subscriptions')) is bundled by Rolldown to a promise that resolves to undefined (G5-I01 in docs/ai-and-plans/modernization/build-and-test-stack.md). Remove the alias, its comment and the TODO.
  • test/vitest/setup.ts hooks require('vscode') for CommonJS azext packages (review finding S2-F03). Check whether the hook can go, or record which CommonJS dependency still needs it.

How to verify

  • npm run build, npm run lint, npm run typecheck:tests, npx vitest run, npm run l10n:check.
  • npm run package, npm run verify:vsix -- <vsix>, npm run prove:vsix -- <vsix>, L3 (npm run test:vsix -- <vsix>).
  • Bundle scan: no Promise.resolve().then(() => X()) left where X is an __esmMin initialiser (G5-I01), and only one copy of vscode-azext-azureauth in the bundle.
  • Manual, on the installed VSIX:
    • first sign-in; Azure vCore, RU and VM discovery; expanding all three (one listing, not three);
    • the tenant and subscription filter wizard; the subscription filter shared with Azure Resources;
    • new connection and update credentials through Azure (PromptTenantSteps);
    • sign-out, sign-in, account switch, a second tenant needing sign-in, MFA step-up;
    • a sovereign cloud switch;
    • the Azure Resources view's DocumentDB nodes (dashboard, Collection View, Document View);
    • /connect/azure deep links (vCore and RU; with and without tenantId; hidden subscription, tenant or provider; cancelling the progress notification). The trace log ([DeepLink] lines) shows each step's timing.

References

Activity

  1. added
    dependencies
    on-hold
    on Oct 6, 2026
  2. removed
    on-hold
    on Nov 5, 2026
  3. changed the title [-]Upgrade @microsoft/vscode-azext-azureauth to its ES module build and remove the arm-resources-subscriptions alias (after #880)[/-] [+]Upgrade @microsoft/vscode-azext-azureauth to v6: ES module build, cached and faster subscription loading[/+] on Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

dependencies

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions