Skip to content

fix(query): stop relational words hijacking seed selection; relax starving heuristic filters (#37) - #44

Merged
filipechagas merged 6 commits into
v8from
feat/seeding-fix-37
Aug 6, 2026
Merged

filipechagas merged 6 commits into
v8from
feat/seeding-fix-37

Conversation

@filipechagas

Copy link
Copy Markdown
Collaborator

Closes #37.

Natural-language impact questions ("Who calls X?", "callers of X", "what code uses X") now render the real callers within the default token budget instead of failing silently on junk seeds or a stranded context filter.

Three default-inert changes, all opted into only by the natural-language query pipeline (upstream positioning: direction 2 of Graphify-Labs#2507, extended; upstream PR to follow on this same branch):

Summary of the branch: 6 commits implementing fork issues #40–#43 (all closed, each with red-first evidence and adversarial review); version 0.9.36; suite 4,177 passed / 36 skipped (base: 4,168 / 36; the 4 test_ollama_retry_cap.py failures are pre-existing env issues present at base). Zero baseline test edits (git diff --stat v8..HEAD -- tests/ = 2 new files only); benchmark equality gate holds.

Live grading on the pinned 48.5k-node repro corpus (full table on #37): "Who calls ChargeCustomerService?" 0-of-3 → 3-of-3 rendered, no junk seed; "callers of" junk seed gone, 3-of-3; "what code uses … to charge a customer" 2,307 → 138 nodes (−94%), 3-of-3; explain listener check regression-free at an identical 417 tok. Documented residual (code→coder.md guarantee seed, 6/44 shown) per the spec's Out of Scope.

🤖 Generated with Claude Code

filipechagas and others added 6 commits August 6, 2026 13:53
)

"Who calls ChargeCustomerService?" / "callers of X" used to seed an unrelated
decoy: relational words survive stopwording, their junk matches lose everywhere
on merit, but the Graphify-Labs#1445 per-term guarantee hands every query term an
unconditional seed slot — so a verb's incidental prefix decoy (a
`callStoreWithAmount()` test helper prefix-matching "calls") entered the
traversal and spent the budget on an unrelated test neighborhood.

C1: `_RELATIONAL_INTENT_TERMS`, derived from `_CONTEXT_HINTS` +
`_CONTEXT_FILTER_ALIASES` plus a documented caller/use/listen extension set
(those two families appear in neither table), and a demotion step in
`_query_graph_text` that filters `best_seed_by_term` between `_score_query` and
`_pick_seeds`. That placement keeps the scorer byte-identical and the picker's
signature and semantics unchanged for every other caller, so the change is
inert outside the natural-language query pipeline.

This is demotion, not stopwording: relational terms still score, still compete
in the gap window, so a corpus symbol literally named `calls` keeps its
exact-match dominance. An all-relational query keeps the unfiltered map,
mirroring `_query_terms`' all-stopword fallback.

Also adds the synthetic seeding fixture from the spec (service class, three
known callers, verb-prefix decoy with a busy test-method neighborhood,
generic-noun hub, `coder.md` doc decoy) as a reusable helper for #41-#43.

Refs #37
The Graphify-Labs#1445 per-term seed guarantee exists to keep a term from being starved,
but it fires unconditionally, so a natural-language question's generic nouns
each drag in their own hub seed even when the queried identifier already
matches them. "what code uses ChargeCustomerService to charge a customer"
seeded `Customer` and `.charge()` alongside `ChargeCustomerService`, and the
hub's member fan-out then made up the bulk of the answer (measured on the
fixture: 12 of 22 nodes; 2,206 of 2,307 on the pinned repro graph).

Add a keyword-only, default-off `skip_covered_terms` to `_pick_seeds`: in the
guarantee loop, skip a term that is a substring of an already-picked seed's
normalized label — the same predicate as _score_nodes' weakest match tier, so
"covered" means the seed would have matched the term in scoring. It runs in the
existing sorted-term order, layered after the Graphify-Labs#1766 label-dedup gate, and
`_query_graph_text` is the only caller that opts in.

This refines the guarantee's invariant to *every term with any match is matched
by at least one seed* (was: every term's own singleton winner gets a slot).
A genuinely starved term — one no picked seed's label matches — still gets its
seed, so the starvation protection survives.

Fixture measurements at depth 2: phrasing C goes 22 nodes with the hub and
`.charge()` seeded to 10 with neither, 3/3 known callers rendered either way.
The `code` -> `coder.md` guarantee seed is the documented residual (#37 Out of
Scope): it is covered by no seed's label, so it is not starved.

Refs #37, #41
"Who calls <Service>?" infers a `call` context filter, but a class node owns
no call edges — calls attach to its methods and the class->member edge carries
`context=None` — so the filtered traversal cannot leave the seed and the query
answers with one node, confidently. After traversal, when the active filters
came from the heuristic and nothing was discovered beyond the seeds, retraverse
the unfiltered graph and annotate the `Context:` header, so the answer is
neither near-empty nor silently unfiltered.

The zero-expansion threshold is deliberate: "few nodes" would need a tuning
constant, and a filter that found something is doing its job. Applies
identically to BFS and DFS. An explicit context filter is an instruction, not a
guess, and is never overridden — even when it strands the traversal.

Implements C3 of #37.
…node id (#41)

Review catch on cebf231. The coverage predicate reused `_seed_label_key`, whose
`or nid` tail fires even with `G` non-None whenever a seed's label normalizes to
empty. That tail is correct for the dedup gate — a labelless node still needs
something unique to dedup on — but wrong for coverage.

`norm_label == ""` nodes are real: build.py's `_fold_node_aliases` documents an
alias-only node entering the graph with no label, and such a node is still
seedable because _score_nodes' source-file tier (serve.py:565) scores it. Via
the tail, a ghost seeded from `src/customer_utils.py::helper` declared the term
"customer" covered through a node-id substring — a match the scorer never makes,
since its substring tier (serve.py:561) reads `norm_label`, built at :500 with no
nid fallback. The term's real winner (`CustomerModel`) was then starved, breaking
the very invariant the flag is supposed to refine.

Add `_seed_norm_label`, which returns the normalized label or "" and is used by
the coverage check alone; `_seed_label_key` and the dedup gate are unchanged. A
seed with no label now covers nothing.

Red-first regression test asserts the labelless seed's term winner still gets its
guaranteed seed under `skip_covered_terms=True`, and grounds both premises first
(the winner is the labelled node; the ghost really does score).

Refs #37, #41
Integrates C3 with C2 (feat/seeding-fix-37-c2). Two C3 no-fallback guard
tests were reconstructed for the merged semantics: their scenarios relied
on the per-term guarantee seeding ChargeCustomerService.charge() for the
term "charge", which C2 now correctly skips (covered by the class label).
The replacement scenario ("Who invoked BillingController?") seeds a method
node on merit, independent of the guarantee. Zero-expansion boundary
mutation check re-run on the merged tree: a +1 threshold fails the boundary
test and a pre-existing test_serve.py sentinel.

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

Releases the three serve-side seeding changes behind fork #37 (upstream
issue 2507): relational-intent demotion from the per-term seed guarantee
(#40), the covered-term guarantee skip (#41), and the heuristic
context-filter starvation fallback with an annotated header (#42).

Serve-side only — no extraction, merge or graph-format change, so no
rebuild is needed to pick it up. uv.lock records the new project version;
it also had been lagging at 0.9.34 since the upstream v0.9.35 sync merge
bumped pyproject.toml alone.

Refs #43
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.

query: relational verbs ("calls"/"callers"/"uses") hijack seed selection and bury the real identifier's callers (upstream Graphify-Labs#2507)

1 participant