Skip to content

CF-02 "Hallucinated I/O Variable" fires on fields defined in the task's own copybooks (copybook fields are missing from the ground truth) #2

Open

Description

@dovk

Affected tasks (seen so far): LCB-T2-033 (BBANK60P), LCB-T2-034 (BBANK20P), LCB-T3-010 (CBTRN02C). Each is scored 0 by CF-02 for a field that exists in one of the task's own input files.

Task Field flagged Where it is defined (a task input file) Where the program uses it
LCB-T2-033 HELP01O-DATA sources/copybook/CHELPD01.cpy line 30 (10 HELP01O-DATA.) BBANK60P.cbl line 61 COPY CHELPD01., line 156 MOVE HELP01O-DATA TO BANK-HELP-DATA
LCB-T2-034 HELP01O-DATA sources/copybook/CHELPD01.cpy line 30 BBANK20P.cbl line 71 COPY CHELPD01., line 170 MOVE HELP01O-DATA TO BANK-HELP-DATA
LCB-T3-010 TRAN-RECORD app/cpy/CVTRA05Y.cpy line 4 (01 TRAN-RECORD.) CBTRN02C.cbl line 107 COPY CVTRA05Y., line 564 WRITE FD-TRANFILE-REC FROM TRAN-RECORD

Why CF-02 fires. CriticalFailureDetectorV231._extract_valid_identifiers builds the set of valid names only from the main program's data_structures, file_records and files. The copybook ground truth is never read, and it is empty anyway, for three reasons:

  1. critical_failures_v231._extract_valid_identifiers does not read ground_truth["copybooks"].
  2. GroundTruthGenerator._process_copybook extracts from get_data_division_content(). A copybook has no DATA DIVISION header, so that content is "" and every copybook gets 0 structures. For LCB-T2-033, all 5 copybooks give 0, and the valid set holds 21 names.
  3. DataStructureExtractor.extract starts a structure only at level 01, so a copybook that begins at level 05 (CHELPD01: 05 HELP01-DATA.) is dropped even when its text is passed in.

As a result, any submission that correctly names a copybook field in an I/O sentence ("... returns HELP01O-DATA ...") gets a zero-tolerance CF-02, and the task scores 0.

Suggested fix (diff below, 3 small changes):

  • _process_copybook: when there is no DATA DIVISION, extract from the whole copybook text.
  • DataStructureExtractor.extract: let the first item of a copybook that starts below level 01 open the structure.
  • _extract_valid_identifiers: also add the fields of ground_truth["copybooks"][*]["data_structures"].

With the diff applied, the valid set for LCB-T2-033 grows from 21 to 486 names and contains HELP01O-DATA; for LCB-T3-010 it grows from 99 to 144 and contains TRAN-RECORD. CF-02 no longer fires on these three tasks.

Cached ground truth (cache/ground_truth) has to be cleared after the fix. Submissions already scored may be affected wherever CF-02 named a copybook field, so a re-score of the published results may be needed.

Reproduce: score any document for LCB-T2-033 that contains the sentence "BBANK60P returns HELP01O-DATA to the screen." with legacycodebench evaluate --task-id LCB-T2-033 --submission doc.md (v3, no Docker). The result has critical_failures: CF-02 'HELP01O-DATA' does not exist in source.

Suggested diff
--- a/legacycodebench/static_analysis/ground_truth_generator.py
+++ b/legacycodebench/static_analysis/ground_truth_generator.py
@@ -145,6 +145,9 @@
 
         # Extract data structures (main purpose of copybooks)
         data_div = self.parser.get_data_division_content(parsed)
+        if not data_div.strip():
+            # A copybook normally has no DATA DIVISION header: its whole text is the data description.
+            data_div = copybook_file.read_text(encoding='utf-8', errors='ignore')
         data_structures = self.data_extractor.extract(
             data_div,
             line_offset=parsed.divisions.get('DATA', None).start_line if 'DATA' in parsed.divisions else 0
--- a/legacycodebench/static_analysis/data_structure_extractor.py
+++ b/legacycodebench/static_analysis/data_structure_extractor.py
@@ -169,6 +169,19 @@
                     field_stack = [field]
 
                 else:
+                    # A copybook may start below level 01 (e.g. "05 HELP01-DATA." included under the
+                    # program's own 01): its first item opens the structure instead of being dropped.
+                    if current_structure is None and level not in (66, 77, 88):
+                        current_structure = DataStructure(
+                            name=name,
+                            level=level,
+                            line_number=line_num,
+                            has_redefines=(redefines is not None)
+                        )
+                        current_structure.fields.append(field)
+                        field_stack = [field]
+                        all_fields.append(field)
+                        continue
                     # Add to current structure
                     if current_structure:
                         # Determine parent based on level hierarchy
--- a/legacycodebench/evaluators_v231/critical_failures_v231.py
+++ b/legacycodebench/evaluators_v231/critical_failures_v231.py
@@ -618,6 +618,17 @@
                     if isinstance(field, str):
                         valid.add(field.upper())
 
+        # From the task's copybooks (input files 2..n): their fields are as real as the program's own
+        for cpy in ground_truth.get("copybooks", []) or []:
+            cds = cpy.get("data_structures", {}) if isinstance(cpy, dict) else {}
+            if isinstance(cds, dict):
+                cds = cds.get("structures") or cds.get("data_structures") or []
+            for ds in cds or []:
+                if isinstance(ds, dict):
+                    extract_from_structure(ds)
+                elif isinstance(ds, str):
+                    valid.add(ds.upper())
+
         # From file records (often stored separately)
         file_records = ground_truth.get("file_records", [])
         if isinstance(file_records, list):

Activity

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