Skip to content

Write BE's release files and assemble transport builds into release builds - #1801

Draft
anth-volk wants to merge 12 commits into
mainfrom
claude/be-release-files
Draft

anth-volk wants to merge 12 commits into
mainfrom
claude/be-release-files

Conversation

@anth-volk

@anth-volk anth-volk commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1800. Tracker task 5b · 13 ("BE builder: write source coverage, demographics and reform validation into each build") of the collector/emitter project.

What this does

Since #1744, a new build of a BE release must carry the six files BE's release contract lists and declare the three added ones (source_coverage, demographics, reform_validation) in its release manifest. Nothing wrote those three files, and nothing turned a BE build into a directory microcosm-publish-release-build can publish, so no new BE build could publish. Microcosm's own BE builds run through the spec-driven transport command, which writes a local --out folder and has no release step; this PR adds that step, modelled on the UK national assembler, and the three files.

UK national (on main) BE (this PR)
Release step tools/assemble_uk_release_dir.py tools/assemble_spec_release_dir.py (microcosm.build.spec_release_assembly), country-neutral
What it reads the candidate's own outputs: H5, build record, signed diagnostics (commit and runtime), gate reports the transport build's own outputs: build-status.json (commit and runtime, now recorded there), the H5 read back against its export descriptor, the calibration diagnostics, the run manifest's gate outcomes
What it writes the release directory, a weights NPZ beside the H5, validated, plus the publish and promote commands; nothing uploaded the same, with each file the country's release contract requires
Source coverage uk_source_coverage.json (dense release only, UK-specific) source_coverage.json with the US file's fields under be_source_coverage
Demographics, reform validation none demographics.json and reform_validation.json (below)
  • microcosm.build.spec_release_files builds the three files from the country's spec and the build's calibration diagnostics; it reads no population and runs no simulation.
    • source_coverage.json: the shared source_coverage_gate over the spec's target categories. A category with an executable calibration reference is a hard target (BE: Statbel demography), one whose references are all parked is a source gap, and each held-out category is validation-only. It fails when the build left out an executable reference or calibrated a held-out one, and the release step treats it as a release gate.
    • demographics.json: the US file's fields for the spec's executable demography references (BE: Statbel population by NUTS1 region, sex and age band), each cell's calibrated population and benchmark from the calibration rows, and their sums by age band. BE calibrates these cells, so the file reports in-sample fit (in_sample true), where the US file reports an uncalibrated age distribution.
    • reform_validation.json: schema 1, no reforms, out_of_sample_simulated true (as the US writer records when no out-of-sample reform exists, so publication accepts it), until scored BE reforms exist (Validate populace-be against EUROMOD-BE and Federal Planning Bureau scores #264).
  • microcosm.build.spec_release_assembly refuses a build that still owes outputs; records no clean Microcosm commit, no runtime or no spec digests; ran on another spec; has an H5, export descriptor, diagnostics file or run manifest that changed after the build wrote it; has a gate that did not pass; has a year without a release that publishes into build folders; or fails its source coverage check. The release is microcosm-<country>-<year>-national; the build is microcosm-<country>-<year>-chronicle-<Chronicle pin>-<finish time>. The H5 is copied beside the build as populace_be_<year>.h5 and its household weights written as populace_be_<year>_calibration.npz; both are declared and publish into BE's private repository, as the contract's private file list names them.
  • microcosm.build.transport.cli: build-status.json now records the Microcosm commit of the checkout that tracks the command's code and whether a tracked file differed from it (code_revision), the Python and package versions (transport_build_provenance), the digest of each JSON spec resource (spec) and the run manifest's digest.
  • Docs and changelog: docs/release-contract.md (C5), docs/agent-guide.md, changelog.d/1800-be-release-files-and-assembly.added.md.

Commits

  • 89217fcc9 adds the tests and placeholder modules: all 30 failed on assertions (11 as "DID NOT RAISE"), run by file and, for test_transport_composed_graph.py, by the one modified test's node ID.
  • 317c0ffd8 is the change.
  • Review round 1: 720f9f42a (tests) and 1ab647435 (fix) for its two medium-priority bugs and the low one; d86fb35d7 (tests) and 807a12ecf (fix) for its high-priority bug.
  • Review round 2: bd7d83732 (tests) and 401d4045d (fix) for its two low-priority bugs.
  • Review round 3: 088672fd5 (tests) and 54a92c807 (fix) for its low-priority bug.
  • a299890f1 merges main (8ea088de0, with Remove the tagged publisher, microcosm-publish-release #1797's removal of the tagged publisher) at Anthony's request; it merged with no conflict. c84773e7c then reads publication_refusal from microcosm.data.release, where Remove the tagged publisher, microcosm-publish-release #1797 moved it from the removed microcosm.data.publish_cli.

New tests: test_spec_release_files.py, test_spec_release_assembly.py and test_transport_build_provenance.py in packages/microcosm-build/tests/engine_free/shared/, and assertions in test_transport_composed_graph.py::test_cli_checkpoints_write_only_under_out_and_resume_warm. The fixture build folder is test_support/microcosm_build/spec_release.py; its calibration rows are BE's demography references read from BE's spec.

Review

Round 1 (one high, two medium, one low; all fixed):

  • High: reform_validation.json recorded out_of_sample_simulated false, which microcosm-publish-release-build reads as skipped out-of-sample reforms and refuses without --allow-incomplete-reform-validation, so the printed publish command failed for every BE build. Fixed as Anthony chose: the file records true, as the US writer does when no out-of-sample reform exists. A test checks the assembled folder against the publisher's own checks (publication_refusal).
  • Medium: the release step read the spec of the checkout it runs from and never compared it with the build's, so a checkout moved since the build would pair the build with references it did not compile. Fixed: the transport command records the digest of each JSON spec resource in build-status.json (spec), and the release step refuses a build that records none or whose digests differ.
  • Medium: the build's commit was measured in the module's directory without requiring the file to be tracked or removing GIT_DIR and similar variables, so an installed copy inside another repository recorded that repository's commit. Fixed: transport_build_provenance(code_file=...) uses microcosm.graph.reconstruction.code_revision.
  • Low: the age bands lack the US file's min_age and max_age. Documented: BE's spec gives age bands as values without bounds.

Round 2 (two low; both fixed):

  • A spec declaring no categories (NZ's) gave the source coverage check nothing to compare. Fixed: such a reference counts toward its family.
  • The build manifest's run start was that of the transport command's last pass over the stored graph. Fixed: the run record keeps only the run manifest's key and end.
  • Also: the release step compares the export descriptor with its recorded digest, a malformed gate outcome becomes a refusal, and the docs match the code.

Round 3 (one low; fixed):

  • With no categories, a held-out family named like a calibrated target family was reported as calibrated. Fixed: a held-out family whose ID a target family has takes a .held_out suffix.
  • Also: the transport command records the run manifest's digest, and the release step checks it before reading the manifest.

Left after three rounds (not bugs the reviews rated, or not cheap):

  • code_revision runs git status, which can rewrite the checkout's git index file (outside --out); it is shared with Orrery reconstruction, so a change there is its own PR.
  • A build made with --spec-dir assembles only when its JSON resources are byte-identical to the packaged spec.
  • Calibration rows are matched to references by name, not by name and period; the release files read the packaged reference documents, which equal the profile-resolved ones for BE today.
  • The engine record names the Axiom rules engine even when its package is recorded as "unavailable".
  • No test covers a malformed gate outcome (the run manifest's own serializer refuses to write one) or the undo after a failed rename.

Not in this PR

Merge waits for

Tracker task 5b · 12 done, and Anthony.

Environment variables

None: the change reads no environment variable and touches no workflow, image or deployment code. transport_build_provenance runs git rev-parse HEAD and git status in the checkout.

🤖 Generated with Claude Code

anth-volk and others added 12 commits November 27, 2026 18:52
Tracker 5b · 13. Tests, a fixture transport build folder and placeholder
modules, so each test fails on an assertion:

- the three files a spec country's build adds to the base three
  (source coverage, demographics, reform validation), on fixture
  calibration diagnostics and BE's spec;
- an assembler that reads a transport build's output folder and writes
  the release directory microcosm-publish-release-build publishes;
- a transport build recording its Microcosm commit, dirty flag and
  Python and package versions in build-status.json.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…uilds

Tracker 5b · 13 (microcosm#1800). A new BE build must carry the six files
BE's release contract lists, and nothing wrote source_coverage.json,
demographics.json or reform_validation.json, so no BE build could publish.

- microcosm.build.spec_release_files builds the three files from the
  country's spec and the build's calibration diagnostics: source coverage
  with the US file's fields over the spec's target categories, the
  demography references' calibrated cells and age bands, and a reform
  validation with no reforms yet.
- microcosm.build.spec_release_assembly (tools/assemble_spec_release_dir.py)
  reads a transport build's --out folder as the UK national assembler reads
  its candidate's outputs, refuses a build it cannot publish, writes the
  release directory with the H5 and its weights beside the build, validates
  it and prints the publish and promote commands. It uploads nothing.
- A transport build's build-status.json records the Microcosm commit,
  whether the checkout was clean, and the Python and package versions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… copy

Review round 1 of #1801:

- The assembler reads the spec of the checkout it runs from, so a build of
  another spec would be named and judged against references it did not
  compile. Tests require the build to record its spec's resource digests
  and the assembler to refuse a build whose spec differs or is not
  recorded.
- transport_build_provenance measured git in the module's directory, so an
  untracked installed copy inside another repository, or GIT_DIR, recorded
  another repository's commit. Tests name the code file and require it to
  be tracked, ignoring repository-selecting variables.
- Guards: a contract refusal after staging leaves nothing behind, and the
  writers' file table equals the contract's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 1 of #1801:

- execute_transport_graph records the digest of each spec resource the
  graph was composed from under build-status.json 'spec' (the command
  passes load_transport_spec's resource_hashes), and the release step
  refuses a build that records none or whose digests differ from the spec
  it loads.
- transport_build_provenance takes the code file and measures it with
  microcosm.graph.reconstruction.code_revision: the file must be tracked,
  and git runs without repository-selecting variables.
- The run manifest's known failures already cover every gate outcome, so
  the second loop over them goes; demographics docs say the age bands have
  no min_age or max_age.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 1 of #1801 (high): reform_validation.json recorded
out_of_sample_simulated false, which microcosm-publish-release-build reads
as skipped out-of-sample reforms and refuses without an override, so the
printed publish command failed for every BE build. Anthony chose to record
true, as the US writer does when no out-of-sample reform exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eforms

Review round 1 of #1801 (high), as Anthony chose: the US writer records
true when no out-of-sample reform exists, and publication refuses false,
so the printed publish command now passes the publisher's checks. Docs and
changelog also name every refusal, the spec digests, the pandas and NumPy
versions the read-back needs, and the age bands' missing bounds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ecord

Review round 2 of #1801 (two low-priority bugs and one gap):

- A spec whose references declare no category (NZ's) gave the source
  coverage check nothing to compare, so it passed whatever the build
  calibrated.
- The build manifest's run start was the start of the transport command's
  last pass over the stored graph, not of the build.
- The export descriptor, whose weight entity picks the NPZ's weights, was
  not compared with the digest the build recorded.

Guards: the environment-variable test's two repositories are at different
commits, and the command passes the loaded spec's digests to the run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 2 of #1801:

- Source coverage groups a reference whose category the spec does not
  declare by its 'family', so a spec like NZ's, with no categories, still
  has its references checked.
- The build manifest's run record keeps the run manifest's key and end,
  not the start of the command's last pass over the stored graph.
- The release step compares the export descriptor with the digest the
  build recorded, and reports a malformed gate outcome as a refusal.
- Docs: the spec digests cover the JSON spec resources; the refusal list
  drops the release tier, which no transport build records; a refusal may
  leave the out directory created.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 3 of #1801:

- (low) Where a spec declares no categories, a held-out reference and a
  calibrated target in families of the same name made the source coverage
  check report the held-out family as calibrated.
- The run manifest, which decides the gate refusal and the build's name,
  was the only build file the release step read without a digest from
  build-status.json.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 3 of #1801:

- A held-out family whose ID a target family also has takes a '.held_out'
  suffix, so a calibrated target never counts as a calibrated held-out
  reference.
- The transport command records the run manifest's digest under
  build-status.json 'produced', and the release step compares it before
  reading the manifest.
- Docs: only JSON spec resources are hashed; the changelog's refusal list
  names the descriptor and the run manifest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main removed microcosm.data.publish_cli with the tagged publisher and moved
publication_refusal into microcosm.data.release. The assembler test and the
reform validation docstring name the new place; the docstring's old module
name would also have failed test_tagged_publisher_removed's search of
package sources.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

BE builds: write source coverage, demographics and reform validation, and assemble transport builds into release builds

1 participant