Skip to content

fix(query): keep a same-label seed when it is the only match for a query term (#5027) - #5032

Closed
Vaibhav2824 wants to merge 1 commit into
Graphify-Labs:v8from
Vaibhav2824:fix/5027-same-label-term-seed
Closed

Vaibhav2824 wants to merge 1 commit into
Graphify-Labs:v8from
Vaibhav2824:fix/5027-same-label-term-seed

Conversation

@Vaibhav2824

Copy link
Copy Markdown
Contributor

Summary

Fixes #5027.

In _pick_seeds(), seed candidates are deduplicated by normalized label so that generic symbols (e.g. repeated GET() 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 as PreToolUse in 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

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 as v8, so nothing new.
  • uv run ruff check .: all checks passed.
  • uv run pyright: 728 errors, identical to v8; none in the changed code.
  • uv run python -m tools.skillgen --check: OK.
  • Seed tests also pass on Python 3.10 / networkx 3.4.2.
  • Repro graphify query "core alpha PreToolUse hook handler": before, 2 nodes and no core-alpha node; after, 3 nodes including plugins/core-alpha/....

…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]>
Copilot AI balanced review requested due to automatic review settings November 5, 2026 19:46
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

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.

Copilot AI 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.

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.

@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; 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 — impact
  • tests/test_affected_cli.py — impact
  • tests/test_affected_path_file_node.py — impact
  • tests/test_affected_seed_reference_forms.py — impact
  • tests/test_benchmark.py — impact
  • tests/test_benchmark_raw_graph.py — impact
  • tests/test_benchmark_real_query.py — impact
  • tests/test_confidence_score_output.py — impact
  • tests/test_edge_also_seen.py — impact
  • tests/test_explain_same_file_tie.py — impact
  • tests/test_extract.py — impact
  • tests/test_file_label_disambiguation.py — impact
  • tests/test_mcp_graph_view_cache.py — impact
  • tests/test_path_cli.py — impact
  • tests/test_path_confidence.py — impact
  • tests/test_path_type_member.py — impact
  • tests/test_query_induced_edges.py — impact
  • tests/test_query_mcp_direction.py — impact
  • tests/test_query_names_its_graph.py — impact
  • tests/test_query_seed_order.py — impact
  • tests/test_query_seeds.py — impact
  • tests/test_query_source_first.py — impact
  • tests/test_serve.py — impact, changed-test
  • tests/test_serve_http.py — impact
  • tests/test_terraform.py — impact
  • tests/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).

@safishamsi

Copy link
Copy Markdown
Member

Landed on v8 and shipped in 0.9.104 (now on PyPI). I cherry-picked your commit with -x so it keeps your authorship. Thanks for the per-term query seed guarantee, @Vaibhav2824.

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.

[Bug]: query drops a distinct node that has the same label as a seed, and the per-term seed guarantee does not hold

3 participants