Skip to content

COBOL record_data: read every program's DATA DIVISION in a multi-program source (#4245) - #4360

Merged
squid-protocol merged 1 commit into
mainfrom
fix/4245-multi-program-data
Oct 4, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
fix/4245-multi-program-data

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Fixes #4245

What was broken

A source can hold several programs: a nested program, or batch-compiled siblings. IBM DBB epscsmrd.cbl has 13 PROGRAM-IDs, and estate-crucible H-0031 plants PAYMAIN with a nested PAYCALC and a sibling 'PAYRPT'. Each program has its own DATA DIVISION. Both readers took the first DATA DIVISION match up to the first PROCEDURE DIVISION, so the other programs' items were never read:

  • the engine's mainframe_boundary._cobol_records: epscsmrd had 65 records, the last at line 138;
  • the answer key's cobol_answer_key._data_items: the same 65.

The fix

  1. Both readers now read every DATA DIVISION up to its own PROCEDURE DIVISION. The level stack is reset between programs, so no group stays open from one program into the next. epscsmrd now has 996 records, the last at line 4026.
  2. The owning program can be derived (the issue's "recorded or derivable"). The issue puts PROGRAM-ID recording out of scope, so no DB column is added. GalaxyIR sets EngineDataItem.program from the programs' PROCEDURE DIVISION lines. An item belongs to the first program whose PROCEDURE DIVISION follows it, and a statement belongs to the last program whose PROCEDURE DIVISION precedes it. This holds for nested programs and siblings alike. A one-program source, or one where the PROCEDURE DIVISIONs don't pair up with the PROGRAM-IDs, is unscoped, which is the old reading.
  3. Same-named records of sibling programs do not collide. Reading the extra programs on its own made things worse: with every program's WS-AREA visible, each MOVE became ambiguous, and the storage key (file, root name) merged two different records. GalaxyIR now scopes name resolution to the program a statement is written in, and record keys and spans carry program. Scoped consumers:
    • data_flows
    • call_contracts: caller and callee bytes. CALL 'PAYRPT' also enters PAYRPT's own PROCEDURE DIVISION USING.
    • dynamic_call_targets: VALUEs and MOVEs.
    • ims_calls and ims_psbs: VALUE lookups.
    • field_lineage: new optional program= argument; overlap and keys compare the program.
  4. GLOBAL. A name a program does not declare falls back to the nearest earlier program that does. Example: NIST IC228A-1 reads IC228A's 01 GLOBAL-DATA IS GLOBAL. The compiler rejects any other undeclared name, so this fallback is safe. Without it, 6 NIST MOVEs regressed to unresolved during development.

Not scoped (they keep the whole-file lookup they had): CICS COMMAREA/record lookups (commarea_contracts, _commarea_unpack, CICS record_of, _position_in, _length_expr). Multi-program CICS members are rare. These lookups take the first match or require a unique one, so they are no worse than before.

Evidence (before → after)

  • New tests/cobol_mainframe/test_multi_program_data_4245.py (9 tests; 8 fail on main). It covers a nested program plus a quoted sibling:
    • both readers return all 16 items, each tree per program;
    • each item names its owning program;
    • MOVE WS-IN TO WS-A in PAYMAIN resolves to WS-AREA/PAYMAIN @0+4, and in PAYRPT to WS-AREA/PAYRPT @2+8 (both ambiguous with only the reader fix);
    • CALL USING bytes are 8 vs 10;
    • CALL 'PAYRPT' pairs with LK-RPT (12 bytes);
    • dynamic CALL WS-PGM gives PAYSUB1 vs PAYSUB2;
    • field_lineage(program=) stays in its program;
    • a GLOBAL item resolves from a nested program;
    • a one-program source has program None.
  • DBB MortgageApplication completeness, data flows: 141/568 → 549/567 (pin updated, with an explanation in test_completeness.py). One MOVE XML-CODE TO ERROR-CODE became system. The 18 still open are XML PARSE special registers (XML-TEXT / XML-NTEXT): 11 in EPSCSMRD and 7 in EPSCSMRT, not this issue.

Estate-crucible (v0.3.0), main 8be548a → this branch

data_items   276 pass / 4 missing  ->  279 / 1
layouts       77 pass / 3 missing  ->   80 / 0
H-0031 #4243 FAIL -> PASS   (missing 01 WS-I @53, 01 WS-GROSS @54, 01 WS-LINES @75 + their layouts)

No other horror or channel moves (32/49 horrors pass).

Golden masters (both legs regenerated; identical diffs)

  • record_layout: +20 items, all in the 4 NIST CCVS85 sources whose later programs have a DATA DIVISION: IC2244 (+8), IC2264 (+5), IC2374 (+6), IC4014 (+1). Nothing else moves.
  • llm_brief: record items 33019 → 33039.
  • skeleton completeness: unresolved operands 1161 → 1160. IC2374:421 MOVE L-A1 TO L-C now resolves its source.

I checked every flow in the 7 multi-program crucible sources before and after. The only change is that one resolution. The GLOBAL fallback keeps IC2284's GLO-DATA-1..4 and IC2344's DILFRAP resolved.

pytest -m golden_crucible passes in both venvs.

Found while reading the golden diff: IC2244's new 77-level items get the FILE SECTION 01 above them as parent. This is a pre-existing bug (366 such rows on main). It is filed as #4359 and not fixed here.

Ground-truth ledger

ground_truth_ledger.py update: no change. check: clean (10 mismatches, all the deliberate engine_dead_is_unreferenced_by_name).

Refraction differential

DBB [full] was blessed at 33 unexplained, with a note to "re-bless when #4245 lands". The forge's cobol_schema_forge still renders a multi-program source from its first program only. So I added the cause forge_first_program: a schema delta that the engine's schema over the first program alone does not show. The rule has a unit test and a row in docs/refraction_engine_differential.md. DBB is now 26 unexplained (the same 26 first-program forge_flat_schema names as before), 198 forge_first_program. The baseline note was rewritten; the gate number only went down.

Local checks

tests/cobol_mainframe, tests/extraction and tests/core_engine (pinned corpora): 13,231 passed in the full venv. mypy_audit --ci, ruff_audit --ci (0.16.0) and dead_key_audit --ci report nothing new.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FNWHcUSn5p7eMxFTsB5rFo

…ram source (#4245)

A source holding several programs (a nested program, batch-compiled siblings;
IBM DBB epscsmrd.cbl has 13 PROGRAM-IDs) has one DATA DIVISION per program.
The engine's _cobol_records and the answer key's _data_items read only the
first one. Both now read each DATA DIVISION up to its own PROCEDURE DIVISION,
and no group stays open from one program into the next.

GalaxyIR derives each item's owning program (EngineDataItem.program) from the
programs' PROCEDURE DIVISION lines. Name resolution is scoped to the program a
statement is written in, so sibling programs' same-named records are separate
storage. This covers data_flows, call_contracts, dynamic CALL targets, DL/I
operands and field_lineage. Record keys and spans carry the program. A name a
program does not declare falls back to the nearest earlier program (a
container's GLOBAL item).

The refraction differential gains a forge_first_program cause: the forge still
renders a multi-program source from its first program only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FNWHcUSn5p7eMxFTsB5rFo
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol marked this pull request as ready for review October 4, 2026 19:43
@squid-protocol
squid-protocol merged commit 2d7052c into main Oct 4, 2026
39 checks passed
@squid-protocol
squid-protocol deleted the fix/4245-multi-program-data branch October 4, 2026 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

COBOL engine and answer key read only the first program's DATA DIVISION in a multi-program source

1 participant