Skip to content

Bug: cobol class_start never matches PROGRAM-ID in real corpus (0/19 real classes found) #1858

Closed

Description

@squid-protocol

Description

Found via the new tri-comparison tool (tests/tools/tri_comparison_chart.py on feature/tri-comparison-audit), which checks GitGalaxy's own extraction against tree-sitter and universal-ctags with neither treated as ground truth — cobol is one of the 9 languages tree-sitter has no grammar for at all, so this is the first external check cobol's class detection has ever had.

Across the full pinned language-crucible cobol corpus (34 files), GitGalaxy's class_data returns zero rows for every file that ctags independently identifies a PROGRAM-ID on — 0/19 real occurrences found, where ctags finds 19/19.

gitgalaxy/standards/language_standards.py's cobol class_start regex explicitly lists PROGRAM-ID as a matched keyword:

"class_start": re.compile(
    r"^(?:[0-9a-zA-Z \t]{6}[ \-]?)?[ \t]*(?:PROGRAM-ID|CLASS-ID|INTERFACE-ID|FACTORY|OBJECT)\.\s+([A-Za-z0-9_-]+)(?:[ \t\n]+(?!DIVISION\b)[A-Za-z0-9_-]+){0,6}(?=[ \t]*\.|\n|$)",
    ...
)

but it isn't producing any real class_data rows on production COBOL source.

Steps to Reproduce

Real, confirmed example — language-crucible/data/cobol/cics-banking-sample-application-cbsa/BANKDATA.cbl, line 35:

       PROGRAM-ID. BANKDATA.

ctags finds it (kind:P "program", line 35). GitGalaxy's class_data for this file is empty. Same shape confirmed on at least 4 more files in the same corpus subdirectory (BNKMENU.cbl, XFRFUN.cbl, cics-genapp/lgacdb01.cbl, cics-genapp/lgacdb02.cbl).

Note: GitGalaxy's cobol function detection (paragraphs) is working and non-trivial (126/259 real occurrences matched against the corpus) — this looks isolated to class_start specifically, not a language-routing or corpus problem (cobol files are being correctly identified as language="cobol" in file_data).

Why this wasn't caught before

#1264 (closed) covered class detection regressions for apex/csharp/fortran/solidity but did not include cobol. #854 (closed, "Extraction hardening: cobol") predates any real-corpus check against cobol specifically — until this tri-comparison tool, cobol had no tree-sitter grammar to diff against and no external validator at all, so a 0%-match regex could pass every synthetic unit test in tests/extraction/languages/test_cobol_strict.py while silently not firing on real production formatting (sequence-number columns, continuation, etc.).

Suggested next step

Reproduce directly against the regex in isolation with real corpus lines (starting with the BANKDATA.cbl example above) to find where the match is failing — worth checking the leading (?:[0-9a-zA-Z \t]{6}[ \-]?)? sequence-number-column allowance against this file's actual column formatting first, since that's the part most likely to differ from the synthetic test fixtures.

Evidence

Full discrepancy record (19 total occurrences, up to 10 examples) in docs/self_scan/tri_comparison_ledger.json, shape cobol/class/existence/agree[ctags]_vs[gitgalaxy], once feature/tri-comparison-audit merges.

Activity

  1. added
    bug
    testing
    legacy-modernization
    on Aug 18, 2026
  2. squid-protocol commented on Aug 20, 2026

    @squid-protocol
    OwnerAuthor

    Corrected root cause (found via tri-comparison-ledger-sweep, 2026-08-19)

    The original diagnosis here is wrong on one key point: the class_start regex does match PROGRAM-ID in real corpus source. Verified directly:

    >>> from gitgalaxy.standards.language_standards import LANGUAGE_DEFINITIONS
    >>> rx = LANGUAGE_DEFINITIONS["cobol"]["rules"]["class_start"]
    >>> list(rx.finditer(open("language-crucible/data/cobol/cics-banking-sample-application-cbsa/BANKDATA.cbl").read()))
    [<re.Match object; span=(2194, 2222), match='PROGRAM-ID. BANKDATA.'>]  # group(1) == "BANKDATA"

    The real bug is one step downstream: gitgalaxy/core/detector.py's _CLASS_START_NAMED_EXTRACTION_LANGS (line 369-402) is an allowlist gating which languages use their own class_start rule for named-entity extraction (added by epic #1295, closed 2026-08-12, 11/13 languages done). "cobol" was never added to it — not decided out like css/html, just never considered, because #1295's own verification method (tree_sitter_accuracy_audit.py) requires a tree-sitter grammar as ground truth, and cobol has none.

    Any language missing from that allowlist falls through to a hardcoded, language-agnostic fallback regex (detector.py:733-735):

    r"^\s*(?:export\s+|public\s+|abstract\s+)?(?:class|struct|interface|trait|enum)\s+([a-zA-Z0-9_]+)..."

    which structurally cannot match PROGRAM-ID. BANKDATA. (no class/struct/interface/trait/enum keyword ever appears in COBOL). That's why class_data comes back empty for every cobol file despite the language's own class_start regex working correctly — the correct match is computed (and feeds the numeric class_start risk-signal count) but discarded before named-entity output.

    Fix: add "cobol" to _CLASS_START_NAMED_EXTRACTION_LANGS in gitgalaxy/core/detector.py. Since cobol has no tree-sitter grammar, verification for this one can't use #1295's standard tree_sitter_accuracy_audit.py method — use ctags as the alternate ground truth instead (already available in tests/tools/ctags_reader.py/the tri-comparison harness this was found through), confirming class recall goes from 0/19 to 19/19 (or close) after the allowlist add.

    Full discrepancy record: docs/self_scan/tri_comparison_ledger.json, shape cobol/class/existence/agree[ctags]_vs[gitgalaxy].

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

    buglegacy-modernizationpriority: mediumtesting

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions