Skip to content

tree_sitter_accuracy_audit: csharp's #1427 exclusion misdiagnosed the trigger and undersold scope (~100x) #1567

Closed

Description

@squid-protocol

Background

#1427 found that tests/tools/tree_sitter_accuracy_audit.py's csharp ground truth (via tree-sitter-c-sharp) was missing 3 real methods (AccumulateExplicitInterfaceName, CanFollowCast, CanReuseVariableDeclarator) from language-crucible/data/csharp/roslyn/LanguageParser.cs (14,680 lines), and attributed it to private ref struct DisposableResetPoint at line 14575 failing to parse. The fix added a 3-name exclusion in NODE_MAPS's csharp handling (search for #1427 in tests/tools/tree_sitter_accuracy_audit.py — there's a comment around line 229-233 in the module docstring and another around line 1507 in the alignment/measure logic, both currently describing the wrong root cause and need updating alongside any code fix).

What's Actually Wrong

Verified 2026-08-14 while investigating csharp's overall func_start precision (csharp currently measures 67.0% precision / 316 "extra" false-positives per docs/self_scan/tree_sitter_accuracy_history.csv, the 2nd-worst precision of any language after dart):

  1. Tested private ref struct DisposableResetPoint : IDisposable { ... } in isolation with tree_sitter_language_pack.get_parser("c_sharp") (wrapped in a plain class) — it parses cleanly, has_error == False. The ref struct itself was never broken; tree_sitter_accuracy_audit.py: csharp ground truth misses a real method due to a tree-sitter parse error in a large corpus file #1427's attribution was wrong.

  2. Bisecting the real file's parse tree for the earliest actual ERROR node instead finds one starting at line 5198 — over 9,000 lines before the ref struct:

// LanguageParser.cs:5198
if (modifiers is [.., SyntaxToken { Kind: SyntaxKind.ScopedKeyword } scopedKeyword])

A C# 11 list pattern ([.., ...]) combined with a property pattern (SyntaxToken { Kind: ... }) and a pattern-variable capture. Tested in isolation (same technique as above), this construct alone reliably produces has_error == True in the currently-pinned tree_sitter_language_pack c_sharp grammar.

  1. Once tree-sitter hits this construct, it never resynchronizes for the rest of the file. Measured directly against the real corpus scan:
    • real_functions (tree-sitter ground truth) for everything before line 5198: 157, essentially matching GitGalaxy (only 2 "extra" false-positives in that region — a normal rate).
    • real_functions for everything from line 5198 to EOF (line 14680): 0 — despite that region containing hundreds of ordinary real C# methods (spot-checked several directly against source: GetOriginalModifiers, ParseEventFieldDeclaration, HasEntryPointSignature, TryGetInterceptor, CloneNodeAsRoot, GetSymbolInternal, and many more — all real, all correctly found by GitGalaxy).
    • All 316 of csharp's current "extra" (false-positive) entries fall in this post-5198 region. None are actual GitGalaxy bugs — they're all real functions tree-sitter simply can't see anymore after the cascade started.

Fix Direction

Replace the current 3-name exclusion with something scoped to the actual failure region — either exclude LanguageParser.cs entirely from real_functions/found_functions accounting past line 5198 (a line-range-based exclusion keyed to this file), or (better long-term) detect programmatically when a file's root node has_error and its error span covers a large trailing fraction of the file, and exclude that whole trailing span from ground truth rather than hand-listing affected names — since any future edit to this pinned corpus file could shift which specific names are affected.

Also correct the two comments in tree_sitter_accuracy_audit.py (module docstring ~line 229-233, and the inline comment ~line 1507) that currently describe the ref-struct-at-14575 diagnosis, since that diagnosis is now known to be wrong.

Doc Reference

docs/why_gitgalaxy_beats_ast_here.md's Claim 3 has already been corrected in-place (2026-08-14) with this same evidence — that doc contains the fuller writeup and tracker research on the grammar's known parse-error cascade mechanisms. This issue is the measurement-tool fix counterpart.

Impact

Once fixed, csharp's measured func_precision_pct in docs/self_scan/tree_sitter_accuracy_history.csv should jump dramatically (currently 67.0%, artificially depressed almost entirely by this one file's ~9,500-line unparseable tail) — this is a measurement-tool fix, not a GitGalaxy engine change, same class as #1505/#1511/#1319.

Relates to: #1427 (prior misdiagnosis)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdata-integritytesting

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions