Skip to content

Semantic extractor emits cross-language INFERRED calls edges by collapsing common identifiers within a chunk #991

Closed

Description

@gnesher

Problem

Semantic (LLM subagent) extraction can emit [calls] [INFERRED] edges whose source and target are in different languages, by mapping a call-site identifier in one language to a same-named definition in another language that happened to be in the same subagent chunk.

The result: a single low-importance symbol (a const cancel = ... local in a JS test file) becomes a graph hub with inbound calls from 17+ communities of Go code, polluting community detection, god-node ranking, and queries.

Concrete repro

In a mixed Go + TypeScript repo (≈ 700+ files, semantic extraction via Claude Code subagents, graphifyy 0.8.10):

The node:

id:    clusterdetail_clusterjobsstorage_test_cancel
label: cancel
file:  ui/src/pages/ClusterDetail/clusterJobsStorage.test.ts L52

Its definition is a local const inside a Vitest it() block:

const cancel = runSupportBundleSimulation(clusterId, { ... });

Not exported. Not a function definition. Not reachable from anything outside that it() block.

The spurious inbound edges: 28 INFERRED calls edges, 100% from .go source files, e.g.

{
  "source": "re_sim_main_runregister",
  "target": "clusterdetail_clusterjobsstorage_test_cancel",
  "relation": "calls",
  "confidence": "INFERRED",
  "confidence_score": 0.8,
  "source_file": "api/cmd/re-sim/main.go",
  "source_location": "L300",
  "weight": 1.0
}

The Go sites are all ctx, cancel := context.WithCancel(ctx); defer cancel() — the standard Go context-cancel pattern. They invoke the local closure returned by context.WithCancel, which has nothing to do with the JS variable.

These edges span 17 communities (worker tests, otel tests, healthz handlers, sim runners, HTTP handlers, …), making cancel look like a top god node.

Why I think this happens (not 100% certain on the internals)

This is not the AST cross-file resolver — that's per-language. Hard evidence:

  • All 28 spurious edges have confidence: INFERRED (AST emits EXTRACTED)
  • Source ext: 100% .go, target ext: .ts (no Go AST extractor would produce a TS target)

So the edges came from a semantic subagent. The most plausible mechanism: the subagent's chunk contained both api/cmd/re-sim/main.go and ui/src/pages/ClusterDetail/clusterJobsStorage.test.ts. When the model saw cancel called in main.go, it scanned its visible window for a cancel definition, found the JS const cancel, and serialized the full long-form ID as the edge target. The skill prompt tells the model how to build IDs but doesn't tell it what to do when the only available definition is in a different language.

Related issues

Distinct from but related to:

The blocklist approach those PRs use would also help here (cancel is a strong candidate to add), but it doesn't solve the general case: any common identifier in a chunk window will produce the same failure. cancel is the most visible offender because of Go's context.WithCancel idiom, but Close, Start, Stop, Run, Get, Set, New, Error are all at risk.

Suggested fix (cheapest → most invasive)

  1. Post-extraction validator (recommended for first cut). Drop semantic calls edges whose source and target source-file extensions belong to different language families (.go ↔ .ts/.tsx/.js/.jsx, .py ↔ .go, etc.). Cross-language calls is essentially never legitimate; FFI/binding cases would still be detectable as references or via explicit hints. Near-zero false positives, ~3 lines of code.

  2. Reject semantic edges to non-definition targets. A const x = expr() inside a test block is a binding, not a callable definition. The extractor could flag nodes that don't represent functions/classes/methods and refuse to use them as calls targets in semantic edges. This requires the extractor to know whether a node is "callable" — but it already distinguishes file_type and could add a kind discriminator.

  3. Prompt hardening (best long-term). Add an explicit anti-rule to the subagent prompt:

    Do not emit a calls edge whose target lives in a file written in a different language from the source. The Go idiom ctx, cancel := context.WithCancel(ctx); defer cancel() invokes the local closure returned by context.WithCancel, not any same-named symbol in another file or language.

    With an example. The current prompt's ID-format guidance is precise about how to name an ID, but silent on whether to draw the edge at all in this case.

(1) gives the biggest immediate quality win and is composable with (2) and (3).

Environment

  • graphifyy 0.8.10
  • Extraction backend: Claude Code subagents (no GEMINI_API_KEY set)
  • Corpus: ~700 files, mixed Go (api/) + TypeScript (ui/)
  • Graph: ~10k nodes, semantic chunk size 20–25 files

Activity

  1. gnesher commented on May 23, 2026

    @gnesher
    Author

    Second confirmed instance in the same repo, even more severe than cancel:

    The node: Default at ui/src/foundation/filters/cluster-filters.stories.tsx:16 — a Storybook story:

    export const Default: Story = { render: () => { ... } };

    Inbound edges: 39 total. 1 legit (contains, EXTRACTED). 38 spurious INFERRED calls — 100% from .go source files, across 33 communities.

    Sample Go callers:

    slog.Default()              — api/internal/auth/service.go:84
    http.DefaultTransport       — api/internal/connectors/re/client.go:19
    slog.Default()              — api/internal/connectors/re/client.go:25
    NewService()                — api/internal/auth/service.go (calls slog.Default)
    ... 34 more
    

    None of these can reach a Storybook story export. They're all Go stdlib Default references (slog.Default, http.DefaultTransport, time.UTC-style defaults, etc.).

    Why this matters for prioritization: Default is in the top-tier of "common across all languages" identifiers — Storybook conventions (export const Default), Go stdlib (slog.Default, http.DefaultTransport, tls.DefaultCipherSuites...), Python (default=), .NET (default(T)), TS enums (enum X { Default }). Any mixed-language repo with both a Default-exported TS symbol and Go stdlib usage will exhibit this. In our 10k-node graph it produced one of the loudest god-node false positives.

    This supports the language-boundary post-extraction validator as fix #1 — it would have caught both cancel and Default with one ~3-line check, and the false-positive rate for a .go → .tsx calls edge is essentially zero in practice (no FFI bridge between Go and TS storybook code is plausible).

  2. gnesher commented on May 23, 2026

    @gnesher
    Author

    Third instance — and this one shows the bug isn't only cross-language, which has implications for the fix.

    The node: getEnv at api/internal/config/config.go:332 — func getEnv(key, fallback string) string. Note the lowercase name: Go's visibility rule makes this function callable only from within api/internal/config.

    Inbound calls edges:

    • 51 total from .go source files
    • 5 from inside api/internal/config/ ✓ legitimate (within-package callers)
    • 46 from outside (api/internal/worker, api/internal/service/clusters, api/internal/auth, api/cmd/e2e-fixture, …) ✗ impossible — Go won't compile cross-package access to an unexported identifier

    The 46 outside callers are real call sites in other packages that happen to invoke os.Getenv(...) or a similarly named local helper. The semantic subagent collapsed all of them onto the only getEnv node it could see in its chunk window.

    Why this matters for the proposed fixes:

    Fix #1 (cross-language .go ↔ .tsx validator) would catch cancel, Default, int(). It would not catch this — source and target are both .go. Yet the edges are just as impossible.

    This pushes Fix #2 ("reject semantic calls edges to non-callable / non-reachable targets") higher up the priority list. For Go specifically, that means honoring the lowercase-is-unexported rule when validating semantic edges — an edge whose target identifier starts with a lowercase letter and whose source is in a different package directory is provably wrong. Similar visibility rules exist in other languages (Java private, TS private/non-export, Python _-prefixed conventions, Rust pub).

    A minimum-effort version of Fix #2 that just covers Go visibility would already eliminate this class. Together with Fix #1, both cancel/Default/int() (cross-language) and getEnv (same-language, cross-package) would be caught.

  3. safishamsi commented on May 23, 2026

    @safishamsi
    Member

    Fixed in 4dce16f: two-layer defense - (1) skill.md prompt now explicitly forbids cross-language calls edges; (2) build_from_json drops any INFERRED calls edge where source and target nodes live in different language families.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions