Skip to content

cobol avg_func_args stays 0: a paragraph's ENTRY … USING is one line outside the Mode A args window, so hit_vector.args=1 while the function's own args=0 #2863

Closed

Description

@squid-protocol

avg_func_args for cobol reads 0.0 against a median 1.0 (−100%) even though every one of the corpus's nine probe paragraphs now declares a parameter, and the engine's own function record says so. Inside a single functions[] entry the two args fields disagree:

PROBE-GLOBALS: args=0   hit_vector.args=1
PROBE-TEST:    args=0   hit_vector.args=1
PROBE-SAFETY:  args=0   hit_vector.args=1

hit_vector — the block's own rule tally — correctly attributes the USING clause to the paragraph. The args field, which is what avg_func_args averages (signal_processor.py L589, sum(f["args"]) / len(real_functions)), reads 0.

Measured on engine main 2655985 against keyword-rosetta corpus/2804-cobol-entry-using (the #2804 shape (a) plant: USING ARGV-BLOCK appended to the nine existing ENTRY lines in data/cobol/{a,b,c}.cpy). This is the open question #2804 flagged and could not settle from a regex screen; it resolves as that issue feared.

Cause: the Mode A args window is one physical line, and COBOL's ENTRY is on the next one

detector.py L3376 bounds the per-function args search for the four Mode A languages to the label's own statement span:

if self.primary_lang_id in ("cobol", "fortran", "dockerfile", "jcl"):
    args_window_end = self._mode_a_args_window_end(code, start_idx, start_idx + end_offset)
    args_search_text = code[start_idx:args_window_end]

_mode_a_args_window_end extends the window only while a line ends in the language's own continuation marker, and _MODE_A_ARGS_CONTINUATION_MARKER (L3122) has entries for dockerfile, fortran and jcl only. Its docstring states the consequence outright:

A language with no continuation marker (cobol) never extends past its own first line.

That is correct as written — cobol's fixed-format continuation is a column-7 indicator on the continuing line, not a trailing marker on the line before, so cobol rightly gets no marker entry. But it means the window for a COBOL paragraph is exactly the label line PROBE-GLOBALS., and a paragraph label is terminated by its own period. The ENTRY 'PROBE-GLOBALS' USING ARGV-BLOCK. that declares the paragraph's parameters is a separate statement on the next line, and therefore outside the window — while still being inside the block, which is why hit_vector sees it and the args field does not.

Micro-repro — one variable, the ENTRY statement's line position

data/cobol/a.cpy, unchanged except for folding the ENTRY statement up onto the paragraph label's line (legal COBOL either way):

as planted (ENTRY on next line)  -> PROBE-GLOBALS: args=0  hit_vector.args=1
ENTRY folded onto label line     -> PROBE-GLOBALS: args=1  hit_vector.args=1
folded + USING A, B, C           -> PROBE-GLOBALS: args=3  hit_vector.args=1

Two things this pins down:

  1. The window is the sole blocker. Nothing else about the plant changes.
  2. fix(cobol): globals drops WORKING-STORAGE header (#2805); args counts operands not clauses (#2804) #2830's operand counting already reaches the per-function path — the folded 3-operand case reads args=3, not 1. So this is purely a window-extent question; _count_cobol_using_operands needs no change.

Why the corpus is not authored around it

Folding the ENTRY onto the label line would turn the cell green and would be legal COBOL, and it is deliberately not what keyword-rosetta#97 does. Real Enterprise COBOL writes ENTRY on its own line, so folding would buy a green rosetta cell while every real COBOL program in the crucible corpus kept reading 0 — the opposite of what #2830 landed for. The corpus keeps the idiomatic form and ledgers the cell (cobol-entry-args-outside-mode-a-window, disposition upstream-question, pointing here).

Shape of a fix

An ENTRY statement immediately following a paragraph label is that alternate entry point's parameter declaration, so the window should reach it. The narrow version: for cobol, let _mode_a_args_window_end extend past the label's own line across leading ENTRY statement(s) before stopping — a cobol-specific transparent-line rule in the same shape as the fortran one already in that function (blank / ! comment / cpp lines are skipped rather than treated as terminators).

Worth checking before implementing, because it is exactly what the bound was added to prevent (#1973/#2483): the window must still stop before it can reach main.cbl's program-level PROCEDURE DIVISION USING ARGV-BLOCK, or every paragraph would inherit the program's linkage as its own. Extending across ENTRY lines only — not across arbitrary statements — keeps that protection, since PROCEDURE DIVISION is not an ENTRY.

Expected effect if fixed: corpus avg_func_args 0.0 → 0.69 (9 of 13 functions declaring one arg; main.cbl's four paragraphs have no ENTRY and #2804 declines to give them one, because that would take main's raw_arch_api 1 → 5 and break the api-non-function-surfaces plant). That is still short of the 1.0 median, so the corpus cell would move from −100% to −31% — an improvement, not a green, and the remaining gap is the honest morphology residue #2804 already priced. The crucible corpus is where the real gain is: any real COBOL program using alternate entry points currently reports 0 args per paragraph.

Related: #2804 (parent, args half), #2830 (the operand-count fix), #1973 / #2483 (why the bound exists).

Activity

  1. added
    bug
    metrics
    core-engine
    legacy-modernization
    on Sep 7, 2026
  2. squid-protocol commented on Sep 7, 2026

    @squid-protocol
    OwnerAuthor

    Landed in #2864. Corpus half is keyword-rosetta#98 (CI green): cobol-entry-args-outside-mode-a-window retired, no successor entry.

    Correction to this issue's predicted outcome. I wrote here that avg_func_args would move 0.0 → 0.69, i.e. −100% → −31%, "an improvement, not a green". That was wrong on both numbers. The measured result is 0.0 → 0.75, −25.0%, in band — the cell is green.

    The error: avg_func_args is a mean per file, not corpus args over corpus functions.

    file args / real functions value
    main.cbl 0 / 4 0.0
    a.cpy 3 / 3 1.0
    b.cpy 3 / 3 1.0
    c.cpy 3 / 3 1.0
    mean 0.75

    Not 9/13 = 0.6923. Worth reading a metric's aggregation level off the engine before predicting where a plant lands.

    The green has zero margin, though. 0.75 is exactly the band edge (median 1.0 × 0.75) and passes only because bias_report's predicate is a strict abs(dev) > GREEN_DEV. A fifth cobol file, or a paragraph without an ENTRY, tips it back out — and would need a new ledger entry, not the retired one. main.cbl's four paragraphs can't cheaply gain one: screened, all four do go args 0 → 1, but four ENTRY lines take main.cbl api 1 → 5, the trade #2804 already declined. Both facts are recorded in the retired ledger entry and the cobol manifest notes.

    Also worth keeping from the investigation: the real-world corpus took a provable zero diff. All 158 paragraphs carrying a USING/RETURNING inside their block across 570 crucible COBOL files are CALL invocations (123), the program-level PROCEDURE DIVISION (26) or XML PARSE … RETURNING (3) — not one is a parameter declaration. That is why the window extends across ENTRY only, and why golden masters were unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcore-enginelegacy-modernizationmetrics

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions