Skip to content

docs(cobolrt): write and enforce the public API contract (Part of #4718) - #7356

Merged
squid-shepherd[bot] merged 2 commits into
mainfrom
docs/cobolrt-api-contract
Oct 31, 2026
Merged

squid-shepherd[bot] merged 2 commits into
mainfrom
docs/cobolrt-api-contract

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Part of #4718 (epic #4710). This does not close #4718: its version, licence and developer-docs items stay open.

What this does

cobolrt ships inside every port, but nothing said what a port may call. This PR writes that down and enforces it:

  • docs/language_status/cobolrt_api.json: every public type and member of the runtime, each classified public or internal, with the evidence for the call.
  • docs/cobolrt_api_contract.md: what public means, the compatibility promise, the variants, how to change the surface, and the commands.
  • tests/tools/cobolrt_api.py writes and checks the manifest. tests/cobol_mainframe/test_cobolrt_api.py fails when:
    • (a) the surface changes without the manifest;
    • (b) a committed port, a translator string or a live translation uses something not public.

Nothing under gitgalaxy/tools/cobol_to_java/** changes, so no proof record goes stale. The det-sweep plan for this diff is none.

The surface

There is no single runtime artifact, so the scope follows what a project actually gets: the 48 Java files, CicsSpec.java, and the classes the forges emit (CicsTask, the batch runtime, CobolRecords, CobolEdit, CobolCompare, Db2Dates, CobolRef). Forge text comes from the forges' own constants and functions, parsed with tree-sitter-java. Java's accessibility rules decide what is in scope, so the package-private Codec, Editing and Zoned are out. CicsRegion and BatchJobController are generated per estate: they are callers, not surface.

types members public internal
all 124 (101 public) 1178 781 397
cobolrt.* 67 535 347 188
cics.CicsTask* 533 365 168
other forge classes 110 69 41

The classification is evidence-based. It was seeded from all 152 committed Java files that call the runtime (the ports plus the frozen copies), the translator's strings, and det_port.py --translate-only over all 201 cases in three forms (default, --style structured, --no-typed --groups).

Classification calls to review

  1. CicsTask is almost half the surface. 365 of the 781 public members are on it. That is honest, because ports program against it directly, but it is the part of the promise that would cost most to keep.
  2. The with* builders are internal. CicsTask.withClock, withStartcode and so on are harness-facing (191 internal members carry harness evidence). A customer running ports outside our harness may need some of them. That is a product decision.
  3. The *Spec tables, QueueManager, Lossless and Field.Kind are internal. A port never names them.
  4. Record constructors are internal; their accessors are public. Ports read these records and never build them.
  5. 67 public members are public only on emitter-dynamic evidence. Computed emission (f"Cobol.{fn}", f"{var}.nextInput()") can't be read literally, so this over-approximates on purpose. Some accessors are probably public by name match alone. The cost of the safe direction: a new internal helper whose name matches such a string fails the check until it is made public or renamed.
  6. The compatibility promise is deliberately narrow: source, within one generation. It says plainly that it does not yet cover running a port on a later runtime, because that needs the version stamp.

What ports call that may surprise you

Nothing calls a member the Java does not expose: the check reports 0 unresolved names. Since the seed made every used member public, the review question is which uses should have been public at all:

  • Model-written ports use 13 members the translator never emits, including CicsTask.events() (tests/cics_crucible/ports/ca-link-lengths/CALINK), which reads the task's event log, and abcodeFor, receiveText(int) and startAt(...). events() looks like harness introspection, not port API.
  • DetCics.within(Field,int,String) is called by 8 committed det ports but no longer emitted (the translator now writes withinRecord). Those ports are older translations.
  • The earlier "17 unused Cobol.x" count was an artefact of the literal grep. Of the 75 Cobol members, 69 have a real or possible generated caller, 3 are runtime-only, setTruncBinary and setTruncOpt are test-only, and only NAN_SCALE has no caller found.
  • 173 internal members have no caller in any scan. That is not proof they are dead: reflection, Spring injection and hand-written tests outside these roots aren't seen.

The frozen overlays

tests/cics_crucible/ports/pc-wizard/PCCONF/overlay/cobolrt and pc-return-immediate/PCIMMA/overlay/cobolrt are the only places a port runs on an older runtime. They are handled like this:

  • Their declarations are not surface.
  • Their calls to each other bind to the copy and are ignored.
  • Their calls out to freshly generated classes are real cross-version calls, so they are scanned: 10 members carry frozen-overlay evidence. Four are public mainly because of that (CicsSpec.condition, CicsTask.acquireReceived, addressOf, storageAt).
  • The services beside them are scanned as ordinary ports.

Against the current runtime, the copies declare only two members that no longer exist: Sort.rewind() and the 5-argument Ceesecs.call. No overlay service calls either.

Limits

These are stated in the tool and the doc:

  • Overloads are told by name and argument count, so a call binds every overload of that count.
  • A receiver the inference can't type is not checked. Across all 516,448 calls scanned, 160,133 have a receiver that is not a runtime type or can't be typed; 110 of those match an internal-only method name, and the sampled hits are JDK calls (contains, end, execute) or original estate Java.
  • The full generated scan needs the corpora, so CI runs the committed ports, the emitter strings and one live translation. cobolrt_api.py --check --generated DIR is the local form.

Class / Sibling gaps

Class: the runtime's callable surface, across every unit a generated project receives (cobolrt, CicsSpec, the forge-emitted classes), against every caller (committed ports, generated output, emitter strings). Every member of the class is handled here: all 124 public types, including every class port_runner._RUNTIME_HELPERS names.

Sibling gaps, none done here because each needs a different mechanism or an excluded file:

Gap Status Why not here
--style structured writes invalid Java for a digit-first COBOL name: zecs-zecs001 gets private final Field 50702Message. defect, non-default style Translator change; found by this scan. --check --generated on a structured work directory reports that one file until it is fixed. Default-style and --no-typed --groups output parse clean.
Run --check --generated in the det sweep, so CI sees all generated output. missing det-sweep.yml is a DET_INPUTS file, so it would trigger a full sweep.
Annotate internals in the Java (@Internal or a package move). missing Would edit gitgalaxy/tools/cobol_to_java/** and stale proof records.
A runtime version constant, stamped in ports and evidence records. open in #4718 Generator and evidence-input change.
Compatibility tests between generated code and runtime versions. open in #4718 Needs the version first.
Licence decision. open in #4718 Owner and counsel.
Developer docs, changelog, and the fail-loudly audit. open in #4718 Separate slices.

Test evidence

  • tests/cobol_mainframe/test_cobolrt_api.py: 61 passed, also from an unrelated working directory with the plain pytest script, as CI runs it. Time ratchet: 61 tests checked, 0 over the per-test limit, 0 warned.
  • pr_gates.py --fast: 9/9 gates pass.
  • tests/tools/ under heavy-run.sh: exit 0. audit_check.py: all clear.
  • Pre-PR tree-wide guards plus test_det_sweep_plan.py: 315 passed.
  • cobolrt_api.py --check: holds. --check --generated over the default and --no-typed --groups work directories: holds. Over the --style structured one: exit 1 on the one zecs-zecs001 file listed under Sibling gaps.
  • Sabotage on the real manifest: flipping Cobol.move, CicsTask.storageAt, Sort.nextInput and Funcs.abs to internal fails on the right caller label for each, and dropping a manifest row fails as a surface change.

Lessons for agents

  • A real NUL in a Java char literal breaks tree-sitter-java across the whole enclosing class, with the ERROR node reported far from the cause. CICS_TASK_JAVA has one, because the forge's Python string writes '\0' as the byte. Mask literals before parsing (cobolrt_api.parse).

🤖 Generated with Claude Code

The runtime had no definition of what generated code may call. Add a
manifest read from the real sources (cobolrt, CicsSpec and the classes the
forges emit), a contract doc, and tests that fail when the surface moves
without the manifest or when a port or generator string uses an internal
member. Nothing under gitgalaxy/tools/cobol_to_java changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@squid-protocol
squid-protocol marked this pull request as ready for review October 31, 2026 22:00
@squid-protocol squid-protocol added the shepherd:merge Maintainer: merge when green (auto-merge, squash). Guide: docs/ci.md label Oct 31, 2026
@squid-shepherd

Copy link
Copy Markdown
Contributor

No description provided.

@squid-shepherd
squid-shepherd Bot enabled auto-merge (squash) October 31, 2026 22:05
@squid-shepherd

Copy link
Copy Markdown
Contributor

No description provided.

@squid-shepherd
squid-shepherd Bot merged commit f842015 into main Oct 31, 2026
35 checks passed
@squid-shepherd
squid-shepherd Bot deleted the docs/cobolrt-api-contract branch October 31, 2026 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

shepherd:merge Maintainer: merge when green (auto-merge, squash). Guide: docs/ci.md

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cobolrt as a shippable product: stable API, versioning, licence, documentation

1 participant