codegraph refresh hangs on virtualenvs with non-default names (e.g. .venv-leann)
Summary
memorix codegraph refresh hangs indefinitely (never returns; killed at a 60s timeout with rc=124) on projects that keep a Python virtualenv under a non-default directory name — for example .venv-leann. Because every command that triggers a CodeGraph refresh cascades from this, context --refresh auto/always, resume, and the MCP context_pack tool all hang as well. codegraph status and context --refresh never are unaffected.
Environment
- memorix 1.9.1 (also reproduces on the published
dist/cli/index.js) - node v26.8.2
- macOS 15 (Darwin arm64, Apple M1 Max)
Reproduction
# fresh repo with a real source file and a venv under a non-default name
mkdir repro && cd repro && git init -q
echo 'def hello(): return 1' > app.py
python3 -m venv .venv-leann # any venv name that is not exactly .venv / venv
# (populate it — e.g. pip install torch/numpy — so site-packages is large)
git add -A && git commit -qm init
timeout 60 memorix codegraph refresh # -> rc=124, never completes
Renaming the same directory to .venv (a built-in excluded name) makes refresh complete in a few seconds. Adding [codegraph]\nexclude_patterns = [".venv-leann/**"] to memorix.toml also fixes it. So the exclude mechanism itself works — the directory simply is not being excluded.
Measured on a real 34,647-file venv (torch/mlx/pymupdf):
| Directory name | Config | Result |
|---|---|---|
.venv-leann |
none | rc=124, hang |
.venv (built-in exclude) |
none | rc=0, ~3s |
.venv-leann |
exclude_patterns=[".venv-leann/**"] |
rc=0, ~11s |
Root cause
DEFAULT_CODEGRAPH_EXCLUDES in src/codegraph/exclude.ts lists only .venv/** and venv/**. The matcher matchesPattern() treats .venv/** as "path is .venv or starts with .venv/", so .venv-leann/... does not match, and the pattern language has no way to express a .venv* wildcard.
walk() in src/codegraph/lite-provider.ts therefore descends into the virtualenv, collects up to maxFiles (5000) large generated .py files from site-packages, and the subsequent per-file symbol scan (extractSymbols — matchAll plus the O(n) lineOf() on every match) combined with SQLite persistence does not finish within the timeout. This is an aggregate-cost stall, not single-file regex backtracking (the worst single-file parse measured was ~9ms on a 2.6MB file). Not CPU-bound: during the hang the parent is idle waiting on the heap-bumped child over pipes.
Suggested fix
Detect virtualenvs by the PEP 405 pyvenv.cfg marker rather than by directory name, so any env created by venv/uv/virtualenv/poetry is skipped regardless of what it is called. Only virtualenv roots carry that marker, so no real source directory is ever skipped. PR opening shortly.
Ravi,已核对并在本地真实复现了这个问题。你的修复思路是对的:用 PEP 405 的 pyvenv.cfg 标记识别虚拟环境,比依赖目录名可靠,也覆盖了 .venv-leann 这类自定义名称。PR #287 已通过 focused 测试、构建和 Windows/macOS/Linux CI,现已合并进 main;感谢你把这个 CodeGraph 卡死问题抓出来。