Skip to content

fix(hooks): emit the hook-guard nudge once per session per kind (#2984) - #2985

Open
yotamleo wants to merge 6 commits into
Graphify-Labs:v8from
yotamleo-org:fix/hook-guard-session-nudge-throttle
Open

yotamleo wants to merge 6 commits into
Graphify-Labs:v8from
yotamleo-org:fix/hook-guard-session-nudge-throttle

Conversation

@yotamleo

Copy link
Copy Markdown
Contributor

Closes #2984.

The problem

hook-guard search / hook-guard read emit their nudge on every matching tool call. Nothing tracks that the agent has already been told, so re-reading one file re-prints the identical MANDATORY: graphify-out/graph.json exists... line each time.

Measured on 0.9.48 over 10,506 Claude Code session transcripts from a single repo:

Metric Value
hook-guard search / read firings 1,739
Sessions those landed in 42
Resulting graphify query / explain calls 21
Conversion ~1.2%
Est. cost ~55 tokens/firing → ~95K tokens

#1840 scoped the nudge to the graph's own project root, which is a different half of the problem — the numbers above are from after it shipped. It changed whether a call is in scope, not how often an in-scope reminder repeats.

Repro

In a project with a built graph, wire the default hooks (graphify install) and read the same source file three times in one session. The nudge fires three times, identically.

The fix

The nudge is orientation, not information: once the agent has been told the graph exists it has either used it or decided not to, and repeating that only spends the context window the hook is trying to protect.

_mark_session_denied already did exactly this once-per-session claim for the strict block — an O_CREAT | O_EXCL marker under graphify-out/cache/hook_sessions/. So rather than inventing a second mechanism, that helper is generalized to _claim_session_marker(session_id, suffix, on_error), and _nudge_once() takes a marker per kind (search / read). The strict marker filename ({sid}.denied) is unchanged.

Two details worth flagging in review:

  • The two callers need opposite fail directions, hence the explicit on_error argument. If a claim can't be tracked at all, the strict deny must not fire (never block a read on a bug) while the nudge must still print (never go silent). Guessing one direction for both would be wrong in one of them.
  • Directory setup moved out of the claim's try block. An unusable cache path can itself raise FileExistsError from mkdir, which the old single-block shape would have read as "already claimed" — i.e. silently fail closed. Separating them keeps the FileExistsError catch attached only to the os.open that actually means it.

The strict deny keeps its own marker, so a denied read still leaves the session its one soft nudge. Stale reads share the read budget (same reminder, softer words). Scoping stays orthogonal: a call #1840 declines to nudge for does not spend the budget.

GRAPHIFY_HOOK_NUDGE_ONCE=0 restores the previous nudge-every-call behaviour, matching the GRAPHIFY_HOOK_STRICT toggle convention. README updated next to the strict-mode note.

Scope

Once-per-session-per-kind only. The issue also floated N-per-session and once-per-file; happy to add a count if you'd prefer it configurable, but a fixed 1 seemed like the honest default and the smaller change. hook-guard gemini is untouched — it reads no stdin and so has no session id.

Tests

tests/test_hook_nudge_throttle.py — 10 cases. The fail-open paths get equal weight to the happy path: untrackable session keeps nudging, unusable cache dir keeps nudging, out-of-project call doesn't spend the budget, strict deny doesn't eat the following nudge, kill switch restores every-call.

pytest tests/ is green apart from 15 failures that are identical on v8 at b2cd362 (Windows-only: fifo/unix-socket/symlink, install paths). Full suite run on Windows/py3.12; ruff --config pyproject.toml and tools.skillgen --check clean.

No CHANGELOG entry — the history suggests those land in your own batched docs(changelog) commits. Say the word and I'll add one.

@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. 2 change(s) tested, no difference found (not proven).


Graphify review — findings

Adds a once-per-session throttle to the PreToolUse hook nudge via a new _nudge_once/_claim_session_marker helper, refactoring _mark_session_denied onto that shared marker-claim logic so each nudge kind (search/read) fires at most once per session. Guards the strict deny path to keep its own claim separate from the nudge budget, and adds GRAPHIFY_HOOK_NUDGE_ONCE=0 to restore always-nudge behavior; untrackable sessions and unwritable caches fall back to the historical every-call nudge. Includes tests/test_hook_nudge_throttle.py and README docs for the new frequency behavior.

No blocking issues surfaced. 5 lower-confidence candidates did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 287 functions depend on the 101 functions this change touches.

Health — this change adds coupling hotspots:

  • new: dispatch_command() — 2 callers, 119 callees
  • new: _run_hook_guard() — 6 callers, 8 callees
  • new: _stale_graph_sources() — 7 callers, 6 callees
  • new: test_poisoned_manifest_is_healed() — 0 callers, 6 callees

Verification — 287 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: 240 function(s) in the blast radius were not formally verified this run

Formal verification

No difference found (not proven): No behavior difference found in \_mark\_session\_denied (not a proof).

The verifier ran both versions of \_mark\_session\_denied 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.

No difference found (not proven): No behavior difference found in \_run\_hook\_guard (not a proof).

The verifier ran both versions of \_run\_hook\_guard 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; 3 more finding(s) on lines outside this diff (see the check run).

Comment thread graphify/cli.py
v = os.environ.get("GRAPHIFY_HOOK_NUDGE_ONCE", "").strip().lower()
if v in ("0", "false", "no", "off"):
return True
return _claim_session_marker(session_id, f"{kind}.nudged", on_error=True)


def _run_hook_guard(kind: str, strict: bool = False) -> None:

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 — _run_hook_guard()

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fair catch — the throttle did add a callee to _run_hook_guard(), so I've paid it back and then some rather than just arguing about the delta.

_strict_denies(d, fp, root, strict) now holds the strict-block precondition chain, which was inline in the guard body. Counting distinct call targets in the function:

module-local callees all call targets
base (v8 @ b2cd362) 5 33
this PR before the refactor 6 34
now 3 31

So the guard ends up below where it started rather than back at parity. Afferent coupling is untouched by this PR — it adds no new callers of _run_hook_guard.

Behaviour is identical, and one detail is worth flagging for review since it's the only way this extraction could have gone wrong: the last term of that chain, _mark_session_denied(), mutates — it claims the session's one strict-block marker. Left-to-right short-circuit evaluation is what stops an ineligible read from reaching it and silently spending that block. The chain is moved intact and in order, and there's now a test pinning it directly (a read of a file the graph doesn't index must produce the soft nudge and leave <session>.denied uncreated, so the next eligible read still denies).

Happy to drop the extraction and take the +1 instead if you'd rather a feature PR didn't touch the surrounding predicate — it's a self-contained commit.

@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.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.

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


Graphify review — findings

Throttles the PreToolUse soft nudge to fire at most once per session per kind (search/read) via a new _claim_session_marker helper, with GRAPHIFY_HOOK_NUDGE_ONCE=0 to restore always-nudge behaviour. Refactors _mark_session_denied onto that shared marker primitive and extracts the strict-deny preconditions into _strict_denies, keeping the one-time block out of the nudge budget so a denied read still gets its soft nudge. Adds tests/test_hook_nudge_throttle.py covering the per-kind budgets, the untrackable-session/unwritable-cache fallbacks, and the kill switch, plus a README note.

Worth a look

  • Default hook nudge behavior changed from every call to once per session — graphify/cli.py:583 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 294 functions depend on the 108 functions this change touches.

Health — this change adds coupling hotspots:

  • new: dispatch_command() — 2 callers, 119 callees
  • new: _stale_graph_sources() — 7 callers, 6 callees
  • new: _run_hook_guard() — 7 callers, 5 callees
  • new: test_poisoned_manifest_is_healed() — 0 callers, 6 callees

Verification — 294 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: 247 function(s) in the blast radius were not formally verified this run

Formal verification

No difference found (not proven): No behavior difference found in \_mark\_session\_denied (not a proof).

The verifier ran both versions of \_mark\_session\_denied 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.

No difference found (not proven): No behavior difference found in \_run\_hook\_guard (not a proof).

The verifier ran both versions of \_run\_hook\_guard 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; 3 more finding(s) on lines outside this diff (see the check run).

Comment thread graphify/cli.py
and not _query_stamp_fresh()
and _target_is_indexed(fp, root)
and _mark_session_denied(str(d.get("session_id") or ""))
)


def _run_hook_guard(kind: str, strict: bool = False) -> None:

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 — _run_hook_guard()

7 callers depend on it (afferent coupling).

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks — the callee half looks clear now, and the afferent number was mine too: the new tests were calling _run_hook_guard() from three separate places in one file, because two cases had each grown a local copy of the stdin/stdout plumbing just to pass strict=True.

_invoke() takes a strict flag now and every case in the file goes through it, so that file is back to a single call site. Net effect on callers of _run_hook_guard(): 3 → 1 from this PR's tests.

Coupling summary for the PR as it stands, against v8 @ b2cd362:

module-local callees all call targets
base 5 33
now 3 31

Behaviour is unchanged throughout — the consolidation is test plumbing only, and the suite is the same 163 passing hook tests before and after.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Measured this one from clean checkouts of v8 @ b2cd362 and this branch's head, counting repo-wide (callers include test modules):

Ca Ce Ca·Ce
base 4 8 32
this PR 5 6 30

So the product is below where it started, and Ce is down 2 against base rather than up.

The one number that rose is Ca, by exactly 1, and it's the new test module: Ca here counts test files, and each tests/test_hook_*.py contributes its own _invoke helper — test_hook_guard.py, test_hook_strict.py and test_hook_out_of_project_paths.py are already three of the four callers on base. test_hook_nudge_throttle.py is the fourth, following the same one-module-per-hook-feature layout test_hook_strict.py established.

I've stopped here deliberately. The two ways left to push the product lower are to fold these tests into an existing module against that layout, or to decompose _run_hook_guard() itself into per-kind handlers — and the second is a restructuring of your hook entry point that a throttle PR has no business making uninvited. Happy to do either if you'd like it, but I'd rather you chose it than have me assume it.

For the record, the full sequence on this function: 8 callees / 6 callers → callee clause cleared → 7 callers → Ca·Ce 25 by your counter, 30 by mine, against a base of 32.

@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.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.

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


Graphify review — findings

Throttles the hook-guard soft nudge to fire at most once per session per kind (search/read), keyed off O_EXCL marker files, with GRAPHIFY_HOOK_NUDGE_ONCE=0 as a kill switch and untrackable sessions falling back to always-nudge. Refactors _mark_session_denied onto a shared _claim_session_marker helper and extracts the strict-block preconditions into _strict_denies, keeping the deny's session claim off the nudge budget. Adds tests/test_hook_nudge_throttle.py and a README note.

Worth a look

  • Stale-marker GC can unlink a freshly recreated session marker — graphify/cli.py:585 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 295 functions depend on the 109 functions this change touches.

Health — this change adds coupling hotspots:

  • new: dispatch_command() — 2 callers, 119 callees
  • new: _stale_graph_sources() — 7 callers, 6 callees
  • new: _run_hook_guard() — 5 callers, 5 callees
  • new: test_poisoned_manifest_is_healed() — 0 callers, 6 callees

Verification — 295 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: 248 function(s) in the blast radius were not formally verified this run

Formal verification

No difference found (not proven): No behavior difference found in \_mark\_session\_denied (not a proof).

The verifier ran both versions of \_mark\_session\_denied 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.

No difference found (not proven): No behavior difference found in \_run\_hook\_guard (not a proof).

The verifier ran both versions of \_run\_hook\_guard 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; 3 more finding(s) on lines outside this diff (see the check run).

Comment thread graphify/cli.py
and not _query_stamp_fresh()
and _target_is_indexed(fp, root)
and _mark_session_denied(str(d.get("session_id") or ""))
)


def _run_hook_guard(kind: str, strict: bool = False) -> None:

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 — _run_hook_guard()

high coupling complexity (Ca·Ce = 25).

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

yotamleo and others added 5 commits September 1, 2026 13:07
…hify-Labs#2984)

The PreToolUse nudge had no throttle, so the identical MANDATORY line was
re-emitted on every matching call — including repeated reads of the same file.
Measured on 0.9.48 across 10,506 Claude Code session transcripts in one repo:
1,739 firings across 42 sessions produced 21 `graphify query`/`explain` calls,
a ~1.2% conversion at roughly 55 tokens a firing. Graphify-Labs#1840 scoped the nudge to the
graph's own project, which is a different half of the problem; it did not
change how often an in-scope nudge repeats.

The nudge is orientation, not information: once an agent has been told the
graph exists it has either used it or decided not to, and repeating that
spends the one resource the hook is trying to help it spend well.

`_mark_session_denied`'s O_EXCL marker already did exactly this claim for the
strict block, so it is generalized to `_claim_session_marker(session_id,
suffix, on_error)` and the nudge takes a second marker per kind. The two
callers need opposite fail directions, hence the explicit `on_error`: an
untrackable claim must never block a read, and must never silence the nudge
either. Directory setup moved out of the claim's try block so an unusable
cache path cannot raise FileExistsError and be misread as "already claimed".

The strict deny keeps its own marker, so a denied read still leaves the
session its one soft nudge. `GRAPHIFY_HOOK_NUDGE_ONCE=0` restores the old
behaviour.

Co-Authored-By: Claude Fable 5 <[email protected]>
)

One nudge per session per kind, search and read budgets independent, a new
session gets its own, and the stale variant spends the read budget. The
fail-open paths get equal weight: an untrackable session and an unusable
cache dir must both keep nudging rather than go silent, an out-of-project
call must not spend the budget, and the strict deny must not eat the soft
nudge that follows it.

Co-Authored-By: Claude Fable 5 <[email protected]>
…rd (Graphify-Labs#2984)

The coupling check on this PR flagged _run_hook_guard()'s efferent fan-out.
Adding the nudge throttle did grow it, so rather than only paying that back,
the strict-block precondition chain moves into _strict_denies() and the guard
body ends up leaner than it started: module-local callees go 5 (base) -> 6
(with the throttle) -> 3, and total call targets 33 -> 34 -> 31.

Behaviour is identical. The chain is left intact and in order inside the new
predicate, which matters more than it looks: its last term claims the session
marker, so an ineligible read reaching it would silently spend that session's
single strict block. Python's left-to-right short-circuit is what prevents
that, and the extraction preserves it — a test now pins it directly, via a
read of a file the graph does not index.

Also stop the tests inheriting GRAPHIFY_HOOK_NUDGE_ONCE from the environment,
which would quietly turn the default-behaviour cases into kill-switch cases.

Co-Authored-By: Claude Fable 5 <[email protected]>
…raphify-Labs#2984)

Two cases had grown their own local copy of the stdin/stdout plumbing just to
pass strict=True, so the suite called _run_hook_guard() from three places for
no reason. _invoke() takes a strict flag instead and every case goes through
it, which is what the rest of the file already did.

Co-Authored-By: Claude Fable 5 <[email protected]>
@yotamleo
yotamleo force-pushed the fix/hook-guard-session-nudge-throttle branch from f922142 to 498bc9d Compare September 1, 2026 13:27

@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.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.

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


Graphify review — findings

Throttles the PreToolUse soft nudge to at most once per session per kind (read/search) via _nudge_once, which claims a once-per-session marker through the new shared _claim_session_marker; untrackable sessions or unwritable caches fall back to always nudging, and GRAPHIFY_HOOK_NUDGE_ONCE=0 disables the throttle entirely. Extracts the strict-block preconditions into _strict_denies with load-bearing short-circuit order so a non-eligible read never burns the session's single block, and keeps that deny separate from the nudge budget so a denied read still gets its one soft nudge. Hardens _claim_session_marker to treat cache-prep errors as fail-open rather than misreading them as an existing claim.

Worth a look

  • Soft search hook no longer emits nudges on repeated calls by default — graphify/cli.py:923 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 325 functions depend on the 116 functions this change touches.

Health — this change adds coupling hotspots:

  • new: dispatch_command() — 2 callers, 123 callees
  • new: _stale_graph_sources() — 7 callers, 6 callees
  • new: _run_hook_guard() — 5 callers, 6 callees
  • new: test_poisoned_manifest_is_healed() — 0 callers, 6 callees

Verification — 325 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: 271 function(s) in the blast radius were not formally verified this run

Formal verification

No difference found (not proven): No behavior difference found in \_mark\_session\_denied (not a proof).

The verifier ran both versions of \_mark\_session\_denied 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.

No difference found (not proven): No behavior difference found in \_run\_hook\_guard (not a proof).

The verifier ran both versions of \_run\_hook\_guard 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; 3 more finding(s) on lines outside this diff (see the check run).

Comment thread graphify/cli.py
)


def _run_hook_guard(kind: str, strict: bool = False) -> None:

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 — _run_hook_guard()

fans out to 6 callees (efferent coupling).

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Re-measured against the current base — v8 has moved since the last round, so this branch's merge-base is now 33362d9 rather than the b2cd362 my earlier numbers were against.

From clean checkouts of v8 @ 33362d9 and this branch's head 498bc9d, walking the AST repo-wide (tests included):

Ca Ce (repo-defined callees, bare-name calls) Ca·Ce
base 33362d9 1 7 7
this PR 498bc9d 1 5 5

Counting every call target, including attribute and stdlib calls: Ce 28 → 26, Ca 2 → 2.

At the edge level, which is the part that doesn't depend on whose counter you use: the branch removes _hook_strict_enabled, _mark_session_denied, _query_stamp_fresh and _target_is_indexed from the guard body — they moved into _strict_denies — and adds _nudge_once and _strict_denies. Net -2 callees. Afferent coupling is untouched: the same callers as base, with no new one from this branch.

So the function ends below where it started on both axes, and the "6 callees" in this round is an absolute count rather than a rise this branch caused.

I've deliberately stopped restructuring it here, for the same reason as the earlier round: the two ways left to push the number lower are to fold the new tests into an existing module against the one-module-per-hook-feature layout test_hook_strict.py established, or to decompose _run_hook_guard() into per-kind handlers — and the second is a restructuring of your hook entry point that a throttle PR has no business making uninvited. Either is a small change and I'll do whichever you prefer; I'd just rather you picked it than have me assume it.

@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.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.

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


Graphify review — findings

Throttles the Claude Code hook-guard soft nudge to fire at most once per session per kind (read vs. search) via _nudge_once, which claims a marker so an oriented agent isn't reminded on every later call and wastes context; set GRAPHIFY_HOOK_NUDGE_ONCE=0 to restore nudge-on-every-call. Refactors the one-time strict-deny claim and the new nudge claim onto a shared _claim_session_marker, where an untrackable session or unwritable cache returns each caller's on_error default — the deny fails closed (never blocks) and the nudge fails open (keeps nudging). Pulls strict-deny eligibility into _strict_denies with a load-bearing short-circuit order so a non-eligible read never burns the session's single block, and keeps the deny's claim off the nudge budget so a denied read still gets its one soft nudge.

Worth a look

  • Stale-marker GC can unlink a freshly recreated session marker — graphify/cli.py:744 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 335 functions depend on the 116 functions this change touches.

Health — this change adds coupling hotspots:

  • new: dispatch_command() — 2 callers, 125 callees
  • new: _stale_graph_sources() — 7 callers, 6 callees
  • new: _run_hook_guard() — 5 callers, 6 callees
  • new: test_poisoned_manifest_is_healed() — 0 callers, 6 callees

Verification — 335 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: 273 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

284 of 284 test file(s) selected (100%) via static blast radius.

Escalated to a full run for safety — the selection is not trustworthy on its own (see below). CI should run the whole suite.

  • tests/test_affected_cli.py — impact, full-run-safety
  • tests/test_affected_member_seed.py — full-run-safety
  • tests/test_agents_platform.py — impact, full-run-safety
  • tests/test_analyze.py — full-run-safety
  • tests/test_anthropic_custom_endpoint.py — full-run-safety
  • tests/test_antigravity_install.py — full-run-safety
  • tests/test_apm_fallback_version.py — full-run-safety
  • tests/test_architecture_doc.py — full-run-safety
  • tests/test_astro_extraction.py — full-run-safety
  • tests/test_astro_import_ids.py — full-run-safety
  • tests/test_atomic_canvas_export.py — full-run-safety
  • tests/test_atomic_version_stamp.py — full-run-safety
  • tests/test_atomic_writes.py — full-run-safety
  • tests/test_backend_env_isolation.py — full-run-safety
  • tests/test_backend_extras.py — full-run-safety
  • tests/test_benchmark.py — full-run-safety
  • tests/test_benchmark_raw_graph.py — full-run-safety
  • tests/test_build.py — full-run-safety
  • tests/test_build_merge_dedup_scope.py — full-run-safety
  • tests/test_build_merge_hyperedges_and_prune.py — full-run-safety
  • tests/test_build_merge_shrink_guard.py — full-run-safety
  • tests/test_builtin_global_type_refs.py — full-run-safety
  • tests/test_cache.py — full-run-safety
  • tests/test_callflow_html.py — full-run-safety
  • tests/test_cargo_introspect.py — full-run-safety
  • tests/test_carried_hyperedge_remap.py — full-run-safety
  • tests/test_case_sensitive_resolution.py — full-run-safety
  • tests/test_charmap_encoding.py — full-run-safety
  • tests/test_chunking.py — full-run-safety
  • tests/test_cjs_module_extension.py — full-run-safety
  • tests/test_claude_cli_backend.py — full-run-safety
  • tests/test_claude_md.py — full-run-safety
  • tests/test_cli_broken_pipe.py — full-run-safety
  • tests/test_cli_export.py — full-run-safety
  • tests/test_cli_help.py — full-run-safety
  • tests/test_cluster.py — full-run-safety
  • tests/test_codebuddy.py — impact, full-run-safety
  • tests/test_community_hub_labels.py — full-run-safety
  • tests/test_community_labels_skill.py — full-run-safety
  • tests/test_confidence.py — full-run-safety
  • tests/test_corrupt_graph_json.py — full-run-safety
  • tests/test_cpp_nested_and_cli.py — full-run-safety
  • tests/test_cpp_objc_cross_file_calls.py — full-run-safety
  • tests/test_cpp_preprocess.py — full-run-safety
  • tests/test_cross_extension_reexport_self_cycle.py — full-run-safety
  • tests/test_cross_language_call_resolution.py — full-run-safety
  • tests/test_cross_repo_external_call_guards.py — full-run-safety
  • tests/test_cross_repo_member_calls.py — full-run-safety
  • tests/test_cross_repo_shared_types.py — full-run-safety
  • tests/test_csharp_call_site_generic_args.py — full-run-safety
  • … and 234 more

non-code file(s) changed (README.md) → running the full suite for safety (a code graph can't see config/fixture/data deps)

changed code file(s) with no mapped test (README.md) — a coverage gap or a missing link — running the full suite rather than only the selected tests

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 \_mark\_session\_denied (not a proof).

The verifier ran both versions of \_mark\_session\_denied 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.

No difference found (not proven): No behavior difference found in \_run\_hook\_guard (not a proof).

The verifier ran both versions of \_run\_hook\_guard 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; 3 more finding(s) on lines outside this diff (see the check run).

Comment thread graphify/cli.py
)


def _run_hook_guard(kind: str, strict: bool = False) -> None:

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 — _run_hook_guard()

fans out to 6 callees (efferent coupling).

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

This branch has not been deployed

No deployments
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.

hook-guard: Read/Glob PreToolUse nudge has no session-scoped rate limit — fires on every matching call

1 participant