Skip to content

fix(cli): stop cleanly on SIGTERM with MCP clients connected; one endpoint for several Hosts - #140

Open
Eternal-Wanderer-Vegetable wants to merge 1 commit into
mainfrom
codex/mcp-multihost-shutdown
Open

Eternal-Wanderer-Vegetable wants to merge 1 commit into
mainfrom
codex/mcp-multihost-shutdown

Conversation

@Eternal-Wanderer-Vegetable

@Eternal-Wanderer-Vegetable Eternal-Wanderer-Vegetable commented Dec 6, 2026 •

Copy link
Copy Markdown
Member

Summary

Issues found while driving command_tools from an external, generic Python MCP client (SDK 1.30.0 and 2.3.0) against one daemon running the NoneBot, Koishi and AstrBot Hosts. Nothing here is specific to any bot; every fix applies to any MCP client.

Problem Fix
The daemon ignored SIGTERM, so kill/systemd/docker stop left Hosts and their isolated Workers running daemon.rs: SIGTERM requests the same graceful shutdown as Ctrl-C (Unix)
With any MCP client connected, graceful shutdown hung forever because axum waits for open SSE streams; POST /v1/shutdown hung the same way http.rs: Streamable HTTP sessions use a child of the shutdown token; daemon.rs: HTTP drain is bounded to 10 s, then Hosts are stopped
AstrBot commands without a docstring exposed partial(func, *args, **keywords) - new function with partial application… as their MCP tool description hosts/astrbot/.../commands.py: handler_description unwraps functools.partial and uses the real docstring or an empty string
A bot or agent wants one endpoint for all ecosystems, but the samples produced one daemon per Host configure.py accepts repeated --host (combined profile on 127.0.0.1:26780, --profile/--port); set_plugin.py --profile; mcp_client.py --host combined. Single-Host output is unchanged

The guides (plugin-installation.md, bot-integration.md, sample README) document the combined profile, shutdown behaviour, and the client-side handling of Connection closed (-32000) after a Core restart.

Related issues

Follow-ups found during this work: #141 (session DELETE 202 vs SDK), #142 (pre-existing clippy errors), #143 (released packages cannot run untrusted Workers behind one endpoint).

Verification

Local, WSL Ubuntu 24.04 with Docker 29.1.3:

  • cargo fmt --check passes; ligamina-cli daemon unit tests 8/8, including new sigterm_requests_graceful_shutdown and internal_token_requests_shutdown; Windows cargo check -p ligamina-cli --all-targets passes (non-Unix branch).
  • python -m unittest lab.tests.test_plugin_installation_configure: 6/6 (new).
  • hosts/astrbot/tests/bridge_smoke.py passes, including a new description check.
  • bash init.sh docs passes.
  • Live: one combined daemon with 3 Hosts and 31 tools, third-party plugins in pinned no-network Workers. An external MCP client called commands in all three ecosystems, including 猜数字 and 组队昵称. Host-crash and full-daemon-restart recovery both work. SIGTERM with an uncooperative client still connected exits in 1.2 s, with no leftover containers. set_plugin.py --profile combined disable/enable changed the game tools 2 → 0 → 2.

Not verified locally (environment gaps, not caused by this change, left to CI):

  • In cargo test --workspace --locked, the two command_tools integration tests failed: the WSL box has no Linux Node, so the Koishi TypeScript build ran with the Windows npm on PATH.
  • The full Lab run has 22 P7 tests that error on a missing external Ligamina-artifact-cache directory.
  • Existing clippy errors (in report.rs and ligamina-core) are untouched.

Known and left as is: on session DELETE, rmcp answers 202, and the Python SDK logs "Session termination failed: 202" (it expects 200/204). There is no functional impact.

🤖 Generated with Claude Code

…point for several Hosts

Found while driving command_tools from an external Python MCP client (SDK
1.30.0 and 2.3.0) against one daemon running NoneBot, Koishi and AstrBot.

- daemon: handle SIGTERM like Ctrl-C so Hosts and their Workers stop
  gracefully instead of being left running.
- http: bind rmcp Streamable HTTP sessions to the shutdown token and bound the
  HTTP drain to 10 s; an open SSE stream no longer blocks shutdown (this also
  fixes POST /v1/shutdown hanging while a client is connected).
- astrbot host: a command without a docstring no longer exposes the
  functools.partial class docstring as its MCP tool description.
- samples: configure.py accepts repeated --host to put several Hosts behind
  one daemon/endpoint (--profile/--port); set_plugin.py takes --profile;
  mcp_client.py knows the combined profile.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant