Skip to content

Async context entry failures leave earlier connection contexts unclosed #97

Open

Description

@akshitkhokhani

MCPAdapt.__aenter__ acquires connections into an AsyncExitStack before adapting the tools. If a later connection or tool adaptation raises, context entry fails and Python does not call __aexit__, leaving the already-entered connection contexts without their normal cleanup.

I reproduced this locally using two synthetic MCP stdio servers followed by a failing setup step. Both failure cases miss the expected reverse-order exits on the current main revision (538cd856); a successful entry/exit control passes. A focused local fix keeps the stack in an async with block during setup and transfers it with pop_all() only after adaptation succeeds. All three regressions then pass, and the full suite passed with 48 tests and one optional audio skip. A separate AI reviewer checked the patch and additional cleanup controls.

This overlaps the __aenter__ code touched by #76, but concerns cleanup when entry fails rather than adding fault-tolerance behavior.

Before opening a PR, I checked the documented 95% coverage requirement. An isolated run using the Makefile's default collection scope reports 86% overall; production-only coverage is 77%, versus 76% on the unchanged baseline. That coverage run had 47 passes and two skips (optional audio and an existing HTTP fixture startup timeout). The changed entry path is covered. Would you prefer a focused cleanup PR with those reported coverage results documented, or separate coverage work first?

Prepared with AI assistance. Testing used local synthetic processes and temporary data with external networking disabled.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions