Skip to content

hook install: post-commit rebuild can silently collapse a graph built on a subfolder #2603

Closed

Description

@ozoknar

Environment

  • graphifyy (pip), macOS, installed via uv tool install
  • Graph was built via the Claude Code skill's manual step-by-step flow with INPUT_PATH=src (a subfolder of the repo), but graphify-out/ stays at the repo root the whole time (this is the skill's own documented/intentional behavior — every code block writes to graphify-out/... relative to CWD, independent of INPUT_PATH).

Steps to reproduce

  1. Build a full graph on a subfolder via the skill flow → graphify-out/graph.json at repo root, ~7244 nodes.
  2. Run graphify hook install (installs git post-commit/post-checkout hooks).
  3. Make a small change to any file, commit.

Expected

The hook re-extracts only the changed file(s) and preserves the existing 7244 nodes.

Actual

The hook silently collapses the graph to ~4-129 nodes and overwrites graphify-out/graph.json. Reproduced twice, with different (small) node counts each time — looks non-deterministic. The commit itself is never corrupted, only the working-tree graphify-out/* files.

Root-cause hypothesis (could not fully isolate)

_rebuild_code(watch_path, ...) in graphify/watch.py computes out = watch_path / GRAPHIFY_OUT, coupling the output directory to the scan root. The git hook reads watch_path from .graphify_root, which is written once in the skill's Step 1 but never updated when the user later narrows the scan to a subfolder (Step 2's corpus-size prompt).

I pinned GRAPHIFY_OUT to an absolute repo-root path (via the env-var override contract documented in graphify.paths) and corrected .graphify_root to point at src. Calling _rebuild_code() directly in Python with this fix worked correctly twice (7244→7245 on an added symbol, 7245→7244 on reverting it). But applying the identical env-var fix inside the installed git hook script and triggering it via a real git commit still corrupted the graph (down to 129 nodes). So the bug isn't just the output-path mismatch — likely something in _StoredSourcePaths identity matching (the extraction's project_root/watch_root anchoring doesn't agree with the skill's root='src' (relative) build), or something is lost in the hook's own process chain (detached subprocess.Popen + _rebuild_lock + _queue_pending/_drain_pending).

Impact

Silent data loss risk for anyone who (a) builds on a subfolder via the interactive skill, then (b) installs the git-hook automation — a very plausible combination for exactly the audience the skill targets.

Workaround

Don't use hook install in this scenario. The PreToolUse hook from claude install is unaffected (it's read-only and always resolves graphify-out/ relative to CWD via graphify.paths.out_path(), independent of .graphify_root).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions