Skip to content

fix(cobol): link the paragraphs inside a PERFORM ... THRU range - #5424

Closed
pavansystems wants to merge 2 commits into
Graphify-Labs:v8from
pavansystems:cobol-perform-thru-range
Closed

pavansystems wants to merge 2 commits into
Graphify-Labs:v8from
pavansystems:cobol-perform-thru-range

Conversation

@pavansystems

@pavansystems pavansystems commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

PERFORM A THRU Z runs every paragraph written from A to Z, but only the two ends get a calls edge (the behaviour from #3814). A paragraph in the middle of a range has no inbound edge: "what performs M?" answers nothing, and M looks like dead code unless something else performs it by name.

This records each program's paragraphs and sections in the order they are written and, once the program has been read, links the performing paragraph to everything between the two ends, tagged context: "perform_range". A range that ends on a section runs to the end of that section, so its paragraphs are included up to the next section header.

The range is filled in only when both ends are paragraphs of the same program and the end is written after the start. Otherwise the two endpoint edges stay as they were and nothing is added.

Not covered: paragraphs that a COPY statement inside the range brings in from a copybook (the extractor reads one file at a time), and a GO TO that leaves the range early.

Follow-up commit (test(cobol): tell a reversed THRU range apart from a real one), after the automated review: the reversed and the unresolved range stood in the same paragraph as the real one, so the test could not tell a wrongly filled range from the real one. They now stand in a paragraph of their own. No change to the extractor.

Rebased onto v8 after #5423 landed (conflicts in cobol.py and the test file, resolved by keeping both sides).

On the two points of the second automated review, neither changed here:

  • PERFORM S THRU S on one section does not link the section's paragraphs. A plain PERFORM S of a section does not either, on v8 as here; linking a section's paragraphs when the section is performed is a separate change.
  • A paragraph range that crosses a section header also links that section node. That is as written: the header lies inside the range. Say so if you would rather have section nodes left out of a paragraph range.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

Invariant: the two endpoint edges are emitted exactly as before. The edges in between are added only for a range whose ends both resolve in the same program in source order; a reversed or unresolved range adds nothing (both are controls in the test).

Persisted state: the AST cache holds per-file results from before this change, so a cached COBOL file keeps its old result until the file changes or the cache is cleared. I did not bump _AST_CACHE_SCHEMA, following the earlier COBOL fixes; say so if you want it bumped.

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary.
  • Added a regression test (if bug fix) or isolated boundary test.
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly.

How was this tested?

On this branch (macOS, Python from uv sync --all-extras --frozen):

uv run --frozen --all-extras pytest tests/test_cobol_extractor.py   # 13 passed
uv run --frozen ruff check .                                        # All checks passed
uv run --frozen pyright                                             # 771 errors, the same count as unmodified v8 (ba33a18)

The new tests were also run against unmodified v8, where they fail.

Before the rebase, the full suite (uv run --frozen --all-extras pytest tests) passed on a local branch that combined this change with my other COBOL changes (11883 passed, 165 skipped, 1 xfailed). Not rerun on this branch after the rebase; the COBOL tests were.

The combined branch was also run on a private COBOL codebase and the result compared with links I had been adding outside Graphify; it produced no link that the comparison did not also have.

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. (Not applicable: no skill fragment changed.)
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.

The code, tests and this description were written with Claude Code; the commit carries a Co-Authored-By line.

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @pavansystems. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic.

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify review View in Graphify

Nothing blocking · 2 possible issues to check · Merge confidence 4/5

1 bug (1 preexisting) · 2 possible issues to check · Medium impact

The COBOL extractor now records procedure order and adds call edges for paragraphs inside valid `PERFORM ...

P2  A section performed through itself omits its paragraphs · cobol.py:386

2 possible issues we couldn't confirm

They don't change the score.

Code graph · 38 functions depend on this change
  • 625 of 625 test files are affected by this change.
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed c0d66fc · 2 earlier findings not re-checked

Comment on lines +337 to +340
order = procedure_order.get(program_id, [])
ids = [paragraph_id for paragraph_id, _ in order]
start, end = ids.index(start_id), ids.index(end_id)
if end <= start:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2  Performing a section through itself omits its paragraphs

When a caller performs a section THRU the same section, the graph links the section but omits the paragraphs it contains.

Expand equal section endpoints in extract_cobol.

Evidence · checked against the code

Expected: The graph contains calls edges from the caller to the paragraphs in that section.
Actually: The endpoint calls resolve to the section, but the range expansion skips equal endpoint indices, leaving the section's paragraphs without calls edges from the caller.

This was already on the base branch; the change keeps it.

  • Independent source review: Reviewed the range tests: they cover distinct endpoints and a range ending at a section, but not identical section endpoints. The identical endpoints are not rescued by endpoint processing; both resolve to the section itself, not its paragraphs.
  • Some lookups asked for files or lines that do not exist; the review was told and carried on.
Prompt to fix with AI
In graphify/extractors/cobol.py, extract_cobol (lines 337-340):
Problem: Performing a section through itself omits its paragraphs
Expected: The graph contains calls edges from the caller to the paragraphs in that section.
Actually: The endpoint calls resolve to the section, but the range expansion skips equal endpoint indices, leaving the section's paragraphs without calls edges from the caller.
Fix it at the cause, and add a test that fails without the fix.

Graphify · Checked against the code · View in Graphify

Comment on lines +346 to +349
end += 1
# The end of the range already has its endpoint edge; add_edge keeps that one.
for paragraph_id in ids[start + 1:end + 1]:
add_edge(caller_id, paragraph_id, "calls", line, context="perform_range")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2  Paragraph ranges create calls to intervening section nodes

A PERFORM A-PARA THRU Z-PARA that crosses a section boundary can show a call to the intervening section, even though the range names paragraphs rather than that section.

Exclude section nodes when expanding paragraph ranges in extract_cobol.

Evidence · checked against the code

Expected: The graph represents the range's paragraphs as call targets, not the intervening section header as a separately named target.
Actually: The range loop adds a calls edge to each intermediate entry, including section nodes.

  • Independent source review: Reviewed the existing section-range test: it explicitly names section nodes as endpoints and does not cover paragraph endpoints crossing an intervening section. It does not negate the reported case.
Prompt to fix with AI
In graphify/extractors/cobol.py, extract_cobol (lines 346-349):
Problem: Paragraph ranges create calls to intervening section nodes
Expected: The graph represents the range's paragraphs as call targets, not the intervening section header as a separately named target.
Actually: The range loop adds a calls edge to each intermediate entry, including section nodes.
Fix it at the cause, and add a test that fails without the fix.

Graphify · Checked against the code · View in Graphify

@pavansystems
pavansystems force-pushed the cobol-perform-thru-range branch from 5345eb7 to c0d66fc Compare November 24, 2026 21:40
Comment on lines +383 to +386
# left at the two endpoint edges above.
for caller_id, program_id, first, last, line in pending_ranges:
start_id = paragraphs.get((program_id, first.casefold()))
end_id = paragraphs.get((program_id, last.casefold()))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2  A section performed through itself omits its paragraphs

When a caller uses PERFORM SEC THRU SEC, the graph links the caller to SEC but leaves out the paragraphs in that section.

Handle equal PERFORM THRU endpoints in extract_cobol.

Evidence · checked against the code

Expected: The graph links the caller to the paragraphs in that section as part of the performed range.
Actually: The section is linked as an endpoint, but the equal endpoint indices cause range processing to skip before section paragraphs are added.

This was already on the base branch; the change keeps it.

  • Independent source review: The section-range test covers a range from FIRST-SEC through a different section, and checks that paragraphs in the ending section are linked. It does not cover identical endpoints; its distinct endpoint indices avoid the skip condition.
  • Some lookups asked for files or lines that do not exist; the review was told and carried on.
Prompt to fix with AI
In graphify/extractors/cobol.py, extract_cobol (lines 383-386):
Problem: A section performed through itself omits its paragraphs
Expected: The graph links the caller to the paragraphs in that section as part of the performed range.
Actually: The section is linked as an endpoint, but the equal endpoint indices cause range processing to skip before section paragraphs are added.
Fix it at the cause, and add a test that fails without the fix.

Graphify · Checked against the code · View in Graphify

pavansystems and others added 2 commits November 25, 2026 18:06
`PERFORM A THRU Z` runs every paragraph written from A to Z, but only the
two ends got a `calls` edge (Graphify-Labs#3814). A paragraph in the middle of a range
had no inbound edge: "what performs M?" answered nothing, and M looked like
dead code unless something else performed it by name.

Record each program's paragraphs and sections in the order they are
written, and once the program has been read link the performing paragraph
to everything between the two ends, tagged `context: "perform_range"`. A
range that ends on a section runs to the end of that section, so its
paragraphs are included up to the next section header.

The range is filled in only when both ends are paragraphs of the same
program and the end is written after the start. Otherwise the two endpoint
edges stay as they were and nothing is added.

Not covered: paragraphs that a COPY statement inside the range brings in
from a copybook (the extractor reads one file at a time), and a GO TO that
leaves the range early.

Regression tests: a range with two paragraphs in the middle, with a
reversed and an unresolved range as controls, and a range that ends on a
section. Both fail without the change.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The reversed range (`PERFORM Z-PARA THRU A-PARA`) and the unresolved one
stood in the same paragraph as the real range over the same paragraphs, so
the test could not tell a range that was wrongly filled in from the real
one. They now stand in a paragraph of their own, which must get its
endpoint edges and nothing between them.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@pavansystems
pavansystems force-pushed the cobol-perform-thru-range branch from c0d66fc to ae7b949 Compare November 25, 2026 17:08
safishamsi added a commit that referenced this pull request Nov 26, 2026
…a-57

Both change extraction output and ship in the same release as the 56->57
bump, so they share schema 57 with a combined rationale.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.121, landed via authorship-preserving cherry-pick so your commits keep your name. Thanks @pavansystems!

@safishamsi safishamsi closed this Nov 26, 2026
scarsnow added a commit to scarsnow/graphify that referenced this pull request Nov 27, 2026
… 0.9.121

v8 0.9.121 also lands schema 57 (Rust Graphify-Labs#5398, COBOL Graphify-Labs#5424-Graphify-Labs#5426). Bump
_AST_CACHE_SCHEMA to 58 with the C/C++ reachability lead and keep v8's
schema-57 text verbatim as "prior (57)".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

2 participants