Skip to content

cobol-refractor keys every output and its dead-code state by file stem, so same-named programs overwrite each other (and merge dead code in SQLite mode) #3218

Closed

Description

@squid-protocol

Found while verifying #3217 end to end on IBM/zopeneditor-sample 8f98353. That repo has two copies of each of its programs, COBOL/SAM1.cbl / COBOL/SAM2.cbl and multiroot/sam/SAM1.cbl / multiroot/sam/SAM2.cbl. This is a common layout: variants, versions or per-environment copies of one program.

What happens

cobol_refractor_controller.py names everything after file_path.stem:

output key effect of a second SAM2.cbl
04_ir_state_dumps/<stem>_ir.json stem overwritten: only the last program's IR survives
01_zero_trust_jcls/<stem>.jcl stem overwritten
02_cloud_schemas/<stem>_schema.sql / .json stem overwritten
05_microservice_slices/<stem>_slice.json stem overwritten
IRStateManager program_id (process_payload: program_id = filepath.stem) stem see below
cobol_agent_task_forge.forge_agent_jobs [file.name] → source_dir.rglob(file_name) first hit, <stem>_ir.json ticket built from whichever same-named file rglob yields first, joined to the IR dump of whichever was written last

Observed: after a run on zopeneditor, 04_ir_state_dumps/SAM2_ir.json has "path": ".../multiroot/sam/SAM2.cbl". The IR for COBOL/SAM2.cbl is gone.

The worse case is SQLite mode. calibrate_ir_medium switches to it on large repos, which are exactly the ones likely to have same-named programs. record_dead_code does INSERT OR IGNORE keyed by (program_id, entity_type, entity_name). So the second SAM2 reads back the union of both programs' dead paragraphs and orphaned variables. It then masks paragraphs that are live in its own source when running extract_lineage (lost OPENs → lost inputs/outputs → wrong JCL DISP) and the slicer, and drops variables from the schema forge's output. RAM mode overwrites the entry before reading it, so it is only affected through the files above.

On the two answer-key corpora: zopeneditor has 2 colliding stems (SAM1, SAM2); CBSA has none.

Suggested fix

Key by the path relative to the target, not the stem. For example:

Use the same key in IRStateManager (program_id → relpath) and in forge_agent_jobs: carry the relpath in the anomaly string and in the IR, and never re-find the file with rglob(name). Add a test with two same-named programs in different directories, in both RAM and SQLite modes. #3212's snapshot test should include zopeneditor's multiroot layout.

Related: #3206 (fixed in #3217), #3212.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugUnintended behavior or logic failure in the enginelegacy-modernizationCOBOL refractor, dead-code extraction, and JCL forging

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions