Repository navigation
fix(query): keep a same-label seed when it is the only match for a query term (#5027) - #5032
Vaibhav2824 wants to merge 1 commit into
Conversation
…ery term (Graphify-Labs#5027) `_pick_seeds` caps seeds at one per normalized label so homonymous symbols (dozens of `GET` handlers) cannot flood the BFS (Graphify-Labs#1766). The per-term guarantee loop (Graphify-Labs#1445) applied the same cap, so a node that is `best_seed_by_term[t]` was dropped whenever a higher-scoring node with the same label was already seeded. When `t` is not part of that label, the node won `t` through its source path, rationale or attributes, and the seeded twin may not match `t` at all. The term was then left with no seed, breaking the docstring's "at least one seed per distinct query term" guarantee. Example: two `PreToolUse` classes in different plugins, where only one path contains the query term `alpha`. Narrow the cap in the per-term loop: skip a same-label winner only when `term` is a substring of the shared normalized label. Then the seeded twin matches `term` through that label (the same `t in norm_label` test the scorer uses), so the term is already covered. Graphify-Labs#1766 still holds: a second `GET` cannot be added for the term `get`. The first loop is unchanged; a node it skips that is the only match for a term is now added by the per-term loop. Tests: the issue's 3-node repro (fails before the fix), and a degree tie-break case where a second `GET` wins the term `get` per term. That case is still capped, and it fails if the cap is removed entirely. The existing Graphify-Labs#1766 per-term test cannot catch that, because its per-term winner is already the first-loop seed. Co-Authored-By: Claude <[email protected]>
|
Thanks for the pull request, @Vaibhav2824. 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. |
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
There was a problem hiding this comment.
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; formal verification proved 0 of 1 changed function(s) (1 sampled, not proven).
Formal verification. PR-changed functions: 1/1 verified (0 proven, 1 may-equivalent, 0 distinguished) · 0 not verified.
Graphify review — findings
Relaxes the per-label seed cap in _pick_seeds so the per-term guarantee can seed a same-label node when it is the best match for a query term that isn't in the shared label. Before, a node like a second PreToolUse that was the only match for alpha (via its source path) was dropped because a twin with the same label was already seeded, leaving alpha with no seed. When the term is in the label, the cap still applies, so generic duplicates like multiple GET nodes aren't reintroduced (#1766). Adds two tests, one for each side of that rule.
No blocking issues surfaced. 1 lower-confidence candidate did not survive cross-model review.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 908 functions depend on the 451 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
_score_query()— 23 callers, 7 callees
Verification — 908 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: 683 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
26 of 526 test file(s) selected (5%) via static blast radius.
tests/test_4874_jvm_resolution.py— impacttests/test_affected_cli.py— impacttests/test_affected_path_file_node.py— impacttests/test_affected_seed_reference_forms.py— impacttests/test_benchmark.py— impacttests/test_benchmark_raw_graph.py— impacttests/test_benchmark_real_query.py— impacttests/test_confidence_score_output.py— impacttests/test_edge_also_seen.py— impacttests/test_explain_same_file_tie.py— impacttests/test_extract.py— impacttests/test_file_label_disambiguation.py— impacttests/test_mcp_graph_view_cache.py— impacttests/test_path_cli.py— impacttests/test_path_confidence.py— impacttests/test_path_type_member.py— impacttests/test_query_induced_edges.py— impacttests/test_query_mcp_direction.py— impacttests/test_query_names_its_graph.py— impacttests/test_query_seed_order.py— impacttests/test_query_seeds.py— impacttests/test_query_source_first.py— impacttests/test_serve.py— impact, changed-testtests/test_serve_http.py— impacttests/test_terraform.py— impacttests/test_truncation_full_answer.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 \_pick\_seeds (not a proof).
The verifier ran both versions of \_pick\_seeds 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 more finding(s) on lines outside this diff (see the check run).
|
Landed on |
Summary
Fixes #5027.
In
_pick_seeds(), seed candidates are deduplicated by normalized label so that generic symbols (e.g. repeatedGET()route handlers) cannot take every BFS seed slot (#1766). The same cap was also applied, unconditionally, in the per-term seed guarantee loop (#1445). When two distinct nodes share a label (such asPreToolUsein two different plugins) and one of them is the only match for a query term, that node was dropped because its label was already seeded. The term was left with no seed, and the query never reached that node.Changes
graphify/serve.py(_pick_seeds): the label cap in the per-term loop now applies only when the term is part of the shared label (key not in seen_labels or term not in key). In that case the already-seeded node matches the term through the same label, so the term is covered. Otherwise the candidate won the term through its path, rationale or attributes, so it is kept. The first loop is unchanged. The comments and docstring are updated.tests/test_serve.py, I added two tests:test_pick_seeds_keeps_same_label_node_that_is_only_match_for_a_term: the issue's 3-nodePreToolUserepro. It fails before the fix and passes after.test_pick_seeds_per_term_still_caps_same_label_winner_of_a_label_term: a secondGETthat wins the termget(degree tie-break) is still capped, so the query: homonymous generic symbols (e.g. many GET() route handlers) all get seeded, flooding results — related to #1303 #1766 flooding protection holds. This test fails if the cap is removed entirely. The existing query: homonymous generic symbols (e.g. many GET() route handlers) all get seeded, flooding results — related to #1303 #1766 per-term test cannot catch that, because its winner is already the first-loop seed.Test Plan
uv run pytest tests/test_serve.py tests/test_query_seed_order.py -q: 187 passed.uv run pytest tests/ -q: 10092 passed. 23 failed, the same 23 pre-existing Windows failures asv8, so nothing new.uv run ruff check .: all checks passed.uv run pyright: 728 errors, identical tov8; none in the changed code.uv run python -m tools.skillgen --check: OK.graphify query "core alpha PreToolUse hook handler": before, 2 nodes and nocore-alphanode; after, 3 nodes includingplugins/core-alpha/....