Skip to content

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

Closed

Description

@jaredswanson

Pre-flight checks

  • I have checked the Troubleshooting section in the README

Graphify version

0.9.102 (latest release; v8 branch has the same serve.py)

What happened?

_pick_seeds removes any seed candidate whose normalized label is already a seed (#1766). This also applies to the "one seed for each query term" step (#1445).

Two different nodes can share a label. Example: two classes named PreToolUse in two different plugins. When their scores are close, only the higher one is a seed. The other is dropped, even when it is the only node that matches one of the query terms.

In the repro below, the query names alpha. Only the alpha node matches that term (best_seed_by_term["alpha"] == "alpha_pre"). That node has a lower score (29.11 against 29.81), so it is dropped. The result has no seed for alpha, and the node is not in the output.

The docstring of _pick_seeds says the step "guarantees at least one seed per distinct query term that has any match at all". The label cap breaks this guarantee.

I expect #1766 to stay. It prevents many GET() handlers from filling the seeds. I ask for a narrower rule.

Steps to reproduce

Create graph_a.json:

import json
def node(i, label, src):
    return {"id": i, "label": label, "source_file": src, "file_type": "code"}
nodes = [
    node("hooks_pre", "PreToolUse", "plugins/core/lib/core_hooks/handler/pre_tool_use.rb"),
    node("hooks_run", ".run", "plugins/core/lib/core_hooks/handler/pre_tool_use.rb"),
    node("alpha_pre", "PreToolUse", "plugins/core-alpha/lib/alpha/pre_tool_use.rb"),
]
links = [{"source": "hooks_pre", "target": "hooks_run", "relation": "contains", "confidence": "EXTRACTED"}]
json.dump({"directed": False, "multigraph": False, "graph": {}, "nodes": nodes, "links": links},
          open("graph_a.json", "w"))
graphify query "core alpha PreToolUse hook handler" --graph graph_a.json
grep -c alpha <(graphify query "core alpha PreToolUse hook handler" --graph graph_a.json --budget 5000)

Error output or graph output

| Traversal: BFS depth=2 | Start: ['PreToolUse', '.run'] | 2 nodes found

NODE PreToolUse [src=plugins/core/lib/core_hooks/handler/pre_tool_use.rb ...]
NODE .run [src=plugins/core/lib/core_hooks/handler/pre_tool_use.rb ...]

No plugins/core-alpha/... node is in the output, and the grep -c alpha count is 0.

In-process, with _score_query and _pick_seeds:

29.81 hooks_pre
29.11 alpha_pre
 2.08 hooks_run
best_seed_by_term: {'core': 'hooks_run', 'pretooluse': 'hooks_pre', 'hook': 'hooks_run',
                    'handler': 'hooks_run', 'alpha': 'alpha_pre'}
seeds: ['hooks_pre', 'hooks_run']

Expected: alpha_pre is a seed, because it is the best match for the term alpha and no other seed covers that term.

Source reference

graphify/serve.py, _pick_seeds: the seen_labels check in the first loop, and the key not in seen_labels check in the per-term loop.

Suggested direction (optional)

Apply the label cap only to a candidate that adds no uncovered query term. A candidate that is the best match for a term with no seed yet should be kept.

Related

Environment

  • Operating System: Linux
  • Python Version: 3.12
  • Installation Method: uv tool install (graphifyy 0.9.102)

Activity

  1. github-actions commented on Nov 5, 2026

    @github-actions

    Thanks for opening this issue, @jaredswanson. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

  2. Vaibhav2824 commented on Nov 5, 2026

    @Vaibhav2824
    Contributor

    I’d like to take this. Plan: in _pick_seeds, apply the seen_labels cap only to candidates that cover no uncovered query term. A candidate that is best_seed_by_term for a term with no seed yet is kept even if its label is a duplicate. I’ll add a regression test from your 3-node repro, plus one confirming #1766’s GET()-flooding protection still holds. Does that match what you’d want?

  3. safishamsi commented on Nov 8, 2026

    @safishamsi
    Member

    Fixed in 0.9.104 (now on PyPI) via #5032: query now keeps a same-label node that is the only match for a term as a seed, so the per-term guarantee holds while generic-label flooding stays capped.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions