Skip to content

fix: add cancellation token support#34

Merged
StevanFreeborn merged 8 commits intomainfrom
stevanfreeborn/fix/add-cancellation-token-support
May 19, 2025
Merged

fix: add cancellation token support#34
StevanFreeborn merged 8 commits intomainfrom
stevanfreeborn/fix/add-cancellation-token-support

Conversation

@StevanFreeborn
Copy link
Owner

closes #33

  • fix: copilot first attempt
  • fix: cleanup copilot mistakes with passing cancellation token to methods that don't accept them
  • chore: upgrade test project to .NET 9
  • chore: upgrade dependencies

@StevanFreeborn StevanFreeborn requested a review from Copilot May 19, 2025 20:20
@StevanFreeborn StevanFreeborn self-assigned this May 19, 2025
@StevanFreeborn StevanFreeborn added the bug Something isn't working label May 19, 2025
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 adds support for cancellation tokens across all API methods, upgrades both client and test projects to .NET 9, and bumps related dependencies.

  • Extend interface and implementation to pass CancellationToken through all requests
  • Upgrade target frameworks and package references in test and library projects
  • Clean up Copilot-generated method signatures and overloads

Reviewed Changes

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

File Description
tests/AnthropicClient.Tests/AnthropicClient.Tests.csproj Bumped test project to net9.0 and updated package versions
src/AnthropicClient/IAnthropicApiClient.cs Added optional CancellationToken to all API method signatures and XML docs
src/AnthropicClient/AnthropicClient.csproj Updated Microsoft.Bcl.AsyncInterfaces and System.Text.Json package versions
src/AnthropicClient/AnthropicApiClient.cs Propagated cancellation tokens into SendRequestAsync and method overloads
Comments suppressed due to low confidence (4)

src/AnthropicClient/AnthropicApiClient.cs:305

  • The ReadResultsAsync() call does not receive the outer cancellationToken, so cancellation won’t propagate into the result stream. Pass the token: ReadResultsAsync(cancellationToken).
return AnthropicResult<IAsyncEnumerable<MessageBatchResultItem>>.Success(ReadResultsAsync(), anthropicHeaders);

src/AnthropicClient/IAnthropicApiClient.cs:99

  • The summary for ListAllModelsAsync is identical to ListModelsAsync. Update it to something like Lists all models asynchronously to clarify its behavior.
/// <summary>Lists the models asynchronously</summary>

tests/AnthropicClient.Tests/AnthropicClient.Tests.csproj:1

  • [nitpick] New cancellation support should be covered by unit tests. Consider adding tests that assert cancellation requests properly abort ongoing operations for at least one API method.
<Project Sdk="Microsoft.NET.Sdk">

src/AnthropicClient/AnthropicApiClient.cs:306

  • [nitpick] The inner generator parameter is named ct, but other methods use cancellationToken. Rename ct to cancellationToken for consistency and readability.
async IAsyncEnumerable<MessageBatchResultItem> ReadResultsAsync([EnumeratorCancellation] CancellationToken ct = default)

@codecov
Copy link

codecov bot commented May 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.85%. Comparing base (fc2932f) to head (16ee80a).
Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #34      +/-   ##
==========================================
- Coverage   98.98%   98.85%   -0.14%     
==========================================
  Files          81       81              
  Lines        1478     1479       +1     
  Branches      126      127       +1     
==========================================
- Hits         1463     1462       -1     
  Misses          5        5              
- Partials       10       12       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@StevanFreeborn StevanFreeborn requested a review from Copilot May 19, 2025 20:28
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 adds CancellationToken support across the API surface and upgrades to .NET 9, including test and CI dependencies.

  • Introduces optional CancellationToken parameters to all client methods
  • Updates project SDKs and package references to .NET 9
  • Updates CI workflows and editor settings for .NET 9 compatibility

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/AnthropicClient.Tests/AnthropicClient.Tests.csproj Upgraded test project to net9.0 and bumped test dependencies
src/AnthropicClient/IAnthropicApiClient.cs Added CancellationToken overloads and updated XML docs
src/AnthropicClient/AnthropicClient.csproj Bumped library dependencies to versions compatible with .NET 9
src/AnthropicClient/AnthropicApiClient.cs Wired CancellationToken through all HTTP calls
.vscode/settings.json Added new vocabulary for .NET 9 tooling
.github/workflows/pull_request.yml Switched CI to use .NET 9 SDK
.github/workflows/publish.yml Switched publish pipeline to use .NET 9 SDK

StevanFreeborn and others added 2 commits May 19, 2025 15:30
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@StevanFreeborn StevanFreeborn merged commit 69484ff into main May 19, 2025
3 of 4 checks passed
@StevanFreeborn StevanFreeborn deleted the stevanfreeborn/fix/add-cancellation-token-support branch May 19, 2025 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Provide ability to pass cancellation token

1 participant