Skip to content

ToolRegistry.execute() catches Exception, but asyncio.CancelledError#1743

Open
pixan-ai wants to merge 1 commit intoHKUDS:mainfrom
pixan-ai:fix/registry-cancelled-error-propagation
Open

ToolRegistry.execute() catches Exception, but asyncio.CancelledError#1743
pixan-ai wants to merge 1 commit intoHKUDS:mainfrom
pixan-ai:fix/registry-cancelled-error-propagation

Conversation

@pixan-ai
Copy link
Copy Markdown
Contributor

@pixan-ai pixan-ai commented Mar 8, 2026

What

Add explicit asyncio.CancelledError handling in ToolRegistry.execute().

Why

ToolRegistry.execute() wraps tool calls in try/except Exception, but
asyncio.CancelledError inherits from BaseException (not Exception)
since Python 3.9. This means task cancellations from /stop escape the
handler without being properly propagated.

This is the registry-level counterpart to the MCP tool-level fix in PR #1728.

How

  • Add except asyncio.CancelledError: raise before the except Exception handler
  • Ensures /stop cancellations propagate correctly through tool execution

Testing

  1. Start a long-running tool call (e.g. shell command)
  2. Send /stop → should cancel cleanly
  3. Normal tool errors should still return error messages to the LLM

Acknowledgment

Fix identified and developed with assistance from Claude Opus 4.6

inherits from BaseException (Python 3.9+), so it escapes unhandled.
Adding an explicit re-raise ensures /stop task cancellation propagates
correctly through the tool execution layer.
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.

1 participant