Skip to content

fix(anthropic): Patch Stream.close() and MessageStream.close() to finish spans#5674

Open
alexander-alderman-webb wants to merge 15 commits intomasterfrom
webb/anthropic/sync-iterators
Open

fix(anthropic): Patch Stream.close() and MessageStream.close() to finish spans#5674
alexander-alderman-webb wants to merge 15 commits intomasterfrom
webb/anthropic/sync-iterators

Conversation

@alexander-alderman-webb
Copy link
Contributor

@alexander-alderman-webb alexander-alderman-webb commented Mar 16, 2026

Description

Close AI Client Spans when the Anthropic SDK's HTTP connection is closed and not merely when the streamed response iterator is consumed or the GC collects the private _iterator instance variable. Patch the close() method that also closes the connection.

Issues

Reminders

@alexander-alderman-webb alexander-alderman-webb changed the title fix(anthropic): Respect iterator protocol in synchronous streamed res… fix(anthropic): Respect iterator protocol in synchronous streamed responses Mar 16, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


Bug Fixes 🐛

  • (anthropic) Patch Stream.close() and MessageStream.close() to finish spans by alexander-alderman-webb in #5674

Other

  • Update CHANGELOG.md by sentrivana in #5685

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

Codecov Results 📊

6 passed | Total: 6 | Pass Rate: 100% | Execution Time: 1.20s

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

❌ Patch coverage is 0.00%. Project has 15976 uncovered lines.
❌ Project coverage is 21.76%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
anthropic.py 6.02% ⚠️ 390 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    21.80%    21.76%    -0.04%
==========================================
  Files          189       189         —
  Lines        20385     20419       +34
  Branches      7008      7018       +10
==========================================
+ Hits          4443      4443         —
- Misses       15942     15976       +34
- Partials       379       379         —

Generated by Codecov Action

@alexander-alderman-webb alexander-alderman-webb marked this pull request as ready for review March 17, 2026 12:37
@alexander-alderman-webb alexander-alderman-webb requested a review from a team as a code owner March 17, 2026 12:37
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

@alexander-alderman-webb alexander-alderman-webb marked this pull request as draft March 17, 2026 13:06
@alexander-alderman-webb alexander-alderman-webb changed the title fix(anthropic): Respect iterator protocol in synchronous streamed responses fix(anthropic): Patch Stream.close() and MessageStream.close() to finish spans Mar 17, 2026
@alexander-alderman-webb alexander-alderman-webb marked this pull request as ready for review March 17, 2026 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant