Skip to content

fix(hooks): report hooks written by an older release as out of date (#3771) - #3951

Closed
bercedev wants to merge 1 commit into
Graphify-Labs:v8from
bercedev:fix/hook-status-stale-block
Closed

bercedev wants to merge 1 commit into
Graphify-Labs:v8from
bercedev:fix/hook-status-stale-block

Conversation

@bercedev

Copy link
Copy Markdown
Contributor

What does this PR do?

Refs #3771.

Upgrading the package never touches hooks that are already on disk. So a repo that ran graphify hook install before a hook fix (for example the #2253 console-window launcher) keeps running the old script. Until now, graphify hook status still said installed, so nothing told the user the hook was stale.

status now compares the graphify block in each hook with the current template and reports blocks from an older release:

$ graphify hook status        # repo whose hooks were written by 0.9.25
post-commit: installed (out of date: run `graphify hook install` to refresh it)
post-checkout: installed (out of date: run `graphify hook install` to refresh it)
merge driver: registered

$ graphify hook install
post-commit: updated existing post-commit hook at .../.git/hooks/post-commit
post-checkout: updated existing post-checkout hook at .../.git/hooks/post-checkout
merge driver: already registered (graphify-out/graph.json merge=graphify)

$ graphify hook status
post-commit: installed
post-checkout: installed
merge driver: registered

Before this change, the first status printed installed for both hooks.

The comparison only looks at the text between the start and end markers, so user content around the block doesn't count. It also ignores the two values that differ per install: the _PINNED interpreter path and the GRAPHIFY_VIZ_NODE_LIMIT export. status already checks the viz limit against .graphifyrc separately. The refresh itself needed no change, because hook install already rewrites an existing block in place.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

Invariant: hook status says plain installed only when the installed graphify block is the one the current release would write, apart from its per-install values.

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary.
  • Added a regression test (if bug fix) or isolated boundary test.
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly.

Limitations:

  • This makes stale hooks visible. It does not refresh them automatically, because nothing runs when the package is upgraded. Each repo still needs graphify hook install. Refreshing automatically (for example from the hook itself) would be a bigger change, so I left it for you to decide.
  • Hooks copied from an init.templateDir template are checked once they are in a repo, but the template itself is not checked or updated.
  • A block with no end marker is not flagged. hook install can't rewrite those in place either.

How was this tested?

# new tests against the unchanged v8 hooks.py
.venv/bin/python -m pytest -q tests/test_hooks.py -k "<the 3 new tests>"
FAILED tests/test_hooks.py::test_status_flags_a_hook_block_from_an_older_graphify
1 failed, 7 passed

# with the fix
.venv/bin/python -m pytest -q tests/test_hooks.py
121 passed

.venv/bin/python -m pytest -q
6164 passed, 14 skipped

test_status_flags_a_hook_block_from_an_older_graphify is the regression test. The other two guard against false positives: a different pinned interpreter, and user lines outside the graphify block, must still report installed. They pass both before and after.

I also installed hooks with the real 0.9.25 hooks.py into a scratch repo, then ran status and install from this branch. The output is shown above.

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments.
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.

Note: I used Claude Code while working on this fix. I reviewed and ran all of it myself.

…raphify-Labs#3771)

Upgrading the package never touches hooks already on disk, so repos
initialised before a hook fix (such as the Graphify-Labs#2253 console-window launcher)
keep running the old script while `graphify hook status` says
"installed". Status now compares the installed graphify block with the
current template, ignoring the two per-install values (the pinned
interpreter and the viz limit export), and tells the user to run
`graphify hook install`, which already rewrites the block in place.
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @bercedev. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).

Formal verification. 1 change(s) tested, no difference found (not proven).


Graphify review — findings

Makes status report a hook as "installed (out of date: run graphify hook install to refresh it)" when its graphify block differs from what the current release would write. Package upgrades never rewrite hooks already on disk (#3771). The comparison covers only the text between the block's start and end markers, with the pinned interpreter (_PINNED) and the viz-limit export blanked. That way, user commands around the block or a different install-time Python don't trigger the warning. A block with no end marker skips the check and still reports plain "installed".

No blocking issues surfaced. 1 lower-confidence candidate did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 430 functions depend on the 236 functions this change touches.

Health — this change adds coupling hotspots:

  • new: main() — 98 callers, 3 callees
  • new: install() — 40 callers, 7 callees
  • new: dispatch_command() — 2 callers, 126 callees
  • new: status() — 11 callers, 6 callees
  • new: dispatch_install_cli() — 2 callers, 31 callees
  • new: uninstall() — 9 callers, 5 callees
  • new: _run_cli() — 6 callers, 7 callees
  • new: uninstall_all() — 2 callers, 13 callees
  • …and 1 more — each is listed as a finding

Verification — 430 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 251 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

22 of 308 test file(s) selected (7%) via static blast radius.

  • tests/test_affected_cli.py — impact
  • tests/test_agents_platform.py — impact
  • tests/test_codebuddy.py — impact
  • tests/test_devin.py — impact
  • tests/test_explain_cli.py — impact
  • tests/test_extract_cli.py — impact
  • tests/test_global_add_tag_inference.py — impact
  • tests/test_god_nodes_cli.py — impact
  • tests/test_hollow_chunks_arm_shrink_guard.py — impact
  • tests/test_hook_chain_survives_skip.py — impact
  • tests/test_hooks.py — impact, changed-test
  • tests/test_incomplete_build_guard.py — impact
  • tests/test_install.py — impact
  • tests/test_install_references.py — impact
  • tests/test_merge_chunks_validation.py — impact
  • tests/test_multigraph_diagnostics.py — impact
  • tests/test_no_dedup_flag.py — impact
  • tests/test_path_cli.py — impact
  • tests/test_query_cli.py — impact
  • tests/test_query_induced_edges.py — impact
  • tests/test_skill_auto_refresh.py — impact
  • tests/test_unverified_semantic_shrink.py — impact

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Formal verification

No difference found (not proven): No behavior difference found in status (not a proof).

The verifier ran both versions of status on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

· 1 grounded finding(s) anchored inline below; 8 more finding(s) on lines outside this diff (see the check run).

Comment thread graphify/hooks.py
return _VIZ_EXPORT_LINE_RE.sub("", _PINNED_LINE_RE.sub("_PINNED=''", block))


def status(path: Path = Path(".")) -> str:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Health regression — status()

fans out to 6 callees (efferent coupling); 11 callers depend on it (afferent coupling).

Grounded coupling-delta finding (deterministic), not an LLM guess.

safishamsi added a commit that referenced this pull request Sep 30, 2026
Solidity free functions (#3906), VB.NET qualified calls (#3909), Astro
frontmatter-only AST pass (#3902), surprise bonus/reason alignment (#3934),
exclude-hubs stranded-neighbour (#3933), graph-DB push index (#3957),
label retry keep-named (#3956), stale-hook status (#3951), virtual-workspace
Cargo.toml skip (#3930), and symlinked-instructions install/uninstall
handling (#3950/#3953).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.73 (now on PyPI) via an authorship-preserving cherry-pick, so your commit keeps contributor-graph credit. Thanks @bercedev!

Release: https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.73

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants