Repository navigation
fix(extract): keep Go and Rust same-file declarations that differ only by case - #4468
abdulsamie10 wants to merge 3 commits into
Conversation
…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]>
|
Thanks @abdulsamie10! One small thing: our changelog and release notes are built from PR titles, so we use the conventional-commits format, for example: Prefixes we use: |
|
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. |
There was a problem hiding this comment.
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— impacttests/test_cache_stale_import_target.py— impacttests/test_charmap_encoding.py— impacttests/test_chunking.py— impacttests/test_csharp_partial_classes.py— impacttests/test_definition_file_portability.py— impacttests/test_detect.py— impacttests/test_extract.py— impacttests/test_extract_cache_location.py— impacttests/test_extract_cli.py— impacttests/test_go_qualified_resolution.py— impact, changed-testtests/test_grammar_cache_key.py— impacttests/test_ignore_file_encoding.py— impacttests/test_incremental_mtime_collision.py— impacttests/test_java_member_calls.py— impacttests/test_language_override_lifecycle.py— impacttests/test_language_overrides.py— impacttests/test_languages.py— impacttests/test_llm_backends.py— impacttests/test_manifest_ingest.py— impacttests/test_multilang.py— impacttests/test_objc_field_table_remap.py— impacttests/test_out_dir_evidence.py— impacttests/test_partial_cache.py— impacttests/test_pipeline.py— impacttests/test_python_inherited_method_calls.py— impacttests/test_python_property_reads.py— impacttests/test_rust_case_collisions.py— impact, changed-testtests/test_rust_in_file_call_binding.py— impacttests/test_rust_macro_rules.py— impacttests/test_rust_self_member_calls.py— impacttests/test_rust_use_trees.py— impacttests/test_semantic_cache_basename_recovery.py— impacttests/test_semantic_cache_out_root.py— impacttests/test_skill_persisted_scan_options.py— impacttests/test_skill_semantic_all_cached.py— impacttests/test_stale_prune.py— impacttests/test_stat_index_husk.py— impacttests/test_stat_index_multi_root.py— impacttests/test_stat_index_portability.py— impacttests/test_watch_manifest_location.py— impacttests/test_word_count_cache.py— impacttests/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)
CHANGELOG.md§ 0.9.83 (2026-10-09) (lines 158-172): references changed symbolsidsCHANGELOG.md§ 0.9.62 (2026-09-15) (lines 448-466): references changed symbolsidsCHANGELOG.md§ 0.9.52 (2026-08-29) (lines 570-585): references changed symbolsidsCHANGELOG.md§ 0.9.34 (2026-08-05) (lines 800-808): references changed symbolsidsCHANGELOG.md§ 0.9.15 (2026-07-13) (lines 1049-1056): references changed symbolsidsCHANGELOG.md§ 0.9.5 (2026-07-02) (lines 1209-1232): references changed symbolsidsCHANGELOG.md§ 0.8.43 (2026-06-19) (lines 1371-1380): references changed symbolsidsgraphify/skill-agents.md§ Part A - Structural extraction for code files (lines 178-206): references changed symbolsidsgraphify/skill-amp.md§ Part A - Structural extraction for code files (lines 178-206): references changed symbolsidsgraphify/skill-claw.md§ Part A - Structural extraction for code files (lines 178-206): references changed symbolsids
…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).
| return plain_nid | ||
| return symbol_nid(plain_nid, name) | ||
|
|
||
| def walk(node) -> None: |
There was a problem hiding this comment.
walk()
fans out to 12 callees (efferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.
…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]>
|
I checked the three advisory findings against this branch and against 1. "Salted colliding Rust fns may lose their intra-file call edges" ( In-file calls bind through I reproduced it with
This is pinned by 2. "Forward references to a retained colliding Rust type resolve to an external node" ( #3782 deliberately left a reference placed above Reproduced with
This PR gives the other items ids of their own, so the struct now owns its id and can be pre-registered (
3. "Non-colliding Go type declarations are salted" (
One thing the measurement did show: on Coupling note on 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:
|
… 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)
|
Landed in 0.9.92 (authorship-preserving cherry-pick, so it shows on your contributions). Thanks @abdulsamie10! Released to PyPI: https://pypi.org/project/graphifyy/0.9.92/ · https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.92 |
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. Gotypedeclarations and Rust items still collapse the same way. Onv8at10130e7:response_writer.go:type ResponseWriter interface(L23) andtype 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 nottype_spec.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 incrates/core/messages.rs,struct Logger/const LOGGER, andfn e/fn Eincrates/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 theIgnoreshape a call made insidefn ignore()comes out as a call fromstruct Ignore.This PR applies the same rule to both extractors:
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 census now also countstypedeclarations, using its existing rule. The unique exported member keeps the plain id. Every other member is salted withsha1(name)[:6], and with no unique exported member every member is salted. A salted type's 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.implblocks name the type, so it and its methods keep their ids. Every other member is salted the same way. With no single declared type (fn e/fn E,static MESSAGES/fn messages), every member is salted, so the result doesn't depend on declaration order.#[cfg]twins are one name and still share one node. A reference placed above the declared type now resolves to it. Rust: a type used above its declaration stays a sourceless stub when the name is defined in 2+ files #3782 had to leave that case on a sourceless stub while another item could hold the type's id. A name that a non-type item also uses exactly (fn Foo()besidestruct Foo {}) and atypealias still keep the stub.Supersedes #3322, cut down as proposed there. Related: #3302 (closed by
343f76f), #2810.Deliberately not in this PR:
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 the343f76fpre-scan to them. Python functions and methods, including case-only pairs like sqlalchemy'svisit_TEXT/visit_text, are already handled onv8.v8at10130e7, with the same command and zod commit, I get 566inheritsedges, 18inheritsself-loops and 1 node labelled_Zod*. That is still the self-loop count from their table. This PR doesn't change those numbers.v8).implthat differ only by case are not counted. Only file-level items are.Type of change
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 getmake_id(plain, sha1(raw_name)[:6]), the same salt shape as #2779 and343f76f.Measured on shallow clones with an AST-only
graphify update <repo> --no-cluster. Both sides ran from the same absolute path,v8=10130e7.inheritsself-loopscallsself-loops0f09c3a3fce3b50b216ef611c616f46ead85dda14f52ac781graph.jsonnode and edge sets are identical before and after.parser/Parser,query/Query,pool/Pool, …).v8the plain id went to whichever member was declared first. It now goes to the member the rule picks. That happens in 4 groups:storage/series.gosamples→Samples, which also moves the plain ids of.Get()and.Len()with it;util/stats/query_stats.goquerySamples→QuerySamples;time/interval.rsfn interval→struct Interval;task.rsfn spawn→struct Spawn.responseWriterthat 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 iscontext.go's sourcelessresponseWriterreference, which now lands on the struct.static MESSAGES,static IGNORE_MESSAGES,static ERROREDandfn 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:
fn E(a test helper incrates/regex/src/literal.rs) becomes a unique match. Seven files had a per-file sourcelessEstub for a generic parameter, and those stubs collapse onto it, so 14referencesedges now point atfn E. That's wrong: a type reference is being bound to a function.Sleep,Interval,Spawn, anduse tokio::signal::unix::{signal, SignalKind}landing onfn signal.parkimports of a module orstd::thread::parkland onfn parkinruntime/jspi.rs, and 2use tokio::signal;module imports land onfn signal.poolreferences instorage/remoteand 1Samplesintsdb/chunks/chunks.gohad been correct same-package bindings.Samplesinstorage/series.goL96 had been bound totsdb/chunks'sSamples, the wrong package. Its real target is the same file'sSamples, declared below it, andv8never resolves an in-file Go forward reference.QuerySamplesgo 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_SCHEMAis 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.How was this tested?
15 new tests and 1 rewritten:
tests/test_go_qualified_resolution.pynext to the 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 tests. They use the gin shape: both types extracted; methods owned by their own type; in-file field reference lands on the struct; exported type and its methods keep their solo ids; ids independent of declaration order; other types in the file keep their ids.tests/test_rust_case_collisions.py. They use the ripgrep shapes:struct Ignore+fn ignore; the struct keeps its solo id and methods; the salted function owns its own calls; in-file calls reach the salted functions; ids independent of order;fn e/fn Eboth salted;#[cfg]twins stay one node next to a case-only sibling; a forward reference lands on the retained type when another file declares the same name.tests/test_multilang.py: the Rust: a type used above its declaration stays a sourceless stub when the name is defined in 2+ files #3782 test that pinned a sourceless stub for the case-only shapes now asserts they resolve to the struct. A new test keeps the stub assertion for the shapes that still share a node (type HANDLEalias,fn Handle()besidestruct Handle {}).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.Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments. (not applicable: no skill sources touched)