Skip to content

bug(cli/mcp): find_importers reads module.alias but the alias is stored on the IMPORTS relationship, so import_alias is always null #1515

Closed

Description

@Shashankss1205

tools/code_finder.py:657

who_imports_module collects the alias from the Module node:

MATCH (file:File)-[imp:IMPORTS]->(module:Module)
...
WITH file, repo, COLLECT({
    imported_module: module.name,
    import_alias: module.alias,        // <- always null
    full_import_name: module.full_import_name
}) AS imports

But the writer stores the alias on the relationship, not the node (tools/indexing/persistence/writer.py:581 and :597):

r.alias = row.alias
...
SET r.alias = coalesce(row.alias, ""),

Module nodes are never written with an alias property, so module.alias evaluates to null on every row. Note the relationship is already bound as imp in the same pattern — the data is right there.

Impact

The find_importers MCP tool reports import_alias: null for every result, including import numpy as np where the alias is the whole point of the query. An agent asking "what name is this module imported under here?" gets nothing back and has no way to tell that the field is broken rather than genuinely absent.

Suggested fix

-    import_alias: module.alias,
+    import_alias: imp.alias,

Environment
Commit c0e0bed (main)
Python 3.12.3, Linux

Verified by cross-checking the query's property reads against every alias write in writer.py.

Activity

  1. added
    bugSomething isn't working
    severity: lowCosmetic, dead code, or a narrow-trigger correctness issue
    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 1, 2026

    @Shashankss1205
    CollaboratorAuthor

    Cross-linking: this shares a root cause with item 3 of #1533 (the C++ toolkit reads m.alias in query_tool_languages/cpp_toolkit.py:46).

    In both places the alias is read off the Module node, but writer.py:580-598 only ever writes it to the IMPORTS relationship:

    MATCH (m:Module)         RETURN count(m), count(m.alias)   ->  160, 0
    MATCH ()-[i:IMPORTS]->() RETURN count(i), count(i.alias)   ->  249, 249
    

    Whoever picks either one should fix both call sites together — the change is m.alias → i.alias in each. A repo-wide grep for .alias against Module patterns would be worth doing at the same time in case there is a third.

  4. moved this from Backlog tasks to In progress in CGC Progress Boardon Aug 1, 2026
  5. moved this from In progress to Done in CGC Progress Boardon Aug 2, 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 workinggood first issueGood for newcomersseverity: lowCosmetic, dead code, or a narrow-trigger correctness issue

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions