[azsdk] Enforce cancellation token usage#14445
Merged
benbp merged 12 commits intoAzure:mainfrom Mar 17, 2026
Merged
Conversation
danieljurek
reviewed
Mar 10, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces (and wires into the build) a new Roslyn analyzer (AZSDK001) intended to enforce CancellationToken parameters on async methods, and updates the azsdk-cli codebase to plumb cancellation tokens through tool, service, helper, and test layers to support responsive cancellation (e.g., Ctrl+C).
Changes:
- Add AZSDK001 analyzer to require
CancellationTokenin async method signatures and document its conventions. - Thread
CancellationTokenparameters through many CLI tools/services/helpers (DevOps, GitHub, APIView, telemetry, upgrade, etc.). - Update unit tests and mocks to match the new signatures and pass tokens through.
Reviewed changes
Copilot reviewed 77 out of 77 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Tools/TypeSpec/DelegateAPIViewFeedbackTool.cs | Pass ct through APIView feedback service and GitHub issue creation calls. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Tools/ReleasePlan/SpecWorkFlowTool.cs | Add ct to workflow tools and propagate to DevOps/GitHub service calls. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Tools/ReleasePlan/PackageReleaseStatusTool.cs | Add ct to release status update flow and service calls. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Tools/Pipeline/PipelineTool.cs | Add ct to pipeline status query. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Tools/Pipeline/PipelineTestsTool.cs | Add ct support to artifact download/query path. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Tools/Pipeline/PipelineAnalysisTool.cs | Pass ct through HTTP calls and log analysis helpers. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Tools/Package/VersionUpdateTool.cs | Pass ct to config helper when determining update behavior. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Tools/Package/SdkReleaseTool.cs | Add ct to release flow and DevOps pipeline calls. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Tools/Package/MetadataUpdateTool.cs | Pass ct to config helper for metadata updates. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Tools/Package/ChangelogContentUpdateTool.cs | Pass ct to config helper for changelog updates. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Tools/GitHub/PullRequestTools.cs | Add ct to GitHub tool operations and underlying service calls. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Tools/Example/ExampleTool.cs | Pass ct through sample service calls. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Tools/EngSys/TestAnalysisTool.cs | Add ct plumbing for TRX parsing helpers. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Tools/EngSys/LogAnalysisTool.cs | Pass ct into log analysis helper routines. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Tools/Core/UpgradeTool.cs | Pass ct into shutdown coordination. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Tools/Core/MCPToolBase.cs | Pass cancellationToken into telemetry activity creation. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Tools/Core/InstrumentedTool.cs | Pass ct into telemetry activity creation for MCP tool invocations. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Tools/Config/GitHubLabelsTool.cs | Add ct to label operations and DevOps/GitHub calls. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Tools/Config/CodeownersTool.cs | Add ct to CODEOWNERS operations and validation helper flows. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Tools/APIView/APIViewReviewTool.cs | Add ct to APIView comment/content retrieval. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Telemetry/TelemetryService.cs | Add ct-aware tag initialization and updated activity APIs. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Telemetry/InformationProvider/WindowsMachineInformationProvider.cs | Add ct parameter to device ID creation API. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Telemetry/InformationProvider/UnixMachineInformationProvider.cs | Add ct propagation to disk read/write helpers. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Telemetry/InformationProvider/MachineInformationProviderBase.cs | Add ct to MAC hash API. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Telemetry/InformationProvider/IMachineInformationProvider.cs | Update interface to include ct parameters. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Telemetry/InformationProvider/DefaultMachineInformationProvider.cs | Update default provider signatures for ct. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Services/Upgrade/UpgradeShutdownService.cs | Add ct to shutdown request API. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Services/Languages/LanguageService.cs | Add ct to DiffAsync and pass ct to config helper. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Services/Languages/JavaLanguageService.cs | Update DiffAsync override signature to include ct. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Services/Languages/DotNetLanguageService.Checks.cs | Add ct to .NET checks and process invocation. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Services/GitHubService.cs | Add ct parameters to GitHub service interface and methods. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Services/APIViewFeedbackService.cs | Add ct plumbing across APIView metadata/comment processing and GitHub lookups. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Services/APIView/APIViewService.cs | Add ct to APIView service APIs and HTTP calls. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Services/APIView/APIViewHttpService.cs | Add ct to HTTP calls and cache lock waits. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Services/APIView/APIViewAuthenticationService.cs | Add ct to auth token acquisition/configuration. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Program.cs | Add ct to Run and pass through to command runner. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Helpers/UserHelper.cs | Add ct to Graph SDK query. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Helpers/TypeSpecHelper.cs | Add ct to TypeSpec project parsing and file reads/process execution. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Helpers/TestHelper.cs | Add ct to file IO for TRX parsing. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Helpers/SpecGenSdkConfigHelper.cs | Add ct to config file reads and value lookups. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Helpers/LogAnalysisHelper.cs | Add ct to streaming log reads. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Helpers/ICodeownersManagementHelper.cs | Add ct to CODEOWNERS view helper APIs. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Helpers/GitHelper.cs | Pass ct to GitHub parent repo URL lookup. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Helpers/ConversationLogger.cs | Add ct to file IO for conversation logging. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Helpers/CommonLanguageHelpers.cs | Remove unused System.Threading using after refactor. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Helpers/CodeownersValidatorHelper.cs | Add ct to org membership and permission checks. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Helpers/CodeownersManagementHelper.cs | Add ct to DevOps queries and hydration flows. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Helpers/CodeownersGenerateHelper.cs | Add ct to DevOps queries and CODEOWNERS file IO. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/CopilotAgents/CopilotSessionWrapper.cs | Suppress analyzer for fixed IAsyncDisposable.DisposeAsync signature. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli/Commands/CommandRunner.cs | Add ct parameter to main command runner entrypoint. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli.Tests/Tools/TypeSpec/DelegateAPIViewFeedbackToolTests.cs | Update mocks/verifications for new ct-accepting APIs. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli.Tests/Tools/TypeSpec/CustomizedCodeUpdateToolTests.cs | Update test language service override signature for DiffAsync(ct). |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli.Tests/Tools/ReleasePlan/SpecWorkFlowToolTests.cs | Update GitHub service mocks for ct parameters. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli.Tests/Tools/ReleasePlan/ReleasePlanToolTests.cs | Update test mocks and invocations to include ct. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli.Tests/Tools/ReleasePlan/ReleasePlanManualTests.cs | Update manual tests to pass CancellationToken.None. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli.Tests/Tools/ReleasePlan/PackageReleaseStatusToolTests.cs | Update tests/mocks for ct parameters on DevOps calls. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli.Tests/Tools/Package/VersionUpdateToolTests.cs | Update config helper setups/verifications for ct. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli.Tests/Tools/Package/SdkBuildToolTests.cs | Update config helper setups/verifications for ct. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli.Tests/Tools/Package/MetadataUpdateToolTests.cs | Update config helper setups/verifications for ct. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli.Tests/Tools/Package/ChangelogContentUpdateToolTests.cs | Update config helper setups/verifications for ct. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli.Tests/Tools/Example/ExampleToolTests.cs | Update DevOps service setups/verifications for ct. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli.Tests/Tools/Config/CodeownersToolsTests.cs | Update GitHub service setups/verifications for ct. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli.Tests/Tools/APIView/ApiViewReviewToolTests.cs | Update APIView service setups and invocations for ct. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli.Tests/Services/DevOpsServiceTests.cs | Update DevOps service calls to pass ct. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli.Tests/Services/APIViewFeedbackServiceTests.cs | Update APIView/GitHub service mocks and calls for ct. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli.Tests/Mocks/Services/MockGitHubService.cs | Update mock interface implementation for ct parameters. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli.Tests/Mocks/Services/MockDevOpsService.cs | Update mock interface implementation for ct parameters. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli.Tests/Helpers/TypeSpecHelperTests.cs | Update helper callsites for ct. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli.Tests/Helpers/SpecGenSdkConfigHelperTests.cs | Update helper callsites for ct. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli.Tests/Helpers/LogAnalysisHelperTests.cs | Update helper callsites for ct. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli.Tests/Helpers/GitHelperTests.cs | Update GitHub service mock setups for ct. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli.Tests/Azure.Sdk.Tools.Cli.Tests.csproj | Reference analyzer project and Roslyn package for test compilation. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli.Analyzer/README.md | Document AZSDK001 conventions and exclusions. |
| tools/azsdk-cli/Azure.Sdk.Tools.Cli.Analyzer/EnforceAsyncCancellationToken.cs | Add AZSDK001 analyzer implementation. |
tools/azsdk-cli/Azure.Sdk.Tools.Cli.Analyzer/EnforceAsyncCancellationToken.cs
Outdated
Show resolved
Hide resolved
tools/azsdk-cli/Azure.Sdk.Tools.Cli.Analyzer/EnforceAsyncCancellationToken.cs
Outdated
Show resolved
Hide resolved
danieljurek
reviewed
Mar 11, 2026
tools/azsdk-cli/Azure.Sdk.Tools.Cli.Analyzer/EnforceAsyncCancellationToken.cs
Show resolved
Hide resolved
raych1
reviewed
Mar 12, 2026
c884be8 to
2b43c7c
Compare
Add CancellationToken as the last parameter to all public and internal async methods in the Helpers/ directory that were missing it: - ConversationLogger: 4 methods (required ct, no optional params) - CodeownersManagementHelper + interface: 4 methods (3 required, 1 with default) - CodeownersValidatorHelper + interface: 1 method (with default, has optional params) - UserHelper + interface: 1 method (required ct) - TestHelper + interface: 3 methods (1 with default, 2 required) - SpecGenSdkConfigHelper + interface: 2 methods (required ct) - LogAnalysisHelper + interface: 2 methods (1 required, 1 with default) - TypeSpecHelper + interface: 1 method (required ct) Convention: required CancellationToken ct when no other optional params exist; CancellationToken ct = default when other optional params exist. Also adds using System.Threading where missing, propagates ct to inner calls, and fixes pre-existing caller issues in CodeownersValidatorHelper and GitHelper where IGitHubService methods now require ct. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add CancellationToken parameter to 13 private async methods across 7 files in the Tools directory that were missing it. Thread ct to internal async calls (service methods, HTTP clients) where possible. Files changed: - ReleasePlan/SpecWorkFlowTool.cs - ReleasePlan/ReleasePlanTool.cs - Config/CodeownersTool.cs - Config/GitHubLabelsTool.cs - Pipeline/PipelineAnalysisTool.cs - Pipeline/PipelineTestsTool.cs - Package/SdkReleaseTool.cs Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2b43c7c to
7f895ab
Compare
raych1
approved these changes
Mar 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds an analyzer to enforce cancellation tokens in async method signatures, over having to do it in PR comments. Additionally it looks like there was a ton of async usage without cancellation passed through, so this is a big update to plumb that through everywhere. The main idea is that we should always be cancellable as a CLI or server app, so we don't hang for the user on ctrl-c.
Resolves #14435