Skip to content

fix(server): deregister terminated streamable HTTP sessions - #3302

Open
mikemikimike wants to merge 1 commit into
modelcontextprotocol:mainfrom
mikemikimike:codex/3300-session-deregister
Open

fix(server): deregister terminated streamable HTTP sessions#3302
mikemikimike wants to merge 1 commit into
modelcontextprotocol:mainfrom
mikemikimike:codex/3300-session-deregister

Conversation

@mikemikimike

Copy link
Copy Markdown

Summary

  • remove terminated existing sessions from both session registries immediately after handling the request
  • add a regression test for the clean DELETE/session termination path

Fixes #3300

Validation

  • uv run --frozen ruff format ...
  • uv run --frozen ruff check src/mcp/server/streamable_http_manager.py tests/server/test_streamable_http_manager.py
  • uv run --frozen pyright src/mcp/server/streamable_http_manager.py tests/server/test_streamable_http_manager.py
  • uv run --frozen pytest tests/server/test_streamable_http_manager.py -q (31 passed)
  • git diff --check

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="tests/server/test_streamable_http_manager.py">

<violation number="1" location="tests/server/test_streamable_http_manager.py:316">
P3: This regression test does not verify `_session_owners` cleanup because it never adds `session_id` to `_session_owners` before the request. Seed that registry first so the assertion can fail if owner removal breaks.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

transport = AsyncMock()
transport.is_terminated = True
transport.idle_scope = None
manager._server_instances[session_id] = transport

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: This regression test does not verify _session_owners cleanup because it never adds session_id to _session_owners before the request. Seed that registry first so the assertion can fail if owner removal breaks.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tests/server/test_streamable_http_manager.py, line 316:

<comment>This regression test does not verify `_session_owners` cleanup because it never adds `session_id` to `_session_owners` before the request. Seed that registry first so the assertion can fail if owner removal breaks.</comment>

<file context>
@@ -304,6 +304,36 @@ async def mock_receive():
+    transport = AsyncMock()
+    transport.is_terminated = True
+    transport.idle_scope = None
+    manager._server_instances[session_id] = transport
+
+    scope = {
</file context>

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.

Cleanly terminated streamable-HTTP sessions are never deregistered: the DELETE path skips its own cleanup

1 participant