Skip to content

fix(agent): keep MCP connection failures from cancelling gateway - #288

Open
guix4ever wants to merge 1 commit into
EverMind-AI:mainfrom
guix4ever:fix/mcp_cancelled_error_escape
Open

fix(agent): keep MCP connection failures from cancelling gateway#288
guix4ever wants to merge 1 commit into
EverMind-AI:mainfrom
guix4ever:fix/mcp_cancelled_error_escape

Conversation

@guix4ever

Copy link
Copy Markdown

Summary

  • Isolate a bare asyncio.CancelledError leaked by an MCP transport or session during connection setup.
  • Keep a failed MCP server from terminating gateway startup while logging the affected server.
  • Re-raise cancellation when Raven's own connection task has an active cancellation request.
  • Add deterministic regression coverage for both SDK-side and external cancellation paths.

Type

  • Fix
  • Feature
  • Docs
  • CI / tooling
  • Refactor
  • Other

Verification

  • uv run pytest tests/test_sandbox_unit.py tests/test_tool_registry_timeout.py -x -q - 76 passed.

  • uv run --extra dev ruff check raven/agent/tools/mcp.py tests/test_sandbox_unit.py - passed.

  • uv run --extra dev ruff format --check raven/agent/tools/mcp.py tests/test_sandbox_unit.py - passed.

  • git diff --check - passed.

  • Relevant tests pass locally

  • Relevant lint / type checks pass locally

  • User-facing docs or screenshots are updated when needed

No user-facing documentation or screenshots are required because this change only corrects connection failure isolation.

Risk

  • Security impact considered
  • Backward compatibility considered
  • Rollback path is clear for risky changes

External gateway or task cancellation still propagates when Task.cancelling() reports an active cancellation request. Only a bare cancellation with no pending task cancellation is treated as an MCP server failure. Existing handling for ordinary exceptions and exception groups is unchanged. The change can be rolled back by reverting this commit.

Related Issues

Closes #231

@guix4ever
guix4ever marked this pull request as ready for review August 10, 2026 09:18
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.

fix: prevent a bare CancelledError during MCP connection from terminating the gateway

1 participant