Repository navigation
Certify a UK build from its own folder in the policyengine.py certification tool - #1764
Conversation
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>
juaristi22
left a comment
There was a problem hiding this comment.
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.jsonentry in one commit, and promotion or withdrawal changes onlyreleases.json, so the last commit of a build's manifest onmainis 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.
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>
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.pyread a UK national build's manifest only at a Hugging Face tag (--national-tag) and checkedbuild.cut_tag. Since #1537 (2026-11-09), UK builds are published intoreleases/<release>/<build>/folders listed inreleases.json, with no tag. The tool reachedmainthrough #1405, whose branch never contained #1537, and it hasn't been run since.policyengine/populace-uk-privatehasreleases.jsonatmain. 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 hasreleases.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)--national-build BUILD(required) and the regional route--dense-build BUILDreplace--national-tagand--dense-tag. Tags are no longer accepted. A name must match the emitter's folder-name rule.--base-ref, the tool refuses a base that cannot read builds in their own folders (noread_build_folder, policyengine.py#683), before anything is downloaded or written.releases.json: the tool downloads it afresh frommainand refuses a build it doesn't list or has withdrawn, throughmicrocosm.data.build_folder_manifests.require_offered_build. These are the same checks as policyengine.py'scertify-data, run before anything is written. A build doesn't have to be current, since a certificate pins one build.release_manifest.jsononmain, from the Hub's paths-info, because a build folder never changes.--national-data-commitor--dense-data-commitpins another commit instead. It must be a full 40-character commit inmain's history, because a commit on another ref may hold an edited copy of the folder, and--dense-data-commitgoes only with--dense-build.releases.json, asking which commit published a folder, listingmain's history, reading a manifest or downloading a regional file is a refusal (REFUSED: …, exit 2) that names the request.built_with_model_packageandbuilt_with_core_packageat 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.policyengine-corepin (core_binding: bundle_pin), .py's default.certify-datagets--core-versiononly 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.UK_LOCAL_AREA_RELEASE_REVISION.Names in the policyengine.py handoff
certify-uk-<build>.changed.md, the name policyengine.py#766 used.certify-uk-<last 8 hex digits>, and the writer check looks for that marker or the build's name.release_manifest_pathwith 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 tocertify-data(none on the drop route). The first attempt's constant rewrite already moved the constants to its own builds.../beside it,~/under the home directory), and each JSON object argument by its size. So--open-prposts 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.mdrecords 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.d/1762-uk-certification-tool-build-folders.fixed.md.Decisions (Anthony, 2026-11-26)
--national-data-commitor--dense-data-commit.run_uk_cut.py's message anddocs/release-contract.mdas they are onmain, 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
main(d2c1ca466) is merged into this branch at3f538dd2f, with a merge commit.run_uk_cut.py's closing message. It keeps Publish run_uk_cut.py builds through the emitter and refuse new direct Hugging Face imports #1743'sbuildvariable and promote command, and prints the certification command for the build,--national-build {build}, in place of Publish run_uk_cut.py builds through the emitter and refuse new direct Hugging Face imports #1743's "cannot certify this build yet".docs/uk-cut-anyone.mdand indocs/release-contract.md's list of leftovers merged without a conflict. They are removed, since this branch certifies build folders.main:require_offered_build,releases_record, and thehuggingface_hubimport rule, which already lists this tool.docs/uk-cut-anyone.md. Whichever merges second resolves that.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.pyand.../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.76864f111(tests only)--national-build(SystemExit), the missingPublishedBuild,read_published_build,BuildPinandhub_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)ruff format,ruff check) passes on the changed files, and--helpruns.beeee7b72(round 1 tests)test_an_operators_commit_must_be_in_mains_history(DID NOT RAISE), both cases oftest_a_hub_failure_is_a_refusal(the Hub'sRuntimeErrorescaped),test_a_resumed_worktree_must_certify_the_same_commits(nocheck_resumed_pins) andRunnerTests::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)--helpruns.7b7c0f89e(round 2 tests)test_a_failing_regional_download_is_a_refusal(the Hub'sRuntimeErrorescaped),test_an_unreadable_releases_record_is_named_in_the_refusal(the pattern didn't match) andRunnerTests::test_a_resume_at_another_commit_refuses_before_any_download(the regional files were fetched first).test_a_failing_history_listing_is_a_refusalpasses at red, because it covers round 1's fix.af3a1b574(round 2 fixes)--helpruns.2fc1ab9d0(round 3 tests)test_the_build_folder_support_check_reads_the_base(nobuild_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) andRunnerTests::test_a_resume_that_stops_routing_regions_refuses(CertifyError not raised).586d23a1f(round 3 fixes)--helpruns.091e76263(tests for María's review)test_a_command_is_shown_without_local_paths_or_recordsandtest_the_pr_body_shows_each_command_without_local_paths_or_records(nopublic_commandorpublic_commands),RunnerTests::test_certify_data_follows_the_bundles_core_pin_by_default(--core-versionpassed),RunnerTests::test_an_operators_core_version_binds_the_certificate(no binding in the body) andRunnerTests::test_each_rewritten_constant_file_is_listed_once(files repeated).f32bc3382(fix)--helpruns.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
maingivesa80a4bf7…for national builduk-frs-calibration-attempt-20261122T100732Z-b891aa69and9da09946…for local-area builduk-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_TOKENorHF_TOKENfor the Hub, andgh'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):Code quality fixed:
Left as found:
run_uk_cut.py's closing message still prints the tagged promote command, and the Hub client is typedAny. 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:
releases.jsonis named in the refusal;main-history rule and the resume refusal;Left as found: on the keep route, a resume after a first attempt with
--drop-regional-releaseis 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):Also fixed:
Left as found:
--model-version, which predates this PR;releases.jsonprefix 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):091e76263/f32bc3382: the certificate now follows the bundle's core pin unless--core-versionis given.No bugs are known to remain.
🤖 Generated with Claude Code