Skip to content

fix(extract): keep Go and Rust same-file declarations that differ only by case - #4468

Closed
abdulsamie10 wants to merge 3 commits into
Graphify-Labs:v8from
abdulsamie10:fix/id-collisions-beyond-python
Closed

abdulsamie10 wants to merge 3 commits into
Graphify-Labs:v8from
abdulsamie10:fix/id-collisions-beyond-python

Conversation

@abdulsamie10

@abdulsamie10 abdulsamie10 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

343f76f (#3302) and #4415 stopped Python and C# from dropping one of two same-file declarations whose names fold to the same node id. Go type declarations and Rust items still collapse the same way. On v8 at 10130e7:

  • Go, gin response_writer.go: type ResponseWriter interface (L23) and type responseWriter struct (L49) mint …_responsewriter. The struct has no node, and all 13 of its methods attach to the interface. Seven become nodes under the interface's id. The other six (Status, Size, Written, …) merge into the interface's own method requirements and have no node of their own. Go's existing case-only census (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) covers functions and methods but not type_spec.
  • Rust, ripgrep: struct Ignore / fn ignore (crates/ignore/src/dir.rs), struct Types / fn types, struct Filter / fn filter, static MESSAGES / fn messages() and two more pairs in crates/core/messages.rs, struct Logger / const LOGGER, and fn e / fn E in crates/regex/src/literal.rs. In each pair walk() keeps whichever item comes first and drops the other. The dropped function's calls are credited to the survivor: in the Ignore shape a call made inside fn ignore() comes out as a call from struct Ignore.

This PR applies the same rule to both extractors:

Supersedes #3322, cut down as proposed there. Related: #3302 (closed by 343f76f), #2810.

Deliberately not in this PR:

  • Python module-level classes (class Session / def session() in requests, Insert / insert() in sqlalchemy): fix(python): salt module-level class ids that collide with a function or class (#2810) #4467 extends the 343f76f pre-scan to them. Python functions and methods, including case-only pairs like sqlalchemy's visit_TEXT / visit_text, are already handled on v8.
  • TypeScript/JavaScript: fix: preserve case-colliding TypeScript symbols #3738 covers top-level case collisions there. That includes the zod shapes @krishhgg measured on Fix: same-file node-id collisions silently drop definitions (#3302) #3322 (thanks for that table). On v8 at 10130e7, with the same command and zod commit, I get 566 inherits edges, 18 inherits self-loops and 1 node labelled _Zod*. That is still the self-loop count from their table. This PR doesn't change those numbers.
  • Other config-driven languages (Java, Kotlin, PHP, Ruby, …): each needs its own pre-scan in the style of the Python and C# ones. They are not attempted here.
  • Cross-file pairs: the census is per file. A Go case-only type pair split across two files of one package is not covered, and a method declared in another file on the unexported type still lands on the plain id (unchanged from v8).
  • Methods and associated items inside one Rust impl that differ only by case are not counted. Only file-level items are.

Type of change

  • Bug fix

Verification & Invariants

Invariant: a symbol with no colliding sibling keeps exactly the id it has on v8. Inside a collision group, the member the rule picks keeps the plain id. That is the exported Go type, or the single declared Rust type. Other members get make_id(plain, sha1(raw_name)[:6]), the same salt shape as #2779 and 343f76f.

Measured on shallow clones with an AST-only graphify update <repo> --no-cluster. Both sides ran from the same absolute path, v8 = 10130e7.

corpus (commit) nodes sourced nodes edges inherits self-loops calls self-loops definitions recovered definitions lost sourced ids that moved sourceless stubs removed
gin-gonic/gin 0f09c3a 1994 → 2000 1870 → 1877 5766 → 5798 0 0 7 0 7 1
BurntSushi/ripgrep 3fce3b5 4517 → 4518 4126 → 4134 10308 → 10318 0 1 8 0 4 7
colinhacks/zod 0b216ef 6776 6632 11008 18 62 0 0 0 0
psf/requests 611c616 1319 1158 2795 0 1 0 0 0 0
sqlalchemy/sqlalchemy f46ead8 44510 41990 113068 12 90 0 0 0 0
prometheus/prometheus 5dda14f 17199 → 17233 15916 → 15947 72974 → 73024 2 11 31 0 40 1
tokio-rs/tokio 52ac781 13593 → 13598 10953 → 10976 28540 → 28609 0 0 23 0 9 18
  • zod, requests, sqlalchemy: they contain no Go or Rust, and their graph.json node and edge sets are identical before and after.
  • gin and ripgrep: two runs of the patched tree produce identical node and edge sets.
  • Every id that moved is a member of a collision group, or a node owned by one. No id outside those groups changed. In prometheus, each of the 10 salted types has a same-file partner that differs only by case (parser/Parser, query/Query, pool/Pool, …).
  • A plain id can change holder inside a group. On v8 the plain id went to whichever member was declared first. It now goes to the member the rule picks. That happens in 4 groups:
    • prometheus storage/series.go samples → Samples, which also moves the plain ids of .Get() and .Len() with it;
    • prometheus util/stats/query_stats.go querySamples → QuerySamples;
    • tokio time/interval.rs fn interval → struct Interval;
    • tokio-test task.rs fn spawn → struct Spawn.
    • gin: the 7 moved ids are methods of responseWriter that sat under the interface's plain id. They are now under …_responsewriter_ab7ca3. The interface and its 6 method requirements keep their ids. The removed stub is context.go's sourceless responseWriter reference, which now lands on the struct.
    • ripgrep: the 4 moved ids are static MESSAGES, static IGNORE_MESSAGES, static ERRORED and fn e. They are all-salted groups with no declared type.

Known knock-ons, all through the corpus-wide name-only stub rewire (#1402). Recovered definitions change which names are unique across the corpus. This PR adds no rewire logic; the effects below are the existing rewire seeing the new nodes:

  • ripgrep: the recovered fn E (a test helper in crates/regex/src/literal.rs) becomes a unique match. Seven files had a per-file sourceless E stub for a generic parameter, and those stubs collapse onto it, so 14 references edges now point at fn E. That's wrong: a type reference is being bound to a function.
  • tokio: 53 references and imports move from sourceless stubs to recovered definitions.
    • 47 are right: Sleep, Interval, Spawn, and use tokio::signal::unix::{signal, SignalKind} landing on fn signal.
    • 6 are wrong: 4 park imports of a module or std::thread::park land on fn park in runtime/jspi.rs, and 2 use tokio::signal; module imports land on fn signal.
  • prometheus: 5 references go from a sourced type to a sourceless stub. A recovered unexported type made the name ambiguous corpus-wide, so the rewire now declines it.
    • 3 pool references in storage/remote and 1 Samples in tsdb/chunks/chunks.go had been correct same-package bindings.
    • 1 Samples in storage/series.go L96 had been bound to tsdb/chunks's Samples, the wrong package. Its real target is the same file's Samples, declared below it, and v8 never resolves an in-file Go forward reference.
    • 2 references to QuerySamples go the other way, from a stub to the declaration.

The fix for these belongs in the rewire: type-like targets for type-reference contexts, and package-aware matching for Go. I can do that as a separate PR if it's wanted.

Persisted state: _AST_CACHE_SCHEMA is bumped to 17, so a warm cache can't serve pre-fix nodes for these files. Graphs that already contain the collapsed node keep working. Where the member the rule picks was also the one declared first, it keeps the plain id it already had. The 4 groups listed above are the exceptions measured here.

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary.
  • Added a regression test.
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly.

How was this tested?

15 new tests and 1 rewritten:

13 of these fail on v8, and all pass on this branch. The 3 that pass on both are guards rather than reproductions: the struct keeps its id, other Go types keep their ids, and the shapes that still share a node keep their stub.

uv run --frozen pytest tests/test_go_qualified_resolution.py tests/test_rust_case_collisions.py tests/test_multilang.py -q
#   this branch:                 121 passed
#   same test files on v8:       13 failed, 108 passed
uv run --frozen pytest tests/ -q --tb=short
#   v8 10130e7:   6 failed, 8043 passed, 15 skipped
#   this branch:  6 failed, 8058 passed, 15 skipped
#   The 6 failures are tests/test_security.py URL/fetch tests that need DNS for example.com
#   (no network in my environment). Their failure output is identical on both trees.
uv run --frozen ruff check .          # All checks passed
uv run --frozen pyright graphify/extractors/go.py graphify/extractors/rust.py tests/test_go_qualified_resolution.py tests/test_rust_case_collisions.py tests/test_multilang.py
#   1 error, pre-existing on v8 (go.py:185). The 8 rust.py set/frozenset errors are gone: local_type_names is now a frozenset
graphify update <corpus> --no-cluster   # table above, both trees, HOME and GRAPHIFY_NO_AUTO_REFRESH isolated

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. (not applicable: no skill sources touched)
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed that no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.

…case apart

make_id casefolds, so in one file `type ResponseWriter interface` and
`type responseWriter struct` (gin), or `struct Ignore` and `fn ignore`
(ripgrep), mint one node id. The walk keeps whichever
declaration it meets first and drops the other: the dropped struct's
methods hang off the interface, and a dropped function's calls are
credited to the struct.

Go: the Graphify-Labs#2779 census now also counts `type` declarations, using its
existing rule. The exported type keeps the plain id and the other is
salted; its methods, receiver anchors and in-file type references use the
salted id. Types are counted first so methods are keyed under their
owner's final id.

Rust: the Graphify-Labs#3782 pre-scan already lists every file-level item behind an
id, so it doubles as the census. The one declared struct/enum/trait in a
group keeps the plain id (type positions and `impl` blocks name it, so it
and its methods do not move) and every other member is salted with a
hash of its own name; with no single declared type, every member is
salted. `#[cfg]` twins are one name and still share one node.

A name that does not collide keeps its id. The census is per file: a
case-only pair split across two files of one Go package is not covered.

Related to Graphify-Labs#3302 and Graphify-Labs#2810.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the needs:title PR title should follow the conventional-commit format label Oct 15, 2026
@github-actions

Copy link
Copy Markdown

Thanks @abdulsamie10! One small thing: our changelog and release notes are built from PR titles, so we use the conventional-commits format, for example:

fix(python): resolve a bare stdlib import correctly

Prefixes we use: feat, fix, docs, chore, refactor, test, perf, build, ci. Editing the PR title clears this automatically. This is just a nudge and does not block review.

@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @abdulsamie10. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

@abdulsamie10 abdulsamie10 changed the title fix(go,rust): keep same-file declarations whose names differ only by case apart fix(extract): keep Go and Rust same-file declarations that differ only by case Oct 15, 2026
@github-actions github-actions Bot removed the needs:title PR title should follow the conventional-commit format label Oct 15, 2026

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 3 advisory finding(s) below merit a look before merge.

Not checked: tests were not run; formal verification proved 0 of 2 changed function(s) (2 sampled, not proven).

Formal verification. PR-changed functions: 2/2 verified (0 proven, 2 may-equivalent, 0 distinguished) · 0 not verified.


Graphify review — findings

Fixes Go type declarations and Rust file-level items whose names differ only by case (ResponseWriter / responseWriter, fn ignore / struct Ignore) collapsing into one node id. Each file now runs a per-file census of names that fold to the same id: Go salts the colliding types, along with their methods, receivers and in-file references, while Rust keeps the plain id for the single declared type in a group and salts every other member with a hash of its own name. The Go census is per file, so a pair split across two files of one package still collapses, and the Rust salting has to carry intra-file call edges and forward type references over to the new ids. Bumps _AST_CACHE_SCHEMA to 17 so stale cached extractions are rebuilt.

Worth a look

  • Salted colliding Rust fns may lose their intra-file call edges — graphify/extractors/rust.py:389 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
  • Forward references to a retained colliding Rust type resolve to an external node — graphify/extractors/rust.py:373 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
  • Non-colliding Go type declarations are salted — graphify/extractors/go.py:443 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 2654 functions depend on the 201 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract() — 961 callers, 58 callees
  • worse: extract_go() — 17 callers, 10 callees
  • worse: walk() — 1 callers, 14 callees
  • worse: walk() — 1 callers, 12 callees

Verification — 2654 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 1435 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

43 of 423 test file(s) selected (10%) via static blast radius.

  • tests/test_cache.py — impact
  • tests/test_cache_stale_import_target.py — impact
  • tests/test_charmap_encoding.py — impact
  • tests/test_chunking.py — impact
  • tests/test_csharp_partial_classes.py — impact
  • tests/test_definition_file_portability.py — impact
  • tests/test_detect.py — impact
  • tests/test_extract.py — impact
  • tests/test_extract_cache_location.py — impact
  • tests/test_extract_cli.py — impact
  • tests/test_go_qualified_resolution.py — impact, changed-test
  • tests/test_grammar_cache_key.py — impact
  • tests/test_ignore_file_encoding.py — impact
  • tests/test_incremental_mtime_collision.py — impact
  • tests/test_java_member_calls.py — impact
  • tests/test_language_override_lifecycle.py — impact
  • tests/test_language_overrides.py — impact
  • tests/test_languages.py — impact
  • tests/test_llm_backends.py — impact
  • tests/test_manifest_ingest.py — impact
  • tests/test_multilang.py — impact
  • tests/test_objc_field_table_remap.py — impact
  • tests/test_out_dir_evidence.py — impact
  • tests/test_partial_cache.py — impact
  • tests/test_pipeline.py — impact
  • tests/test_python_inherited_method_calls.py — impact
  • tests/test_python_property_reads.py — impact
  • tests/test_rust_case_collisions.py — impact, changed-test
  • tests/test_rust_in_file_call_binding.py — impact
  • tests/test_rust_macro_rules.py — impact
  • tests/test_rust_self_member_calls.py — impact
  • tests/test_rust_use_trees.py — impact
  • tests/test_semantic_cache_basename_recovery.py — impact
  • tests/test_semantic_cache_out_root.py — impact
  • tests/test_skill_persisted_scan_options.py — impact
  • tests/test_skill_semantic_all_cached.py — impact
  • tests/test_stale_prune.py — impact
  • tests/test_stat_index_husk.py — impact
  • tests/test_stat_index_multi_root.py — impact
  • tests/test_stat_index_portability.py — impact
  • tests/test_watch_manifest_location.py — impact
  • tests/test_word_count_cache.py — impact
  • tests/test_zero_node_no_cache.py — impact

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Docs that may be stale (advisory)

…and 10 more.

Formal verification

No difference found (not proven): No behavior difference found in extract\_go (not a proof).

The verifier ran both versions of extract\_go on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

No difference found (not proven): No behavior difference found in extract\_rust (not a proof).

The verifier ran both versions of extract\_rust on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

· 1 grounded finding(s) anchored inline below; 3 more finding(s) on lines outside this diff (see the check run).

Comment thread graphify/extractors/go.py
return plain_nid
return symbol_nid(plain_nid, name)

def walk(node) -> None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Health regression — walk()

fans out to 12 callees (efferent coupling).

Grounded coupling-delta finding (deterministic), not an LLM guess.

abdulsamie10 and others added 2 commits October 15, 2026 15:12
…side a case-only sibling

Graphify-Labs#3782 left a reference placed above `struct Handle` on a sourceless stub
whenever another file-level item folded to the same id (`fn handle`,
`const HANDLE`, an `impl` for `HANDLE`), because walk() gave that id to
whichever item came first. Those items now get ids of their own, so the
struct owns its id and the reference can resolve to it, as a reference
below the declaration already did. Without this, the stub only folds back
when the type's name is unique across the corpus.

A declared type is now pre-registered unless a non-type item has its
exact name (`fn Foo()` beside `struct Foo {}` still share one node), and a
`type HANDLE` alias still keeps its stub. The Graphify-Labs#3782 test that pinned the
stub for the case-only shapes now asserts the resolution; the shapes that
still share a node keep the stub assertion.

local_type_names becomes a frozenset, which is what
_rust_collect_type_refs is annotated to take.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… collision group

Two guards for the review questions on Graphify-Labs#4468: an in-file call to
`ignore()`, `e()` or `E()` binds by the name as written and reaches the
salted node (on v8 the calls to `ignore()` and `E()` bind nowhere, since
those functions had no node), and the other types in a Go file that holds
a case-only pair keep the ids they have without the pair.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@abdulsamie10

Copy link
Copy Markdown
Contributor Author

I checked the three advisory findings against this branch and against v8 (10130e7), each with a small fixture.

1. "Salted colliding Rust fns may lose their intra-file call edges" (rust.py:389): not a bug.

In-file calls bind through label_to_nid, which is built after walk() from each node's label (rust.py:789). A bare call looks that map up by the name as written (rust.py:888). A salted node keeps its raw label, so ignore(), e() and E() resolve to their salted ids.

I reproduced it with caller() calling all three, plus a second file doing use crate::dir::ignore; ignore():

  • This branch emits caller -> ignore(), caller -> e(), caller -> E() (EXTRACTED) and remote -> ignore() (INFERRED).
  • v8 emits only caller -> e(), because ignore and E had no nodes there.

This is pinned by test_calls_to_salted_functions_keep_their_in_file_edges (fails on v8, passes here) and by the existing test_salted_function_owns_its_own_body. Added in 5c49344.

2. "Forward references to a retained colliding Rust type resolve to an external node" (rust.py:373): real, and pre-existing on v8. Fixed in f710c8a.

#3782 deliberately left a reference placed above struct Handle on a sourceless stub whenever another file-level item folded to the same id. walk() gave that id to whichever item came first, and test_rust_forward_reference_to_a_casefold_colliding_type_keeps_its_stub pinned the stub.

Reproduced with fn before() -> Ignore above struct Ignore, with fn ignore in the same file:

  • extract_rust emits a sourceless Ignore stub on both v8 and bef78ff.
  • With a second file declaring its own Ignore, the corpus rewire declines the ambiguous name and the stub stays.

This PR gives the other items ids of their own, so the struct now owns its id and can be pre-registered (rust.py:370). A name that a non-type item uses exactly (fn Foo() beside struct Foo {}) still shares one node, and a type alias is still not a node, so both keep the stub. I split the #3782 test accordingly:

  • test_rust_forward_reference_to_a_casefold_colliding_type_resolves_to_it (fails on v8 and on bef78ff)
  • test_rust_forward_reference_keeps_its_stub_when_a_non_type_shares_the_name

test_forward_reference_to_the_retained_type_lands_on_it covers the two-file case (fails on v8 and on bef78ff). local_type_names is now a frozenset, which also clears the 8 pre-existing pyright errors at its call sites.

3. "Non-colliding Go type declarations are salted" (go.py:443): not a bug.

type_symbol_nid (go.py:441) returns the plain id unless the name is itself in a same-file case group (go.py:443), and symbol_nid salts only groups with two or more distinct names.

test_non_colliding_types_keep_their_ids_beside_a_colliding_pair pins this. It passes on v8 and here, so it is a guard, not a reproduction. I also measured on prometheus 5dda14f: all 10 types that get a salted id have a same-file partner differing only by case (parser/Parser, query/Query, pool/Pool, …), as gin's responseWriter does. No id outside a group moved.

One thing the measurement did show: on v8 the plain id went to whichever member came first, and it now goes to the member the rule picks. In prometheus that moves it from samples to Samples and from querySamples to QuerySamples. In tokio's Rust it moves interval/spawn to the declared types. The PR description now lists these.

Coupling note on go.py walk(): it gained one callee, type_symbol_nid, in place of a direct _make_id at the receiver and type_spec sites. I left it; moving the call behind another helper would not reduce what walk() does.

The description now also has prometheus and tokio rows. It says where recovered definitions change what the existing name-only stub rewire (#1402) resolves, in both directions, with counts.

Checks on 5c49344:

  • Full suite: 6 failed, 8058 passed, 15 skipped. The 6 are the DNS-dependent tests/test_security.py cases, with output identical to v8's.
  • ruff check .: clean.
  • pyright on the changed files: 1 error, pre-existing at go.py:185.
  • gin and ripgrep numbers are unchanged.

safishamsi pushed a commit that referenced this pull request Oct 16, 2026
… collision group

Two guards for the review questions on #4468: an in-file call to
`ignore()`, `e()` or `E()` binds by the name as written and reaches the
salted node (on v8 the calls to `ignore()` and `E()` bind nowhere, since
those functions had no node), and the other types in a Go file that holds
a case-only pair keep the ids they have without the pair.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 5c49344)
@safishamsi

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants