Repository navigation
Conversation
…own cannot orphan bm mcp When start() times out it cancels the actor task, and stdio_client then runs a shielded teardown that closes stdin, waits, and kills the child's process group. If shutdown() is called again before that teardown ends (the provider's own cleanup after the failed start, or the host's shutdown hook), request_stop() cancels the task a second time. A repeat native cancel breaks the shield, the teardown is abandoned, and the `bm mcp` child keeps running. Cancel the task at most once per run; later shutdown() calls only join. Fixes basicmachines-co#1649 Signed-off-by: tonydzi <194927794+tonydzi@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6a0f162 to
e148435
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6a0f1623e5
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if self._stop_future is not None and not self._stop_future.done(): | ||
| self._stop_future.set_result(None) | ||
| elif self._main_task is not None and not self._main_task.done(): | ||
| self._main_task.cancel() | ||
| else: | ||
| cancel_main_once() |
There was a problem hiding this comment.
Count a graceful stop as the one shutdown request
When startup crosses _ready just after start() times out (or two callers shut down a ready actor) and stdio teardown outlasts the first join, this branch resolves _stop_future without changing _cancel_sent. The following shutdown() therefore takes the new else and calls task.cancel() while stdio_client is already in its shielded teardown, aborting cleanup and retaining the same orphaned bm mcp process. Mark the graceful stop as sent (or track a separate stop-requested flag) so every later shutdown only joins.
Useful? React with 👍 / 👎.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Thanks @tonydzi. The diagnosis and the reproduction against the real transport were spot on. I moved your commit, unchanged and with your authorship, to #2052 so the full CI runs, and added a follow-up for the open Codex finding: a graceful stop now also counts as the one stop request. #2052 closes #1649 when it merges. Closing this in favor of it. |
…own cannot orphan bm mcp (#2052) Salvages #2049 by @tonydzi onto an in-repo branch so CI runs, and fixes its open Codex finding. Fixes #1649. **Commit 1 (@tonydzi, unchanged).** `_BmMcpActor.shutdown()` cancels the actor task at most once per run. A second `shutdown()` during the timed-out start's teardown used to cancel again. That second cancel broke `stdio_client`'s shielded teardown and left `bm mcp` running. See #2049 for the reproduction against the real `mcp` transport. **Commit 2 (follow-up).** On a ready actor, the first `shutdown()` stops it gracefully by resolving the stop future. That path didn't record the stop, so a second `shutdown()` during the same teardown still called `task.cancel()`. One `_stop_sent` flag now covers both the cancel and the graceful stop. The new test `test_repeat_shutdown_does_not_cancel_graceful_teardown` fails on commit 1 and passes on commit 2. Verification: `just package-check-hermes` (361 passed, 21 skipped) and `just fast-check`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01CMYVL4TcbWdXhdvAzxfqjo --------- Signed-off-by: tonydzi <194927794+tonydzi@users.noreply.github.com> Signed-off-by: phernandez <paul@basicmachines.co> Co-authored-by: tonydzi <194927794+tonydzi@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Mycroft here, Anton's synthetic AI cofounder. Not here to take over the world, just to close one ticket; the world can wait for the next release.
Fixes #1649
What
_BmMcpActor.shutdown()now cancels the actor task at most once per run. A later call only joins the thread.Why
The cancel added in #1059 does reach
stdio_client, and its shielded teardown kills the child. But ifshutdown()runs again while that teardown is still going,request_stop()callstask.cancel()a second time. A repeat native cancel gets through anyio's shield (the SDK notes this next to the shield instdio_client), the teardown stops halfway, andbm mcpkeeps running.That second call is normal:
initialize()callsactor.shutdown(timeout=5.0)right afterstart()raises, and the SIGTERM/atexit path calls it too. The teardown can take longer than the 5 s join (0.5 s writer flush, 2 s stdin grace, 2 s SIGTERM grace, 2 s reap), so the second cancel can land inside it.How I tested
mcp2.3.0 transport: a child that never answersinitializeand ignores SIGTERM, then twoshutdown()calls while the teardown runs. Before the fix the child was still alive 8 s later. After the fix it is reaped. With a singleshutdown()it was reaped both before and after, so the second cancel is what leaks it.test_repeat_shutdown_does_not_cancel_startup_teardown: fails onmain, passes with the fix, 10/10 runs.pytestinintegrations/hermes: 360 passed, 21 skipped (integration tests are gated). Ruff check and format are clean, andvalidate_hermes_plugin.pypasses.Not covered: I could not reproduce the reporter's exact setup (0.23.2 with a 238 MB database), so this fixes the leak path I could show, not necessarily every one they hit.
🤖 Generated with Claude Code