Skip to content

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

Merged
alexander-alderman-webb merged 16 commits intomasterfrom
webb/anthropic/sync-iterators
Mar 18, 2026
Merged

fix(anthropic): Patch Stream.close() and MessageStream.close() to finish spans#5674
alexander-alderman-webb merged 16 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

Internal Changes 🔧

  • Add client report tests for span streaming by sentrivana in #5677

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 📊

13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 7.01s

All tests are passing successfully.

❌ Patch coverage is 0.00%. Project has 14331 uncovered lines.

Files with missing lines (1)
File Patch % Lines
anthropic.py 5.98% ⚠️ 393 Missing

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
Copy link
Contributor

@sentrivana sentrivana left a comment

Choose a reason for hiding this comment

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

lgtm, see one suggestion

@alexander-alderman-webb alexander-alderman-webb merged commit 8203912 into master Mar 18, 2026
158 checks passed
@alexander-alderman-webb alexander-alderman-webb deleted the webb/anthropic/sync-iterators branch March 18, 2026 13:20
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.

2 participants