Repository navigation
Description
Summary
graphify hook install registers a git post-commit hook (hooks.py:46-93) that
spawns a detached Python process to rebuild the entire repo's graph. The hook
has no concurrency cap, no memory/CPU limit, no timeout, and does not use the
GRAPHIFY_CHANGED data it computes. When multiple repos with the hook commit
in the same time window — or when a single watcher fires _rebuild_code across
many projects — the system fills with concurrent multi-GB rebuilds.
This caused a full UI freeze on a Mac mini (32 GB RAM) this morning: ~10
concurrent rebuilds, peak 4.1 GB / 99% CPU each, free RAM dropped to 60 MB,
load average hit 31, mouse clicks froze for 30+ minutes.
Reproduction
graphify hook installin three or more repos- Trigger commits in all of them within ~10 seconds (e.g. via a multi-repo
sync tool, autocommit script, orpre-commitchain) - Observe: N independent
python -c "from graphify.watch import _rebuild_code; _rebuild_code(Path('.'))"
processes, each holding the full code graph in memory, no shared state,
no lock, no nice level
Severity scales with repo size and number of repos. On macOS, runaway
fseventsd traffic from rebuild output compounds the problem.
Code References (v0.7.10)
Issue 1 — No concurrency control on detached rebuild
hooks.py:71-91 — nohup graphify_python -c "..." > $log 2>&1 & then disown.
No lock file, no semaphore, no nice/ionice, no max-concurrent-rebuilds env.
Issue 2 — GRAPHIFY_CHANGED computed but discarded
hooks.py:75-87 — the inline script reads the env var, parses it into
changed: list[Path], then exits if empty. But the actual rebuild on line 87
calls _rebuild_code(Path('.'), force=_force) and ignores changed entirely.
_rebuild_code re-globs every code file every time. For a 446-file repo this
is ~5 s of CPU + heavy fseventsd traffic per commit, even when one file changed.
Issue 3 — No timeout on the background process
If a rebuild leaks memory or hangs (network volumes, Spotlight contention,
parser bug on a specific file), it stays alive indefinitely. macOS has no
default kill-after-N-minutes for detached nohup children.
Suggested Fix
-
Concurrency lock —
flockon~/.cache/graphify/rebuild.lock(or
per-repo lock in<repo>/graphify-out/.rebuild.lock). Skip if held; an
in-progress rebuild covers later commits anyway. -
Honour
GRAPHIFY_CHANGED— extend_rebuild_codesignature:def _rebuild_code( watch_path: Path, *, changed_paths: list[Path] | None = None, follow_symlinks: bool = False, force: bool = False, ) -> bool: ...
When
changed_pathsis provided, re-extract only those files and merge
into the existing graph instead of rebuilding from scratch. -
Resource limits —
nice -n 10,GRAPHIFY_REBUILD_TIMEOUT(default
10 min), optionalGRAPHIFY_REBUILD_MEMORY_LIMIT_MBenforced via
resource.setrlimit(RLIMIT_AS, ...)in the inline script.
Happy to send a PR for any/all of these if there's interest.
Environment
- macOS 15.4 (Sequoia), Apple Silicon Mac mini, 32 GB RAM
- Python 3.14.4 (Homebrew)
- graphify 0.7.10 (PyPI)
- Hook installed across ~17 directories via
graphify_watcher_worker.py
Activity
fix hook OOM, lift worker cap, fix antigravity .agents path and front…
safishamsi commentedon May 9, 2026
Fixed in v7. Three root causes addressed:
1. Per-repo lock —
_rebuild_codenow acquires afcntl.flocknon-blocking lock ingraphify-out/.rebuild.lock. If a rebuild is already running for that repo, the new invocation skips instead of spawning a second 4 GB process. The lock releases automatically on SIGKILL (kernel closes the fd) so no stale-lock cleanup is needed. Falls back to a no-op on Windows (nofcntl).2. Honour
GRAPHIFY_CHANGED—changed_pathsis now wired all the way from the hook script through_rebuild_codeto the AST extractor. Only modified files are re-extracted; unchanged files come from the cache. Deleted files have their nodes evicted from the preserved graph bysource_filematch.3. Resource ceiling —
GRAPHIFY_REBUILD_TIMEOUT(default 600s) watchdog viaSIGALRM;GRAPHIFY_REBUILD_MEMORY_LIMIT_MBcap usingRLIMIT_DATAon Darwin (notRLIMIT_ASwhich is broken under libmalloc) andRLIMIT_ASon Linux;nice -n 10in the background script.Interactive
graphify updatepassesblock_on_lock=Trueso it waits instead of silently exiting when a hook rebuild is running.Your diagnosis was accurate — the original
nohup ... & disownpatch from #650 fixed the synchronous-block problem but left no concurrency story. This closes that gap.safishamsi commentedon May 9, 2026
Fixed in v0.7.12 — hooks now use a per-repo
fcntl.flocknon-blocking lock so concurrent commits skip rather than stack unbounded rebuilds. Addednice -n 10,RLIMIT_DATA/RLIMIT_ASmemory cap, andSIGALRMwatchdog timeout.graphify updateusesblock_on_lock=Trueto wait rather than silently skip.fix(hooks): arm the rebuild timeout without SIGALRM on Windows
Squashed commit of the following:
fix hook OOM, lift worker cap, fix antigravity .agents path and front…
fix(hooks): arm the rebuild timeout without SIGALRM on Windows
fix hook OOM, lift worker cap, fix antigravity .agents path and front…