Repository navigation
fix(memory): close MCP backend on shutdown - #2905
Conversation
PR governanceThis PR does not yet satisfy the required template fields:
Please update the PR body, or move the PR back to draft while it is still in progress. |
JerrettDavis
left a comment
There was a problem hiding this comment.
Cleanup is idempotent and serialized, cancels and awaits an in-flight initializer, and relies on _init_backend’s existing cancellation path to close partially constructed resources exactly once. A completed backend is detached before close, and _run invokes cleanup in finally across normal and exceptional stdio exits. The actual MCP Server supports the attached cleanup callback; focused tests cover initialized, initializing, and run-exit paths. Broader CI has not run.
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
chopratejas
left a comment
There was a problem hiding this comment.
Maintainer review complete: cleanup is serialized and idempotent, cancels and awaits in-flight initialization, closes completed or partially initialized backends exactly once, and runs from the transport finally path. Merge after full CI.
Description
Closes the initialized LocalBackend and cancels in-flight initialization whenever the memory MCP stdio transport exits.
Fixes #2898
Type of Change
Changes Made
_run()through afinallyblock after the stdio transport exits, including transport errors._run()shutdown behavior.Testing
pytest)ruff check .)mypy headroom)Test Output
Real Behavior Proof
create_memory_server()closure and an embedded server transport stub.python -m pytest -q tests/test_memory/test_mcp_server.py; the regression tests initialized a backend through the server's registered tool lifecycle, returned the stdio transport, and invoked the cleanup callback from_run()'sfinallypath.LocalBackend.close(); no native code or runtime network access is introduced.headroom._coreextension.Review Readiness
Checklist
CHANGELOG.md- it is generated by release-please from my Conventional Commit PR title.Screenshots (if applicable)
Not applicable.
Additional Notes
Cleanup is attached to each created memory MCP server and is idempotent, so embedded callers can invoke the same lifecycle callback safely if needed.