Skip to content

fix(query): match a label's name after its schema/namespace qualifier - #5095

Closed
houyunsun wants to merge 1 commit into
Graphify-Labs:v8from
houyunsun:fix/query-qualified-label-tail
Closed

houyunsun wants to merge 1 commit into
Graphify-Labs:v8from
houyunsun:fix/query-qualified-label-tail

Conversation

@houyunsun

Copy link
Copy Markdown
Contributor

What does this PR do?

graphify query sweep_widget_state does not find public.sweep_widget_state(), while graphify explain sweep_widget_state lists it. The query came back seeded on SWEEP, WIDGET and State — nodes whose whole label happens to be one of the query's tokens.

Why: the full-query tier in _score_query only fires when the joined query tokens equal or prefix the label. With a schema prefix the label's token string is public sweep widget state, which neither equals nor is prefixed by sweep widget state, so the function falls back to the per-token tiers. There a single-token exact label scores _EXACT_MATCH_BONUS, more than the target can collect from four substring hits, and _pick_seeds then drops everything below 20% of the top score.

The fix adds a tier between exact and prefix for the case the user cannot avoid typing: the label is <qualifier><sep><rest> and the query names exactly <rest>. The schema is usually implied, so the match is on the name the user actually typed.

  • Splits on ., ::, /, \, : and @, plus a CamelCase qualifier on the last segment (Index.ClientLive -> client live), so fmt.Println, Widget::sweep and dotted SQL names all work.
  • Scaled down by the qualifier's token count and capped at 4, so public.f() is trusted more than a.b.c.d.f().
  • Trailing file-extension and numeric segments are skipped: lib/foo/bar.py is the name bar, not py, and 3.14 is not a qualified name.
  • The bonus sits below the exact tier, so a label that really is the query still wins.

Nothing changes when the query equals or prefixes a label, or for plain snake_case identifiers — neither reaches the new branch. explain and path go through _score_nodes, the same code, so they pick up the same ordering.

Fixes #5080

Type of change

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

Verification & Invariants

The invariant is that the existing tiers keep their meaning: exact label > qualified name > prefix > per-token bag-of-words. A query that previously resolved to an exact or prefix label resolves to the same node; the new branch is only reachable when both of those miss, which is exactly the case that used to fall through to the token tiers.

No generated or persisted state is involved — this is pure scoring at query time, so no cache or index can be invalidated. The trigram prefilter's candidate set is unchanged (norm_terms + [joined]); the new tier only re-ranks candidates that were already being scored.

  • 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, on purpose:

  • Only the last segment is treated as the name. a.b.c.f() matches a query for f; a query naming an intermediate segment is still only handled when the label starts with it (prefix tier).
  • The qualifier must be at most 4 tokens. Deeper nesting falls back to the old behaviour rather than letting a long-tail match outrank real hits.
  • A qualifier that is itself one of the query's tokens does not need this tier: query public sweep_widget_state already matches through the exact/prefix case, which scores above it.

How was this tested?

$ python - <<'PY'   # the synthetic graph from the issue, no model or network
before: Traversal: BFS depth=3 | Start: ['SWEEP', 'State', 'WIDGET']
        (public.sweep_widget_state() never traversed)
after:  Traversal: BFS depth=3 | Start: ['public.sweep_widget_state()', 'SWEEP', 'State', 'WIDGET']
PY

$ pytest tests/test_serve.py -k qualified -q
4 passed

# new tests kept, graphify/serve.py reverted
$ pytest tests/test_serve.py -k qualified -q
2 failed, 2 passed

$ pytest tests/ -q
before: 381 failed
after:  379 failed
# the difference is exactly the two new tests. The rest are pre-existing
# failures from optional parsers missing here (objc/terraform/etc.),
# identical before and after.

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.

Skillgen not run: nothing under graphify/skills/ or tools/skillgen/ changed.

Who can review?

Whoever owns serve.py scoring — happy to change the bonus weight or the cap if you'd rather keep the tier tighter.

`query sweep_widget_state` missed `public.sweep_widget_state()` even though
`explain` on the same name found it. The full-query tier only fires when the
joined query tokens equal or prefix the label, so a leading `public` defeated
it, and the per-token tiers handed the seed slots to unrelated nodes whose
whole label is one of the query's tokens (`SWEEP`, `WIDGET`, `State`).

Add a tier between exact and prefix for labels of the shape
`<qualifier><sep><rest>` where the query names exactly `<rest>`: dotted,
`::`, `/`, `:` and `@` segments, plus a CamelCase qualifier on the last
segment. It is scaled down by the qualifier's token count and capped at four
tokens, so `public.f()` is trusted more than `a.b.c.d.f()`. Trailing
file-extension and numeric segments are skipped, so `lib/foo/bar.py` is the
name `bar` rather than `py`.

Nothing changes for a query that already equals or prefixes a label, or for
plain snake_case identifiers: those never reach the new branch.

Fixes #5080

Co-Authored-By: Claude <[email protected]>
@houyunsun
houyunsun requested a review from safishamsi as a code owner November 8, 2026 13:00
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown

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

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

Not checked: tests were not run; formal verification proved 0 of 1 changed function(s) (1 not verified).

Formal verification. PR-changed functions: 0/1 verified (0 proven, 0 may-equivalent, 0 distinguished) · 1 not verified (1 vacuous).

Not verified on this run: \_score\_query (vacuous: never exercised).


Graphify review — findings

Adds a qualified-name tier to query scoring, so a label like public.sweep_widget_state() or fmt.Println matches a query that names only its tail and outranks unrelated nodes whose whole label equals one query token (#5080). _score_query adds _QUALIFIED_MATCH_BONUS, scaled down by qualifier length, when _qualified_tail returns a tail equal to the joined query. The bonus stays below the exact-label tier, and labels with more than four qualifier tokens or no matching tail fall through to the existing per-token tiers. The CamelCase split in _qualified_tail works on the already-lowercased norm_label, and _name_key keeps parameter lists in the tail, so those label shapes drop back to per-token scoring.

Worth a look

  • CamelCase-qualifier branch never runs because it is fed a lowercased norm_label — graphify/serve.py:400 · Escalate · medium
    • NOT verified (no proof, no reproducing execution) — needs human review
  • CamelCase qualified tails are collapsed instead of tokenized — graphify/serve.py:408 · Escalate · medium
    • NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 928 functions depend on the 468 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: _query_graph_text() — 52 callers, 7 callees
  • worse: _score_query() — 23 callers, 8 callees

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

Test selection

Test selection

26 of 532 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

Could not verify: Could not verify \_score\_query.

The verifier did not have enough to check \_score\_query, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 47 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly TypeError — names the real obstacle, not a sampling gap)

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

safishamsi added a commit that referenced this pull request Nov 9, 2026
…ied-tail doc

Fold the Markdown mention change (#5093) into #5098's AST schema-41 comment with a
chained prior (40), since both change per-file extractor output and share one
release window. Correct the _qualified_tail docstring example (a dotted tail is
one token, not CamelCase-split) and note the CamelCase fallback only fires on
cased input the lowercased-norm_label callers never pass (#5095 tweak).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Landed on v8 and shipped in 0.9.105 (now on PyPI), cherry-picked with -x. Small follow-up: I corrected the _qualified_tail docstring example (a dotted tail is one token, not a CamelCase split) and noted that the CamelCase fallback only fires on cased input, which the lowercased norm_label callers never pass. The separator-qualified matching itself is unchanged. Thanks @sunhouy (#5080).

@safishamsi safishamsi closed this Nov 9, 2026
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.

query: a snake_case name with a schema prefix (public.<name>()) loses to single-token labels; explain finds it

2 participants