Skip to content

fix: word the hook reminders as facts, not orders - #4764

Closed
smngvlkz wants to merge 1 commit into
Graphify-Labs:v8from
smngvlkz:fix/hook-reminder-wording
Closed

smngvlkz wants to merge 1 commit into
Graphify-Labs:v8from
smngvlkz:fix/hook-reminder-wording

Conversation

@smngvlkz

Copy link
Copy Markdown
Contributor

Fixes #2202.

What this fixes

The graphify hook adds a reminder before searches and file reads. It was written as an order: "MANDATORY... You MUST run graphify", and the read one also said "include it in every subagent prompt". That shows up in the middle of the agent's tool output, so it looks just like a prompt injection. Agents in the issue flagged it as one and ignored it, which means the reminder did nothing.

What changed

  • the search and read reminders now just say what's there: the project has a graph, and graphify query / explain / path usually gets you the right files in far fewer tokens than grepping or reading files one by one
  • dropped "include it in every subagent prompt". Subagents already get their own reminder from the per agent budget (PreToolUse soft nudge has no session cap — measured 8,348 injections (~651k tokens) in a single project #3435), so they don't need to pass it on
  • strict mode still blocks the first read like before, I only took out the line asking to copy it into subagent prompts
  • the stale reminder was already worded as a fact, so it's unchanged

New reminders, as the hook prints them:

graphify: this project has a knowledge graph at graphify-out/graph.json. graphify query "<question>" returns the files and relations that matter for a question, usually in far fewer tokens than grepping raw files. Grep works best once the graph or an earlier read has pointed to the exact file and lines.

graphify: this project has a knowledge graph at graphify-out/graph.json. graphify query "<question>" (scoped subgraph), graphify explain "<concept>" and graphify path "<A>" "<B>" show which files and lines matter — usually in far fewer tokens than reading source files one by one. Reading a file directly works best once the graph has pointed to the exact lines.

How I tested it

  • added tests that check the reminders, both as written and as the hook actually prints them, don't contain "MANDATORY", "MUST" or ask to be copied into subagent prompts. They fail on current v8 and pass with this change
  • the existing hook tests looked for the word "MANDATORY" to tell a reminder fired, so I switched them to a phrase that's in the new reminders
  • all 621 hook tests pass
  • full test suite: 8,423 passed. The 8 that fail (7 in test_ext_tagged_id_clash.py, 1 in test_skill_no_backtick_substitution.py) fail the same way on v8 without this change

Heads up

@smngvlkz
smngvlkz requested a review from safishamsi as a code owner October 25, 2026 14:28
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @smngvlkz. 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.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Oct 25, 2026

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

No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.

Not checked: tests were not run; no formal proof of the changed code.


Graphify review — findings

Rewords the graphify hook reminders (_SEARCH_NUDGE, _READ_NUDGE, and the strict _READ_DENY) to state facts about the knowledge graph instead of commanding the agent ("MANDATORY", "You MUST", "include this in every subagent prompt"). Because they arrive in the tool-result stream, the old wording reads like a prompt injection and gets ignored or flagged (#2202). The strict deny no longer asks the agent to pass the rule on to subagents, since each subagent already gets its own nudge budget. Existing hook tests now match on "knowledge graph at" instead of "MANDATORY", and a new test_hook_nudge_wording.py fails if any nudge, including the emitted output of _run_hook_guard, reintroduces command-style phrasing.

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

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 443 functions depend on the 188 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: _run_hook_guard() — 5 callers, 14 callees

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

Test selection

Test selection

36 of 454 test file(s) selected (8%) via static blast radius.

  • tests/test_affected_cli.py — impact
  • tests/test_agents_platform.py — impact
  • tests/test_cli_export.py — impact
  • tests/test_cloud_cta.py — impact
  • tests/test_codebuddy.py — impact
  • tests/test_compact_graph_json.py — impact
  • tests/test_dedup_shrink_refuses_force_write.py — impact
  • tests/test_devin.py — impact
  • tests/test_explain_cli.py — impact
  • tests/test_explain_same_file_tie.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_guard.py — impact, changed-test
  • tests/test_hook_guard_token_match.py — impact
  • tests/test_hook_nudge_wording.py — impact, changed-test
  • tests/test_hook_out_of_project_paths.py — impact, changed-test
  • tests/test_hook_strict.py — impact, changed-test
  • tests/test_incomplete_build_guard.py — impact
  • tests/test_install.py — impact
  • tests/test_install_references.py — impact
  • tests/test_lookup_exit_codes.py — impact
  • tests/test_merge_chunks_validation.py — impact
  • tests/test_multigraph_diagnostics.py — impact
  • tests/test_no_dedup_flag.py — impact
  • tests/test_opencode_plugin_refresh.py — impact
  • tests/test_partial_cache.py — impact
  • tests/test_path_cli.py — impact
  • tests/test_query_cli.py — impact
  • tests/test_query_induced_edges.py — impact
  • tests/test_query_seeds.py — impact
  • tests/test_skill_auto_refresh.py — impact
  • tests/test_stale_prune.py — impact
  • tests/test_truncation_full_answer.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.

· 1 more finding(s) on lines outside this diff (see the check run).

@safishamsi

Copy link
Copy Markdown
Member

Landed in v0.9.96, now on PyPI (pip install graphifyy==0.9.96). Hook reminders are worded as facts, not orders. Thanks for the fix, @smngvlkz.

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

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Claude Code strict-mode hook reminder reads as prompt injection to a subagent (MANDATORY + self-propagation phrasing)

2 participants