Repository navigation
fix(watch): bypass shrink-guard when caller declared explicit deletions - #1000
Merged
safishamsi merged 1 commit intoMay 24, 2026
Merged
Conversation
The post-commit hook passes `git diff --name-only HEAD~1 HEAD` as changed_paths to `_rebuild_code`. That list includes deletions, and `_rebuild_code` correctly identifies them (lines 352-367 in watch.py) and evicts the stale nodes from the preserved set. The rebuilt graph is intentionally smaller. `_check_shrink` then refuses to overwrite the existing graph.json because it only sees the node-count delta, not the cause. The guard fires with "Refusing to overwrite — you may be missing chunk files from a previous session. Pass --force to override." Result: every commit that deletes a tracked file silently leaves stale nodes in graph.json. The user must either pass --force (which also disables the guard for legitimate failure modes) or manually re-run `graphify update . --force` after delete-heavy commits. Fix: thread a `had_explicit_deletions` flag from `_rebuild_code` into `_check_shrink`. When the caller has declared the deletions, the smaller graph is the expected outcome and the guard is skipped. The guard remains intact for SILENT shrinkage — its actual purpose — from failed semantic chunks or corrupted runs. The fix is opt-in by design: callers that don't pass `changed_paths` (e.g. the post-checkout full rebuild path) keep the old conservative behavior. Only paths that explicitly track deletions get the bypass. Tests added (tests/test_watch.py): - `test_check_shrink_blocks_silent_shrink` — pre-existing behavior intact - `test_check_shrink_allows_force_override` — pre-existing behavior intact - `test_check_shrink_allows_explicit_deletions` — new: deletion bypass - `test_check_shrink_allows_no_existing_data` — first-run case - `test_check_shrink_allows_growth` — sanity - `test_check_shrink_unlinks_tmp_on_refuse` — cleanup on refusal - `test_check_shrink_keeps_tmp_when_deletions_declared` — no spurious unlink - `test_rebuild_code_prunes_deleted_file_nodes` — end-to-end probe of the exact scenario the post-commit hook triggers (git init, build, delete one file, re-run with the deleted path in changed_paths, verify the graph shrinks and the surviving file's nodes are preserved) All 8 new tests pass; full test_watch.py + test_build.py + test_export.py (74 tests) pass with no regressions.
Merged
3 tasks done
PerryLin-0420
pushed a commit
to PerryLin-0420/graphify-decouple
that referenced
this pull request
Aug 13, 2026
…ns (Graphify-Labs#1000) The post-commit hook passes `git diff --name-only HEAD~1 HEAD` as changed_paths to `_rebuild_code`. That list includes deletions, and `_rebuild_code` correctly identifies them (lines 352-367 in watch.py) and evicts the stale nodes from the preserved set. The rebuilt graph is intentionally smaller. `_check_shrink` then refuses to overwrite the existing graph.json because it only sees the node-count delta, not the cause. The guard fires with "Refusing to overwrite — you may be missing chunk files from a previous session. Pass --force to override." Result: every commit that deletes a tracked file silently leaves stale nodes in graph.json. The user must either pass --force (which also disables the guard for legitimate failure modes) or manually re-run `graphify update . --force` after delete-heavy commits. Fix: thread a `had_explicit_deletions` flag from `_rebuild_code` into `_check_shrink`. When the caller has declared the deletions, the smaller graph is the expected outcome and the guard is skipped. The guard remains intact for SILENT shrinkage — its actual purpose — from failed semantic chunks or corrupted runs. The fix is opt-in by design: callers that don't pass `changed_paths` (e.g. the post-checkout full rebuild path) keep the old conservative behavior. Only paths that explicitly track deletions get the bypass. Tests added (tests/test_watch.py): - `test_check_shrink_blocks_silent_shrink` — pre-existing behavior intact - `test_check_shrink_allows_force_override` — pre-existing behavior intact - `test_check_shrink_allows_explicit_deletions` — new: deletion bypass - `test_check_shrink_allows_no_existing_data` — first-run case - `test_check_shrink_allows_growth` — sanity - `test_check_shrink_unlinks_tmp_on_refuse` — cleanup on refusal - `test_check_shrink_keeps_tmp_when_deletions_declared` — no spurious unlink - `test_rebuild_code_prunes_deleted_file_nodes` — end-to-end probe of the exact scenario the post-commit hook triggers (git init, build, delete one file, re-run with the deleted path in changed_paths, verify the graph shrinks and the surviving file's nodes are preserved) All 8 new tests pass; full test_watch.py + test_build.py + test_export.py (74 tests) pass with no regressions.
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
The post-commit hook (
graphify hook install) silently fails to prune nodes when a commit deletes a tracked file. After every delete-only commit, the rebuilt graph is correct in memory but never written to disk — the shrink-guard refuses to overwrite a largergraph.jsonwith a smaller one.Reproducible end-to-end on the current
v8tip:The nodes for the deleted file linger forever unless the user manually runs
graphify update . --force. Multiple cleanup commits compound the drift.Root cause
graphify/watch.py::_rebuild_codealready correctly handles deletions (lines 352-367): whenchanged_pathscontains a path that no longer exists on disk, it adds the path todeleted_pathsand uses it to evict the stale nodes from the preserved set. The rebuilt graph is intentionally smaller and correct.The bug is downstream:
_check_shrink(line 243) only sees the node-count delta and can't tell silent corruption ("a semantic chunk failed mid-extraction") from intentional shrinkage ("the user deleted a file"). It refuses both, and the in-memory result is dropped.Fix
Thread an opt-in
had_explicit_deletionsflag from_rebuild_codeinto_check_shrink:Both
_check_shrinkcall sites in_rebuild_codenow passhad_explicit_deletions=bool(deleted_paths). The guard remains intact for SILENT shrinkage (its actual purpose) — only callers that explicitly track deletions get the bypass. The post-checkout full-rebuild path doesn't passchanged_paths, so it keeps the old conservative behavior unchanged.The fix is the minimum needed to close the bug:
changed_paths--forcesemanticsTests
8 new tests in
tests/test_watch.py. All pass; no regressions acrosstest_watch.py,test_build.py,test_export.py(74 tests total, 72 pass, 2 pre-existing skips).test_check_shrink_blocks_silent_shrinktest_check_shrink_allows_force_overrideforce=Truestill bypassestest_check_shrink_allows_explicit_deletionstest_check_shrink_allows_no_existing_datatest_check_shrink_allows_growthtest_check_shrink_unlinks_tmp_on_refusetest_check_shrink_keeps_tmp_when_deletions_declaredtest_rebuild_code_prunes_deleted_file_nodesThe integration test is the load-bearing one — it reproduces the exact scenario the post-commit hook triggers, using a real
git init+ two-file project, and verifies the deleted file's nodes are pruned while the surviving file's nodes are preserved.Why this is the right shape
Three properties I tried to preserve:
changed_pathsat all — sohad_explicit_deletionsis False, the guard fires, the user sees the warning. The protection against silent corruption is unchanged.git diff --name-only HEAD~1 HEADwhich includes deletions. Now they propagate through correctly.I considered an alternative — computing an "expected shrink budget" from the average nodes-per-file and only bypassing within that budget — but it adds heuristic policy where the simpler trust-the-caller approach is correct: if the caller said deletions happened, they're declaring intent.
Test plan
uv run pytest tests/test_watch.py -v -k "check_shrink or prunes_deleted"— 8/8 passuv run pytest tests/test_watch.py tests/test_build.py tests/test_export.py— 72 pass, 2 pre-existing skipsuv run ruff check graphify/watch.py tests/test_watch.py— cleangraphify hook install+ commit that deletes a file → graph.json now updates correctly🤖 Generated with Claude Code