Skip to content

fix(csharp): label C# methods with their owning type (#4883) - #4889

Merged
safishamsi merged 1 commit into
Graphify-Labs:v8from
SyedFahad7:cursor/csharp-method-owner-labels-5c23
Oct 30, 2026
Merged

safishamsi merged 1 commit into
Graphify-Labs:v8from
SyedFahad7:cursor/csharp-method-owner-labels-5c23

Conversation

@SyedFahad7

Copy link
Copy Markdown
Contributor

What does this PR do?

Every C# method node was labeled .Name(), so on the #4883 repro the interface method and both implementations all printed as .Build() and only the line number told them apart:

Node: .Build()
  --> .Build() [dispatches_to] [INFERRED] Report.cs:L2
  --> .Build() [dispatches_to] [INFERRED] Report.cs:L3
  <-- .Run() [calls] [INFERRED] Report.cs:L7

After this change (graphify update . then graphify explain report_ireport_build):

Node: IReport.Build()
  ID:        report_ireport_build
  <-- IReport [method] [EXTRACTED] Report.cs:L1
  --> PdfReport.Build() [dispatches_to] [INFERRED] Report.cs:L2
  --> CsvReport.Build() [dispatches_to] [INFERRED] Report.cs:L3
  <-- Exporter.Run() [calls] [INFERRED] Report.cs:L7

Node IDs and edges are unchanged; only the display label changes.

Where the label is assigned. The .Name() shape is load-bearing during extraction: the direct-call label index, the C# member-call resolvers, interface dispatch (interface_dispatch.method_label), and the build method-ghost passes all match on it. So extraction still emits .Name(). The owner-qualified label is applied as the last step of build_from_json and in both --no-cluster writers (watch._rebuild_code, cli). This is the same placement and contract as the #2032 file-label disambiguation. The owner comes from the source of the method's method edge, read through _src/_tgt on undirected graphs.

Reading persisted labels back. Code that reads labels from an existing graph.json now converts Owner.Name() back to .Name() through one helper, bare_csharp_method_label:

The issue's refs (extractors/csharp.py ~49/~126) are the type-def index and namespace lookup. Both already reject dotted labels and never see method labels, so they need no change.

Fixes #4883

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

Invariants protected:

  • Node identity: IDs and the edge set are unchanged. The test compares the built graph against raw extract() output.
  • Resolver contract: extract() still returns .Name() for C# methods.
  • Incremental = full build: with only the caller re-extracted, the calls and dispatches_to edges and the labels match a full rebuild.
  • Idempotent: labels are derived from the bare form, so rebuilding from an already-qualified graph never produces PdfReport.PdfReport.Build().
  • Fail-closed: a method with no owner, with owners carrying different labels, or with a non-plain owner label (for example a dotted namespace) keeps .Name().
  • Language gate: the change applies only to files whose effective_suffix is .cs. Java and Swift labels are unchanged (tested).

Persisted state: existing graphs pick up the new C# labels on the next build. Extraction output and the per-file AST cache are unchanged, so no cache schema bump is needed. Community names derived from C# method labels (for example in GRAPH_REPORT.md or the wiki) may change text accordingly.

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

Each added piece was shown to be necessary by reverting it on its own and re-running tests/test_csharp_method_owner_labels.py:

  • Build/writer wiring reverted: 6 tests fail (issue repro clustered and --no-cluster, incremental, context normalization, god nodes, ghost collapse).
  • extract() context normalization reverted: 2 tests fail (incremental rebuild, context normalization).
  • analyze predicate reverted: 1 test fails (god nodes).
  • Build ghost-index normalization reverted: 1 test fails (extraction-spec method IDs omit the class segment the AST extractor emits, so method nodes never dedupe #3705 ghost collapse).
  • Build alias-index normalization reverted: 1 test fails (class-segment-less alias).

Limitations / unsupported cases

  • Swift has the same problem (protocol Report, PdfReport, CsvReport all show .build()). It is not changed here. Swift needs the same treatment plus its own checks: extension members merged across files by _merge_swift_extensions, and the Swift member-call and protocol-dispatch resolvers reading context labels. The helpers here are suffix-gated, so a follow-up can extend them, but that is a separate concern with its own tests.
  • Razor (.razor / .cshtml) methods keep .Name(). Only .cs (including rcfile-mapped suffixes) is relabeled.
  • Nested types show their immediate owner only (Inner.Deep(), not Outer.Inner.Deep()).

How was this tested?

# repro from the issue (Report.cs), before and after
graphify update .
graphify explain report_ireport_build

uv run pytest tests/test_csharp_method_owner_labels.py -q      # 19 passed
uv run pytest tests -q                                        # 8985 passed, 17 skipped, 1 xfailed
uv run ruff check .                                           # All checks passed
uv run pyright graphify/extractors/csharp.py graphify/build.py graphify/analyze.py \
  graphify/extract.py graphify/watch.py graphify/cli.py tests/test_csharp_method_owner_labels.py
# no new diagnostics vs. upstream v8 (remaining errors are pre-existing)

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. (N/A: no skill fragments 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 no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.
Open in Web Open in Cursor 

)

Every C# method was labeled `.Name()`, so an interface method and each of
its implementations printed identically (`.Build()` x3) and only the line
told them apart.

The graph build now assigns C# methods an `Owner.Name()` display label,
taken from the source of the method's `method` edge, as the last step of
build_from_json and in both --no-cluster writers (same placement as the
Graphify-Labs#2032 file-label disambiguation). Ids and edges are unchanged, and a method
with zero or several owners keeps its bare label.

Extraction keeps emitting the bare `.Name()` form that call resolution,
interface dispatch, and the method-ghost index match on. Readers of a
persisted graph normalize back to it: incremental resolution context in
extract(), the build method-ghost and old-stem alias indexes, and the
analyze method-stub predicate.

Fixes Graphify-Labs#4883

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: Syed Fahad <[email protected]>
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @SyedFahad7. 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.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Oct 30, 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.

No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.

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

Formal verification. PR-changed functions: 1/6 verified (0 proven, 1 may-equivalent, 0 distinguished) · 5 not verified (3 vacuous, 2 unsupported).

Not verified on this run: \_is\_file\_node (vacuous: never exercised), \_alias\_index (unsupported), build\_from\_json (vacuous: never exercised), dispatch\_command (vacuous: never exercised), \_rebuild\_code (unsupported).


Graphify review — findings

Adds owner-qualified display labels for C# methods (Owner.Name() instead of bare .Name()), applied as a final pass in build_from_json and in the --no-cluster writer path. Ids and edges stay unchanged, and a method with no owner, several distinct owners, or a non-plain owner name keeps its bare label. Resolvers, the method-ghost alias index, and the analyze file-node check all go through bare_csharp_method_label, so they still recognise the qualified form. extract reverts persisted labels to the bare form before using them as resolution context, so incremental runs match fresh extractions.

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

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 5157 functions depend on the 738 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract() — 1059 callers, 63 callees
  • worse: _rebuild_code() — 209 callers, 66 callees
  • worse: build_from_json() — 277 callers, 22 callees
  • worse: dispatch_command() — 5 callers, 136 callees
  • worse: finalize_raw_graph_endpoints() — 11 callers, 4 callees
  • new: csharp_method_label_reassignments() — 5 callers, 3 callees
  • worse: _alias_index() — 2 callers, 7 callees

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

Test selection

Test selection

352 of 470 test file(s) selected (75%) via static blast radius.

  • tests/test_affected_cli.py — impact
  • tests/test_affected_overrides.py — impact
  • tests/test_affected_path_file_node.py — impact
  • tests/test_agents_platform.py — impact
  • tests/test_alias_folding.py — impact
  • tests/test_analyze.py — impact
  • tests/test_astro_extraction.py — impact
  • tests/test_astro_import_ids.py — impact
  • tests/test_atomic_canvas_export.py — impact
  • tests/test_atomic_writes.py — impact
  • tests/test_backend_opt_in.py — impact
  • tests/test_benchmark.py — impact
  • tests/test_benchmark_raw_graph.py — impact
  • tests/test_benchmark_real_query.py — impact
  • tests/test_blade_extractor.py — impact
  • tests/test_build.py — impact
  • tests/test_build_located_semantic_identity.py — impact
  • tests/test_build_merge_dedup_scope.py — impact
  • tests/test_build_merge_hyperedges_and_prune.py — impact
  • tests/test_build_merge_shrink_guard.py — impact
  • tests/test_builtin_global_type_refs.py — impact
  • tests/test_c_include_resolution.py — impact
  • tests/test_cache.py — impact
  • tests/test_cache_stale_import_target.py — impact
  • tests/test_carried_hyperedge_remap.py — impact
  • tests/test_case_sensitive_resolution.py — impact
  • tests/test_charmap_encoding.py — impact
  • tests/test_chunking.py — impact
  • tests/test_cjs_module_extension.py — impact
  • tests/test_claude_cli_backend.py — impact
  • tests/test_cli_export.py — impact
  • tests/test_cloud_cta.py — impact
  • tests/test_cluster.py — impact
  • tests/test_cobol_extractor.py — impact
  • tests/test_codebuddy.py — impact
  • tests/test_community_labels_skill.py — impact
  • tests/test_compact_graph_json.py — impact
  • tests/test_confidence.py — impact
  • tests/test_corrupt_graph_json.py — impact
  • tests/test_cpp_method_declarations.py — impact
  • tests/test_cpp_nested_and_cli.py — impact
  • tests/test_cpp_objc_cross_file_calls.py — impact
  • tests/test_cpp_template_type_params.py — impact
  • tests/test_cpp_type_alias.py — impact
  • tests/test_cross_extension_reexport_self_cycle.py — impact
  • tests/test_cross_language_call_resolution.py — impact
  • tests/test_cross_repo_external_call_guards.py — impact
  • tests/test_cross_repo_member_calls.py — impact
  • tests/test_csharp_call_site_generic_args.py — impact
  • tests/test_csharp_delegate_declarations.py — impact
  • … and 302 more

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

Could not verify: Could not verify \_is\_file\_node.

The verifier did not have enough to check \_is\_file\_node, 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 \_alias\_index.

The verifier did not have enough to check \_alias\_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: parameter `nodes` is annotated `'Iterable[tuple[str, dict]]'` — outside the synthesizable primitive/collection set

Could not verify: Could not verify build\_from\_json.

The verifier did not have enough to check build\_from\_json, 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 11 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous

Could not verify: Could not verify dispatch\_command.

The verifier did not have enough to check dispatch\_command, 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 40 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly SystemExit — names the real obstacle, not a sampling gap)

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

The verifier ran both versions of extract 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 \_rebuild\_code.

The verifier did not have enough to check \_rebuild\_code, 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: nondeterministic output (both versions disagreed with themselves on the witness) — not a behaviour change; a function whose output is not a function of its inputs (random / time / uuid / os.urandom, or state carried across calls) cannot be soundly distinguished by execution, so this tier abstains for the whole function

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

return out


def csharp_method_label_reassignments(

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 — csharp_method_label_reassignments()

high coupling complexity (Ca·Ce = 15).

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

@safishamsi
safishamsi merged commit 2daf687 into Graphify-Labs:v8 Oct 30, 2026
12 checks passed
safishamsi added a commit that referenced this pull request Oct 30, 2026
…els, path weakest-hop confidence, Type.Member path endpoints

Covers the SyedFahad7 batch: #4891 and #4889 merged on GitHub; #4892 and
#4893 landed via authorship-preserving cherry-pick (their CI matrix was
gated pending first-contributor approval, so brought in through the local
gate instead). Credit by GitHub PR-author login @SyedFahad7.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
safishamsi added a commit that referenced this pull request Oct 30, 2026
…4888)

#4888 was built on 0.9.97, before #4881 (path weakest-hop refactor),
#4889 (qualified C# method labels) and #4891 (also_seen) landed. Its
cherry-pick dropped the merge commit that reconciled expectations. Update
the per-hop confidence assertions to carry scores ([INFERRED 0.85]) and
the C# path/explain/neighbor labels to their owner-qualified form
(Exporter.Run, IReport.Build) - the correct composed output of all four
features. Resolved the serve.py conflict by keeping #4881's _path_weakest/
_path_confidence_line and adding only #4888's _confidence_tag, applied over
edge_evidence so parallel/also_seen evidence keeps its scores.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: C# method labels should carry the owning type (PdfReport.Build(), not .Build())

3 participants