Skip to content

[codex] Add Anthropic early-close regression coverage#2080

Open
chocoHacks33 wants to merge 3 commits into
pydantic:mainfrom
chocoHacks33:codex/anthropic-stream-close-regression
Open

[codex] Add Anthropic early-close regression coverage#2080
chocoHacks33 wants to merge 3 commits into
pydantic:mainfrom
chocoHacks33:codex/anthropic-stream-close-regression

Conversation

@chocoHacks33

@chocoHacks33 chocoHacks33 commented Jul 15, 2026

Copy link
Copy Markdown

Summary

  • add a regression test for closing an Anthropic streaming response before consuming it to exhaustion
  • force stream finalizer cleanup inside the test so the no-error assertion covers the reported cleanup path

Testing

  • python -m uv run pytest tests/otel_integrations/test_anthropic.py -q

Closes #1607.

Review in cubic

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 93039ca1-5d6d-45c1-86d1-b74b555f3953

📥 Commits

Reviewing files that changed from the base of the PR and between b282866 and 1f4be1d.

📒 Files selected for processing (1)
  • tests/otel_integrations/test_anthropic.py
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • pydantic/logfire (manual)
  • pydantic/pydantic-ai (manual)
  • pydantic/platform (auto-detected)
  • pydantic/pydantic (auto-detected)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/otel_integrations/test_anthropic.py

📝 Walkthrough

Walkthrough

Adds an Anthropic integration test for partially consumed synchronous message streams. The test reads the first text delta, deletes the streaming response, triggers garbage collection, and verifies that exactly one chunk was observed without an OpenTelemetry “Failed to detach context” error. It also verifies the expected exported spans. Imports for garbage collection and log capture are added.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: adding regression coverage for Anthropic early-close cleanup behavior.
Description check ✅ Passed The description is directly related to the test-only change and the cleanup regression it targets.
Linked Issues check ✅ Passed The new test covers early stream close cleanup and checks for the reported detach-context error path from #1607.
Out of Scope Changes check ✅ Passed The PR appears limited to targeted test coverage in the Anthropic test file with no unrelated changes.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 1 file

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

Failed to detach context/Token has already been used once errors with instrument_anthropic()

2 participants