Skip to content

TS: fabricated EXTRACTED calls edge via name-only type matching — third-party-typed field binds to unrelated same-named local class (v0.9.33/v0.9.35) #2553

Closed

Description

@Earthfreedom

Summary

graphify extract's cross-file TS/JS member-call resolver (_resolve_typescript_member_calls) binds this.field.method() calls to a same-named class anywhere else in the corpus by bare type-name text match, with no verification that the type actually comes from that class (no import-chain check). When a field's declared type name happens to collide with an unrelated, differently-sourced class of the same name elsewhere in the project, graphify emits a fabricated calls edge between them — at confidence: "EXTRACTED", the tool's own highest-confidence tier, normally reserved for edges backed by real import/AST evidence.

This is the same class of bug reported in #631 (claimed fixed via an is_member_call guard in v0.5.6, closed) and reported again as a regression in #2041 (still open). Current source inspection (both v0.9.33 and v0.9.35) shows the specific case those issues describe — a call to a JS/TS built-in global (e.g. console.error(...)) matching an unrelated local method of the same name — is now explicitly guarded against via a hardcoded _LANGUAGE_BUILTIN_GLOBALS allowlist (see "Note" below). However, that fix only covers the ~60 names on the hardcoded list. Any type name that is not a JS/TS/Python/Swift built-in — including any type imported from a third-party package — is not covered, and the underlying defect (name-only matching, no import verification) still produces false edges. This report reproduces the surviving general case on v0.9.35, the latest release.

Note on the reproduction below: the literal "built-in global" scenario from #631/#2041 (console.error() colliding with an unrelated .error() method) was tried first and does not reproduce on v0.9.33 or v0.9.35 — see the "Builtin-global control check" section. The repro below instead uses a constructor-injected field typed via a third-party import, which is the officially documented resolution path for this resolver (see its own docstring, quoted below) and demonstrates the same root cause is still live for anything off the hardcoded allowlist.

Environment

  • graphifyy version: 0.9.33 and 0.9.35 (both tested; identical behavior)
  • Python: 3.12.13
  • OS: Linux (python:3.12-slim Docker container; host OS macOS 26.5.1/Docker Desktop, irrelevant to the bug)
  • Invocation: graphify extract <path> --code-only --no-cluster

Minimal reproduction

2 files. fileA.ts's repo field is typed as a third-party Repo (an import from a package that is never scanned by graphify's local, code-only extraction). fileB.ts defines a completely unrelated, project-local class that also happens to be named Repo.

fileA.ts

import type { Repo } from 'external-repo-types';

// `repo` is typed as the *third-party* `Repo` interface, imported from
// 'external-repo-types' (an npm package graphify's local, code-only
// extraction never scans). It has no relation whatsoever to the
// project-local `Repo` class defined in fileB.ts — they only happen to
// share a name.
export class ReportService {
  constructor(private repo: Repo) {}

  run(): void {
    this.repo.save();
  }
}

fileB.ts

// Project-local domain class. Completely unrelated to the third-party `Repo`
// type used in fileA.ts (different package, different shape) — only the
// name `Repo` collides.
export class Repo {
  save(): void {
    throw new Error('not implemented');
  }
}

Run:

graphify extract . --code-only --no-cluster

Expected vs Actual

Expected: no calls/indirect_call edge between fileA.ts and fileB.ts at all — ReportService.repo is a third-party type with no relationship to fileB.ts's Repo class (no import between the two files, no shared declaration).

Actual (identical on v0.9.33 and v0.9.35):

$ jq '.edges[] | select(.relation=="calls")' graph.json
{
  "source": "filea_reportservice_run",
  "target": "fileb_repo_save",
  "relation": "calls",
  "context": "call",
  "confidence": "EXTRACTED",
  "confidence_score": 1.0,
  "source_file": "fileA.ts",
  "source_location": "L12",
  "weight": 1.0
}

A calls edge is fabricated from ReportService.run() to the unrelated Repo.save(), at confidence: "EXTRACTED". This matches the documented mechanism in _resolve_typescript_member_calls's own docstring: "TS constructors with parameter-property modifiers (private repo: IUserRepository) produce a per-file type table mapping field names to their declared types. This pass looks up the receiver field's type, finds a single-definition class/interface owning a method with the callee name, and emits an EXTRACTED calls edge." — the "single-definition" (god-node) guard only checks that exactly one class named Repo exists in the locally-scanned corpus; it has no way to know (and doesn't check) whether that class is actually the type referenced by the third-party import.

Builtin-global control check (does NOT reproduce — for comparison)

// fileA.ts
export function logFailure(message: string): void {
  console.error(message);
}
// fileB.ts
export class UnrelatedThing {
  error(message: string): void {
    throw new Error(message);
  }
}
$ jq '.edges' graph.json   # identical on v0.9.33 and v0.9.35
[
  { "source": "filea", "target": "filea_logfailure", "relation": "contains", ... },
  { "source": "fileb", "target": "fileb_unrelatedthing", "relation": "contains", ... },
  { "source": "fileb_unrelatedthing", "target": "fileb_unrelatedthing_error", "relation": "method", ... }
]

No cross-file edge — confirming console is correctly excluded via the hardcoded _LANGUAGE_BUILTIN_GLOBALS list, but also confirming that exclusion is name-specific rather than a fix for the underlying matching strategy.

Impact

On a real Firebase/TS codebase (~810 files), 238 of 251 cross-file indirect_call edges (95%, all confidence: "INFERRED", emitted by the callback-argument heuristic) pointed at files the source never imports — dominated by builtin console.error/warn calls bound to an unrelated local logging class's .error(), plus minified vendor-bundle single-letter symbols matched across frontend/backend runtime boundaries.

That indirect_call heuristic (callback-argument name matching) and this report's _resolve_typescript_member_calls type-table resolution are two different code paths, but they share the same root strategy: name-only matching with no import/origin verification. The minimal repro above shows that strategy is not confined to the lower-confidence INFERRED heuristic — it survives in the calls relation's highest-confidence EXTRACTED tier too, via the constructor-injection type table. Whichever path produces them, the large majority of cross-file "call" edges surfaced by graphify query/graphify affected/graphify god-nodes for this codebase were spurious, and none of them could be distinguished from genuine edges without manually cross-checking every one against the actual import graph.

Related issues

This report shows the #631 fix (and subsequent _LANGUAGE_BUILTIN_GLOBALS hardening referenced in the current source, citing #726/#1609/#1726/#2137) patches specific known collision names rather than the root cause (name-only matching with no import/origin verification), and provides a minimal repro of the surviving defect on the current latest release (v0.9.35).

Activity

  1. safishamsi commented on Aug 8, 2026

    @safishamsi
    Member

    Fixed in v0.9.37 (graphifyy==0.9.37 on PyPI). TS member-call resolution now requires the matched receiver type to be defined in the same file or actually imported by the caller file, so a third-party import type { Repo } no longer binds to an unrelated local class Repo. Table-inferred receivers are tiered to INFERRED rather than EXTRACTED. Thanks for the sharp report.

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