Skip to content

record_layout: expand EXEC SQL INCLUDE, place a COPY that closes a nested group, report unresolved members (#4278, #4279) - #4340

Merged
squid-protocol merged 3 commits into
mainfrom
fix/4278-sql-include-record-layout
Oct 4, 2026
Merged

squid-protocol merged 3 commits into
mainfrom
fix/4278-sql-include-record-layout

Conversation

@squid-protocol

@squid-protocol squid-protocol commented Oct 4, 2026 •

Copy link
Copy Markdown
Owner

Fixes #4278
Fixes #4279

Both issues come from one mechanism in galaxy_ir.record_layout's COPY expansion, so they ship together (decided with the coordinator).

What was broken

  • COBOL engine: EXEC SQL INCLUDE inside a record is not expanded by record_layout, silently #4278: EXEC SQL INCLUDE member END-EXEC inside a record was never recorded as a copy member, so record_layout didn't expand it and nothing reported it.
    • The fields after it sat too early: carddemo COTRTLIC's fields after line 304 were 817 bytes early.
    • GenApp's 01 DFHCOMMAREA. + EXEC SQL INCLUDE LGCMAREA came back with size unknown.
    • Separately, a member that did not resolve was skipped silently when it sat after a child entry. Only a member in the record's own window was reported.
  • COBOL engine: entries continuing a COPYed record are double-counted #4279: _expanded_children only looked for a COPY recorded on an elementary direct child. A COPY recorded on the last entry deep inside a group child was missed. That covers an 88 under a 05 (COUSR02C: COPY COCOM01Y. after 88 USR-MODIFIED-NO) and a 15 FILLER under 05/10 (COTRTLIC).
    • When the copybook's roots were no deeper than that child, the copybook had closed it. The engine's same-file level stack still threaded the entries after the COPY under the open group.
    • Those same entries were also handed to the copied record (_copy_extension), so they were counted twice.

The fix

  • mainframe_boundary._COPY_IN_ENTRY also matches EXEC SQL INCLUDE member, so the member is recorded in copy_members on the entry it follows, exactly like COPY.
  • _expanded_children:
    • checks the last entry of each child's subtree, including the trailing 88s of an elementary child;
    • a resolved COPY there whose roots are no deeper than the child closes that child, and its roots land at the first level that holds them;
    • a member that doesn't resolve is reported in unexpanded, so bytes comes back None instead of shifting the fields after it;
    • a runtime member after an entry (SQLCA, DFH…, the existing _SYSTEM_COPYBOOK list) counts as its own 01 record and closes the one above it. A program's EXEC SQL INCLUDE SQLCA therefore doesn't make every record before it unknown.

Evidence: engine vs the det translator (det.layout, tree-sitter)

Measured on full scans of the four det-port estates, comparing main with this branch, record_layout of every COBOL 01. All 2,035 records were compared.

record engine before engine after translator
carddemo COTRTLIC.cbl:84 WS-MISC-STORAGE 1,844 2,661 2,661
carddemo COTRN02C.cbl:62 CSUTLDTC-PARM 158 100 100
carddemo COUSR02C.cbl:35 WS-VARIABLES 144 110 110
carddemo COUSR03C.cbl:35 WS-VARIABLES 144 110 110
carddemo COPAUS0C.cbl:93 WS-SWITCHES 227 7 (no det case; seven PIC X(1) flags = 7)
GenApp lgacdb01/lgapdb01/lgdpdb01/lgicdb01/lgipdb01/lgucdb01/lgupdb01 DFHCOMMAREA unknown 32,500 32,500

Those 12 records are the only ones that changed. CBSA (959 records) and DBB mortgage (59) are unchanged.

New tests in tests/cobol_mainframe/test_record_layout_copy_placement_4278.py: 6 tests, 5 of which fail on main. One real scan backs them. They cover:

  • the COTRTLIC INCLUDE of 05 roots after a 15 FILLER, and the same shape through COPY;
  • the COUSR02C COPY-after-a-05's-88s double count, checking both the open record and the continued copied record;
  • the GenApp 01 DFHCOMMAREA. + EXEC SQL INCLUDE;
  • EXEC SQL INCLUDE SQLCA closing the record above it;
  • an unresolved EXEC SQL INCLUDE NOSUCH reported in unexpanded with bytes None.

Golden-master diff (both legs regenerated: 28 diffs each)

  • Record Layout: 44 items in 24 files gain Copy Members for the INCLUDEd member. Members include SQLCA ×20, LGCMAREA ×7, PROCDB2 ×6, ACCDB2 ×4, LGPOLICY ×3, SQLDA ×1, ACCTCTRL/CONTDB2 ×1. No other field of any item changed.
  • Mainframe Skeleton Completeness / copybooks: total goes from 318 to 363, resolved from 288 to 333 (90.6% → 91.7%), and the mean channel score from 64.4% to 64.6%. The INCLUDE members are now counted, and all 45 resolve.
  • LLM Brief: shows the same completeness numbers.
  • pytest -m golden_crucible passes in both venvs.

Completeness pins (tests/cobol_mainframe/test_completeness.py)

Re-pinned on the pinned corpora because the copybooks channel now counts the INCLUDE members, and every one of them resolves:

  • carddemo: 173 → 176
  • CBSA: 88 → 99
  • GenApp: 29 → 40

Ground-truth ledger

ground_truth_ledger.py check is clean after merging main, including #4341's ratchet. The keyed copybook layouts field scores copybooks on their own and does not go through the program-record path changed here.

Local checks

  • tests/extraction, tests/core_engine, tests/cobol_mainframe: 13,169 passed (test_commarea_contracts included)
  • mypy_audit --ci, ruff_audit --ci (0.16.0), dead_key_audit --ci: nothing new

🤖 Generated with Claude Code

…sted group, report unresolved members (#4278, #4279)

#4278: `EXEC SQL INCLUDE member END-EXEC` inside a record is now recorded
as a copy member (mainframe_boundary._COPY_IN_ENTRY) and expands in
record_layout like COPY. A member that does not resolve is reported in
`unexpanded` (bytes unknown) instead of being skipped while the fields
after it silently sit early; a runtime member (SQLCA, DFH...) after an
entry is its own record and closes the one above it.

#4279 (same mechanism): _expanded_children only looked for a COPY on an
elementary direct child. A COPY recorded on the LAST entry deep inside a
group child (a 15 FILLER under 05/10, an 88 under a 05) whose roots are no
deeper than that child now closes it, and its roots land at the level that
holds them. Before, the entries after it were threaded under the open
group AND handed to the copied record -- counted twice.

Against the det translator on the det-port estates: COTRTLIC
WS-MISC-STORAGE +817 bytes, COTRN02C CSUTLDTC-PARM 158 -> 100, COUSR02C/03C
WS-VARIABLES 144 -> 110, COPAUS0C WS-SWITCHES 227 -> 7, GenApp DFHCOMMAREA
unknown -> 32,500 (7 programs). Golden masters regenerated in both legs.

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 and others added 2 commits October 4, 2026 13:17
…nted (#4278)

carddemo 173 -> 176, CBSA 88 -> 99, GenApp 29 -> 40 copybooks; every new
member resolves (resolved == total), an engine improvement.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FNWHcUSn5p7eMxFTsB5rFo
@squid-protocol
squid-protocol marked this pull request as ready for review October 4, 2026 17:40
@squid-protocol
squid-protocol merged commit 6085893 into main Oct 4, 2026
38 checks passed
@squid-protocol
squid-protocol deleted the fix/4278-sql-include-record-layout branch October 4, 2026 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant