Skip to content

fix: prevent non-type nodes from hijacking C# type resolution - #3815

Closed
hopstreax wants to merge 2 commits into
Graphify-Labs:v8from
hopstreax:fix/3795-csharp-type-resolution
Closed

hopstreax wants to merge 2 commits into
Graphify-Labs:v8from
hopstreax:fix/3795-csharp-type-resolution

Conversation

@hopstreax

@hopstreax hopstreax commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #3795 by preventing C# member nodes from being incorrectly indexed as type definitions.

Previously, enum members, properties, and methods could collide with actual type names during C# type resolution. The initial fix introduced a contains-edge requirement, which caused a regression for partial/cross-repo graphs that do not contain structural contains edges.

This update removes that requirement and instead excludes nodes that are targets of member-specific relations.

Changes

  • Exclude case_of targets from the C# type definition index.
  • Exclude defines targets from the C# type definition index.
  • Exclude method targets from the C# type definition index.
  • Support both _tgt and target edge fields.
  • Preserve type resolution for partial and cross-repo graphs without contains edges.
  • Add a regression test for CsharpNameResolver on partial graphs.

Verification

  • pytest tests/test_csharp_type_resolution.py -q — 43 passed
  • pytest tests/test_cross_repo_external_call_guards.py -q — 3 passed
  • pytest tests/test_cross_repo_member_calls.py -q — 19 passed
  • pytest tests/test_cross_repo_shared_types.py -q — 7 passed
  • All C# tests — 158 passed
  • git diff --check — clean

The full suite was also rerun after the regression fix and the previously failing cross-repo C# visibility test now passes.

@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 1 advisory finding(s) below merit a look before merge.


Graphify review — findings

Restricts the C# type-def index to genuine type declarations by consulting the edge list: _build_csharp_type_def_index now takes all_edges and only indexes nodes reached by a contains edge, excluding those targeted by case_of, defines, or method relations. This stops enum members, properties, and methods that share a name with a real type from hijacking inheritance and parameter-type references regardless of file sort order, and threads the edge list through _resolve_cross_file_csharp_imports and CsharpNameResolver. Adds tests covering same-file and cross-file name collisions between enum members/properties and classes/external stubs.

Worth a look

  • non_type_ids relation list may exclude legitimate types via 'defines' — graphify/extractors/csharp.py:36 · 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 — 1444 functions depend on the 79 functions this change touches.

Health — this change adds coupling hotspots:

  • new: extract() — 690 callers, 45 callees
  • new: _rebuild_code() — 144 callers, 55 callees
  • new: main() — 98 callers, 3 callees
  • new: dispatch_command() — 2 callers, 125 callees
  • new: link_cross_repo_member_calls() — 21 callers, 9 callees
  • new: global_add() — 12 callers, 9 callees
  • new: run_pipeline() — 8 callers, 13 callees
  • new: watch() — 5 callers, 7 callees
  • …and 16 more — each is listed as a finding

Verification — 1444 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: 633 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

6 of 298 test file(s) selected (2%) via static blast radius.

  • tests/test_cross_repo_external_call_guards.py — impact
  • tests/test_cross_repo_member_calls.py — impact
  • tests/test_csharp_type_resolution.py — impact, changed-test
  • tests/test_extract.py — impact
  • tests/test_global_add_tag_inference.py — impact
  • tests/test_global_graph.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.

· 24 more finding(s) on lines outside this diff (see the check run).

@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.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).

Formal verification. 1 change(s) alter behavior, breaking input(s) attached.

Behavior changes: extract\_python changes behavior, here is the input that shows it.

The verifier found a concrete input on which extract\_python behaves differently before and after the change. If that change is intended, ship it; if not, this is your bug.

Guarantee: This difference was REPRODUCED, the verifier actually ran both versions on that input and saw them disagree. It is real, not an artifact.

Evidence: On input \{"path":"\_\_import\_\_\('pathlib'\)\.Path\('missing/deeper\.txt'\)"\}, the old code produced raises TypeError but the new code produces \{'nodes': \[\], 'edges': \[\], 'error': "\[Errno 2\] No such file or directory: 'missing/deeper\.txt'"\}. Paste that input straight into a regression test.


Graphify review — findings

Excludes member nodes from the C# type-definition index by having _build_csharp_type_def_index collect the targets of case_of, defines, and method edges and skip any candidate whose id appears there, so enum members, methods, and properties can no longer be matched as type definitions. Threads all_edges through the index builder from both _resolve_cross_file_csharp_imports and CsharpNameResolver, letting type resolution stay correct regardless of file sort order or missing structural edges.

No blocking issues surfaced. 3 lower-confidence candidates did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 1445 functions depend on the 80 functions this change touches.

Health — this change adds coupling hotspots:

  • new: extract() — 690 callers, 45 callees
  • new: _rebuild_code() — 144 callers, 55 callees
  • new: main() — 98 callers, 3 callees
  • new: dispatch_command() — 2 callers, 125 callees
  • new: link_cross_repo_member_calls() — 21 callers, 9 callees
  • new: global_add() — 12 callers, 9 callees
  • new: run_pipeline() — 8 callers, 13 callees
  • new: watch() — 5 callers, 7 callees
  • …and 16 more — each is listed as a finding

Verification — 1445 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: 634 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

6 of 298 test file(s) selected (2%) via static blast radius.

  • tests/test_cross_repo_external_call_guards.py — impact
  • tests/test_cross_repo_member_calls.py — impact
  • tests/test_csharp_type_resolution.py — impact, changed-test
  • tests/test_extract.py — impact
  • tests/test_global_add_tag_inference.py — impact
  • tests/test_global_graph.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.

Formal verification

Behavior changes: extract\_python changes behavior, here is the input that shows it.

The verifier found a concrete input on which extract\_python behaves differently before and after the change. If that change is intended, ship it; if not, this is your bug.

Guarantee: This difference was REPRODUCED, the verifier actually ran both versions on that input and saw them disagree. It is real, not an artifact.

Evidence: On input \{"path":"\_\_import\_\_\('pathlib'\)\.Path\('missing/deeper\.txt'\)"\}, the old code produced raises TypeError but the new code produces \{'nodes': \[\], 'edges': \[\], 'error': "\[Errno 2\] No such file or directory: 'missing/deeper\.txt'"\}. Paste that input straight into a regression test.

Could not verify: Could not verify to\_obsidian.

The verifier did not have enough to check to\_obsidian, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 200 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly TypeError — names the real obstacle, not a sampling gap)

Could not verify: Could not verify extract.

The verifier did not have enough to check extract, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 90 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly TypeError — names the real obstacle, not a sampling gap)

Could not verify: Could not verify \_import\_python.

The verifier did not have enough to check \_import\_python, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 200 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly AttributeError — names the real obstacle, not a sampling gap)

Could not verify: Could not verify \_resolve\_python\_member\_calls.

The verifier did not have enough to check \_resolve\_python\_member\_calls, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: non-vacuity: domain too small (only 1 distinct inputs exercised, need 3) — 'no divergence' would be near-vacuous

Could not verify: Could not verify \_safe\_extract.

The verifier did not have enough to check \_safe\_extract, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: parameter `extractor` is annotated `Callable` — outside the synthesizable primitive/collection set

No difference found (not proven): No behavior difference found in \_safe\_extract\_with\_xaml\_root (not a proof).

The verifier ran both versions of \_safe\_extract\_with\_xaml\_root 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.

Could not verify: Could not verify \_build\_csharp\_type\_def\_index.

The verifier did not have enough to check \_build\_csharp\_type\_def\_index, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: non-vacuity: domain too small (only 1 distinct inputs exercised, need 3) — 'no divergence' would be near-vacuous

Could not verify: Could not verify \_\_init\_\_.

The verifier did not have enough to check \_\_init\_\_, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 27 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly __init__ raised on the synthesized receiver args — names the real obstacle, not a sampling gap)

Could not verify: Could not verify \_resolve\_cross\_file\_csharp\_imports.

The verifier did not have enough to check \_resolve\_cross\_file\_csharp\_imports, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: non-vacuity: domain too small (only 1 distinct inputs exercised, need 3) — 'no divergence' would be near-vacuous

Could not verify: Could not verify \_extract\_generic.

The verifier did not have enough to check \_extract\_generic, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: parameter `config` is annotated `LanguageConfig` — outside the synthesizable primitive/collection set

Could not verify: Could not verify \_apply\_symbol\_resolution\_facts.

The verifier did not have enough to check \_apply\_symbol\_resolution\_facts, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: parameter `facts` is annotated `_SymbolResolutionFacts` — outside the synthesizable primitive/collection set

Could not verify: Could not verify \_augment\_symbol\_resolution\_edges.

The verifier did not have enough to check \_augment\_symbol\_resolution\_edges, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: non-vacuity: domain too small (only 1 distinct inputs exercised, need 3) — 'no divergence' would be near-vacuous

Could not verify: Could not verify \_collect\_python\_symbol\_resolution\_facts.

The verifier did not have enough to check \_collect\_python\_symbol\_resolution\_facts, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: parameter `facts` is annotated `_SymbolResolutionFacts` — outside the synthesizable primitive/collection set

Could not verify: Could not verify \_resolve\_cross\_file\_imports.

The verifier did not have enough to check \_resolve\_cross\_file\_imports, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: non-vacuity: domain too small (only 2 distinct inputs exercised, need 3) — 'no divergence' would be near-vacuous

No difference found (not proven): No behavior difference found in \_redact\_value (not a proof).

The verifier ran both versions of \_redact\_value 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 \_pin\_hash\_seed\_if\_needed (not a proof).

The verifier ran both versions of \_pin\_hash\_seed\_if\_needed 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.

Could not verify: Could not verify to\_wiki.

The verifier did not have enough to check to\_wiki, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 200 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly TypeError — names the real obstacle, not a sampling gap)

· 24 more finding(s) on lines outside this diff (see the check run).

safishamsi added a commit that referenced this pull request Sep 25, 2026
Complete the skillgen --watch INPUT_PATH injection fix in the add-watch
reference (#3742), preserve cross-file edges on incremental update
(#3812), stop C# type references resolving to same-named non-type nodes
(#3815), prefer a real source location over richness in dedup (#3786),
and resolve Maven inherited groupId + ${...} properties in pom.xml
(#3823).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.68 (now on PyPI) via an authorship-preserving cherry-pick, so your commit keeps contributor-graph credit. Thanks @hopstreax! C# type references no longer resolve to same-named non-type nodes; partial-class resolution restored.

Release: https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.68

@safishamsi safishamsi closed this Sep 25, 2026
safishamsi pushed a commit that referenced this pull request Oct 2, 2026
…stub

When a class is only referenced in a type annotation (Python) or a generic
argument (C#) earlier in the file, that reference mints a source-less stub
with the class name. A later `Parser()` / `new Widget()` in the same file
found the stub in the local lookup, was recognised as an external stub, and
was dropped: it was neither emitted as a local edge nor queued for
cross-file resolution. Since 0.9.62 these constructor edges were missing.

Queue those calls for cross-file resolution as well. That pass already
refuses source-less targets (#3156), so the stub itself still never becomes
a calls hub.

These calls did not bind to anything before, so a rescued call is marked
and only binds with evidence: an import of the target, or for C# the
namespace / `using` scope via CsharpNameResolver. Without that, a file that
imports `com.lib.Client` or uses `System.Collections.Generic` would bind
`new Client()` / `new List<int>()` to an unrelated same-named class.

For C#, `new X()` also drops `case_of` / `defines` targets from its
candidates, the same exclusion the C# type-definition index uses (#3815),
so it cannot bind to an enum member or property named X.

Fixes #3888

(cherry picked from commit e4a9270)
safishamsi pushed a commit that referenced this pull request Oct 13, 2026
A C# object creation was resolved against every definition named X, methods
included. Inside a helper like `static Bounds Bounds(..) => new Bounds(..)`
(Unity's Bounds, outside the corpus) it became an EXTRACTED self-loop; across
files the bare-name pass bound every `new List<T>()` in the corpus to an
unrelated `List()` method, minting an INFERRED hub with one false caller per
construction site.

The same-file path now defers a construction whose bare-name target is a
method, and the cross-file pass drops method candidates for `csharp_new`
calls, next to the enum-member/property exclusion (#3815, #4245). A real
type with the same name still wins.

Dropping those candidates removes ties that used to hide a separate guess: a
qualified construction (`new QuickSlotsBar.Slot()`) with several bare-name
`Slot` classes went to the path-proximity tie-break, which ignores the
qualifier and picks the Slot next to the caller. A qualified construction now
takes the one candidate nested in a type named by the qualifier's last
segment, or gets no edge; namespace qualifiers stay with
`_resolve_csharp_qualified_calls`.

Fixes #4419.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 68202f9)
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.

C#: base types and type references resolve to enum members (and properties) of the same name

2 participants