Skip to content

fix(go): link a method value passed as an argument as an indirect_call (#1566) - #4868

Closed
nothariharan wants to merge 1 commit into
Graphify-Labs:v8from
nothariharan:fix/go-method-value-indirect-call
Closed

nothariharan wants to merge 1 commit into
Graphify-Labs:v8from
nothariharan:fix/go-method-value-indirect-call

Conversation

@nothariharan

Copy link
Copy Markdown
Contributor

What does this PR do?

Refs #1566. In Go, a handler or callback is registered by passing a method value: routing.Wrap(hs.CheckDatasourceHealth), r.Get("/health", s.Health), pool.Submit(w.run). On v8 such a method gets no edge from the registration site. The call walk only looks at what a call expression invokes, not at its arguments. A handler that is reached only through its route registration therefore shows no caller, and affected does not reach it.

Minimal repro on v8 (0a8cd4e1):

// routing/routing.go
package routing
type Handler func(string) string
func Wrap(h Handler) Handler { return h }

// api/server.go
package api
type Server struct{}
func (s *Server) Health(name string) string { return name }

// api/routes.go
package api
import "example.com/m/routing"
func (s *Server) Register() routing.Handler {
	return routing.Wrap(s.Health) // Register -> Wrap only; nothing reaches Health
}

On Grafana, pkg/api/api.go:420 registers routing.Wrap(hs.CheckDatasourceHealth). With pkg/api extracted on v8, HTTPServer.CheckDatasourceHealth (pkg/api/datasources.go:829) has no incoming calls or indirect_call edge.

Extracting pkg/api, pkg/api/routing, pkg/cmd/grafana-cli/commands and pkg/storage/unified/sql/db/dbimpl (74 non-test files):

  • v8: 426 calls edges, 0 indirect_call; HTTPServer.CheckDatasourceHealth has 0 incoming edges.
  • With this change: 426 calls edges (none added or removed), 176 indirect_call edges. CheckDatasourceHealth gets HTTPServer.registerRoutes -> CheckDatasourceHealth at api.go:420.
  • I checked all 176 new edges against their source line. Each line holds x.Method not followed by (. 175 targets are HTTPServer methods; 151 come from registerRoutes (routing.Wrap(hs.X) route registrations); the others are callbacks such as cookies.DeleteCookie(c.Resp, name, hs.CookieOptionsFromCfg) (login.go:125) and authn.HandleLoginRedirect(..., hs.ValidateRedirectTo, ...) (login_oauth.go:66).

Why #1566 is not resolved yet on v8

#1566 tracks indirect_call (a function passed by name, or listed in a dispatch table, is linked as an INFERRED indirect_call so affected reaches it). The slices that shipped cover Python (call arguments, dispatch tables, assignments and returns, getattr) and JS/TS (callbacks and dispatch tables). Go has none of them: extractors/go.py never emits an indirect raw call, and _resolve_go_member_calls only emits calls.

The change

  1. extractors/go.py: in walk_calls, each argument of a call that is a selector x.M on a plain identifier (not an imported package) is recorded as a raw member call with indirect: True and context: "argument". Its receiver is typed exactly as a direct x.M() call is: the method's own receiver, or the enclosing function's parameter/local type.
  2. extract.py _resolve_go_member_calls: an indirect raw call resolves through the same path as a direct member call (receiver type, single declaration, single method of that name), and is emitted as indirect_call, INFERRED, 0.85, which matches the Python/JS indirect_call. It is never parked as an unresolved call for a merge: f(x.y) is just as often a field read as a method value, so an unknown type here is not evidence of a missing call.
  3. cache.py: _AST_CACHE_SCHEMA 29 → 30.

The shared cross-file pass skips every is_member_call, so it does not see these entries. An existing direct calls edge between the same pair still takes precedence, so no pair gets both.

This is independent of #4853 (receivers typed from another package). It only adds a second kind of entry to the resolver #4853 also changes. A method value on a receiver typed *pkg.T resolves once both are in.

Type of change

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

Verification & Invariants

Invariant: an indirect_call from a Go function to a method is emitted only when the argument names a method of the one type its receiver is declared as. A field passed as an argument, a package function value, or a receiver of unknown type links nothing and parks nothing.

  • test_a_field_passed_as_an_argument_links_nothing_and_parks_nothing

  • test_a_package_function_value_is_not_read_as_a_method_value

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

Not covered (unchanged):

How was this tested?

Run on Windows 11, Python 3.12, in the environment uv run --all-extras syncs (.venv; the later runs call .venv/Scripts/python -m pytest directly because uv run rewrites uv.lock on Windows).

uv run --all-extras pytest tests/test_go_method_value_indirect_calls.py -q
  # 4 passed (on unchanged v8: 2 failed, 2 passed; the two negatives pass on both)
uv run --all-extras pytest tests/test_go_*.py tests/test_sql_go_batches.py tests/test_languages.py tests/test_cache*.py tests/test_indirect*.py -q
  # 796 passed (with tests/test_indirect*.py)
uv run --all-extras pytest tests -q
  # 8878 passed, 10 failed, 99 skipped. All 10 are in files that fail on unchanged v8 on Windows\n  # (test_code_only_update_all_hosts x2, test_hooks, test_language_override_lifecycle,\n  # test_resolve_memoization, test_source_key_memoization, test_unmapped_at_alias_resolution).\n  # test_hooks.py run alone gives 1 failure (test_shebang_parse_requires_leading_hash_bang), the same on v8.
uv run ruff check graphify/extractors/go.py graphify/extract.py graphify/cache.py tests/test_go_method_value_indirect_calls.py
  # All checks passed!

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments.
  • 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.

Graphify-Labs#1566)

A Go handler or callback is registered by passing a method value:
`routing.Wrap(s.Health)`, `r.Get("/p", s.Health)`. The call walk looked
only at what a call expression invokes, so the method got no edge from
its registration and a handler reached only through its route had no
caller.

walk_calls now records each `x.M` argument (on a plain identifier, not an
imported package) as an `indirect` raw member call, typed the way a direct
`x.M()` is. _resolve_go_member_calls resolves it through the same receiver
type, single-declaration and single-method guards and emits an INFERRED
`indirect_call`, as Python and JS do. It is never parked for a merge: a
value argument is as often a field as a method. The AST cache schema goes
to 30.
@github-actions

Copy link
Copy Markdown

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

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

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

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

Not verified on this run: \_resolve\_go\_member\_calls (vacuous: never exercised).


Graphify review — findings

Adds Go method-value tracking: a method passed as an argument (routing.Wrap(s.Handle)) is recorded as a raw member call marked indirect, and _resolve_go_member_calls links it to the method as an indirect_call edge (#1566). The dedup applied to these method-value edges shares its target with direct calls to the same method, so what it collapses decides which edge type survives. Bumps _AST_CACHE_SCHEMA to 30 so cached Go extractions re-run and pick up the new edges.

Worth a look

  • Method value dedup suppresses a later direct calls edge to the same method — graphify/extract.py:7448 · Escalate · medium
    • NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 3824 functions depend on the 465 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract() — 1056 callers, 62 callees

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

Test selection

Test selection

248 of 470 test file(s) selected (53%) via static blast radius.

  • tests/test_affected_overrides.py — impact
  • tests/test_astro_extraction.py — impact
  • tests/test_astro_import_ids.py — impact
  • tests/test_binary_media_words.py — impact
  • tests/test_blade_extractor.py — impact
  • tests/test_build.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_long_paths.py — impact
  • tests/test_cache_stale_import_target.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_cobol_extractor.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
  • tests/test_csharp_enum_members.py — impact
  • tests/test_csharp_field_generic_args.py — impact
  • tests/test_csharp_foreach_loop_variable.py — impact
  • tests/test_csharp_generic_callsites.py — impact
  • tests/test_csharp_interface_dispatch.py — impact
  • tests/test_csharp_member_calls.py — impact
  • tests/test_csharp_member_chain_calls.py — impact
  • tests/test_csharp_member_nodes.py — impact
  • tests/test_csharp_object_creation.py — impact
  • tests/test_csharp_overloads.py — impact
  • tests/test_csharp_partial_classes.py — impact
  • tests/test_csharp_tuple_type_refs.py — impact
  • tests/test_csharp_type_resolution.py — impact
  • tests/test_csharp_underscore_collisions.py — impact
  • tests/test_csharp_var_call_return_type.py — impact
  • tests/test_csharp_verbatim_interpolation.py — impact
  • tests/test_definition_file_portability.py — impact
  • tests/test_detect.py — impact
  • tests/test_dotnet.py — impact
  • tests/test_duplicate_annotation_edges.py — impact
  • tests/test_ejs_extractor.py — impact
  • tests/test_elixir_defdelegate.py — impact
  • tests/test_elixir_import_resolution.py — impact
  • … and 198 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 \_resolve\_go\_member\_calls.

The verifier did not have enough to check \_resolve\_go\_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

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.

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

safishamsi added a commit that referenced this pull request Oct 30, 2026
Go (#4867/#4868/#4866) and Python (#4773) extractor changes alter
per-file AST output and are AST-cached, so one combined _AST_CACHE_SCHEMA
bump 30->31 forces stale caches to re-extract. Install (#4770/#4771) and
the skill reword (#4721) need no bump. Folded into the unreleased 0.9.99.
Each PR omitted its own bump / carried a stale number; the single combined
bump lands here.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Landed in v0.9.99, now on PyPI (pip install graphifyy==0.9.99). A Go method value passed as a function argument is linked as an indirect_call. Thanks for the fix, @nothariharan.

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.

2 participants