fix: cap BLAS/OpenMP threads to avoid concurrent-proc oversubscription (closes #316)#317
Open
Huntehhh wants to merge 1 commit into
Open
Conversation
Sets OMP_NUM_THREADS=1, MKL_NUM_THREADS=1, OPENBLAS_NUM_THREADS=1, NUMEXPR_NUM_THREADS=1 via setdefault in main() before _preload_models(). Why: Claude Code spawns one MCP subprocess per session, and sub-agent fan-out can push this to 10+ concurrent procs on a single host. With default thread counts each proc tries to use every CPU core for PyTorch/sentence-transformers inference. N procs * N cores worth of threads competing for N cores produces a context-switching collapse — empirical symptom is multi-minute m.add() hangs (one confirmed 19-minute hang in ~/.truememory/logs/mcp-debug.log under sub-agent load). setdefault preserves user override: a beefy single-proc workstation can still set OMP_NUM_THREADS=4 etc. explicitly. Co-Authored-By: Claude Opus 4.7 <[email protected]>
f5367fb to
5b8fd11
Compare
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
Caps BLAS/OpenMP threads to 1 per MCP proc via
os.environ.setdefaultinmain()before_preload_models(). Prevents concurrent-proc thread oversubscription that produces multi-minuteengine.add()hangs under Claude Code sub-agent fan-out.Closes #316.
Changes
truememory/mcp_server.pysetdefaultforOMP_NUM_THREADS,MKL_NUM_THREADS,OPENBLAS_NUM_THREADS,NUMEXPR_NUM_THREADSbefore_preload_models()Why
setdefault(not assignment)User override preserved. A beefy single-proc workstation can still set
OMP_NUM_THREADS=4explicitly; the fix only kicks in when the user hasn't expressed an opinion.Test plan
No breaking changes
setdefaultpreserves existing env-var behavior. No public API affected.Co-Authored-By: Claude Opus 4.7 [email protected]