Skip to content

Relative imports are dropped when their file name exists more than once in the repo (C/JS/Ruby/Zig) #3553

Closed

Description

@squid-protocol

Problem

A relative import names exactly one file by its location: #include "internal.h" from src/unix/core.c, require('./db'), require_relative 'request', @import("ast.zig"). When the repo has several files with that name (src/unix/internal.h and src/win/internal.h, or one db.js per example directory), the engine draws no edge, even though the path relative to the importing file resolves the ambiguity. The resolver treats the token as an ambiguous bare stem (the #261 "skip rather than misattribute" rule) and never tries the importing file's own directory.

Measured

tests/tools/import_graph_accuracy.py, merged in #3547. Each miss below was checked against the source:

language repo recall typical miss
c libuv 91.1% (78 misses) src/unix/aix.c: #include "internal.h" → src/unix/internal.h (also src/win/internal.h, src/internal.h…)
javascript express 47.6% (33 misses) examples/content-negotiation/index.js: require('./db') → examples/content-negotiation/db.js (every example has a db.js)
ruby rack 96.2% (9 misses) lib/rack/common_logger.rb: require_relative 'request' → lib/rack/request.rb (also lib/rack/auth/abstract/request.rb)
zig zls 79.0% (57 misses) src/DocumentScope.zig: @import("ast.zig") → src/ast.zig

Impact

The most-included internal headers and modules in a real repo are the ones whose names repeat across platform or example directories. They lose all their in-edges, so their PageRank and blast radius are understated.

Fix direction

In network_risk_sensor.py, before the bare-stem lookup (or when it returns several candidates), resolve the token against the importing file's directory: dirname(src)/token with the language's extensions. If exactly that file exists, link it.

  • Languages whose rule tries the including file's directory first: C/C++ quoted includes, Ruby require_relative, Zig @import("x.zig"), and JS/TS ./ and ../ specifiers.
  • Angle-bracket includes and bare module names are unchanged (Dependency Attribution Error duplicate filenames #261 still holds for them).

Gate: import_graph_accuracy.py c javascript ruby zig recall should rise. Regenerate that baseline and re-bless the golden masters.

Activity

  1. added
    bug
    core-engine
    on Sep 25, 2026
  2. squid-protocol commented on Sep 25, 2026

    @squid-protocol
    OwnerAuthor

    Fixed by #3562 (merged). Relative imports, plus C/C++/ObjC/Ruby/Zig includes, now resolve from the importing file's directory first. A file name that repeats elsewhere in the repo no longer drops the edge. Measured recall: C 100%, Ruby 99.6%, JS 100%, Zig 94.1%.


    Generated by Claude Code

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

    bugcore-engine

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions