Skip to content

tree_sitter_accuracy_audit.py: duplicate function names within a file collapse in the per-file comparison #1526

Closed

Description

@squid-protocol

What

Found while chasing the remaining ~1.4% args_exact_match gap after #1524/#1525 fixed python's
node-type undercounting (63.0% → 98.6%). The rest of the gap is a different, more fundamental
methodology issue in measure() (tests/tools/tree_sitter_accuracy_audit.py), not language-specific.

For each file, the tree-sitter walk builds real_funcs: dict[str, int] keyed by function name:

def walk(node):
    if node.type in func_node_types:
        name = _get_node_name(node)
        if name:
            real_funcs[name] = _get_param_count(node, lang)   # <-- last occurrence wins

and the GitGalaxy side does the mirror-opposite:

for r in gg_funcs:
    gg_args_by_name.setdefault(r["func_name"], r["args"])     # <-- first occurrence wins

When a file has multiple functions/methods sharing the same name — extremely common in Python
(__init__/__new__/__call__ across different classes in the same file, @property/@x.setter
pairs sharing a name) — the two sides silently compare unrelated functions: whichever one
tree-sitter walked last against whichever one GitGalaxy's SQL query returned first.

Confirmed concretely: language-crucible/data/python/numpy/core.py defines shape, mask, and
recordmask each 2× (property getter/setter pairs on different classes) and outer 2× (a method
and an unrelated module-level function). cython/Nodes.py has 14 separate __init__ methods
across different node classes.

Impact

This is NOT python-specific — any NODE_MAPS language can have repeated method names within one
file (any OOP language with multiple classes sharing method names: toString, __init__,
constructors, etc.). It also isn't limited to args_exact_match: metrics["real_functions"] += len(real_funcs) and the found/missing/extra set arithmetic all key off the same
collapsed-by-name dict/set, so func_recall/func_precision are also quietly undercounting real
occurrences
whenever names repeat within a file, not just args comparability.

Suggested direction (not a full design, needs its own pass)

Something that preserves per-occurrence identity instead of collapsing to one dict entry per name
-- e.g. pairing same-named occurrences positionally (by walk order vs. SQL row order, both of
which should roughly track file order) rather than keeping only first/last, or keying by
(name, ordinal_occurrence) on both sides. Whichever approach, the found_functions/
extra_functions/missing_functions set-based metrics need the same fix, not just
args_comparable/args_exact_match, since they share the same root cause.

Scoped out of #1524/#1525 deliberately -- that PR only widened the per-parameter node-type
whitelist and left this pairing issue alone, since it's a bigger cross-language measurement
redesign, not a mechanical whitelist gap.

Activity

  1. added this to the v2.4.8 milestone on Aug 16, 2026
  2. added
    scope:infra
    on Oct 16, 2026
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

    scope:infra

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions