modelcontextprotocol / modelcontextprotocol/python-sdk

ExceptionGroup wrapping obscures real errors from task groups

未關閉
#2,114 3 則留言 2 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

bug P1 v2
主要語言
Python
星號
24.3k
分支
4k
平均合併
1 天 1 小時
30 天內合併 PR
31

描述

Summary

When SDK internal anyio task group tasks fail, the real error is wrapped in a BaseExceptionGroup alongside Cancelled exceptions from cancelled sibling tasks. This makes error classification extremely difficult for callers — they cannot reliably determine the root cause of a failure.

There are 16 create_task_group() usages across the SDK with no except* syntax or ExceptionGroup unwrapping anywhere.

Expected Behavior

  • Callers should receive the original exception, not an ExceptionGroup wrapping it alongside cancellation noise
  • When a task group has one real failure and N cancelled siblings, only the real failure should propagate

Current Behavior

  • A single connection failure produces a BaseExceptionGroup containing the real error plus multiple Cancelled exceptions
  • Callers must manually unwrap exception groups to find the root cause
  • This affects ~80+ call sites across the SDK where task groups are used

Affected Code

  • src/mcp/shared/session.py (session task groups)
  • src/mcp/client/streamable_http.py (transport task groups)
  • All other create_task_group() sites

Related

  • #1742 — broader typed error classes design
  • #1830 — CancelledError indistinguishable from external cancellation (closed but related)

AI Disclaimer

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

先閱讀 src/mcp/shared/session.py 和 src/mcp/client/streamable_http.py 中的工作群組處理邏輯,接著檢查 issue 中提到的其他 create_task_group() 位置。重現一個伴隨已取消兄弟工作的連線失敗,並確認真正的例外會在受影響的呼叫點之間傳播,且不會產生取消雜訊。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
backend
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
冷清
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。