feat(mcp): surface alias keys a documented data-shape omits#780
Merged
Conversation
The documented-shape path answers "what fields does <blob> contain" at high
confidence and tells the caller no verification Read is needed. But a docstring
lists the declared shape, which can be a subset of what the records actually
carry: consumers often read a legacy alias the doc never mentions. For
co_change_partners_json, four consumers defensively read
`partner.get("co_change_count") or partner.get("count")` and
`... or partner.get("path")`, so `count` and `path` are real keys the documented
shape omits. Answering high-confidence "cite it, no Read needed" while hiding
those is a confidently-incomplete answer.
Mine them and surface them. After the documented shape is chosen, scan the
identifier's consumer files for the alias idiom `<recv>.get("<A>") or
<recv>.get("<B>")` where one key is a documented field; the other is an alias for
it. Requiring the `or` fallback on a shared receiver keeps this tight: an
assignment that merely co-mentions a documented key on an unrelated record, or a
test assertion, does not match. The extras ride back in a new
`data_shape.also_accessed` block (field + file:line), and the answer text names
them so the agent handles them instead of trusting a subset. The documented
fields stay authoritative; confidence stays high on the declared core.
Adds three tests: an omitted `or`-fallback alias is surfaced, a clean shape with
no divergence carries no also_accessed, and a cross-record co-mention (an
assignment, not a fallback) is correctly not reported as an alias.
|
✅ Health: 7.6 (unchanged) 📋 At a glance Files & modules (2)
🩹 Review priority (files here with the most recent bug-fix history — defects cluster, so review these first)
🔎 More signals (3)🔥 Hotspots touched (3)
🔗 Hidden coupling (1 file)
💀 Dead code (1 finding)
📊 Full report · ⭐ Star Repowise · 📥 Install bot · Last updated 2026-07-11 12:23 UTC |
swati510
approved these changes
Jul 11, 2026
This was referenced Jul 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Follow-up to #779. The documented-shape path answers "what fields does
<blob>contain" at high confidence and tells the caller no verification Read is needed. But a docstring lists the declared shape, which can be a subset of what the records actually carry: consumers often read a legacy alias the doc never mentions.Concrete case in this repo: for
co_change_partners_json, four consumers defensively readThe docstring at
coupling/graph.py:53lists onlyfile_path,co_change_count,last_co_change. So the old response was confidently incomplete — it said "cite it, no Read needed" while hiding keys an agent editing this code would need to handle.How
After the documented shape is chosen, scan the identifier's consumer files for the alias idiom:
where one key is a documented field — the other is an alias for it. Requiring the
orfallback on a shared receiver keeps this tight and avoids false positives: an assignment that merely co-mentions a documented key on an unrelated record (meta["other_count"] = ...meta["file_path"]) or a test assertion does not match.The extras come back in a new
data_shape.also_accessedblock (field+file:line), and the answer names them so the agent handles them. The documented fields stay authoritative and confidence stays high on the declared core; the response just stops hiding the divergence.Example response for
co_change_partners_json:{ "confidence": "high", "grounding": "data_shape", "data_shape": { "identifier": "co_change_partners_json", "fields": ["file_path", "co_change_count", "last_co_change"], "also_accessed": [ {"field": "path", "file": ".../pr_blast.py", "line": 187}, {"field": "count", "file": ".../pr_blast.py", "line": 188}, {"field": "partner", "file": ".../routers/stats.py", "line": 476} ] } }Tests
Three new tests: an omitted
or-fallback alias is surfaced, a clean shape with no divergence carries noalso_accessed, and a cross-record co-mention (an assignment, not a fallback) is correctly not reported as an alias. The alias detection is a generic Python idiom — the tests use synthetic identifiers, not the repo's own field names.