Skip to content

Move a dataset repository's tagged builds into build folders and write releases.json in one commit (P3) - #1534

Merged
anth-volk merged 9 commits into
mainfrom
build-folder-switch-tool
Nov 9, 2026
Merged

anth-volk merged 9 commits into
mainfrom
build-folder-switch-tool

Conversation

@anth-volk

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

Copy link
Copy Markdown
Contributor

Closes #1533. This is plan item P3 (tracker 2c · 1): the one-time tool that moves a dataset repository from tags and latest*.json pointer files to build folders and releases.json. Running it on the UK repository is a separate manual step (tracker 2c · 3 and 2c · 4), not part of this PR.

Based on main at f85c46970.

What changes

microcosm.build.build_folder_switch (new)

Run it as uv run python -m microcosm.build.build_folder_switch <step> <owner/repository> [options]. Both steps read the repository and print, as JSON, what they would do; they change nothing without --write.

copy: one commit per build, adding releases/<release>/<build>/.

  • Which builds move.
    • Every tag <release>-<YYYYMMDDTHHMMSSZ>-<8 hex digits> of a release that publishes_to_build_folder names, whose release manifest's build.cut_tag is that tag. Its build is the manifest's build.attempt_id. --exclude TAG leaves one out.
    • Each release-per-build tag that --include TAG=RELEASE names (the June 2023 UK release, or a US release later). Its build is the tag, in RELEASE.
    • Each tag is resolved to its commit with repo_info(revision=<tag>). The Hub lists an annotated tag with the ID of its tag object, not its commit: two UK tags are annotated, microcosm-uk-2024-25-dense-20261026T105309Z-c9df4b86 among them.
  • What the folder holds.
    • The release manifest, rewritten:
      • release and build as strings;
      • the old build object's built_at and built-with packages at the top level;
      • a role on each artifact (release_artifact_role), its bare file name as path, and no revision;
      • migrated_from: the tag, its commit and the original manifest's SHA-256.
      • A field that both the build object and the top level have must be equal, or be two objects that do not disagree on any field; then they become one object. The June 2023 release has a metadata object in both places, with different fields.
    • The build manifest, with release and build and without build_id, attempt_id or cut_tag.
    • The checksum ledger, when the build has one, with the two manifests' lines changed to the rewritten manifests' digests. Every other line must match the tagged commit's file.
    • Every other file the manifest declares, copied from the tagged commit with CommitOperationCopy, so the Hub copies it on its own servers. Each file's SHA-256 at the tag (from the Hub's LFS information, or by reading a small file) must match the manifest.
  • Running it again. A folder that already holds a copy of the same tagged build is skipped, so the step can run again for builds published since. It writes no releases.json, so the repository keeps publishing through its pointer files until the switch.

switch: one commit that writes releases.json and deletes every latest*.json file.

  • The record.
    • It lists every moved build, with its tagged commit's date as published_at.
    • The build each pointer file names becomes its release's current.
    • default is the release of latest-national.json's build, or else of latest.json's; --default overrides it.
    • --current RELEASE=BUILD sets a current build where no pointer file names one.
  • What it refuses.
    • A build whose folder is not a copy of it. A copy holds exactly the build's files, its release manifest names the release, the build and migrated_from, and every declared file at main's head has the SHA-256 it had at the tag. The rewritten bytes are not compared, so a folder copied by an earlier version of the tool still counts.
    • A pointer file whose build does not move, unless --retire-pointer PATH deletes it with nothing in its place. A pointer may name an included build's release by its old name, the tag.
    • A build folder on main that the record would not list.
    • A change to the repository's tags between its first read and its commit (compared by the IDs one listing gives, in one request), and any release-staging/ branch at either time: the tagged publisher keeps one from before it uploads a build until after it tags it. The step runs only while nobody publishes; the remaining gap is a publication that checks for releases.json just before the switch commit and makes its branch after the switch's last read.
    • Any violation of the emitter interface's check_change, check_repository and check_commit. check_commit is given the files that remain once the pointer files are deleted: the emitter's release writer refuses to change current while a pointer file exists, so the tool makes this one commit through its own write path.
  • Both steps:
    • name the head they checked as each commit's parent_commit;
    • refuse a repository that already has releases.json;
    • refuse to run with HF_HUB_OFFLINE or TRANSFORMERS_OFFLINE set;
    • read the token from HF_TOKEN, then HUGGINGFACE_TOKEN, then the saved hf auth login.

Tests and fixture

  • test_support/microcosm_build/build_folder_switch.py holds FakeDatasetRepository, an in-memory fake of the HfApi calls the tool makes. It applies the real huggingface_hub commit operations and refuses a stale parent_commit.
  • uk_repository() lays it out as the UK private repository is before its switch:
    • the June 2023 release that latest.json names, with both metadata objects;
    • two tagged national builds, of which latest-national.json names the older;
    • a tag-only dense build with a checksum ledger and an annotated tag.
  • packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py has 47 tests (38 node IDs). An autouse fixture sets HF_HUB_OFFLINE=1 and fails any test in which the tool builds a Hub client.

Docs

  • README.md: a paragraph on the switch under "Build folders, after a repository's switch".
  • changelog.d/1533-build-folder-switch-tool.added.md.

Checked against the UK repository (read only, nothing written)

I ran both steps without --write against policyengine/populace-uk-private at main 2874b672, with a read-only token, adding --include populace-uk-2023-dd68c73-4aa4b14-20260619T023711Z=populace-uk-2023.

  • copy exits 0:
    • it would copy 18 builds: 12 national, 5 dense, and the June 2023 build;
    • it leaves out populace-uk-2023-72aeefc-20260611, whose manifest has the older format with no build object;
    • it reports no files left behind.
  • switch refuses only with "run the copy step first", once for each of the 18 builds. The record it would write:
    • default: microcosm-uk-2024-25-national;
    • microcosm-uk-2024-25-national: 12 builds, current uk-frs-calibration-attempt-20261025T091414Z-a6299504, the one latest-national.json names;
    • microcosm-uk-2024-25-dense: 5 builds, current null;
    • populace-uk-2023: 1 build, current;
    • deleted: latest-national.json and latest.json.
  • Rewritten manifests. For one national, one dense and the June 2023 build, the loader's _certified_release_from_manifest accepted the rewritten release manifest from its folder. The interface's check_repository found no violations.
  • Two bugs found by these runs, both fixed here with tests that model them:
    • the June 2023 manifest's two metadata objects made the rewrite refuse that build;
    • the annotated dense tag's listed ID is not a commit, so finding its published_at failed.

Red-green

Each run selects the 24 tests by node ID (listed below), with HF_HUB_OFFLINE=1.

  • 5f44b0905 adds the tests and the fake, with the tool as a stub that keeps main and _default_api: 24 failed, every one on an assertion.
  • 768890d09 adds the tool: 24 passed.

Before those commits, the first draft of the tool, which had never been reviewed, failed 7 of the 24 tests that model the real repository; the fixes above are in 768890d09.

Review round 1 (below), selected by node ID the same way:

  • 64e048684 adds 6 tests and parametrizes the offline test over HF_HUB_OFFLINE and TRANSFORMERS_OFFLINE: the 4 tests for the round's bugs failed, each on an assertion; the 4 that cover --default, a conflicting --current and both offline variables passed, since they cover existing behaviour.
  • f4ddb1cf8 fixes the tool: those 8 passed, and all 31 tests from the 30 node IDs pass.

Review round 2 (below), selected by node ID the same way:

  • aa95e92ab adds 7 node IDs (10 tests) and lets the fake list branches: the 2 tests for the staging branch failed, each on an assertion (the switch exited 0); the 8 that cover gaps in round 1's fixes passed.
  • 209203a34 fixes the tool: those 10 passed, and all 44 tests from the 36 node IDs pass.

Review round 3 (below), selected by node ID the same way:

  • dc9cba40a adds a test that no Hub request follows the switch's last listing of the refs, a test that other branches do not refuse the switch, and a moved annotated tag to the moved-tag test, and makes the fake give a moved annotated tag a new tag object ID: the one-request test failed on its assertion (4 repo_info requests followed the listing); the other 6 selected tests passed.
  • c1acc0acd compares the listed tag IDs instead: those 7 passed, and all 47 tests from the 38 node IDs pass.
Node IDs
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_a_failed_copy_commit_names_the_builds_copied_before_it
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_a_tag_whose_manifest_names_another_tag_moves_only_when_excluded
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_an_annotated_tag_moves_from_the_commit_it_names
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_copied_manifests_name_the_release_and_the_build
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_copy_again_skips_the_builds_already_in_their_folders
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_copy_keeps_both_metadata_objects_of_the_june_2023_build
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_copy_refuses_a_build_whose_file_does_not_match_its_manifest
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_copy_refuses_a_release_role_conflict_before_any_commit
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_copy_refuses_build_metadata_that_disagrees_with_the_release
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_copy_reports_a_release_name_the_interface_refuses_without_writing
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_copy_reports_a_release_role_conflict_without_writing
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_copy_rewrites_the_checksum_ledger_for_the_rewritten_manifests
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_copy_without_write_lists_each_tagged_build_and_changes_nothing
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_copy_writes_each_build_into_its_folder_copying_its_tagged_files
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_each_step_refuses_a_repository_that_has_releases_json[copy]
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_each_step_refuses_a_repository_that_has_releases_json[switch]
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_switch_can_choose_the_default_release
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_switch_can_retire_a_pointer_file_and_make_a_named_build_current
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_switch_ignores_branches_that_are_not_the_tagged_publishers
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_switch_refuses_a_build_folder_that_it_does_not_list
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_switch_refuses_a_copied_build_folder_holding_another_file
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_switch_refuses_a_copied_build_whose_file_changed_since
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_switch_refuses_a_current_build_that_conflicts_with_a_pointer_file
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_switch_refuses_a_folder_copied_earlier_and_left_out_with_exclude
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_switch_refuses_a_pointer_file_whose_build_does_not_move
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_switch_refuses_until_every_build_is_in_its_folder
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_switch_refuses_when_a_tag_appears_while_it_reads
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_switch_refuses_when_a_tag_is_deleted_or_moved_while_it_reads
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_switch_refuses_when_a_tagged_publication_starts_while_it_reads
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_switch_refuses_while_a_tagged_publication_is_in_progress
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_switch_takes_a_pointer_naming_an_included_build_by_its_tag
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_switch_without_write_prints_the_record_and_changes_nothing
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_switch_writes_releases_json_and_deletes_the_pointer_files_in_one_commit
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_the_loader_certifies_a_copied_build_from_its_folder
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_the_switch_reads_tags_and_branches_again_in_one_request
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_the_switched_repository_passes_the_interface_checks_and_the_reader
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_the_tool_finds_build_folders_by_the_interfaces_rule
packages/microcosm-build/tests/engine_free/uk/test_build_folder_switch.py::test_the_tool_refuses_to_run_offline

Review round 1

A fresh read-only review of 768890d09 found four bugs:

  1. The copy step checked the emitter interface's rules only with --write, inside its commit loop and against a record holding one build. A read-only run passed a release name or role the interface refuses, and a run with --write committed earlier builds first, then refused or, for an unsafe name, ended in a traceback. It now builds the record of every moving build and runs the interface's checks on it and on each copy commit before its read-only return, so both are reported problems and nothing is written. Fixed in f4ddb1cf8.
  2. The switch ignored build folders that an earlier copy run wrote for builds this run does not move, so its record could leave a folder on main that no writer could list or remove later. It now refuses any build folder its record would not list. Fixed in f4ddb1cf8.
  3. The switch deletes latest.json, which the ("uk", 2023) registry entry follows. The June 2023 build moves into release populace-uk-2023; After the UK switch, publish UK national, dense and local-area builds only through the emitter #1537 gives that entry release="populace-uk-2023", and the loader then reads it from releases.json after the switch and follows latest.json until then. Not changed here.
  4. A tag created while the switch reads the builds was not noticed: a tagged publication tags before it commits to main, and a tag-only one never commits to main, so parent_commit still matched and the record left that build out. The switch now reads the tags again just before its commit and refuses if they changed. The step also runs only with nobody publishing. Fixed in f4ddb1cf8.

Also from the round: the copy_builds and _folder_state docstrings, the README paragraph and the changelog fragment now say what the code does (including TRANSFORMERS_OFFLINE), and _survey no longer lists SwitchRefusedError beside ValueError. Not done: a Protocol for the seven HfApi methods (no type checker runs in CI), and one commit-history listing per step instead of one per tag (a one-time run over about 19 tags).

Review round 2

A fresh read-only review of f4ddb1cf8 found round 1's fixes correct, and refusing no correct copy or switch of the UK repository, and one more bug:

  1. A tagged publication still in progress when the switch commits was missed. The tagged publisher checks for releases.json only when it starts, then uploads on a release-staging/<release> branch and tags the build; a tag created after the switch's second tag listing left that build in neither the record nor a folder. The switch now reads the staging branches with the tags, in one listing, at its first read and just before its commit, and refuses while any exists (a branch left by a failed publication must be deleted first). Fixed in 209203a34; the saved UK inventory has no branch other than main.

Also from the round, in 73415b30d: the module docstring and README say to run the switch step only while nobody publishes; the README's switch synopsis gains --exclude; and the docstring, README and changelog say that the Hub copies LFS files on its own servers, while huggingface_hub downloads a small regular file and sends it in the commit. New tests in aa95e92ab cover a tag deleted or moved while the switch reads, a folder copied earlier and left out with --exclude, a role conflict in a read-only copy, and the tool's build-folder rule against the interface's.

Review round 3

A fresh read-only review of 73415b30d found no bugs. It found round 2's fix correct against the tagged publisher's order (branch, upload, tag, then delete the branch, so any one listing from the branch's creation on shows the branch, the tag or both), refusing no correct switch of the UK repository, and checked again that the loader, the dashboard, .py and the emitter's release writer accept the switched repository. Of its two code-quality points:

  • The last read resolved every tag with its own request after the listing, so the window before the commit was longer than the docs said, and a tag deleted inside it ended the step in a traceback. Since c1acc0acd the switch compares the IDs the listing gives with those its survey listed, in one request.
  • The staging-branch tests used only release-staging/ branches. dc9cba40a adds a test that other branches, including release-staging-notes, do not refuse the switch.

Not in this PR

  • Running the copy and the switch on the UK repository (tracker 2c · 3 and 2c · 4).
  • The June 2023 release and the dense release at the switch, decided for tracker 2c · 4: the June 2023 build moves with --include …=populace-uk-2023, and --current makes the newest dense build current.
  • The US switch (tracker 2c · 7), which waits for the agreement on the US stable releases.

🤖 Generated with Claude Code

anth-volk and others added 2 commits November 6, 2026 20:59
…1533)

The tests run the tool's copy and switch steps against a fake of the
Hugging Face calls, laid out as the UK private repository is before its
switch: a June 2023 release-per-build release that latest.json names, with
a metadata object both at its top level and in its build object; two
tagged national builds; and a tag-only dense build with a checksum ledger,
whose tag is annotated, so the Hub lists its tag object's ID. The tool is
a stub here, so every test fails on its assertions; the next commit adds
it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`python -m microcosm.build.build_folder_switch` is the one-time switch from
tags and latest*.json pointer files to build folders and releases.json.

- `copy` adds each tagged build's folder, releases/<release>/<build>/, in
  one commit per build: the two manifests rewritten in the build-folder
  layout with `migrated_from` naming the tag, its commit and the original
  manifest's SHA-256, the checksum ledger rewritten to match, and every
  other declared file copied from the tagged commit on the Hub's servers
  after its SHA-256 is checked. A field the build object and the top level
  both have becomes one object when they do not disagree, as the June 2023
  UK release's two metadata objects do. Each tag is resolved to its
  commit, since the Hub lists an annotated tag with its tag object's ID.
- `switch` writes releases.json and deletes every pointer file in one
  commit. Each build keeps its tagged commit's date as published_at, each
  pointer file's build becomes current, and default is the release of
  latest-national.json's build, else latest.json's. It refuses unless each
  folder holds exactly its copied files with the SHA-256 values the tag
  recorded, every pointer file is accounted for, and the emitter
  interface's checks pass.

Both steps only read and report without --write, refuse to run offline,
and commit with the head they checked as the parent commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk and others added 7 commits November 6, 2026 23:14
The copy step must report a release name or role the emitter interface
refuses in its read-only run and refuse it before any commit. The switch
must refuse a build folder on main that its record would not list, and a
tag that appears while it reads the builds. Also cover --default, a
--current that conflicts with a pointer file, and TRANSFORMERS_OFFLINE.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tags (#1533)

From review round 1. The copy step now builds the record its moving builds
make and runs the emitter interface's checks on it and on each copy commit
in its read-only run, so a release name or role the interface refuses is a
reported problem before any folder is written, instead of a refusal or a
traceback after earlier builds were committed. The switch refuses a build
folder on main that its record would not list, and reads the tags again
just before its commit, refusing if they changed, since a tag-only
publication never moves main and parent_commit would not notice it.

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

The tagged publisher checks for releases.json only when it starts, then keeps
a release-staging/<release> branch from before its upload until after it
tags the build. A switch committed in that time would leave the build in
neither the record nor a folder, so the switch must refuse while such a
branch exists, at its first read and just before its commit. The fake
repository lists branches as the Hub does.

The other new tests pass already: the second tag listing also refuses a
deleted or moved tag, the unlisted-folder refusal also covers a tag copied
earlier and left out with --exclude, a read-only copy reports a release role
conflict, and the tool's build-folder rule matches the interface's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The switch now reads the tagged publisher's release-staging/ branches with
the tags, in one listing, both at its first read and just before its commit,
and refuses while any exists: a publication that has checked for
releases.json but not yet tagged its build would otherwise land in neither
the record nor a folder. A branch left by a failed publication must be
deleted first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The module docstring and README now say to run the switch step only while
nobody publishes, and why the staging-branch check leaves a small gap. The
README's synopsis of the switch step gains --exclude, which it needs whenever
the copy step used it. The docstring, README and changelog say that the Hub
copies LFS files on its own servers, while huggingface_hub downloads a small
regular file and sends it in the commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Just before its commit, the switch lists the refs and then resolved each tag
with a request of its own, so a tag made or deleted between those requests
could escape the comparison, and one deleted there ended the step in a
traceback. The new test fails while any request follows that listing. A tag
the Hub lists as annotated gets a new tag object ID when it moves, as git's
does, which the fake now models; the moved-tag test covers a lightweight and
an annotated tag. Another test checks that branches other than the tagged
publisher's release-staging/ ones do not refuse the switch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The switch's survey keeps the ID the Hub lists for each tag beside the
commit it resolves to, and just before its commit it compares a fresh
listing's IDs with those, in one request, instead of resolving every tag
again. A tag that moves gets another listed ID, an annotated one through its
new tag object, so the comparison still sees it, and nothing between the
listing and the commit can now fail on a deleted tag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anth-volk
anth-volk marked this pull request as ready for review November 9, 2026 13:41
@anth-volk
anth-volk merged commit bcef7c7 into main Nov 9, 2026
11 checks passed
@anth-volk
anth-volk deleted the build-folder-switch-tool branch November 9, 2026 13:41
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.

A one-time tool that moves a dataset repository's tagged builds into build folders and writes releases.json

1 participant