Skip to content

test(mcp): tear down SSE GET before client exit - #866

Closed
dplush wants to merge 1 commit into
mainfrom
fix/issue-860-sse-teardown
Closed

dplush wants to merge 1 commit into
mainfrom
fix/issue-860-sse-teardown

Conversation

@dplush

@dplush dplush commented Aug 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Make the long-lived authenticated SSE GET in the Streamable HTTP integration test finish explicitly before TestClient tears down its portal.

Why this path

The test itself owns the background ASGI request. A finally block now signals http.disconnect and joins that request before leaving the client context. This keeps the existing DELETE-driven assertion meaningful: it still verifies that DELETE alone shuts the request down before fallback cleanup runs.

Non-goals

Verification

uv run --extra mcp --extra test pytest -q tests/test_mcp_streamable_http.py
54 passed

Independent current-diff review: approved.

Fixes #860

Summary

  • Updates tests/test_mcp_streamable_http.py to disconnect the background SSE GET request during cleanup.
  • Joins the request thread before TestClient exits, including when assertions fail.
  • Preserves the DELETE assertion that verifies request shutdown.

Architecture impact

  • No changes to Mnemosyne’s memory architecture, retrieval, consolidation, veracity, sync, privacy, or local-first guarantees.
  • No changes to Hermes, MCP, CLI, or product transport behavior.
  • Improves test maintainability by removing an intermittent teardown race.
  • Does not add a pytest-level timeout safeguard.
  • Verification: 54 passed in tests/test_mcp_streamable_http.py.

@dplush
dplush requested a review from AxDSan as a code owner August 25, 2026 17:44
@coderabbitai

coderabbitai Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 9df01d42-b36b-4489-9135-e4f74017ebc4

📥 Commits

Reviewing files that changed from the base of the PR and between 12cffcf and 796522b.

📒 Files selected for processing (1)
  • tests/test_mcp_streamable_http.py

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The streamable HTTP session test now explicitly disconnects the authenticated GET stream. Cleanup runs after session assertions and verifies that the background GET thread terminates, including when an assertion fails.

Changes

Streamable HTTP test

Layer / File(s) Summary
Explicit GET stream cleanup
tests/test_mcp_streamable_http.py
The ASGI receive stub waits for a disconnect event and returns http.disconnect. The test signals the event in finally and verifies GET thread termination after session assertions.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 79652

This change only makes the integration test explicitly finish its background request before client teardown; no product transport behavior changes are introduced. No actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: axdsan, donbowman

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: tearing down the SSE GET request before the client exits.
Linked Issues check ✅ Passed The test now signals http.disconnect and joins the background GET thread in finally before TestClient teardown. This addresses the primary test-fix objective in issue #860. The separate suite-level ti…
Out of Scope Changes check ✅ Passed The changes are limited to cleanup and teardown logic in tests/test_mcp_streamable_http.py. No unrelated product, CI, timeout, or pytest configuration changes are present.
Full details: Linked Issues check

Explanation

The test now signals http.disconnect and joins the background GET thread in finally before TestClient teardown. This addresses the primary test-fix objective in issue #860. The separate suite-level timeout is explicitly out of scope for this PR.

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-860-sse-teardown

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dplush

dplush commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #867, which fixes the actual MCP 2.1 ASGI contract violation by delivering the initial http.request, handles portal-task cancellation on every failure path, and adds the suite-level timeout backstop. Closing this narrower teardown-only attempt to avoid duplicate fixes.

@dplush dplush closed this Aug 25, 2026
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.

CI: the test matrix intermittently hangs in test_mcp_streamable_http and burns the 6-hour job timeout

1 participant