Skip to content

Speed up Foundry project discovery in init#7332

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/fix-slow-search-foundry-projects
Draft

Speed up Foundry project discovery in init#7332
Copilot wants to merge 4 commits intomainfrom
copilot/fix-slow-search-foundry-projects

Conversation

Copy link
Contributor

Copilot AI commented Mar 25, 2026

When azd init reused existing Foundry resources, project discovery could take minutes in subscriptions with many projects because it scanned Cognitive Services accounts and then listed projects per account sequentially. The --project-id path also paid that full scan cost before validating the provided resource.

  • Replace N+1 project discovery with a filtered subscription query

    • Swapped the account-walk + per-account ProjectsClient.List flow for a single ARM subscription resource listing filtered to:
      • Microsoft.CognitiveServices/accounts/projects
    • Mapped the returned resources directly into FoundryProjectInfo
  • Short-circuit --project-id

    • Parse the provided ARM resource ID up front
    • Validate that it belongs to the selected subscription
    • Fetch the project directly with ProjectsClient.Get(...)
    • Avoid any subscription-wide enumeration when the caller already knows the target project
  • Keep selection/configuration flow unchanged

    • Interactive selection still works from the discovered project list
    • Environment setup continues to use the selected project metadata and resource ID as before
  • Add focused helper coverage

    • Resource-to-FoundryProjectInfo mapping
    • Project metadata refresh from direct GET responses
    • Subscription mismatch handling for --project-id

Example of the new discovery shape:

pager := resourcesClient.NewListPager(&armresources.ClientListOptions{
    Filter: new("resourceType eq 'Microsoft.CognitiveServices/accounts/projects'"),
})

for pager.More() {
    page, err := pager.NextPage(ctx)
    // map page.Value -> FoundryProjectInfo
}
Original prompt

This section details on the original issue you should resolve

<issue_title>Searching for Foundry projects in your subscription is slow when there are a lot of projects</issue_title>
<issue_description>When using init, and using existing resources, the Searching for Foundry projects in your subscription can be slow (minutes) when there are a lot (tested on a sub with ~400 projects).

</issue_description>

Comments on the Issue (you are @copilot in this section)

@JeffreyCA The bottleneck is in `listFoundryProjects()` ([init_foundry_resources_helpers.go:107-197](https://github.com/Azure/azure-dev/blob/main/cli/azd/extensions/azure.ai.agents/internal/cmd/init_foundry_resources_helpers.go#L107-L197)). It uses a sequential N+1 pattern:
  1. One call to list all CognitiveServices accounts in the subscription
  2. One call per matching account to list its projects — all sequential

With ~400 projects spread across many accounts, this results in hundreds of serial HTTP round-trips.

Opportunity 1: Use ARM subscription resource listing with server-side filter

Replace the entire account-scan → per-account-project-list pattern with a single ListSubscriptionResources call filtered by resourceType eq 'Microsoft.CognitiveServices/accounts/projects'. This collapses hundreds of sequential API calls into one. Core azd already has this infrastructure in pkg/azapi/resource_service.go and pkg/prompt/prompt_service.go.

Opportunity 2: Short-circuit when --project-id is provided

When projectResourceId is passed via flag (line 875), the code still performs the full subscription scan (line 887) and then linear-searches the results. Instead, extractProjectDetails() can parse the resource ID and ProjectsClient.Get() can validate it directly — turning a minutes-long scan into a single ARM GET.


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Copilot AI and others added 3 commits March 25, 2026 23:36
Co-authored-by: JeffreyCA <9157833+JeffreyCA@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Azure/azure-dev/sessions/5b604433-2cae-4457-965d-b0b5ac1be4fe
Co-authored-by: JeffreyCA <9157833+JeffreyCA@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Azure/azure-dev/sessions/5b604433-2cae-4457-965d-b0b5ac1be4fe
Copilot AI changed the title [WIP] Fix slow searching for Foundry projects in subscription Speed up Foundry project discovery in init Mar 25, 2026
Copilot AI requested a review from JeffreyCA March 25, 2026 23:41
@JeffreyCA JeffreyCA added the ext-agents azure.ai.agents extension label Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ext-agents azure.ai.agents extension

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Searching for Foundry projects in your subscription is slow when there are a lot of projects

2 participants