Skip to content

[azsdk] Enforce cancellation token usage#14445

Merged
benbp merged 12 commits intoAzure:mainfrom
benbp:benbp/analyzer-cancel-token
Mar 17, 2026
Merged

[azsdk] Enforce cancellation token usage#14445
benbp merged 12 commits intoAzure:mainfrom
benbp:benbp/analyzer-cancel-token

Conversation

@benbp
Copy link
Member

@benbp benbp commented Mar 10, 2026

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

@benbp benbp self-assigned this Mar 10, 2026
@benbp benbp added the Central-EngSys This issue is owned by the Engineering System team. label Mar 10, 2026
@benbp benbp requested a review from a team as a code owner March 10, 2026 21:53
@benbp benbp added the azsdk-cli Issues related to Azure/azure-sdk-tools::tools/azsdk-cli label Mar 10, 2026
Copilot AI review requested due to automatic review settings March 10, 2026 21:53
@benbp benbp moved this from 🤔 Triage to 🔬 Dev in PR in Azure SDK EngSys 🖥️🖱️⌨️👨‍💻🤯 Mar 10, 2026
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 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 CancellationToken in async method signatures and document its conventions.
  • Thread CancellationToken parameters 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.

@benbp benbp force-pushed the benbp/analyzer-cancel-token branch 2 times, most recently from c884be8 to 2b43c7c Compare March 16, 2026 22:43
@benbp benbp requested review from danieljurek and raych1 March 17, 2026 00:29
benbp and others added 12 commits March 17, 2026 14:17
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>
@benbp benbp force-pushed the benbp/analyzer-cancel-token branch from 2b43c7c to 7f895ab Compare March 17, 2026 18:20
@benbp benbp merged commit 715ff09 into Azure:main Mar 17, 2026
13 checks passed
@benbp benbp deleted the benbp/analyzer-cancel-token branch March 17, 2026 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

azsdk-cli Issues related to Azure/azure-sdk-tools::tools/azsdk-cli Central-EngSys This issue is owned by the Engineering System team.

Development

Successfully merging this pull request may close these issues.

Codeowners Cleanup: CancellationToken

4 participants