Skip to content

tree_sitter_accuracy_audit: haskell ground truth counts each pattern-match clause as a separate real function, deflating measured func_start recall from ~94% to 50.5% #1614

Closed

Description

@squid-protocol

Summary

tests/tools/tree_sitter_accuracy_audit.py's haskell func_node_types ({"function", "bind"}) treats each pattern-matching equation clause of a multi-clause Haskell function as its own separate real_functions occurrence, because that's how tree-sitter-haskell's grammar structures them (one function node per clause, all siblings under the same declarations/local_binds parent). GitGalaxy's _slice_by_indentation (detector.py) deliberately merges all clauses of one function into a single reported FunctionNode (#1442's own comment: "clauses 2..N would otherwise each spawn their own duplicate, overlapping FunctionNode") — which is the semantically correct behavior (one function, however many equations). The audit tool's per-clause ground truth then scores every clause beyond the first as a "missing" real function, via _align_occurrences_by_line's one-to-one line alignment.

Currently-shipped baseline for language-crucible/data/haskell/pandoc (2026-08-14): real_functions=275, found_functions=139 — 50.5% recall. This is almost entirely a measurement artifact, not a real GitGalaxy defect.

Root Cause

Confirmed directly by parsing a minimal multi-clause definition with tree_sitter_language_pack.get_parser("haskell"):

deNote :: Inline -> Inline
deNote (Note _) = Str ""
deNote x        = x

produces one signature node plus two separate function nodes (rows 1 and 2 of the equations) — tree-sitter has no single node representing "deNote, the function," only per-clause nodes. measure()'s walk() in tree_sitter_accuracy_audit.py records each as its own (start_line, param_count) tuple under real_funcs["deNote"], so a function with N clauses always contributes N real occurrences, while GitGalaxy (correctly) contributes 1 — _align_occurrences_by_line then reports N−1 as unmatched real occurrences for every single multi-clause function.

Verification

Re-walked the same 7-file corpus with a clause-collapse pass (consecutive same-name function/bind siblings under one parent merged into a single occurrence, keyed by the first clause's line — asking the ground truth the same question GitGalaxy's own detector.py already answers), reusing the existing _align_occurrences_by_line and _get_param_count unchanged, against the exact same (unmodified) GitGalaxy output:

real_functions found_functions recall
Current (per-clause) 275 139 50.5%
Clause-collapsed (GG semantics) 148 139 93.9%

Every one of the ~40 names the current measurement lists as "missing" in this corpus (deNote, blockToInlines, isPara, toJSON, tabFilter, compactify, isSingleton, plainToPara, removeNote, splitBy, and more) is a multi-clause pattern-matched definition that GitGalaxy found in full — spot-checked several directly against function_data (e.g. isPara found at its signature line with the full 2-clause block absorbed; blockToInlines's 7-clause block correctly captured as one span).

The residual, genuine gap after collapsing is 9 real misses across 2 files — a much smaller, distinct, already-filed problem (see #1616 and #1615): local where/let-introduced helpers whose defining equation has no = on the naming line itself (guard-only clauses), and single-line where name args = expr openers (same shape #1564 fixed for let, not yet extended to where).

Proposed Fix

In measure()'s walk() (tree_sitter_accuracy_audit.py), for languages where one logical function is represented as multiple sibling clause nodes (currently just haskell), collapse consecutive same-name func_node_types siblings under the same parent into a single real_funcs occurrence before counting — mirroring GitGalaxy's own, already-correct one-function-per-name semantics instead of tree-sitter's raw per-clause node granularity. Gate this behind a lang == "haskell" check (or a new NODE_MAPS flag) so it doesn't change behavior for any other NODE_MAPS language, none of which have this clause-per-node grammar shape.

Note: per CLAUDE.md's standing instruction, this exact mismatch (GitGalaxy's regex-based "one function, one entity" semantics beating tree-sitter's raw per-clause node count for the purpose of counting functions) has been logged as Claim 4 in docs/why_gitgalaxy_beats_ast_here.md.

Related Work

Activity

  1. added
    bug
    testing
    core-engine
    threat: false-negative
    priority: high
    on Aug 14, 2026
  2. added this to the v2.4.8 milestone on Aug 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

    bugcore-enginepriority: hightestingthreat: false-negative

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions