Skip to content

Refuse an ambiguous name in graphify query - #4517

Closed
shivampal46011 wants to merge 1 commit into
Graphify-Labs:v8from
shivampal46011:fix/query-ambiguous-name
Closed

shivampal46011 wants to merge 1 commit into
Graphify-Labs:v8from
shivampal46011:fix/query-ambiguous-name

Conversation

@shivampal46011

@shivampal46011 shivampal46011 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #4511.

graphify explain and graphify path refuse a name that matches several nodes and exit 3. graphify query scored the question and silently picked one node, so exit code 0 could mean either a real answer or a guess. An ambiguous --seed printed a refusal and still exited 0.

query now uses the same uniqueness check as explain:

  • a question that is itself an ambiguous node name lists the candidates and exits 3
  • a sentence that is not a single node name still uses keyword scoring
  • an ambiguous --seed exits 3
  • a --seed that matches nothing exits 4

This change was written with AI assistance.

Type of change

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

Verification & Invariants

The lookup contract is: a name that matches several nodes is refused with the candidates listed, and the exit code tells a script which outcome it got (0 answer, 3 ambiguous, 4 no match). Keyword scoring of a real question is unchanged.

  • 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.

A multi-word question is not treated as a node name, so it still searches by keywords even when one of its words is a common symbol.

How was this tested?

pytest tests/test_lookup_exit_codes.py tests/test_query_seeds.py

29 passed.

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.

query guessed a node when the same name existed in several files, and an ambiguous --seed still exited 0. explain and path already refuse that lookup. query now returns the same candidate list and exits 3, and a --seed that matches nothing exits 4.
@github-actions github-actions Bot added the needs:title PR title should follow the conventional-commit format label Oct 17, 2026
@github-actions

Copy link
Copy Markdown

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

Copy link
Copy Markdown

Thanks @shivampal46011! One small thing: our changelog and release notes are built from PR titles, so we use the conventional-commits format, for example:

fix(python): resolve a bare stdlib import correctly

Prefixes we use: feat, fix, docs, chore, refactor, test, perf, build, ci. Editing the PR title clears this automatically. This is just a nudge and does not block review.

@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 1 advisory finding(s) below merit a look before merge.

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

Formal verification. 1 change(s) alter behavior, breaking input(s) attached. PR-changed functions: 1/2 verified (0 proven, 0 may-equivalent, 1 distinguished) · 1 not verified (1 vacuous).

Behavior changes: \_query\_graph\_text changes behavior, here is the input that shows it.

The verifier found a concrete input on which \_query\_graph\_text behaves differently before and after the change. If that change is intended, ship it; if not, this is your bug.

Guarantee: This difference was REPRODUCED, the verifier actually ran both versions on that input and saw them disagree. It is real, not an artifact.

Evidence: On input \{"G":"\(lambda \_g: \(\_g\.add\_nodes\_from\(\[\(1, \{\}\), \(2, \{\}\), \(3, \{\}\)\]\), \_g\.add\_edges\_from\(\[\(1, 2, \{\}\), \(1, 3, \{\}\), \(2, 3, \{\}\)\]\), \_g\)\[\-1\]\)\(\_\_import\_\_\('networkx'\)\.Graph\(\)\)","question":"' x '"\}, the old code produced 'No matching nodes found\.' but the new code produces raises AttributeError. Paste that input straight into a regression test.

Not verified on this run: dispatch\_command (vacuous: never exercised).


Graphify review — findings

Makes graphify query refuse ambiguous input the way explain and path already do. A question that names one symbol shared by nodes in different files, or an ambiguous --seed, now prints the ambiguity message and exits with EXIT_AMBIGUOUS instead of guessing a node. Sentences that aren't a node name still fall through to keyword scoring, and a --seed that matches nothing keeps EXIT_NOT_FOUND. In _query_graph_text, the refusal is only returned when no seed resolves, so with several seeds an ambiguous one can be skipped while the others still run the query.

Worth a look

  • Ambiguous seed silently dropped when another seed resolves — graphify/serve.py:1442 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 778 functions depend on the 254 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: _query_graph_text() — 48 callers, 7 callees

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

Test selection

Test selection

45 of 432 test file(s) selected (10%) via static blast radius.

  • tests/test_affected_cli.py — impact
  • tests/test_agents_platform.py — impact
  • tests/test_benchmark.py — impact
  • tests/test_benchmark_raw_graph.py — impact
  • tests/test_benchmark_real_query.py — impact
  • tests/test_cli_export.py — impact
  • tests/test_cloud_cta.py — impact
  • tests/test_codebuddy.py — impact
  • tests/test_compact_graph_json.py — impact
  • tests/test_dedup_shrink_refuses_force_write.py — impact
  • tests/test_devin.py — impact
  • tests/test_explain_cli.py — impact
  • tests/test_explain_same_file_tie.py — impact
  • tests/test_extract_cli.py — impact
  • tests/test_file_label_disambiguation.py — impact
  • tests/test_global_add_tag_inference.py — impact
  • tests/test_god_nodes_cli.py — impact
  • tests/test_hollow_chunks_arm_shrink_guard.py — impact
  • tests/test_hook_guard_token_match.py — impact
  • tests/test_hook_out_of_project_paths.py — impact
  • tests/test_hook_strict.py — impact
  • tests/test_incomplete_build_guard.py — impact
  • tests/test_install.py — impact
  • tests/test_install_references.py — impact
  • tests/test_lookup_exit_codes.py — impact, changed-test
  • tests/test_mcp_graph_view_cache.py — impact
  • tests/test_merge_chunks_validation.py — impact
  • tests/test_multigraph_diagnostics.py — impact
  • tests/test_no_dedup_flag.py — impact
  • tests/test_opencode_plugin_refresh.py — impact
  • tests/test_partial_cache.py — impact
  • tests/test_path_cli.py — impact
  • tests/test_query_cli.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_serve.py — impact
  • tests/test_serve_http.py — impact
  • tests/test_skill_auto_refresh.py — impact
  • tests/test_stale_prune.py — impact
  • tests/test_terraform.py — impact
  • tests/test_truncation_full_answer.py — impact
  • tests/test_unverified_semantic_shrink.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

Behavior changes: \_query\_graph\_text changes behavior, here is the input that shows it.

The verifier found a concrete input on which \_query\_graph\_text behaves differently before and after the change. If that change is intended, ship it; if not, this is your bug.

Guarantee: This difference was REPRODUCED, the verifier actually ran both versions on that input and saw them disagree. It is real, not an artifact.

Evidence: On input \{"G":"\(lambda \_g: \(\_g\.add\_nodes\_from\(\[\(1, \{\}\), \(2, \{\}\), \(3, \{\}\)\]\), \_g\.add\_edges\_from\(\[\(1, 2, \{\}\), \(1, 3, \{\}\), \(2, 3, \{\}\)\]\), \_g\)\[\-1\]\)\(\_\_import\_\_\('networkx'\)\.Graph\(\)\)","question":"' x '"\}, the old code produced 'No matching nodes found\.' but the new code produces raises AttributeError. Paste that input straight into a regression test.

Could not verify: Could not verify dispatch\_command.

The verifier did not have enough to check dispatch\_command, 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 40 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly SystemExit — names the real obstacle, not a sampling gap)

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

safishamsi added a commit that referenced this pull request Oct 20, 2026
…#4517)

The ambiguous-name refusal added in #4517 routed through _resolve_single_node,
whose winning tier can be a prefix or substring match, so a bare search keyword
that merely substring-matched several labels was wrongly refused: `query "client"`
returned EXIT 3 because it is a substring of `AlphaClient`/`BetaClient`. That
narrowed query's keyword-search semantics.

Adds _query_name_refusal, which refuses only when the term EXACTLY names several
nodes (the source_exact/exact tiers) -- #4511's `.nonce()` case -- and otherwise
falls through to scoring. The `query` and `--seed` paths use it; explain/path/
get_node keep _resolve_single_node, whose prefix/substring tiers are correct for a
direct node lookup. Adds a regression test that a substring keyword still searches.

Co-Authored-By: shivampal46011 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
safishamsi added a commit that referenced this pull request Oct 20, 2026
@safishamsi

Copy link
Copy Markdown
Member

Landed in 0.9.93, cherry-picked to preserve your authorship. graphify query refuses a bare name that is the exact name of several nodes in different files, matching explain and path; a search keyword still searches. Thanks @shivampal46011. Live on PyPI: https://pypi.org/project/graphifyy/0.9.93/

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

Labels

needs:title PR title should follow the conventional-commit format

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: graphify query silently guesses an ambiguous node name instead of refusing it

2 participants