fix(adapters): kill CLI process tree on timeout + skip MCP for tool-less profiles#6
Merged
Merged
Conversation
…ess profiles
The agent-cli timeout path called `child.kill("SIGTERM")` on the direct child
only. claude-code (and any CLI that spawns stdio MCP servers or other
descendants) leaves those descendants holding the stdout/stderr pipes, so the
parent run-once process never exits and the systemd oneshot service hangs in
`activating` forever — freezing ALL dispatch for that agent. Observed on Lumen:
one council-lens-review task wedged the dispatcher for 2.5h (heartbeat,
email-poll, everything stopped), leaving claude procs stuck in kernel D-state.
1. Spawn CLI children `detached: true` and, on timeout, signal the whole
process group (SIGTERM, then SIGKILL after a 5s grace), tear down the stdio
pipes, and unref the child — so a hung descendant can never hold the
dispatcher (and thus the oneshot service) open. Fleet-wide fix: protects
every CLI adapter from any hang cause.
2. buildClaudeArgs: pass `--strict-mcp-config` when the profile declares no
aibtc integration (`integration_policies.aibtc === "none"`, e.g.
council-lens-review). Read-only reasoning profiles don't need MCP tools, and
loading the user-level ~/.claude.json aibtc stdio MCP server is what triggered
the teardown hang. The timeout fix above is the backstop for every other cause.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The agent-cli timeout path killed only the direct child (
child.kill("SIGTERM")). claude-code — and any CLI that spawns stdio MCP servers or other descendants — leaves those descendants holding the stdout/stderr pipes. Therun-oncedispatcher reads those pipes, so the parent process never exits and the systemd oneshot service hangs inactivatingforever, freezing all dispatch for that agent.Observed (2026-06-03): a single
council-lens-reviewtask on Lumen wedged the dispatcher for 2.5h — heartbeat, email-poll, everything stopped. The hungclaudeprocesses ended up in kernelD-state (__flush_work), un-killable, requiring a reboot.Fix
1. Kill the whole process tree on timeout (fleet-wide fix). Spawn CLI children
detached: trueso each leads its own process group; on timeout,SIGTERMthe group, escalate toSIGKILLafter a 5s grace, tear down stdio pipes, andunref()the child. A hung descendant can no longer hold the dispatcher (or the oneshot service) open — protects every CLI adapter from any hang cause.2. Don't load MCP for tool-less profiles (removes the trigger).
buildClaudeArgspasses--strict-mcp-configwhen the profile declares no aibtc integration (integration_policies.aibtc === "none", e.g.council-lens-review). Read-only reasoning profiles need no MCP tools; loading the user-level~/.claude.jsonaibtcstdio MCP is what triggered the teardown hang.Scope
Only the claude-code driver hits the MCP-teardown variant, and only on VMs whose
~/.claude.jsonregisters a stdio MCP server (today: Lumen). But the process-tree-not-killed bug is in the shared timeout path and affects every CLI adapter on every machine.bunx tsc --noEmitclean.🤖 Generated with Claude Code