Skip to content

fix(cobol): link a GO TO to the paragraph it jumps to - #5423

Closed
pavansystems wants to merge 2 commits into
Graphify-Labs:v8from
pavansystems:cobol-go-to
Closed

pavansystems wants to merge 2 commits into
Graphify-Labs:v8from
pavansystems:cobol-go-to

Conversation

@pavansystems

@pavansystems pavansystems commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

The COBOL extractor reads PERFORM and CALL but has no pattern for GO TO, so a jump leaves no edge. A paragraph that is only reached by GO TO (typically an exit or error paragraph) has no inbound edge and looks like dead code, and a walk along the control flow stops at every jump.

This adds a calls edge from the paragraph the statement stands in to each target, tagged context: "go_to", so a jump can be told apart from a PERFORM without a new relation.

  • GO TO A B C DEPENDING ON X links A, B and C.
  • The target list ends at DEPENDING (a data name follows) and at OF/IN (the qualifying section follows), so neither is taken for a target.
  • Targets resolve against the same per-program paragraph table as PERFORM. A name that is not a paragraph of the program yields no edge.
  • Text inside quotes and EXEC blocks is not read, as for PERFORM.

Not covered: GO without TO, a target list that runs on over several lines, and a GO TO changed at run time by ALTER. When a paragraph both performs and jumps to the same target, the one edge kept is the PERFORM.

I found no existing issue for this.

Follow-up commit (fix(cobol): give a plain GO TO one target), after the automated review:

  • Reproduced: the target list ran to the end of the line, so in IF A = 1 GO TO ERR-PARA ELSE SET CHOICE TO TRUE a paragraph named CHOICE became a target. A plain GO TO now has one target; only a DEPENDING ON list has several. A second GO TO on the same line is read on its own.
  • Found while fixing it: in a DEPENDING ON list, OF/IN ended the list, so targets after a qualified name were lost. The qualifying section is now skipped and the list goes on. (This replaces the second bullet above about OF/IN.)
  • The fixture line the review pointed at did run one column past 72; it is shortened.

Type of change

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

Verification & Invariants

Invariant: an edge is only emitted for a target that is a paragraph of the same program; anything else stays unlinked rather than guessed. Existing PERFORM and CALL edges are unchanged.

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   # 11 passed
uv run --frozen ruff check .                                        # All checks passed
uv run --frozen pyright                                             # 771 errors, the same count as unmodified v8

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

The full suite (uv run --frozen --all-extras pytest tests) was run on a local branch that combines this change with my three other COBOL PRs (#5423 to #5426) and one further COBOL change not yet submitted, not on this branch alone: 11883 passed, 165 skipped, 1 xfailed, none failed (rerun after the follow-up commits).

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

The COBOL extractor read PERFORM and CALL but had no pattern for GO TO, so
a jump left no edge. A paragraph that is only ever reached by `GO TO` (an
exit or error paragraph, typically) had no inbound edge and looked like dead
code, and a walk along the control flow stopped at every jump.

Emit a `calls` edge from the paragraph the statement stands in to each
target, tagged `context: "go_to"` so a jump can be told apart from a
PERFORM without a new relation. `GO TO A B C DEPENDING ON X` links A, B and
C. The target list ends at DEPENDING (a data name follows) and at OF/IN
(the section that qualifies the paragraph before it follows), so neither is
taken for a target. Targets resolve against the same per-program paragraph
table as PERFORM, and a name that is not a paragraph of the program yields
no edge. Text inside quotes and EXEC blocks is not read, as for PERFORM.

Not covered: `GO` without `TO`, a target list that runs on over several
lines, and a GO TO changed at run time by ALTER. When a paragraph both
performs and jumps to the same target, the one edge kept is the PERFORM.

Regression tests: a plain GO TO, and GO TO ... DEPENDING ON with a
qualified target. Both fail without the change.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@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

Review before merging · Merge confidence 4/5

1 bug · 3 possible issues to check · Medium impact

The extractor adds GO TO transfers as calls edges marked with context="go_to", including targets in DEPENDING ON lists.

P2  A matching PERFORM hides the GO TO edge context · cobol.py:363

3 possible issues we couldn't confirm

They don't change the score.

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

Reviewed 3ed7273 · 3 earlier findings not re-checked · Full report in the Graphify check

The target list of a GO TO ran on to the end of the line: every word after
the first target was tried as a paragraph name. In `IF A = 1 GO TO ERR-PARA
ELSE SET CHOICE TO TRUE`, a paragraph named CHOICE became a jump target.

A plain `GO TO A` has exactly one target, so only the first word is taken.
Only `GO TO A B C DEPENDING ON X` has several: there the list runs up to
DEPENDING. A second GO TO on the same line is read as a statement of its
own, with its own target.

In a DEPENDING list, `OF`/`IN` ended the list, so the targets after a
qualified name were lost (`GO TO A OF S1, B DEPENDING ON X` missed B). The
section that qualifies a name is now left out and the list goes on.

One fixture line ran one column past column 72 and lost its period; it is
shortened.

Regression tests: a line with a paragraph name after the jump and a line
with two jumps, and a DEPENDING list with a qualified name in the middle.
Both fail without the change.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Comment on lines +360 to +363
for caller_id, program_id, name, line in pending_go_tos:
target_id = paragraphs.get((program_id, name.casefold()))
if target_id is not None:
add_edge(caller_id, target_id, "calls", line, context="go_to")

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 matching PERFORM hides the GO TO edge context

When the same paragraph both performs and jumps to a target, the graph keeps only an untagged calls edge, so consumers looking for context: go_to miss the jump.

Merge context: go_to into an existing edge in add_edge.

Evidence · checked against the code

Expected: The graph marks the jump edge with context="go_to".
Actually: The earlier untagged PERFORM edge suppresses the later GO TO edge during deduplication.

  • Independent source review: Reviewed the GO TO tests: they check tagged jumps, including multiple targets and multiple GO TO statements on a line, but none combines PERFORM and GO TO to the same target. No guard or alternate path in the inspected extraction code preserves the context for that duplicate pair.
Prompt to fix with AI
In graphify/extractors/cobol.py, add_edge (lines 360-363):
Problem: A matching `PERFORM` hides the `GO TO` edge context
Expected: The graph marks the jump edge with context="go_to".
Actually: The earlier untagged PERFORM edge suppresses the later GO TO edge during deduplication.
Fix it at the cause, and add a test that fails without the fix.

Graphify · Checked against the code · View in Graphify

safishamsi added a commit that referenced this pull request Nov 24, 2026
…batch

Fold the Python-lambda (#5417), Go-import-shadow (#5411) and COBOL GO-TO
(#5423) AST-output changes into one combined _AST_CACHE_SCHEMA bump 53 -> 54,
so cached Python/Go/COBOL extractions re-run. Fix the #5422 regression test's
cwd-fragile `query` assertion to check the queried node (returncode==0 is the
real invariant). 0.9.119 changelog and version bump. The headline is the
#5320 anyio regression fix (graph commands broke on core installs in 0.9.118).

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

Copy link
Copy Markdown
Member

Landed in v0.9.119 via an authorship-preserving cherry-pick. A COBOL GO TO now emits a calls edge to the paragraph it jumps to (including each target of GO TO ... DEPENDING ON), fail-closed on an unknown target. Maintainer tweak: added the AST cache schema bump so cached COBOL files re-extract. Thanks @pavansystems!

@safishamsi safishamsi closed this Nov 24, 2026
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