Fix completed request cancellation cleanup - #2624
Conversation
5db90d2 to
bb76886
Compare
This comment was marked as abuse.
This comment was marked as abuse.
This comment was marked as abuse.
This comment was marked as abuse.
bb76886 to
edb78c0
Compare
|
CI note: I inspected the two failed Ubuntu jobs. They fail in existing tests that are not changed by this PR: Both pass locally on this branch: uv run --frozen --no-sync pytest tests/interaction/lowlevel/test_timeouts.py::test_session_level_timeout_applies_to_every_request -q
uv run --frozen --no-sync pytest tests/shared/test_streamable_http.py::test_client_crash_handled -qI do not have permission to rerun Actions on this repository, but these look like transient CI timing/port failures. Happy to patch if they reproduce consistently. |
Docs-only. `AGENTS.md` is the first file every agent reads in this repo, and its account of `src/hive/_compat.py` had drifted from the code on three points. All three were verified against the source and against the upstream trackers before writing. ## 1. Wrong patch target AGENTS.md said the shim patches `RequestResponder.__exit__` to swallow an anyio `CancelledError`. It patches **`RequestResponder.respond`**, to short-circuit the upstream `assert not self._completed`. The `__exit__` patch was **removed** — `_compat.py`'s own docstring records why: the issue-#75 symptom stopped reproducing on `mcp >= 1.27`, because `Server._handle_request` catches the in-flight cancellation before it can reach `__exit__`. ## 2. Wrong upstream tracker, and a stale instruction AGENTS.md pointed at [python-sdk#2610](modelcontextprotocol/python-sdk#2610) with an escalation deadline of 2026-06-12 and an instruction to port the fix ourselves. The shim's fate is actually tied to [**#2416**](modelcontextprotocol/python-sdk#2416) — open, maintainer-bot-confirmed on both `main` and `origin/v1.x`, with a contributor volunteering to fix it on 2026-07-11 (and our own reproduction already posted there on 2026-06-19). Meanwhile #2610 already has an open upstream fix PR, [#2624](modelcontextprotocol/python-sdk#2624). Porting it ourselves would duplicate existing work. **This matters beyond the docs:** #127 is scoped as "if #2610 is still silent, port the fix as our own upstream PR". That premise no longer holds. #127 is commented separately rather than being silently rescoped here. ## 3. Stale pin, and a guard that no longer holds AGENTS.md quoted `mcp>=1.26,<2.0`, with the rationale that a narrow cap stops a major `RequestResponder` refactor from silently breaking the shim. The actual constraint is now `mcp>=1.27,<3.0` (widened by #316). `<3.0` admits `mcp` 2.x — precisely the major boundary the cap existed to exclude. I recorded this as a **lost guard** rather than silently re-narrowing the pin: `apply()` degrades loudly (logs a warning and no-ops) rather than silently, so this is not a live bug, and re-narrowing a dependency range is a decision with its own consequences, not a docs edit. Flagging it for a deliberate call. ## Verification No code changed, so no test impact. The three claims were checked against `src/hive/_compat.py` (docstring + `apply()`), `pyproject.toml:49`, and the three upstream trackers via the GitHub API.
edb78c0 to
6cedc87
Compare
|
Rebased this fix onto v1.29.0 / |
Summary
Fixes #2610.
CancelScope.__exit__only after aRequestResponderhas completed and sent its response.The implementation is rebased onto the maintained
v1.xline (v1.29.0), whereBaseSessionand this cleanup path remain active.Validation
pytest tests/shared/test_session.py tests/server/test_cancel_handling.py -q— 11 passedruff format --check src/mcp/shared/session.py tests/shared/test_session.pyruff check src/mcp/shared/session.py tests/shared/test_session.pypyright --pythonpath .venv/bin/python src/mcp/shared/session.py tests/shared/test_session.pygit diff --check