Skip to content

Go: case-only sibling symbols (Run / run) collapse to one node id — the unexported half vanishes and its call sites bind to a same-named function in another package #2779

Closed

Description

@catpotd

Version: graphifyy 0.9.44
Environment: macOS arm64, Python 3.12/3.14 (Go codebase, tree-sitter-go)
Related: #993 (case-insensitive resolution, fixed in 4dce16f — this is a different layer: the fix made lookup case-sensitive, but the extractor still emits casefolded node ids), #2774 (Rust: same symptom — private fns absorbing edges via bare-name identity — different trigger), #438 (id collision across files; this one is within a single file, which _disambiguate_colliding_node_ids explicitly skips via its len(source_keys) < 2 guard)

Summary

Node ids are casefolded (ids.py:normalize_id), so a Go file that declares both an
exported Run and an unexported run produces the same id for both. The
extractor's add_node dedups on id alone and silently drops the second
declaration (extractors/go.py, first-wins). Two failure modes follow:

  1. The unexported sibling vanishes from the graph. Its declaration produces
    no node, and the edges of its body are attributed to the exported sibling's
    node.
  2. Its call sites resolve to another package. The call run(1) inside Run
    finds no local run node, so the (case-sensitive, post-Case-insensitive call resolution generates phantom calls edges in Ruby (Pundit authorize → Authorize marker class) #993) resolver's only
    candidate is a same-named unexported function in a different package — an
    INFERRED calls edge that Go's visibility rules make impossible
    (unexported identifiers are package-private; main packages cannot be
    imported at all).

The Run() { return run(...) } exported-wrapper / unexported-worker pattern is
idiomatic Go (it is how test seams are injected), so real codebases hit this.

Minimal repro

// go.mod: module example.com/repro
// pkga/a.go
package pkga

func Run() error {
	return run(1)
}

func run(n int) error {
	return nil
}

// pkgb/b.go
package pkgb

func run(s string) error {
	return nil
}
$ graphify (extract over both files)

nodes:
  pkga_a_run   Run()   pkga/a.go:L3    <- run() L7 is MISSING
  pkgb_b_run   run()   pkgb/b.go:L3
edges:
  pkga_a_run -calls-> pkgb_b_run  [INFERRED 0.8]   <- impossible

Expected: two nodes for a.go (Run L3, run L7) and one
Run -calls-> run edge inside the file.

Control: rename Run to Start (no case collision) and the output is correct —
both nodes appear and Start -calls-> run binds within the file. The trigger is
the id collision, not the resolver.

Impact on a real corpus

On a private Go codebase, one file declares two such exported/unexported pairs:

  • 2 of that file's 10 functions are missing from the graph
  • a phantom calls edge crosses from the exported wrapper into an unrelated
    main package (which cannot be imported at all), and surfaced in
    GRAPH_REPORT.md's "Surprising Connections" as if it were an architectural
    insight
  • 5 body edges of the dropped functions (calls and references emitted while
    walking their bodies) are misattributed to the exported siblings

A quick audit rule — "calls edge crossing a package boundary whose target name
starts lowercase" — is guaranteed-false by the language and found exactly this
one instance in that corpus, so the failure is systematic but low-noise.

Where it sits

I have a patch ready (extractor-level: detect case-only collisions per file,
keep the plain id on the exported member — the one cross-package edges and docs
actually reference, so incremental rebuilds don't re-point stored edges — and
salt the unexported sibling), with tests that fail on unpatched v8, plus
full-suite (4520 passed) and real-corpus A/B verification. PR follows.

Activity

  1. imagineers-tyler commented on Aug 16, 2026

    @imagineers-tyler
    Contributor

    This reproduces outside Go, and the trigger is wider than casefolding — which matters for
    where the fix goes.

    normalize_id runs several lossy normalization stages, yielding at least five collision axes.
    Four are visible in ordinary ASCII identifiers — casefolding, punctuation replacement,
    repeated-underscore collapse, and edge stripping — and NFKC adds a Unicode
    compatibility-collapse axis:

    s = unicodedata.normalize("NFKC", s)
    s = unicodedata.normalize("NFKC", s.casefold())   # case
    s = re.sub(r"[^\w]+", "_", s, flags=re.UNICODE)   # $ # . - space … -> _
    s = re.sub(r"_+", "_", s)
    return s.strip("_")                                # leading/trailing _

    Case (your Run/run) is one axis. The others collide just as silently, and some collisions
    come from stages combining rather than from any single one — #close is
    #close → _close (punctuation) → close (edge strip).

    NFKC-induced collisions — each pair is already equal immediately after the first NFKC step,
    before casefolding or punctuation handling:

    NFKC('file') == NFKC('file') == 'file'    (fi ligature)
    NFKC('Ⅻ')   == NFKC('XII')  == 'XII'     (roman numeral)
    NFKC('fn') == NFKC('fn')   == 'fn'      (fullwidth)
    

    One file, two sibling declarations — graphifyy 0.9.44

    Same shape as your repro: the second declaration produces no node.

    language source nodes produced axis
    JS class R { _onBegin(a){} onBegin(b){} } ._onBegin() leading _
    JS class W { #close(a){} close(b){} } .#close() punctuation + edge strip
    TS declare class Q { $set(a); set(b); } .$set() punctuation + edge strip
    JS function parseURL(a){} + function parseUrl(b){} parseURL() case (your axis)
    Python def _run(a) + def run(b) _run() leading _
    Python def a_(p) + def a(q) a_() trailing _
    control def alpha(p) + def beta(q) alpha(), beta() —

    make_id on each pair:

    _onBegin -> onbegin    onBegin  -> onbegin    COLLIDE
    #close   -> close      close    -> close      COLLIDE
    $set     -> set        set      -> set        COLLIDE
    parseURL -> parseurl   parseUrl -> parseurl   COLLIDE
    _run     -> run        run      -> run        COLLIDE
    a_       -> a          a        -> a          COLLIDE
    alpha    -> alpha      beta     -> beta       ok
    

    Which member survives is declaration order (first-wins), not visibility: in my synthetic
    cases the private one survived, in happy-dom's real files the public one does.

    The #close/close case is worth calling out separately: #close is a private class
    method
    , a distinct language-level member that can coexist with close by design — not a
    naming convention the extractor could reasonably fold.

    Confirmed on real files, with controls

    Run through extract() on 0.9.44, one file at a time:

    file pair result
    happy-dom websocket/WebSocket.js #close / close close only — #close lost
    happy-dom xml-serializer/XMLSerializer.js #serializeToString / serializeToString public only — private lost
    happy-dom nodes/html-form-element/HTMLFormElement.js #submit / submit public only — private lost
    mongoose document.d.ts $set / set $set only — set lost
    playwright lib/runner/index.js _onBegin / onBegin _onBegin only — onBegin lost

    The playwright one has the same control you used. Renaming only the private half:

    original                      nodes=408   _onBegin=1  onBegin=0
    rename _onBegin -> _zzBegin   nodes=409   _zzBegin=1  onBegin=1
    

    The public method reappears and the node count goes up by exactly one, so the trigger is the
    id collision, not one of the "methods not extracted" gaps (#2419 / #2110 / #2524).

    That pair is declared in two different classes in that file and still collides, which is
    worth unpacking because it shows a second ingredient. Both owners are class expressions:

    var TeleReporterReceiver = class { … _onBegin() … }   // L104
    var TerminalReporter     = class { … onBegin(suite) … } // L1113

    JS class_types is frozenset({"class_declaration"}), and the TS set adds only
    abstract_class_declaration / interface_declaration / enum_declaration /
    type_alias_declaration — no class-expression type in either. So neither expression mints an
    owner node (the extraction produces no TeleReporterReceiver / TerminalReporter node at
    all), and their methods fall back to file-level ids rather than class-qualified ones:

    <file> + _onBegin -> …_src_index_onbegin
    <file> + onBegin  -> …_src_index_onbegin
    

    The observed id for the surviving node is exactly that file-level form, and its label is
    _onBegin() rather than ._onBegin(), i.e. it was registered as a file-level function, not a
    method. So the normalization collision and the lost ownership qualifier compound: without an
    owner to qualify against, two methods from unrelated classes land on one id.

    Your second failure mode reproduces too (Python)

    # vendor.py
    def helper(a):
        return a
    
    # b.py
    from vendor import helper
    
    class B:
        def _run(self, helper, p):
            return p.submit(helper)
    
        def run(self, x, p):
            return p.submit(x)
    _run alone            nodes=['._run()', 'helper()']   indirect_call: none
    _run + run            nodes=['._run()', 'helper()']   indirect_call: ._run() -> helper()
    

    The collision is required — delete run and the phantom goes away. run's shadow set ({x})
    lands on the surviving _run entry, so _run's own helper parameter stops shadowing and the
    argument resolves by name to the imported helper. Same mechanism as your misattributed body
    edges, reached through the shadow-set path instead of the resolver.

    Why this changes the fix's scope

    Your read of the mechanism matches what I see, including that
    _disambiguate_colliding_node_ids skips this case — on 0.9.44 the guard is still

    if len(group) < 2 or len(source_keys) < 2:
        continue

    so a within-file collision (one source_key) never reaches the salting path.

    The part I'd add: a fix scoped to Go, or scoped to case-folding, leaves the other axes live
    across the shared extractor stack wherever each language's identifier grammar admits those
    forms, since ids.py is shared by all extractors.

    On where it could go — one caveat worth stating up front, since it constrains the obvious
    answers. ids.py's module docstring sets out that the recipe is shared by three producers
    (AST extractor, LLM subagents, graph builder) and that divergence between them is a recurring
    bug class (#811, #550, #1033, #1104), so changing normalize_id itself has a wide blast
    radius. That might argue for a collision-aware declaration-registration layer near the
    seen_ids check, keyed by the raw declared name. But that layer would have to return the
    resolved id and propagate it, because today the caller owns the id and keeps using its own
    copy after add_node returns nothing — e.g. engine.py around the function-def site:

    func_nid = _make_id(parent_class_nid, func_name)
    add_node(func_nid, f".{func_name}()", line)
    add_edge(parent_class_nid, func_nid, "method", line)
    ...
    callable_def_nids.add(func_nid)
    local_bound_names[func_nid] = _python_local_bound_names(node, source)

    add_edge, callable_def_nids, local_bound_names, function_bodies and the per-language
    tables all key off the caller's func_nid. Salting inside add_node alone would move the node
    and leave every one of those pointing at the old id, so that is not a small change — I'm
    raising it as a constraint on the design rather than proposing it as the fix.

    Related, on the "wider than one language" point: #1522 (closed) reached the same conclusion
    about normalize_id from the path axis, calling it lossy and unsuitable for generating
    unique keys. This issue is the symbol-name axis of the same argument.


    Environment: graphifyy 0.9.44, macOS arm64, Python 3.14.7. Synthetic repros are single-file
    except the Python phantom-edge one (two files); the confirmed rows are real files from
    node_modules, extracted individually.

    I also have an approximate candidate scanner and raw package lists available, but I have kept
    the claims above to the five sites confirmed through extract().

  2. safishamsi commented on Aug 16, 2026

    @safishamsi
    Member

    Fixed in v0.9.45 (on PyPI now) via #2780, thanks @catpotd. Closing.

  3. added a commit that references this issue on Aug 17, 2026
  4. added a commit that references this issue on Aug 30, 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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions