Skip to content

fix(cobol): detect fixed-format source that carries sequence numbers - #3813

Closed
abhay-codes07 wants to merge 1 commit into
Graphify-Labs:v8from
abhay-codes07:fix/cobol-sequence-number-detection
Closed

abhay-codes07 wants to merge 1 commit into
Graphify-Labs:v8from
abhay-codes07:fix/cobol-sequence-number-detection

Conversation

@abhay-codes07

@abhay-codes07 abhay-codes07 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

What

The COBOL fixed/free format detector counts a line as fixed-format only when its first six columns are blank (^ {6}[ *\-/ ]). But legacy mainframe COBOL — the main reason a COBOL extractor exists — puts a sequence number in columns 1-6. Such a file scores zero fixed markers and is misclassified as free-format.

In free mode the code is taken verbatim (no column-8 slice), so the sequence number stays glued to the statement. 000400 MAIN-PARA. then no longer matches the paragraph anchor ^(NAME)(?: SECTION)?\s*\.\s*$, and the entire procedure layer disappears: a seven-line program with two paragraphs and a PERFORM collapses to just the file and program nodes — zero paragraphs, zero calls edges — silently.

$ extract_cobol(seq_numbered.cob)   # before
  program=[PAYROLL] paragraphs=[] calls=0     # 2 nodes total
$ extract_cobol(seq_numbered.cob)   # after
  program=[PAYROLL] paragraphs=[MAIN-PARA, INIT-PARA] calls=1

Fix

Count a fixed-format marker when the six-column sequence area is six spaces OR six digits, followed by a valid indicator column (space = code, *// = comment, - = continuation, D = debug): ^(?: {6}|\d{6})[ *\-/dD]. Once the file is correctly read as fixed-format, the existing column-8..72 slice already strips the sequence number and indicator, so paragraphs and PERFORMs resolve normally.

A six-digit prefix is not something free-format code begins a line with, so blank-sequence fixed-format and genuinely free-format source are both unaffected (verified).

Verification

  • Reproduced: a sequence-numbered program yielded only 2 nodes and 0 calls before.
  • The new regression test asserts the program, both paragraphs, and the PERFORM calls edge — and fails on the old detector.
  • Blank-sequence fixed-format and free-format inputs still extract their paragraphs and calls (no regression). All COBOL extractor tests pass.

The fixed/free format detector counted a line as fixed-format only when its
first six columns were blank (`^ {6}[ *\-/ ]`). Legacy mainframe COBOL — the
main reason to have a COBOL extractor — puts a sequence NUMBER in columns 1-6,
so every such file scored zero fixed markers and was classified free-format.

In free mode the code is taken verbatim (no column-8 slice), so the sequence
number stays glued to the statement: `000400 MAIN-PARA.` no longer matches the
paragraph anchor `^NAME .? .$`, and the whole procedure layer disappears. A
seven-line program with two paragraphs and a PERFORM collapsed to just the file
and program nodes — zero paragraphs, zero `calls` edges — silently.

Match a sequence area that is six spaces OR six digits, followed by a valid
indicator column (space = code, `*`/`/` = comment, `-` = continuation, `D` =
debug). Once the file is correctly read as fixed-format the existing
column-8..72 slice strips the sequence number and paragraphs/PERFORMs resolve
as they should. Blank-sequence fixed-format and genuinely free-format source are
unaffected (a 6-digit prefix is not something free-format code begins a line
with).

Regression test: a sequence-numbered program now yields its program, both
paragraphs, and the PERFORM `calls` edge — and fails on the old detector.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JJbLfztSxm2tH5cJwBbe9q
Copilot AI lite review requested due to automatic review settings September 24, 2026 17:45

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@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 reviewed this change.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.

Formal verification. 1 change(s) tested, no difference found (not proven).


Graphify review — findings

Fixes fixed-format detection in _code_lines so legacy source carrying a six-digit sequence number in columns 1–6 (previously requiring six blank columns) is no longer misread as free-format. This keeps paragraphs and PERFORM edges intact instead of dropping everything but the file and program nodes when the sequence number leaked into the code and broke the ^NAME.$ anchor. Adds test_cobol_fixed_format_with_sequence_numbers covering a sequence-numbered file with a paragraph call edge.

Worth a look

  • Alphanumeric fixed-format sequence areas still misdetected as free format — graphify/extractors/cobol.py:50 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 19 functions depend on the 19 functions this change touches.

Health — this change adds coupling hotspots:

  • new: extract_cobol() — 2 callers, 7 callees

Verification — 19 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 19 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

300 of 300 test file(s) selected (100%) via static blast radius.

Escalated to a full run for safety — the selection is not trustworthy on its own (see below). CI should run the whole suite.

  • tests/test_affected_cli.py — full-run-safety
  • tests/test_affected_member_seed.py — full-run-safety
  • tests/test_agents_platform.py — full-run-safety
  • tests/test_analyze.py — full-run-safety
  • tests/test_anthropic_custom_endpoint.py — full-run-safety
  • tests/test_antigravity_install.py — full-run-safety
  • tests/test_apm_fallback_version.py — full-run-safety
  • tests/test_architecture_doc.py — full-run-safety
  • tests/test_astro_extraction.py — full-run-safety
  • tests/test_astro_import_ids.py — full-run-safety
  • tests/test_atomic_canvas_export.py — full-run-safety
  • tests/test_atomic_version_stamp.py — full-run-safety
  • tests/test_atomic_writes.py — full-run-safety
  • tests/test_backend_env_isolation.py — full-run-safety
  • tests/test_backend_extras.py — full-run-safety
  • tests/test_benchmark.py — full-run-safety
  • tests/test_benchmark_raw_graph.py — full-run-safety
  • tests/test_build.py — full-run-safety
  • tests/test_build_merge_dedup_scope.py — full-run-safety
  • tests/test_build_merge_hyperedges_and_prune.py — full-run-safety
  • tests/test_build_merge_shrink_guard.py — full-run-safety
  • tests/test_builtin_global_type_refs.py — full-run-safety
  • tests/test_cache.py — full-run-safety
  • tests/test_callflow_html.py — full-run-safety
  • tests/test_cargo_introspect.py — full-run-safety
  • tests/test_cargo_missing_manifest.py — full-run-safety
  • tests/test_carried_hyperedge_remap.py — full-run-safety
  • tests/test_case_sensitive_resolution.py — full-run-safety
  • tests/test_charmap_encoding.py — full-run-safety
  • tests/test_chunking.py — full-run-safety
  • tests/test_cjs_module_extension.py — full-run-safety
  • tests/test_claude_cli_backend.py — full-run-safety
  • tests/test_claude_md.py — full-run-safety
  • tests/test_cli_broken_pipe.py — full-run-safety
  • tests/test_cli_export.py — full-run-safety
  • tests/test_cli_help.py — full-run-safety
  • tests/test_cluster.py — full-run-safety
  • tests/test_cobol_extractor.py — impact, changed-test, full-run-safety
  • tests/test_codebuddy.py — full-run-safety
  • tests/test_community_hub_labels.py — full-run-safety
  • tests/test_community_labels_skill.py — full-run-safety
  • tests/test_confidence.py — full-run-safety
  • tests/test_corrupt_graph_json.py — full-run-safety
  • tests/test_cpp_nested_and_cli.py — full-run-safety
  • tests/test_cpp_objc_cross_file_calls.py — full-run-safety
  • tests/test_cpp_preprocess.py — full-run-safety
  • tests/test_cross_extension_reexport_self_cycle.py — full-run-safety
  • tests/test_cross_language_call_resolution.py — full-run-safety
  • tests/test_cross_repo_external_call_guards.py — full-run-safety
  • tests/test_cross_repo_member_calls.py — full-run-safety
  • … and 250 more

changed code file(s) with no mapped test (graphify/extractors/cobol.py) — a coverage gap or a missing link — running the full suite rather than only the selected tests

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Formal verification

No difference found (not proven): No behavior difference found in \_code\_lines (not a proof).

The verifier ran both versions of \_code\_lines on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

· 1 more finding(s) on lines outside this diff (see the check run).

safishamsi added a commit that referenced this pull request Sep 25, 2026
Windows hash-seed re-exec wait (#3816/#3799), Terraform secret-named
variable-default/output redaction (#3817), COBOL fixed-format
sequence-number detection (#3813) and PERFORM...THRU both-endpoint
linking (#3814), and gate the GRAPH_REPORT undocumented-components
reason on a real semantic layer (#3828/#3801).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.68 (now on PyPI) via an authorship-preserving cherry-pick, so your commit keeps contributor-graph credit. Thanks @abhay-codes07! COBOL fixed-format sequence-number detection.

Release: https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.68

@safishamsi safishamsi closed this Sep 25, 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.

3 participants