Skip to content

bug(cli/mcp): find_callers collapses every row's target_file_path to the first row's, misattributing callers across same-named functions #1530

Closed

Description

@Shashankss1205

tools/code_finder.py:1216-1221

find_callers hoists one row's target path into the response envelope, then strips the field from every row:

target_file_path = next((r.pop("target_file_path", None) for r in results), None)

next(...) consumes only the first generator item, so the envelope gets row 0's value — but the surrounding loop still pops the field off all remaining rows, discarding their (different) values.

When context is not supplied, who_calls_function matches Function {name: $function_name} across all files, so rows legitimately carry different target_file_path values.

Reproduction

Two result rows targeting /repo/models/user.py and /repo/models/order.py produce:

{
  "target_file_path": "/repo/models/user.py",
  "callers": [ ...both callers, under the one path... ]
}

Impact

Ask for callers of any common method name — save, run, handle, get — that exists in several files, and every caller is reported as calling the definition in whichever file happened to sort first. An agent acting on that reads or edits the wrong file, with nothing in the response signalling ambiguity.

Suggested fix

Either keep target_file_path per row (drop the envelope hoist), or group results by target path and return a list of {target_file_path, callers} groups so genuine ambiguity is visible to the caller.


Environment
Commit c0e0bed (main)
Python 3.12.3, Linux

Reproduced by driving the result-shaping code with two rows carrying distinct target paths.

Activity

  1. added
    bugSomething isn't working
    severity: mediumIncorrect results, misleading output, or a broken contract
    area: cli/mcpCLI commands, MCP tool contracts, docs
    on Aug 1, 2026
  2. github-actions commented on Aug 1, 2026

    @github-actions
    Contributor

    Hi! 👋 Join our CodeGraphContext Discord channel to collaborate: https://discord.gg/dR4QY32uYQ

  3. Shashankss1205 commented on Aug 5, 2026

    @Shashankss1205
    CollaboratorAuthor

    Fixed in #1577 (merged).

    target_file_path is now hoisted to the envelope only when every row agrees. When the rows genuinely disagree — which is what happens without context, since who_calls_function matches Function {name} across every file — the field stays on each row and the envelope carries a note:

    "'save' is defined in 2 files; each result carries its own target_file_path.
     Pass `context` to disambiguate."
    

    The payload-slimming that motivated the original code is preserved for the unambiguous case. Regression test asserts both directions.

  4. moved this from Backlog tasks to Done in CGC Progress Boardon Aug 5, 2026
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

    area: cli/mcpCLI commands, MCP tool contracts, docsbugSomething isn't workingseverity: mediumIncorrect results, misleading output, or a broken contract

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions