Skip to content

feat(mcp): answer-by-union for homonym symbols in get_answer#772

Merged
RaghavChamadiya merged 1 commit into
mainfrom
feat/mcp-exact-symbol-answer
Jul 11, 2026
Merged

feat(mcp): answer-by-union for homonym symbols in get_answer#772
RaghavChamadiya merged 1 commit into
mainfrom
feat/mcp-exact-symbol-answer

Conversation

@RaghavChamadiya

Copy link
Copy Markdown
Member

What

When a get_answer question names a symbol that has several definitions no qualifier can disambiguate (a helper duplicated across modules, an overloaded name), the tool now runs an exact-name index scan and inlines the union of every definition body in symbol_bodies, instead of returning a low-confidence list of candidate files.

It also adds a guard: a qualified name (Parent.method) that matches no indexed definition returns not-found rather than synthesizing from a same-named symbol in another file.

Why

The low-confidence candidate-file list was the wrong shape for an agent: handed a list of files, it drills back in with get_symbol on each one, or falls back to grep, to find the definition it asked about. For a name with N definitions that costs N follow-up calls. Inlining the bodies answers the question in a single call.

The not-found guard means a precise query (Foo.bar where bar exists only under other classes) never degrades into a confident answer built from the wrong definition.

How it works

  • _anchor_symbol_hits now surfaces unresolvable homonyms and qualified-misses alongside the hits it injects.
  • build_homonym_union_bodies renders the definition bodies greedily under a char budget in Read format (first always renders); any that overflow are listed as get_symbol pointers with a do-not-Read redirect.
  • get_answer returns the union (grounding: "exact_symbol", confidence: "high") or the not-found response before the synthesis gate, so neither path emits the candidate-file list.

Validation

  • New unit tests cover the union/qualified-miss split, the char-budget overflow, and the qualified-miss guard; the existing anchor tests are updated for the new return shape. Full MCP unit suite passes (388).
  • Verified against a real index: a question naming a 4-definition helper returns all four bodies inlined with no candidate-file list. In a headless agent A/B on the same repo, the change cut total tool calls by 50-60% on homonym questions, with the best case answering in a single get_answer call.

When a question names a symbol that has several definitions no qualifier can
disambiguate (a helper duplicated across modules, an overloaded name), get_answer
now runs an exact-name index scan and inlines the union of every definition body
in symbol_bodies, instead of returning a low-confidence list of candidate files.
The candidate-file list pushed agents to drill back in with get_symbol or fall
back to grep; inlining the bodies answers the question in a single call. Bodies
render under a char budget, Read-format, and any that overflow are listed as
get_symbol pointers.

A qualified name (Parent.method) that matches no indexed definition now returns
not-found rather than synthesizing from a same-named symbol elsewhere, so a
precise query never degrades to a confidently-wrong answer.
@repowise-bot

repowise-bot Bot commented Jul 11, 2026

Copy link
Copy Markdown

✅ Health: 7.7 (unchanged)

📋 At a glance
4 hotspots touched · 3 new findings introduced · 5 co-change pairs left out · 1 file with recent fix history · 1 dead-code finding.

Files & modules (2)
  • packages (3 files)
    • .../tool_answer/config.py
    • .../tool_answer/answer.py
    • .../tool_answer/symbols.py
  • tests (1 file)
    • .../mcp/test_answer_calibration.py

⚠️ Change risk: moderate (riskier than 52% of this repo's commits · raw 9.0/10)
This change's risk is driven by:

  • more lines added than baseline
  • more scattered than baseline

🩹 Review priority (files here with the most recent bug-fix history — defects cluster, so review these first)

🔎 More signals (3)

🔥 Hotspots touched (4)

  • .../tool_answer/config.py — 4 commits/90d, 5 dependents · primary owner: Swati Ahuja (94%)
  • .../tool_answer/answer.py — 8 commits/90d, 2 dependents · primary owner: Swati Ahuja (66%)
  • .../mcp/test_answer_calibration.py — 3 commits/90d, 1 dependents · primary owner: Raghav Chamadiya (60%)
1 more
  • .../tool_answer/symbols.py — 4 commits/90d, 3 dependents · primary owner: Swati Ahuja (58%)

🔗 Hidden coupling (2 files)

  • .../tool_answer/answer.py co-changes with these files (not in this PR):
    • .../mcp_server/tool_symbol.py (3× — 🟢 routine)
    • .../mcp_server/tool_search.py (3× — 🟢 routine)
    • .../mcp_server/_meta.py (2× — 🟢 routine)
    • .../templates/claude_md.j2 (2× — 🟢 routine)
  • .../tool_answer/config.py co-changes with .../tool_answer/confidence.py (2× — 🟢 routine) — not in this PR.

💀 Dead code (1 finding)

  • 💀 .../tool_answer/answer.py _json_default (confidence 0.65)

📊 Full report · ⭐ Star Repowise · 📥 Install bot · Last updated 2026-07-11 04:38 UTC
Silence on a single PR with [skip repowise] in the title · Per-repo toggle on repowise.dev/settings?tab=bot

@RaghavChamadiya RaghavChamadiya merged commit 436e155 into main Jul 11, 2026
7 checks passed
@RaghavChamadiya RaghavChamadiya deleted the feat/mcp-exact-symbol-answer branch July 11, 2026 05:37
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.

2 participants