Skip to content

Filter unselected tenants before hitting maximumTenants limit#1406

Merged
alexweininger merged 3 commits intomainfrom
fix/filter-unselected-tenants
Mar 20, 2026
Merged

Filter unselected tenants before hitting maximumTenants limit#1406
alexweininger merged 3 commits intomainfrom
fix/filter-unselected-tenants

Conversation

@alexweininger
Copy link
Member

Problem

Users with many tenants (e.g., 33) see missing subscriptions because the maximumTenants limit (default 10) silently drops tenants — even when only a few are selected in the Accounts & Tenants view.

Root cause: The Accounts & Tenants view stores unselected tenants in globalState (unselectedTenants), but the auth package's getTenantFilters() only reads from selectedSubscriptions config. These are two different filtering mechanisms, and the tenant view checkbox state was never communicated to the subscription loading path. So all 33 tenants were returned, 10 were processed (many failing auth), and the user's actual tenant was silently skipped.

Fix

Creates a ResourceGroupsSubscriptionProvider subclass that overrides getTenantsForAccount() to additionally filter out tenants unchecked in the Accounts & Tenants view. This ensures only selected tenants consume slots in the maximumTenants budget.

Before: User with 33 tenants, 1 selected → all 33 returned → limit of 10 hit → selected tenant likely skipped → 0 subscriptions shown.

After: User with 33 tenants, 1 selected → 1 tenant returned → well under limit → subscriptions loaded correctly.

Fixes #1387

The Accounts & Tenants view checkbox state (stored as 'unselectedTenants'
in globalState) was not being applied during subscription loading. The auth
package's getTenantFilters() only reads from selectedSubscriptions config,
so unchecked tenants still counted toward the maximumTenants limit (default
10), silently preventing selected tenants from being processed.

This creates a ResourceGroupsSubscriptionProvider subclass that overrides
getTenantsForAccount() to additionally filter out tenants unchecked in the
Accounts & Tenants view, ensuring only selected tenants consume slots in
the maximumTenants budget.

Fixes #1387

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 19, 2026 18:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses missing subscriptions for users with many tenants by filtering out tenants unchecked in the Accounts & Tenants view so they don’t consume the maximumTenants budget during subscription loading.

Changes:

  • Added a VSCodeAzureSubscriptionProvider subclass to apply additional tenant filtering based on Accounts & Tenants view state.
  • Updated provider factory/creation to instantiate and cache the new subclass.
  • Added logging when tenant filtering reduces the tenant set.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Addresses PR feedback by extracting isTenantFilteredOut, getUnselectedTenants,
setUnselectedTenants, and getKeyForTenant from the tree-layer registerTenantTree
module into src/utils/tenantSelection.ts. This eliminates the coupling between
the service-layer subscription provider and the tree/view module.

Also keeps the factory return type as the base VSCodeAzureSubscriptionProvider
to avoid leaking the concrete subclass type to consumers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aligns tenant filtering in subscription discovery with the Accounts & Tenants checkbox state by centralizing tenant-selection persistence and applying that selection when enumerating tenants for an account, preventing unselected tenants from consuming the maximumTenants budget.

Changes:

  • Added src/utils/tenantSelection.ts to centralize unselectedTenants globalState logic (getKeyForTenant, getUnselectedTenants, setUnselectedTenants, isTenantFilteredOut).
  • Updated the tenant tree and subscription-selection flows to import tenant-selection helpers from the new utility module.
  • Introduced a ResourceGroupsSubscriptionProvider subclass to filter out unchecked tenants during getTenantsForAccount() when filtering is enabled.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/utils/tenantSelection.ts New shared utility for persisting/reading tenant checkbox selection state and evaluating whether a tenant is filtered out.
src/tree/tenants/registerTenantTree.ts Switches tenant checkbox persistence to use the new tenantSelection utility (removes duplicated local helpers).
src/tree/tenants/TenantResourceTreeDataProvider.ts Updates import to use the new shared isTenantFilteredOut.
src/services/VSCodeAzureSubscriptionProvider.ts Wraps the azureauth subscription provider to exclude unchecked tenants during tenant enumeration when filtering is enabled.
src/commands/accounts/selectSubscriptions.ts Updates import to use the new shared isTenantFilteredOut.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

bwateratmsft
bwateratmsft previously approved these changes Mar 20, 2026
@alexweininger
Copy link
Member Author

this is a performance bug too!

@alexweininger alexweininger marked this pull request as ready for review March 20, 2026 14:56
@alexweininger alexweininger requested a review from a team as a code owner March 20, 2026 14:56
@alexweininger alexweininger merged commit 9add1c2 into main Mar 20, 2026
3 checks passed
@alexweininger alexweininger deleted the fix/filter-unselected-tenants branch March 20, 2026 14:59
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.

Unable to view my Tenant and all the subscription

3 participants