Skip to content

Certify a UK build from its own folder in the policyengine.py certification tool - #1764

Merged
anth-volk merged 11 commits into
mainfrom
claude/uk-certification-build-folders
Nov 27, 2026
Merged

anth-volk merged 11 commits into
mainfrom
claude/uk-certification-build-folders

Conversation

@anth-volk

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

Copy link
Copy Markdown
Contributor

Fixes #1762

Base: main. Tracker: "1. Collector/Emitter", task 5d · 1 ("Microcosm: the policyengine.py certification tool takes a UK build published into its own folder").

Why

tools/certify_uk_cut_in_policyengine_py.py read a UK national build's manifest only at a Hugging Face tag (--national-tag) and checked build.cut_tag. Since #1537 (2026-11-09), UK builds are published into releases/<release>/<build>/ folders listed in releases.json, with no tag. The tool reached main through #1405, whose branch never contained #1537, and it hasn't been run since.

policyengine/populace-uk-private has releases.json at main. Every UK national build since 2026-10-02 is listed there as a build folder, including the builds that used to be tagged. policyengine.py refuses any tagged manifest from a repository that has releases.json (PolicyEngine/policyengine.py#683). So the tool couldn't certify anything. policyengine.py's current UK pair was certified by hand from build folders (PolicyEngine/policyengine.py#766).

What changes

Naming and finding a build (tools/certify_uk_cut_in_policyengine_py.py)

  • Arguments: --national-build BUILD (required) and the regional route --dense-build BUILD replace --national-tag and --dense-tag. Tags are no longer accepted. A name must match the emitter's folder-name rule.
  • The .py base: right after resolving --base-ref, the tool refuses a base that cannot read builds in their own folders (no read_build_folder, policyengine.py#683), before anything is downloaded or written.
  • releases.json: the tool downloads it afresh from main and refuses a build it doesn't list or has withdrawn, through microcosm.data.build_folder_manifests.require_offered_build. These are the same checks as policyengine.py's certify-data, run before anything is written. A build doesn't have to be current, since a certificate pins one build.
  • The pinned commit: each build is pinned at the commit that published its folder. That is the last commit of its release_manifest.json on main, from the Hub's paths-info, because a build folder never changes. --national-data-commit or --dense-data-commit pins another commit instead. It must be a full 40-character commit in main's history, because a commit on another ref may hold an edited copy of the folder, and --dense-data-commit goes only with --dense-build.
  • Hub failures: a failure while reading releases.json, asking which commit published a folder, listing main's history, reading a manifest or downloading a regional file is a refusal (REFUSED: …, exit 2) that names the request.
  • The manifest check: the manifest at that commit must name the release and the build, and must record built_with_model_package and built_with_core_package at its top level, where the build-folder layout puts them.
  • certify-data: it gets each build's folder manifest at its commit, hf://dataset/policyengine/populace-uk-private@<commit>/releases/<release>/<build>/release_manifest.json, which is the form Create the SPI income channel on the microcosm spine with the FRS-only second stage #683 accepts.
  • The core: the certificate follows the bundle's shared policyengine-core pin (core_binding: bundle_pin), .py's default. certify-data gets --core-version only when the operator passes one, which binds the certificate to that core and moves the pin (core_binding: certified). The accepted-mismatch audit installs the core the bundle will serve.

The regional route

  • --keep-regional-release: reads the kept local-area build at the folder and commit the current bundle pins. Before this change, a folder URI held no dense tag, so this route silently skipped the regional model check and the accepted-mismatch audit. A kept regional release in the build repository that isn't a build folder is refused, because policyengine.py would refuse it.
  • Regional microdata (for the audit): read from the build's folder at the build's commit. A file in another repository is still read at its own revision. A path that isn't a bare file name directly inside the folder is refused, the same rule policyengine.py applies. Every file's pin is checked before any file is downloaded.
  • Certified-constant rewrite: it moves the local-area build's commit as well as its name. policyengine.py's constant files hold both, for example UK_LOCAL_AREA_RELEASE_REVISION.
    • The rewrites replace quoted text, so they can't tell two constants with the same value apart. That happens when the previous local-area build's commit is also the old or the new national commit and the new builds' commits differ.
    • In that case the local-area commit is left unchanged, and the pull request body adds a checklist item asking a person to check those constants.

Names in the policyengine.py handoff

  • The changelog fragment is certify-uk-<build>.changed.md, the name policyengine.py#766 used.
  • The branch is still certify-uk-<last 8 hex digits>, and the writer check looks for that marker or the build's name.
  • The resume check compares the modified bundle's release_manifest_path with the build's folder. Once the builds are read, and before any regional file is downloaded, it also refuses a resumed bundle that pins another national commit, or whose regional URI differs from the one this run passes to certify-data (none on the drop route). The first attempt's constant rewrite already moved the constants to its own builds.
  • The commit message and the pull request title are "Certify Microcosm UK build ". The body names the build, its commit and the core binding.
  • The body's commands show paths relative to the worktree (../ beside it, ~/ under the home directory), and each JSON object argument by its size. So --open-pr posts neither the operator's folders nor the full bundle records the constant rewrite is passed. Each rewritten constant file is listed once.

Other places that described the tag form

  • tools/run_uk_cut.py's closing message names --national-build. Only the message's text changes.
  • docs/uk-cut-anyone.md, section "Certifying into policyengine.py", describes the new arguments, the checks and the pinned commit.
  • docs/release-contract.md records that .py has pinned UK builds by folder since policyengine.py#759 (merged 2026-11-16), and that this tool certifies them that way.
  • Changelog: changelog.d/1762-uk-certification-tool-build-folders.fixed.md.

Decisions (Anthony, 2026-11-26)

  1. Remove tags instead of accepting both forms.
  2. The build name is required; there's no default to the current build.
  3. Resolve the publishing commit, and let the operator override it with --national-data-commit or --dense-data-commit.
  4. This pull request also changes run_uk_cut.py's message and docs/release-contract.md as they are on main, accepting text conflicts with Publish run_uk_cut.py builds through the emitter and refuse new direct Hugging Face imports #1743.

Merging with #1743 and #1538

Tests

Run locally: only the 56 test functions this PR adds or changes, by node ID, in packages/microcosm-build/tests/engine_free/uk/test_certify_uk_cut_in_policyengine_py.py and .../test_certify_uk_cut_rehearsal_regressions.py. Per this work's rules, they weren't run again after the change; CI runs them. All Hub and policyengine.py calls are faked.

Commit Result
76864f111 (tests only) Red. The failures are the old parser refusing --national-build (SystemExit), the missing PublishedBuild, read_published_build, BuildPin and hub_api, manifest_uri's old arity, KeyError: 'national_tag' in the PR body, the old resume check, the commit message assertion, and the parser-message assertions. Tests that only expect a refusal, and the writer-check tests, pass at red, because they depend only on renamed arguments.
3ba64272a (change) Not run locally; CI. Lint (ruff format, ruff check) passes on the changed files, and --help runs.
beeee7b72 (round 1 tests) Red: the 23 test functions whose code or helpers changed were run by node ID. Five failed: test_an_operators_commit_must_be_in_mains_history (DID NOT RAISE), both cases of test_a_hub_failure_is_a_refusal (the Hub's RuntimeError escaped), test_a_resumed_worktree_must_certify_the_same_commits (no check_resumed_pins) and RunnerTests::test_a_resume_at_another_commit_refuses_before_any_command (CertifyError not raised). The tightened shared-commit test passes at red, because that behaviour was already right.
0b043382c (round 1 fixes) Not run locally; CI. Lint passes, and --help runs.
7b7c0f89e (round 2 tests) Red: the 20 test functions whose code or helpers changed were run by node ID. Three failed: test_a_failing_regional_download_is_a_refusal (the Hub's RuntimeError escaped), test_an_unreadable_releases_record_is_named_in_the_refusal (the pattern didn't match) and RunnerTests::test_a_resume_at_another_commit_refuses_before_any_download (the regional files were fetched first). test_a_failing_history_listing_is_a_refusal passes at red, because it covers round 1's fix.
af3a1b574 (round 2 fixes) Not run locally; CI. Lint passes, and --help runs.
2fc1ab9d0 (round 3 tests) Red: the 5 test functions whose code or helpers changed were run by node ID, and all 5 failed. test_the_build_folder_support_check_reads_the_base (no build_folder_support), test_a_base_that_cannot_read_build_folders_refuses_before_any_read (DID NOT RAISE), test_a_resumed_worktree_must_certify_the_same_commits (the old signature), RunnerTests::test_local_base_is_resolved_once_and_used_for_old_bundle (no base check spawned) and RunnerTests::test_a_resume_that_stops_routing_regions_refuses (CertifyError not raised).
586d23a1f (round 3 fixes) Not run locally; CI. Lint passes, and --help runs.
091e76263 (tests for María's review) Red: the 23 test functions whose code or helpers changed were run by node ID. The five new ones failed: test_a_command_is_shown_without_local_paths_or_records and test_the_pr_body_shows_each_command_without_local_paths_or_records (no public_command or public_commands), RunnerTests::test_certify_data_follows_the_bundles_core_pin_by_default (--core-version passed), RunnerTests::test_an_operators_core_version_binds_the_certificate (no binding in the body) and RunnerTests::test_each_rewritten_constant_file_is_listed_once (files repeated).
f32bc3382 (fix) Not run locally; CI. Lint passes, and --help runs.

Not run: the tool itself, against Hugging Face or a policyengine.py clone. Checked read-only on 2026-11-26: the Hub's paths-info at main gives a80a4bf7… for national build uk-frs-calibration-attempt-20261122T100732Z-b891aa69 and 9da09946… for local-area build uk-local-candidate-f100-s42-20261123T075147Z-7081d968. Those are the commits policyengine.py#766 pinned.

Environment variables

No workflow or deployment file changes. The tool reads the same variables as before, from the operator's environment: HUGGING_FACE_TOKEN or HF_TOKEN for the Hub, and gh's own login.

Merge waits for

Nothing but review. Stage 4 of the tracker project is done. Anthony marks this ready and merges it.

Review rounds

  • Round 1 (at 3ba64272a): no high or medium bugs. Three low bugs were found, and each now has a red test and a fix (beeee7b72, 0b043382c):

    • a Hub failure ended in a traceback, not a refusal;
    • a commit override was accepted from any Hub ref;
    • the resume check no longer compared commits.

    Code quality fixed:

    • the shared-commit test now checks the pins handed to the rewrite;
    • the release contract document names policyengine.py#759 (merged 2026-11-16), which first pinned the UK builds by folder;
    • the body's shared-commit wording;
    • one helper builds the folder manifest path.

    Left as found: run_uk_cut.py's closing message still prints the tagged promote command, and the Hub client is typed Any. The promote command belongs to Publish run_uk_cut.py builds through the emitter and refuse new direct Hugging Face imports #1743's change of the publication steps.

  • Round 2 (at 0b043382c): no high or medium bugs. All four round 1 fixes were confirmed. One low bug, that a Hub failure while downloading the regional files ended in a traceback, now has a red test and a fix (7b7c0f89e, af3a1b574).

    Code quality fixed:

    • the resume check runs before the regional download;
    • tests cover a failing history listing and a resume at a different commit;
    • a malformed releases.json is named in the refusal;
    • the docs and changelog fragment state the main-history rule and the resume refusal;
    • this description names .py#759.

    Left as found: on the keep route, a resume after a first attempt with --drop-regional-release is refused, which is conservative, not wrong.

  • Round 3 (at af3a1b574): no high or medium bugs. All four round 2 fixes were confirmed. Two low bugs now have red tests and fixes (2fc1ab9d0, 586d23a1f):

    • a resume that switched from a local-area build to the drop or area-coded route wasn't refused;
    • the tool never checked that the .py base reads build folders, so an accepted mismatch on such a base downloaded every regional file and set up a worktree before refusing.

    Also fixed:

    • the operator guide no longer says to test on a branch until .py#699 merges (it merged on 2026-10-27);
    • one constant names .py's bundle manifest path;
    • a code comment is corrected.

    Left as found:

    • no test resumes on the keep route;
    • the resume check doesn't compare --model-version, which predates this PR;
    • the releases.json prefix is chosen by searching the refusal's text.

    Review stopped after round 3, as planned.

  • María's review (at 586d23a1f; she ran the tool against the Hub for .py#766's pair):

    • Her run resolved the same commits as .py#766, and its commit matched .py#766's except for the core binding.
    • That one difference is fixed in 091e76263 / f32bc3382: the certificate now follows the bundle's core pin unless --core-version is given.
    • Her two smaller points are fixed in the same commits: the body's local paths and inline bundle records, and the repeated constant files.

    No bugs are known to remain.

🤖 Generated with Claude Code

anth-volk and others added 8 commits November 26, 2026 18:16
The policyengine.py certification tool reads a UK national build only at a
Hugging Face tag. These tests describe the build-folder form (#1762): the
build named by --national-build and --dense-build, refused unless
releases.json at main lists it and has not withdrawn it, pinned at the
commit that published its folder or one the operator names, and handed to
certify-data as its folder's manifest at that commit. They also cover the
kept local-area build, the regional microdata download, the regional
constant rewrite, resume, the changelog fragment, the commit message and
the pull request body.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tools/certify_uk_cut_in_policyengine_py.py read a UK national build only at
a Hugging Face tag and checked build.cut_tag. UK builds have been published
into releases/<release>/<build>/ folders with no tag since #1537, and
policyengine.py refuses a tagged manifest from a repository with
releases.json, so the tool could certify nothing (#1762).

The tool now takes --national-build and --dense-build, refuses a build that
releases.json at main (read afresh) does not list or has withdrawn, pins each
build at the commit that published its folder (the last commit of its
manifest on main) unless --national-data-commit or --dense-data-commit names
another, checks that the manifest there names the build, and hands
certify-data each build's folder manifest at that commit. The kept regional
release is read at the folder and commit the bundle pins, so its model check
and accepted-mismatch audit run again; a kept tagged release in the build
repository is refused. Regional microdata is read from the build's folder at
its commit. The regional constant rewrite moves the local-area build's commit
as well as its name, and leaves the commit to a person, named in the pull
request body, when the previous local-area build shared a commit with a
national build. The changelog fragment, branch, writer check, resume check,
commit message and pull request body name the build.

run_uk_cut.py's closing message and docs/release-contract.md name the new
flag and the build-folder certification.

The test file's other-repository case no longer names the retired UK data
repository, which the live-tree check forbids, and one test name now says
what it checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 1 of #1764 found that a Hub failure while reading releases.json
or asking which commit published a folder ended in a traceback instead of a
refusal, that a commit override was accepted from any Hub ref instead of only
from main's history, and that a resumed worktree was no longer checked
against the commits being certified. These tests describe the refusals. The
shared-commit test now checks the pins handed to the regional constant
rewrite, including the case where the old local-area commit is the new
national commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes from review round 1 of #1764, all rated low:

- A Hub failure while reading releases.json or asking which commit
  published a folder is now a refusal naming the request, not a traceback.
- A --national-data-commit or --dense-data-commit override must be in
  main's history (list_repo_commits at main); a commit on another ref may
  hold an edited copy of the folder.
- A resumed worktree whose modified bundle pins another national commit,
  or routes regions to another local-area build, is refused before anything
  runs (check_resumed_pins).

Also: the pull request body's shared-commit item says the tool left the
local-area commit to a person, which is true in both shared cases; one
helper builds a build's folder manifest path; and docs/release-contract.md
names policyengine.py#759 (merged 2026-11-16), which first pinned the UK
builds by folder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 2 of #1764 found that a Hub failure while downloading the
regional microdata still ended in a traceback, that a resume at another
commit downloaded every regional H5 before it was refused, and that a
malformed releases.json was refused without naming the file. These tests
describe the refusals, and add the missing case of a failing history
listing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes from review round 2 of #1764:

- A Hub failure while downloading the regional manifest or an H5 is a
  refusal naming the file, its revision and its repository (low).
- check_resumed_pins runs as soon as the builds are read, before the
  accepted-mismatch route downloads every regional H5.
- A releases.json refusal that doesn't name the file, such as a parse
  error, is prefixed with releases.json and the repository.
- docs/uk-cut-anyone.md and the changelog fragment say that an override
  must be in main's history and that a resume at other commits is refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 3 of #1764 found that a resume switching from a local-area
build to the drop or area-coded route was not refused, although the first
attempt's constant rewrite had moved the local-area constants, and that
the tool never checked that the policyengine.py base reads build folders
(policyengine.py#683), so an accepted mismatch on such a base downloaded
every regional file and set up a worktree before refusing. These tests
describe both refusals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes from review round 3 of #1764, both rated low:

- The tool refuses a policyengine.py base that cannot read builds in their
  own folders (no read_build_folder, policyengine.py#683) right after
  resolving it, before anything is downloaded or written.
- check_resumed_pins compares the resumed bundle's regional URI with the one
  this run passes to certify-data, or with none on the drop route, so a
  resume that switches from a local-area build to the drop or area-coded
  route is refused too.

Also: the operator guide drops the stale advice to test on a branch until
policyengine.py#699 merged (it merged on 2026-10-27) and states the base
requirement and the resume rule; the changelog fragment says the same; one
constant names .py's bundle manifest path; and a code comment is corrected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anth-volk
anth-volk marked this pull request as ready for review November 26, 2026 17:52
@anth-volk
anth-volk requested a review from juaristi22 November 26, 2026 17:52

@juaristi22 juaristi22 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 586d23a1f. I ran the tool end to end against the Hub for the pair certified by hand in PolicyEngine/policyengine.py#766, from that PR's base (47d1d8bf), without --push and with --skip-tests. It resolved the commits policyengine.py#766 pinned (a80a4bf7… national, 9da09946… local-area), every step it ran passed, and its commit matches policyengine.py#766 in the lock, pyproject.toml, the model surface snapshot, the three constant files and the changelog fragment.

One thing to change before it certifies the next pair: the tool always passes --core-version to certify-data, so its certificate binds core 3.34.10 ("core_binding": "certified"). That is the only difference from policyengine.py#766's bundle manifest, and the TROs differ only through it. policyengine.py has certified the UK with bundle_pin since its 21 October change ("Let a certificate follow the core pin openly, and re-certify UK that way"), and its data-certification.md says to use that default unless a release must not run on any other core. With certified, bundle.py check --strict-tros refuses any later move of the shared core pin, such as one for a US bump, until the UK is re-certified. The line predates this PR, but this PR puts the tool back into use. Passing --core-version to certify-data only when the operator gives one would keep the current binding.

Apart from that, nothing on our side blocks it. A smaller point: the body draft's "How it was made" prints each command with the operator's absolute local paths and the old and new UK bundle records in full (about 17 KB in all), and --open-pr posts it as it is. It also lists two of the rewritten constant files twice.

What I checked

  • The run's UC floor receipt equals the by-hand one up to floating-point rounding.
  • The emitter writes a build folder and its releases.json entry in one commit, and promotion or withdrawal changes only releases.json, so the last commit of a build's manifest on main is the one that published it.
  • All 130 tests in the two changed test files pass locally, CI is green, and the branch merges cleanly with current main.

anth-volk and others added 3 commits November 27, 2026 16:35
María's review of #1764: the tool always passed --core-version to
certify-data, so its certificate named one policyengine-core
(core_binding: certified) and moved the bundle's shared core pin, where
policyengine.py's default certificate follows that pin (bundle_pin). These
tests describe the default, an operator's --core-version, a pull request
body whose commands carry no local paths or bundle records, and a list of
rewritten constant files without repeats.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From María's review of #1764. The tool always passed --core-version to
certify-data, so the certificate named one policyengine-core
(core_binding: certified) and moved the bundle's shared core pin, and a
later move of the pin for another country would have needed a UK
re-certification first. policyengine.py's default, which it has used for the
UK since 21 October, is a certificate that follows the pin (bundle_pin).

- certify-data gets --core-version only when the operator passes one.
- The accepted-mismatch audit installs the core the bundle will serve: the
  operator's, else the bundle's pin, else the build's own.
- The plan and the pull request body say which core the certificate covers
  and how it binds it.
- The body's commands show paths relative to the worktree, ../ beside it
  and ~/ under the home directory, and each JSON object argument (the
  bundle records the constant rewrite is passed) by its size, since
  --open-pr posts the body as it is.
- Each rewritten constant file is listed once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merges main after #1743, which moved tools/run_uk_cut.py onto build-folder
publication. The one conflict was run_uk_cut.py's closing message: it keeps
#1743's build variable and promote command, and replaces #1743's "cannot
certify this build yet" with the certification command for the build,
--national-build <build>. #1743's matching caveats in docs/uk-cut-anyone.md
("Certifying into policyengine.py") and in docs/release-contract.md's list
of leftovers merged without a conflict and are removed, since this branch
certifies build folders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anth-volk
anth-volk merged commit 37575cd into main Nov 27, 2026
11 checks passed
@anth-volk
anth-volk deleted the claude/uk-certification-build-folders branch November 27, 2026 18:15
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.

The policyengine.py certification tool can't certify a UK build published into its own folder

2 participants