Skip to content

Conversation

@bokelley
Copy link
Contributor

@bokelley bokelley commented Nov 7, 2025

Summary

Extract duplicate cleanup logic and improve error handling during MCP adapter shutdown. Properly handle anyio task group errors without masking original connection failures. Errors like "Attempted to exit cancel scope in a different task" are now logged at debug level rather than raised.

Refactor async resource management to follow DRY principles and update TaskResult to Pydantic v2 ConfigDict pattern, eliminating deprecation warnings.

What Changed

  • Extracted _cleanup_failed_connection() method to eliminate code duplication
  • Enhanced error handling to distinguish between expected and unexpected cleanup errors
  • Updated Pydantic config from deprecated v1 style to v2 ConfigDict
  • Added comprehensive test coverage for connection failure and cleanup scenarios

Tests

All 105 tests pass with no warnings. New tests cover connection failure cleanup, async context manager usage, and cancellation scenarios.

🤖 Generated with Claude Code

bokelley and others added 5 commits November 7, 2025 10:38
Extract duplicate cleanup logic into _cleanup_failed_connection() method to follow DRY principle. Properly handle anyio task group errors without masking original connection failures. Errors like "Attempted to exit cancel scope in a different task" are now logged at debug level rather than raised, allowing the actual connection error to propagate correctly.

Also update TaskResult config to use Pydantic v2 ConfigDict pattern, eliminating deprecation warnings.

Add comprehensive test coverage for connection failure scenarios and async context manager usage.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Demonstrate the recommended async context manager pattern for proper connection cleanup. Update Quick Start example to use context manager, ensuring new users adopt best practices from the start.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Address code review feedback:
- Update examples/ to use async context managers (critical fix)
- Add 'Why use context managers?' explanation with clear benefits
- Add complete imports to all code examples for copy-paste usability
- Expand manual cleanup section with use cases and guidance
- Improve comments to clarify what gets cleaned up

All examples now consistently demonstrate the recommended pattern for proper resource cleanup, making it easier for new users to adopt best practices.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Pull in batch preview API changes from #18 before merging cleanup improvements.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Split long warning message across multiple lines to comply with 100 character line limit.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@bokelley bokelley merged commit 40d83f3 into main Nov 7, 2025
6 checks passed
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