CM-73909 fix resource tracker leak - #564
Merged
Merged
Conversation
ThreadPool creates a multiprocessing lock, which on macOS spawns a resource_tracker process. The tracker inherits the hook's stdout and exits only after the CLI does, so Claude Code sees the hook exit before stdout reaches EOF, discards the verdict and blocks the tool call. Run the scan in a daemon thread with a join timeout instead. A daemon thread keeps the old timeout behaviour: a hung scan does not keep the process alive. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GitPython runs `git version` when it is imported. git_proxy imported it at module load, so every command paid for git subprocesses and the import (about 150ms), even commands that never touch git, such as guardrails scans of MCP calls and prompts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
omer-roth
reviewed
Oct 5, 2026
omer-roth
reviewed
Oct 5, 2026
omer-roth
reviewed
Oct 5, 2026
Move the scan worker to a module-level _run_scan that receives its inputs through Thread args, and drop the narration comments. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ilanlido
enabled auto-merge (squash)
October 5, 2026 08:42
omer-roth
approved these changes
Oct 5, 2026
omer-roth
approved these changes
Oct 5, 2026
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.
Summary
On macOS,
cycode ai-guardrails scanexits before its stdout reaches end-of-stream. Claude Code now treats that as a suspect capture ("its stdio went quiet before end-of-stream … refusing to honor the suspect capture"), so it discards the verdict and blocks the tool call, even though the CLI returnedallow.Cause:
_perform_scanran the scan in amultiprocessing.pool.ThreadPoolto enforce a timeout. AThreadPoolonly uses threads, butPool.__init__still creates a multiprocessing lock. When the start method isspawn(macOS) orforkserver(Linux on Python 3.14+), that lock starts amultiprocessing.resource_trackerprocess. The tracker inherits the hook's stdout and stderr, and by design it exits only after the parent does. In the frozen build, the tracker also runs the full CLI start-up again before it gets to the tracker code, so it holds the pipe for about 0.1–0.2s after the CLI exits.Changes
_perform_scannow uses a daemonthreading.Threadandjoin(timeout)instead of aThreadPool. This creates no multiprocessing lock, so no tracker starts. Timeouts still raiseRuntimeError, exceptions from the scan are re-raised, and a hung scan still doesn't keep the process alive.ThreadPoolExecutordoesn't fit here, because its workers are joined when Python exits.git versionwhen it is imported.git_proxyimported it at module load, so every command paid for those subprocesses and about 150ms of import time, even commands that never use git. MCP and prompt hook events now start no git processes. File-read events still import GitPython, because they look up the repository's remote URL.Notes
fork) is not affected today, but would be after a move to Python 3.14.utils/scan_batch.pyusesThreadPoolthe same way. It is not on the guardrails path. Switching it toThreadPoolExecutorwould make Ctrl+C on a long scan wait for the batches already running, so it is left for a separate change.