Repository navigation
Bound and shield legacy HTTP session cleanup - #3879
ar-ramchandra wants to merge 1 commit into
Conversation
Candidate for modelcontextprotocol#3877, reported by @shivamm-gupta. Five-second cleanup budget requires maintainer agreement. AI-assisted with OpenAI Codex.
|
This PR has been closed automatically. It's still a draft, but we close those early so you don't put in more time only to have it closed the moment you mark it ready. This repo only keeps pull requests open when they come from a maintainer, or from a contributor a maintainer has assigned to the linked issue, and you aren't currently assigned to #3877. If a maintainer assigns you to #3877, this PR reopens on its own and there's nothing more you need to do here. Assignment is a maintainer call based on capacity; comments that only ask to be assigned don't factor in. What does help is engaging on the issue itself by confirming the repro, explaining why it matters for your use case, or describing the approach you'd take. You're welcome to keep pushing commits here (just avoid force-pushing, since GitHub can't reopen a rewritten branch), but that on its own won't get the PR reviewed or the issue assigned, and realistically most auto-closed PRs stay closed. There's no need to open a new PR either way. CONTRIBUTING.md has the full reasoning, but in short:
Maintainers: reopen, remove |
Fixes #3877. Original report by @shivamm-gupta.
Cancellation during Streamable HTTP client exit can abort the session-termination DELETE, leaving the legacy session usable on the server. Shield that cleanup request from caller cancellation and bound it to five seconds, then proceed with local transport shutdown. This is a draft candidate pending assignment and agreement on the cleanup budget; it is available for the original reporter or maintainers to build on.
Motivation and Context
With a real Client and stateful server through the in-process HTTP transport, cancelling before DELETE or while DELETE is in progress leaves the old session accepting ping (HTTP 200). With this patch, completed termination makes that session return HTTP 404. Normal exit and the explicit
terminate_on_close=Falseopt-out remain covered.How Has This Been Tested?
On the local macOS/Python 3.14 environment,
./scripts/test -n 4passed 6,241 tests with 100% coverage and passed strict-no-cover. The repository pre-commit checks passed, including Ruff, pyright, and markdownlint. Regression cases cover cancellation before and during DELETE, normal exit, the cleanup opt-out, stalled DELETE, and connection failure. The before/during cancellation cases fail against unchanged main at77001c9; the ordinary-exit and opt-out controls pass there. No live external server or production workload was tested, and the CI platform matrix remains pending.Breaking Changes
No public signature changes. The proposed five-second total cleanup cap also applies to normal exit, so it can stop a DELETE sooner than a caller's longer HTTP timeout previously allowed. This observable timeout-policy change needs explicit maintainer agreement before the draft is made ready. Caller cancellation can be delayed by up to that cleanup budget; cancellation still propagates afterward.
Types of changes
Checklist
help wanted, or I'm a maintainer)Additional context
Investigation, implementation, regression tests, and independent review were AI-assisted with OpenAI Codex. The before/after checks and validation commands above were executed locally. Three test-only
no branchannotations address coverage.py's cancellation/context-manager arc accounting; no production branches are newly excluded. A formerly excluded exception handler is now exercised by the connection-failure regression.