Skip to content

[azure-ai-ml] Cache tenant id in JobOperations to speed up jobs.list() iteration - #48760

Open
saanikaguptamicrosoft wants to merge 3 commits into
Azure:mainfrom
saanikaguptamicrosoft:saanika/fix-issue-48415-cache-tid
Open

[azure-ai-ml] Cache tenant id in JobOperations to speed up jobs.list() iteration#48760
saanikaguptamicrosoft wants to merge 3 commits into
Azure:mainfrom
saanikaguptamicrosoft:saanika/fix-issue-48415-cache-tid

Conversation

@saanikaguptamicrosoft

@saanikaguptamicrosoft saanikaguptamicrosoft commented Aug 26, 2026

Copy link
Copy Markdown
Member

Fixes #48415

_append_tid_to_studio_url was called for every job returned by MLClient.jobs.list() and decoded the tenant id from a fresh access token each time. TokenCredential.get_token is documented as non-caching, so AzureCliCredential shelled out to az account get-access-token per iteration. The issue reports ~77s for 100 jobs vs ~13s without this call.

The tenant id is stable for the lifetime of a JobOperations instance (self._credential is set once at construction). This change decodes it at most once per instance and reuses the cached value for subsequent jobs. No public API change, no wire change.

samples validation - Azure/azureml-examples#4114 (refer against main Azure/azureml-examples#4113)

Description

Please add an informative description that covers that changes made by the pull request and link all relevant issues.

If an SDK is being regenerated based on a new API spec, a link to the pull request containing these API spec changes should be included above.

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

…) iteration

Fixes Azure#48415. _append_tid_to_studio_url called credential.get_token() on every job during list() iteration to decode the tenant id from a JWT. TokenCredential.get_token is not cached, so AzureCliCredential shelled out to 'az account get-access-token' per job (~77s for 100 jobs in the issue vs ~13s without). The tenant id is stable for a JobOperations instance, so cache it on self._tid_cache after the first decode and reuse for subsequent jobs. No public API or wire change.
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
9 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

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

Caches the tenant ID in JobOperations to avoid repeated token acquisition during job-list iteration.

Changes:

  • Reuses the decoded tenant ID per JobOperations instance.
  • Documents the performance fix in the changelog.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
CHANGELOG.md Records the job-list performance fix.
_job_operations.py Adds and applies the tenant ID cache.

Comment thread sdk/ml/azure-ai-ml/azure/ai/ml/operations/_job_operations.py
Addresses Copilot review feedback on PR: asserts _append_tid_to_studio_url populates both jobs' Studio URLs with the tenant id while credential.get_token() is called exactly once. Existing tests only covered the no-services no-op path.
Copilot AI review requested due to automatic review settings August 26, 2026 10:38

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

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

Collapses the multi-line function signature and AccessToken constructor to single lines at the repo's 120-char line length, matching what black in the CI pipeline expects.
Copilot AI review requested due to automatic review settings August 26, 2026 11:53

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Very slow iteration over jobs with MLClient.jobs.list()

2 participants