From 193e262fa66b512dc11a5759cf36d3c5f929e0b5 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Fri, 13 Nov 2026 01:00:18 +0400 Subject: [PATCH 1/9] Test collector submissions at staging and at release MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Failing tests for 3a · 2 (builds switch collector submissions on and submit calibration diagnostics at staging and at release): - builds refuse an emitter older than 0.15.0, and the Modal image installs at least 0.15.0; - a build's emitter and the short-lived bundle emitter switch the Hugging Face module's collector submissions on, and a loopback collector given for telemetry also takes the submissions; - a staged bundle that names its build waits, after its commit, until the collector accepts its submissions or the first attempt after the commit fails, at most ten minutes; skipped, rejected and failed receipts and submissions still pending are warnings; a bundle that has not landed is asked about once; a bundle without provenance is never asked about; a resumed hand-over that landed waits too; - a release publication names its build for the collector (UK builds licensed, US builds not), waits for the collector after it lands, and prints the collector's status; refused collector settings are a warning and the publication still succeeds; - the installed-emitter fixture records each start's module settings and sends collector submissions to a closed loopback port. The interface pin and lock move to 0.15.0 here, with APPROVED_UV_LOCK_SHA256 re-pinned, so the tests can name the new settings. The source modules gain only unused keywords, fields and a stub `collector_provenance` returning None, so the tests fail on their assertions: 45 cases fail, all with AssertionError. The 9 that pass are the version parametrizations that 0.14.0 and 0.15.0 both satisfy, the country-code lockstep check, a tagged release naming no build, and an emitter without its Hugging Face module. Co-Authored-By: Claude Opus 5.5 --- packages/microcosm-build/pyproject.toml | 2 +- .../microcosm/build/release_publication.py | 17 +- .../src/microcosm/build/staging_dataset.py | 4 + .../src/microcosm/build/telemetry_emitter.py | 4 +- .../build/us_runtime/worker_identity.py | 2 +- .../shared/test_emitter_adapter.py | 75 +++++- .../shared/test_staging_dataset.py | 249 ++++++++++++++++++ .../uk/test_uk_release_publication.py | 184 +++++++++++++ .../us/test_us_modal_stage_plan_tool.py | 2 +- .../us/test_us_release_publication.py | 45 ++++ .../shared/test_installed_emitter_staging.py | 47 +++- test_support/microcosm_build/emitter.py | 40 ++- .../us_modal_stage_plan_tool.py | 2 +- uv.lock | 8 +- 14 files changed, 653 insertions(+), 28 deletions(-) diff --git a/packages/microcosm-build/pyproject.toml b/packages/microcosm-build/pyproject.toml index 6d24e1ffb6..55dd373a18 100644 --- a/packages/microcosm-build/pyproject.toml +++ b/packages/microcosm-build/pyproject.toml @@ -29,7 +29,7 @@ dependencies = [ # microcosm-emitter`) and started as the build's child process, so an # emitter release needs no change here. The socket protocol carries its # own version, and every emitter release accepts the versions in use. - "microcosm-emitter-interface>=0.14.0,<1", + "microcosm-emitter-interface>=0.15.0,<1", ] [project.optional-dependencies] diff --git a/packages/microcosm-build/src/microcosm/build/release_publication.py b/packages/microcosm-build/src/microcosm/build/release_publication.py index 81b0f86b1b..447732bfb0 100644 --- a/packages/microcosm-build/src/microcosm/build/release_publication.py +++ b/packages/microcosm-build/src/microcosm/build/release_publication.py @@ -45,6 +45,7 @@ import json import os import sys +import time from collections.abc import Mapping from dataclasses import dataclass from pathlib import Path @@ -58,7 +59,11 @@ ) from microcosm_emitter_interface.releases import is_pointer_file -from microcosm.build.staging_dataset import hub_offline, write_access_problem +from microcosm.build.staging_dataset import ( + RECEIPT_POLL_SECONDS, # noqa: F401 (used by the change) + hub_offline, + write_access_problem, +) from microcosm.build.telemetry_emitter import start_bundle_emitter from microcosm.data.contract import publishes_to_build_folder from microcosm.data.publish_cli import publication_refusal @@ -157,6 +162,14 @@ def close(self) -> None: ... #: Starts the short-lived emitter a publication uses (only its Hugging Face #: module); tests replace it. _start_release_emitter = start_bundle_emitter +_clock = time.monotonic +_sleep = time.sleep +UK_COLLECTOR_COUNTRY_CODE = "UK" +US_COLLECTOR_COUNTRY_CODE = "US" + + +def collector_provenance(release: str, build: str) -> Any: + return None @dataclass(frozen=True) @@ -175,6 +188,7 @@ class ReleasePublication: wanted_current: bool receipt: ReleaseReceipt problem: str | None = None + collector_receipt: Any = None @property def published(self) -> bool: @@ -234,6 +248,7 @@ def as_json(self) -> dict[str, Any]: "message": self.receipt.get("message"), "commit": self.receipt.get("commit"), "handover_id": self.receipt.get("handover_id"), + "collector_submission": None, } diff --git a/packages/microcosm-build/src/microcosm/build/staging_dataset.py b/packages/microcosm-build/src/microcosm/build/staging_dataset.py index 6ddd39c79d..a33ea7fe9b 100644 --- a/packages/microcosm-build/src/microcosm/build/staging_dataset.py +++ b/packages/microcosm-build/src/microcosm/build/staging_dataset.py @@ -119,6 +119,7 @@ RESTAGE_WAIT_SECONDS = 10800.0 #: How often the build asks the emitter for the bundle's receipt meanwhile. RECEIPT_POLL_SECONDS = 1.0 +COLLECTOR_SUBMISSION_WAIT_SECONDS = 600.0 _MODES = ("local_and_remote", "local_only", "disabled") _STATUSES = ("uploaded", "already_staged", "failed", "skipped") @@ -823,6 +824,7 @@ class StagedBundleHandOver: handover_id: str | None = None #: The run directory the hand-over names its files in. run_dir: str | None = None + collector_receipt: Any = None def may_rewrite(self, name: str) -> bool: """Whether the build may change ``name`` in the run directory now.""" @@ -1140,6 +1142,7 @@ def stage_bundle( sleep: Callable[[float], None] = time.sleep, earlier_files: Mapping[str, Any] | None = None, collector: CollectorProvenance | None = None, + collector_wait_seconds: float = COLLECTOR_SUBMISSION_WAIT_SECONDS, ) -> StagedBundleHandOver: """Hand the bundle and its sidecars to the emitter; record, never raise. @@ -1273,6 +1276,7 @@ def resume_hand_over( poll_seconds: float = RECEIPT_POLL_SECONDS, clock: Callable[[], float] = time.monotonic, sleep: Callable[[float], None] = time.sleep, + collector_wait_seconds: float = COLLECTOR_SUBMISSION_WAIT_SECONDS, ) -> StagedBundleHandOver | None: """Record the outcome of an earlier hand-over the emitter still holds. diff --git a/packages/microcosm-build/src/microcosm/build/telemetry_emitter.py b/packages/microcosm-build/src/microcosm/build/telemetry_emitter.py index 80a6a30f99..5ea5a52b52 100644 --- a/packages/microcosm-build/src/microcosm/build/telemetry_emitter.py +++ b/packages/microcosm-build/src/microcosm/build/telemetry_emitter.py @@ -902,7 +902,9 @@ def _orrery_emitter() -> EmitterClient: ) -def start_bundle_emitter() -> EmitterClient: +def start_bundle_emitter( + *, development_collector_url: str | None = None +) -> EmitterClient: """A short-lived emitter with only the Hugging Face module. A command that stages a finished run's bundle, outside any build, uses diff --git a/packages/microcosm-build/src/microcosm/build/us_runtime/worker_identity.py b/packages/microcosm-build/src/microcosm/build/us_runtime/worker_identity.py index 601a5a0546..6bc0483bad 100644 --- a/packages/microcosm-build/src/microcosm/build/us_runtime/worker_identity.py +++ b/packages/microcosm-build/src/microcosm/build/us_runtime/worker_identity.py @@ -28,7 +28,7 @@ PRIMARY_QRF_WORKER_MODULE = "microcosm.build.us_runtime.puf_qrf_worker" PRIMARY_QRF_INTERPRETER_PLACEHOLDER = "{python_interpreter}" APPROVED_UV_LOCK_SHA256 = ( - "9fcbf2df841c4f18ca1023b5571cad3da85d095f32ecca3477ad0287ed02fa80" + "a742bcdc1117f17b0f42f06a3302a200e6beac54beb491364f50e6b63523dac3" ) LEGACY_CAMPAIGN_UV_LOCK_SHA256 = ( "27f47e385cfa35e2644a37410d1804b361ad9aee123577551c8421547bda65ee" diff --git a/packages/microcosm-build/tests/engine_free/shared/test_emitter_adapter.py b/packages/microcosm-build/tests/engine_free/shared/test_emitter_adapter.py index 0c065f97b2..ae2e53efb5 100644 --- a/packages/microcosm-build/tests/engine_free/shared/test_emitter_adapter.py +++ b/packages/microcosm-build/tests/engine_free/shared/test_emitter_adapter.py @@ -85,9 +85,12 @@ def test_starts_one_emitter_with_telemetry_graph_and_hugging_face_modules( assert options["orrery"].development_collector_url is None hugging_face = options["hugging_face"] assert isinstance(hugging_face, HuggingFaceSettings) - # The hand-over tables stay in their own SQLite file beside the spool. + # The hand-over tables stay in their own SQLite file beside the spool, + # and the build switches the emitter's collector submissions on, with + # the production collector. assert hugging_face.configuration(path) == { - "handover_database_path": str(tmp_path / "jobs.handovers.sqlite3") + "handover_database_path": str(tmp_path / "jobs.handovers.sqlite3"), + "collector_submissions": True, } assert emitter.client is client assert emitter.run is telemetry.run @@ -97,6 +100,55 @@ def test_starts_one_emitter_with_telemetry_graph_and_hugging_face_modules( assert not path.exists() +def test_a_development_collector_receives_every_modules_requests(monkeypatch, tmp_path): + """A loopback collector given for telemetry takes the submissions too.""" + starts = _record_starts(monkeypatch) + monkeypatch.setattr(adapter, "runtime_identity", lambda: {"commit": "synthetic"}) + collector = "http://127.0.0.1:9" + + START( + adapter.LocalTelemetryEmitter, + run_id="run-one", + country_code="uk", + pipeline="full", + spool_path=tmp_path / "events.sqlite3", + development_collector_url=collector, + ) + + (options,) = starts + assert options["telemetry"].development_collector_url == collector + assert options["orrery"].development_collector_url == collector + assert options["hugging_face"] == HuggingFaceSettings( + collector_submissions=True, development_collector_url=collector + ) + + +@pytest.mark.parametrize( + "development_collector_url", + [None, "http://127.0.0.1:9"], + ids=["production", "loopback"], +) +def test_the_short_lived_bundle_emitter_switches_collector_submissions_on( + monkeypatch, development_collector_url +): + """The re-stage and release commands' emitter submits as a build's does.""" + starts = _record_starts(monkeypatch) + options = ( + {} + if development_collector_url is None + else {"development_collector_url": development_collector_url} + ) + + adapter.start_bundle_emitter(**options) + + (started,) = starts + assert set(started) == {"hugging_face", "startup_timeout"} + assert started["hugging_face"] == HuggingFaceSettings( + collector_submissions=True, + development_collector_url=development_collector_url, + ) + + def test_telemetry_requests_reach_the_interface_with_their_fields(): client = FakeEmitterClient() emitter = adapter.LocalTelemetryEmitter( @@ -274,8 +326,12 @@ def _start_build_emitter(monkeypatch, tmp_path): @pytest.mark.parametrize( ("version_answer", "reported"), [ - # The release just before the minimum, 0.14.0, without heartbeat - # readings, sleeps or stage spans. + # The minimum until 2026-11-13 and the release just before 0.15.0, + # without the setting that switches collector submissions on, + # collector provenance on a release publication, or skipped + # collector receipts. + (_version_answer("0.14.0"), "reports version 0.14.0"), + # Without heartbeat readings, sleeps or stage spans, which 0.14.0 added. (_version_answer("0.13.0"), "reports version 0.13.0"), # The minimum until 2026-11-09. (_version_answer("0.12.5"), "reports version 0.12.5"), @@ -293,6 +349,7 @@ def _start_build_emitter(monkeypatch, tmp_path): ("not JSON", "reports no version"), ], ids=[ + "0.14.0", "0.13.0", "0.12.5", "0.11.9", @@ -322,7 +379,7 @@ def test_an_emitter_older_than_the_minimum_is_never_started_and_the_build_contin assert not emitter.available warning = capsys.readouterr().err assert f"The installed microcosm-emitter {reported};" in warning - assert "this build needs 0.14.0 or later" in warning + assert "this build needs 0.15.0 or later" in warning # The warning says what the build loses without the emitter, including # the one option that then fails the build. assert ( @@ -330,7 +387,7 @@ def test_an_emitter_older_than_the_minimum_is_never_started_and_the_build_contin "and queues no Orrery graph publication; a UK build given " "--staging-read-back will fail at the read-back." in warning ) - assert "uv tool install --upgrade 'microcosm-emitter>=0.14.0'" in warning + assert "uv tool install --upgrade 'microcosm-emitter>=0.15.0'" in warning # It also says that a remote stage of the dataset bundle is refused, so # the pre-flight's later refusal does not contradict it. assert "will continue without it" not in warning @@ -355,8 +412,8 @@ def test_the_fake_client_reports_a_release_builds_start(): @pytest.mark.parametrize( "installed_version", # Compared by number, not as text: as text, 0.9.0, which is refused, - # sorts after 0.14.0. - ["0.14.0", "0.14.10", "0.15.0", "1.0.0"], + # sorts after 0.15.0. + ["0.15.0", "0.15.10", "0.16.0", "1.0.0"], ) def test_an_emitter_from_the_minimum_on_starts( monkeypatch, capsys, tmp_path, installed_version @@ -395,7 +452,7 @@ def test_a_short_lived_graph_emitter_older_than_the_minimum_is_never_started( assert starts == [] assert not started.exists() assert client.calls == [] - assert "this build needs 0.14.0 or later" in capsys.readouterr().err + assert "this build needs 0.15.0 or later" in capsys.readouterr().err @pytest.mark.parametrize("failure", ["default_spool_path", "runtime_identity"]) diff --git a/packages/microcosm-build/tests/engine_free/shared/test_staging_dataset.py b/packages/microcosm-build/tests/engine_free/shared/test_staging_dataset.py index ee2654b241..feff28fd03 100644 --- a/packages/microcosm-build/tests/engine_free/shared/test_staging_dataset.py +++ b/packages/microcosm-build/tests/engine_free/shared/test_staging_dataset.py @@ -8,6 +8,7 @@ from types import SimpleNamespace import pytest +from microcosm_emitter_interface import CollectorProvenance from microcosm.build import staging_dataset from microcosm.build.staging_dataset import ( @@ -31,6 +32,13 @@ RUN_ID = "uk-local-candidate-f100-s7-20260917T180000Z-0badcafe" REPOSITORY = "policyengine/populace-uk-private" DATASET = "microcosm_uk_2025_local.h5" +#: The build a described bundle names for the collector. +PROVENANCE = CollectorProvenance( + country_code="UK", + build_id=RUN_ID, + licensed_data=True, + release="microcosm-uk-2024-25-national", +) def _sha(data: bytes) -> str: @@ -583,6 +591,247 @@ def test_the_build_may_rewrite_only_the_files_the_emitter_copied(tmp_path): assert local.may_rewrite(MANIFEST) and local.may_rewrite(SHA256SUMS_FILENAME) +def test_a_described_bundle_waits_until_the_collector_accepts_its_submissions( + tmp_path, capsys +): + """The emitter submits after the bundle's commit; the build waits for the + collector to accept them, so an emitter closed straight afterwards has + sent them.""" + bundle = _bundle(tmp_path) + emitter = FakeEmitterClient( + hub_api=FakeHub(tmp_path), + collector_receipts=[ + { + "status": "pending", + "error_code": "WAITING_FOR_HUGGING_FACE", + "attempts": 2, + }, + # An attempt that began before the commit landed. + { + "status": "pending", + "error_code": "WAITING_FOR_HUGGING_FACE", + "attempts": 3, + }, + {"status": "awaiting_final_status", "attempts": 4}, + ], + ) + clock = Clock() + + staged = staging_dataset.stage_bundle( + bundle, + emitter=emitter, + repository=REPOSITORY, + clock=clock, + sleep=clock.sleep, + collector=PROVENANCE, + ) + + (request,) = emitter.bundle_requests + assert request.collector == PROVENANCE + assert staged.delivery["status"] == "uploaded" + assert emitter.collector_receipt_requests == [request.handover_id()] * 3 + assert clock.slept == [staging_dataset.RECEIPT_POLL_SECONDS] * 2 + assert staged.collector_receipt is not None + assert staged.collector_receipt["status"] == "awaiting_final_status" + assert "warning" not in capsys.readouterr().err + + +def test_the_first_failed_attempt_after_the_commit_ends_the_wait(tmp_path, capsys): + bundle = _bundle(tmp_path) + emitter = FakeEmitterClient( + hub_api=FakeHub(tmp_path), + collector_receipts=[ + { + "status": "pending", + "error_code": "WAITING_FOR_HUGGING_FACE", + "attempts": 1, + }, + {"status": "pending", "error_code": "COLLECTOR_UNAVAILABLE", "attempts": 2}, + ], + ) + clock = Clock() + + staged = staging_dataset.stage_bundle( + bundle, + emitter=emitter, + repository=REPOSITORY, + clock=clock, + sleep=clock.sleep, + collector=PROVENANCE, + ) + + assert len(emitter.collector_receipt_requests) == 2 + assert clock.slept == [staging_dataset.RECEIPT_POLL_SECONDS] + assert staged.collector_receipt["error_code"] == "COLLECTOR_UNAVAILABLE" + assert ( + f"warning: the collector had not accepted the submissions of the staged " + f"dataset bundle staged/{RUN_ID} when the build stopped waiting " + "(COLLECTOR_UNAVAILABLE); the emitter keeps them queued, and it or the " + "next emitter started on this machine sends them." in capsys.readouterr().err + ) + + +@pytest.mark.parametrize( + ("code", "explanation"), + [ + ( + "COLLECTOR_SETTINGS_REFUSED", + "the emitter refused its collector settings or the collector-token " + "variables it inherits", + ), + ( + "COLLECTOR_FOLDER_TOO_LONG", + "its Hugging Face folder is longer than the collector accepts", + ), + ("NOT_STAGED_ON_HUGGING_FACE", "Hugging Face refused it"), + ("A_CODE_FROM_A_LATER_EMITTER", "the emitter skipped them"), + ], +) +def test_a_skipped_collector_receipt_is_a_warning_and_the_bundle_stays_staged( + tmp_path, capsys, code, explanation +): + bundle = _bundle(tmp_path) + emitter = FakeEmitterClient( + hub_api=FakeHub(tmp_path), + collector_receipts=[{"status": "skipped", "error_code": code}], + ) + + staged = _stage(bundle, emitter, collector=PROVENANCE) + + assert staged.delivery["status"] == "uploaded" + # A skipped receipt is final: the build asks once. + assert len(emitter.collector_receipt_requests) == 1 + assert staged.collector_receipt["status"] == "skipped" + warning = capsys.readouterr().err + assert ( + f"warning: the collector receives nothing of the staged dataset bundle " + f"staged/{RUN_ID}: {explanation} ({code})." in warning + ) + + +def test_submissions_not_accepted_when_the_wait_ends_stay_queued(tmp_path, capsys): + """A submission that waited for a long upload retries at most five + minutes apart, so the build waits ten minutes for its next attempt.""" + bundle = _bundle(tmp_path) + emitter = FakeEmitterClient( + hub_api=FakeHub(tmp_path), + collector_receipts=[ + {"status": "pending", "error_code": "COLLECTOR_UNAVAILABLE"} + ], + ) + clock = Clock() + + staged = staging_dataset.stage_bundle( + bundle, + emitter=emitter, + repository=REPOSITORY, + clock=clock, + sleep=clock.sleep, + collector=PROVENANCE, + ) + + assert staged.delivery["status"] == "uploaded" + assert staging_dataset.COLLECTOR_SUBMISSION_WAIT_SECONDS == 600 + assert sum(clock.slept) == 600 + assert staged.collector_receipt["status"] == "pending" + warning = capsys.readouterr().err + assert ( + f"warning: the collector had not accepted the submissions of the staged " + f"dataset bundle staged/{RUN_ID} when the build stopped waiting " + "(COLLECTOR_UNAVAILABLE); the emitter keeps them queued, and it or the " + "next emitter started on this machine sends them." in warning + ) + + +@pytest.mark.parametrize( + ("status", "warned"), + [("rejected", "rejected"), ("failed", "failed")], +) +def test_a_submission_the_collector_turned_down_is_a_warning( + tmp_path, capsys, status, warned +): + bundle = _bundle(tmp_path) + emitter = FakeEmitterClient( + hub_api=FakeHub(tmp_path), + collector_receipts=[{"status": status, "error_code": "content_mismatch"}], + ) + + staged = _stage(bundle, emitter, collector=PROVENANCE) + + assert staged.delivery["status"] == "uploaded" + assert ( + f"warning: the collector {warned} the submissions of the staged dataset " + f"bundle staged/{RUN_ID} (content_mismatch)." in capsys.readouterr().err + ) + + +def test_a_bundle_that_has_not_landed_is_asked_about_once_and_not_waited_for( + tmp_path, capsys +): + """Its submissions wait for the commit, so the build only asks whether the + collector will receive anything.""" + bundle = _bundle(tmp_path) + waiting = FakeEmitterClient( + collector_receipts=[ + {"status": "pending", "error_code": "WAITING_FOR_HUGGING_FACE"} + ], + ) + refused = FakeEmitterClient( + collector_receipts=[ + {"status": "skipped", "error_code": "COLLECTOR_SETTINGS_REFUSED"} + ], + ) + + pending = _stage(bundle, waiting, collector=PROVENANCE, wait_seconds=0) + pending_warning = capsys.readouterr().err + skipped = _stage(bundle, refused, collector=PROVENANCE, wait_seconds=0) + skipped_warning = capsys.readouterr().err + + for staged, emitter in ((pending, waiting), (skipped, refused)): + assert staged.delivery["error_code"] == "UPLOAD_PENDING" + assert len(emitter.collector_receipt_requests) == 1 + assert pending.collector_receipt["status"] == "pending" + assert "collector" not in pending_warning + assert "(COLLECTOR_SETTINGS_REFUSED)" in skipped_warning + + +def test_a_bundle_without_provenance_is_never_asked_about(tmp_path): + bundle = _bundle(tmp_path) + emitter = FakeEmitterClient( + hub_api=FakeHub(tmp_path), collector_receipts=[{"status": "succeeded"}] + ) + + staged = _stage(bundle, emitter) + + assert emitter.collector_receipt_requests == [] + assert staged.collector_receipt is None + + +def test_a_resumed_hand_over_that_landed_waits_for_the_collector(tmp_path): + bundle = _bundle(tmp_path) + hub = FakeHub(tmp_path) + queue = FakeHandoverQueue() + first = _stage( + bundle, + FakeEmitterClient( + hub_api=hub, queue=queue, deliver=False, answer_receipts=False + ), + collector=PROVENANCE, + ) + later = FakeEmitterClient( + hub_api=hub, + queue=queue, + collector_receipts=[{"status": "pending"}, {"status": "succeeded"}], + ) + + resumed = _resume(bundle, later, staging_dataset.handover_record(first)) + + assert resumed is not None + assert resumed.delivery["status"] == "already_staged" + assert later.collector_receipt_requests == [first.handover_id] * 2 + assert resumed.collector_receipt["status"] == "succeeded" + + def test_stage_bundle_requires_the_sidecars_first(tmp_path): run_dir = _write_run(tmp_path) bundle = StagedDatasetBundle.from_manifest( diff --git a/packages/microcosm-build/tests/engine_free/uk/test_uk_release_publication.py b/packages/microcosm-build/tests/engine_free/uk/test_uk_release_publication.py index 1aec78c654..6886ed2f10 100644 --- a/packages/microcosm-build/tests/engine_free/uk/test_uk_release_publication.py +++ b/packages/microcosm-build/tests/engine_free/uk/test_uk_release_publication.py @@ -16,9 +16,11 @@ import httpx import huggingface_hub import pytest +from microcosm_emitter_interface import CollectorProvenance from microcosm_emitter_interface.releases import ReleaseRecordError, ReleasesRecord from microcosm.build import release_publication +from microcosm.build.uk_runtime import rowwise_staging from microcosm.data import release as release_module from microcosm.data.releases_record import parse_releases_record from test_support.microcosm_build.emitter import FakeEmitterClient @@ -104,6 +106,29 @@ def _record(client: FakeEmitterClient) -> dict: return json.loads(client.hub_files[(UK_REPO_ID, "releases.json")]) +class Clock: + """The command's clock and sleep while it waits for the collector.""" + + def __init__(self) -> None: + self.now = 1000.0 + self.slept: list[float] = [] + + def __call__(self) -> float: + return self.now + + def sleep(self, seconds: float) -> None: + self.slept.append(seconds) + self.now += seconds + + +@pytest.fixture +def clock(monkeypatch) -> Clock: + clock = Clock() + monkeypatch.setattr(release_publication, "_clock", clock) + monkeypatch.setattr(release_publication, "_sleep", clock.sleep) + return clock + + def test_publishing_hands_every_file_over_with_its_role( national: Path, artifact_root: Path, # noqa: F811 @@ -141,6 +166,157 @@ def test_publishing_hands_every_file_over_with_its_role( assert client.closed is False, "a client the caller passed stays open" +def test_a_publication_names_its_build_for_the_collector( + national: Path, + artifact_root: Path, # noqa: F811 +) -> None: + """The emitter submits the build's calibration diagnostics to the + collector after the release commit, under the build's own folder.""" + client = FakeEmitterClient() + + release_publication.publish_release_build( + national, artifact_root=artifact_root, client=client + ) + + (request,) = client.release_requests + assert request.collector == CollectorProvenance( + country_code="UK", + build_id=UK_NATIONAL_BUILD, + licensed_data=True, + release=UK_NATIONAL_RELEASE_ID, + ) + + +@pytest.mark.parametrize( + "release", + [ + UK_NATIONAL_RELEASE_ID, + "microcosm-uk-2024-25-dense", + "microcosm-uk-2024-25-local-k1", + "microcosm-uk-2024-25-local-k12", + ], +) +def test_every_uk_release_names_its_builds_as_licensed_uk_builds(release) -> None: + assert release_publication.collector_provenance( + release, UK_NATIONAL_BUILD + ) == CollectorProvenance( + country_code="UK", + build_id=UK_NATIONAL_BUILD, + licensed_data=True, + release=release, + ) + + +def test_the_uk_country_code_is_the_one_staged_bundles_name() -> None: + assert ( + release_publication.UK_COLLECTOR_COUNTRY_CODE + == rowwise_staging.UK_COLLECTOR_COUNTRY_CODE + ) + + +def test_a_release_that_publishes_with_tags_names_no_build() -> None: + assert ( + release_publication.collector_provenance( + "populace-uk-2023-dd68c73", UK_NATIONAL_BUILD + ) + is None + ) + + +def test_a_published_build_waits_until_the_collector_accepts_its_submissions( + national: Path, + artifact_root: Path, # noqa: F811 + clock: Clock, + capsys, +) -> None: + """A short-lived emitter starts no new submission once it is closing, so + the command waits for the collector to accept them before it closes.""" + client = FakeEmitterClient( + collector_receipts=[{"status": "pending"}, {"status": "awaiting_final_status"}] + ) + + outcome = release_publication.publish_release_build( + national, artifact_root=artifact_root, client=client + ) + + (request,) = client.release_requests + assert client.collector_receipt_requests == [request.handover_id()] * 2 + assert clock.slept == [release_publication.RECEIPT_POLL_SECONDS] + assert outcome.collector_receipt is not None + assert outcome.collector_receipt["status"] == "awaiting_final_status" + assert outcome.as_json()["collector_submission"] == { + "status": "awaiting_final_status", + "error_code": None, + } + assert outcome.succeeded + assert "warning" not in capsys.readouterr().err + + +def test_refused_collector_settings_are_reported_and_the_publication_succeeds( + national: Path, + artifact_root: Path, # noqa: F811 + monkeypatch, + capsys, +) -> None: + client = FakeEmitterClient( + collector_receipts=[ + {"status": "skipped", "error_code": "COLLECTOR_SETTINGS_REFUSED"} + ] + ) + monkeypatch.setattr(release_publication, "_start_release_emitter", lambda: client) + + code, output, error = _run( + [str(national), "--artifact-root", str(artifact_root)], capsys + ) + + assert code == 0 + assert output["status"] == "published" + assert output["collector_submission"] == { + "status": "skipped", + "error_code": "COLLECTOR_SETTINGS_REFUSED", + } + assert ( + f"warning: the collector receives nothing of build {UK_NATIONAL_BUILD} " + f"of {UK_NATIONAL_RELEASE_ID}: the emitter refused its collector " + "settings or the collector-token variables it inherits " + "(COLLECTOR_SETTINGS_REFUSED)." in error + ) + # The command asked before it closed the emitter. + assert client.calls.index("collector_submission_receipt") < client.calls.index( + "close" + ) + + +@pytest.mark.parametrize( + "receipt", + [ + {"status": "pending", "error_code": "REPOSITORY_UNAVAILABLE"}, + {"status": "refused", "error_code": "BUILD_FOLDER_EXISTS"}, + ], + ids=["pending", "refused"], +) +def test_a_publication_that_has_not_landed_is_asked_about_once( + national: Path, + artifact_root: Path, # noqa: F811 + clock: Clock, + receipt: dict, +) -> None: + client = FakeEmitterClient( + release_receipts=[receipt], + collector_receipts=[ + {"status": "pending", "error_code": "WAITING_FOR_HUGGING_FACE"} + ], + ) + + outcome = release_publication.publish_release_build( + national, artifact_root=artifact_root, client=client + ) + + assert len(client.collector_receipt_requests) == 1 + assert clock.slept == [] + assert outcome.collector_receipt["status"] == "pending" + + def test_a_build_published_as_current_is_current( national: Path, artifact_root: Path, # noqa: F811 @@ -222,6 +398,13 @@ def test_promoting_makes_a_published_build_current( outcome = release_publication.promote_release_build(national, client=client) assert client.calls.count("promote_build") == 1 + # A promotion changes only releases.json, so it names no build for the + # collector, and the command asks nothing about it. + assert client.collector_receipt_requests == [ + client.release_requests[0].handover_id() + ] + assert outcome.collector_receipt is None + assert outcome.as_json()["collector_submission"] is None (_, promotion) = client.release_requests assert (promotion.release, promotion.build) == ( UK_NATIONAL_RELEASE_ID, @@ -259,6 +442,7 @@ def test_an_emitter_without_its_hugging_face_module_publishes_nothing( assert outcome.receipt["status"] == "unavailable" assert outcome.problem is not None and not outcome.succeeded assert client.release_requests == [] + assert client.collector_receipt_requests == [] def test_a_started_emitter_is_closed_after_the_publication( diff --git a/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_plan_tool.py b/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_plan_tool.py index d330dab792..e2704027ed 100644 --- a/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_plan_tool.py +++ b/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_plan_tool.py @@ -419,7 +419,7 @@ def test_image_installs_the_emitter_command_on_its_own(app) -> None: commands = plan_lib.image_build_commands(plan) sync = next(index for index, command in enumerate(commands) if "uv sync" in command) install_command = ( - "UV_TOOL_BIN_DIR=/usr/local/bin uv tool install 'microcosm-emitter>=0.14.0'" + "UV_TOOL_BIN_DIR=/usr/local/bin uv tool install 'microcosm-emitter>=0.15.0'" ) assert install_command in commands install = commands.index(install_command) diff --git a/packages/microcosm-build/tests/engine_free/us/test_us_release_publication.py b/packages/microcosm-build/tests/engine_free/us/test_us_release_publication.py index 6dbbc1470e..f822134339 100644 --- a/packages/microcosm-build/tests/engine_free/us/test_us_release_publication.py +++ b/packages/microcosm-build/tests/engine_free/us/test_us_release_publication.py @@ -10,8 +10,11 @@ import json import pytest +from microcosm_emitter_interface import CollectorProvenance from microcosm.build import release_publication +from microcosm.data.contract import US_RELEASES +from microcosm.data.release import BuildFolderFile #: The largest US builds, the ACS local-area ones, are about 10 GB. LARGEST_US_BUILD_BYTES = 10e9 @@ -47,6 +50,48 @@ def test_the_command_takes_a_us_release(tmp_path, monkeypatch, capsys) -> None: assert "HF_HUB_OFFLINE" in error_output +@pytest.mark.parametrize("release", sorted(US_RELEASES)) +def test_every_us_release_names_its_builds_as_public_us_builds(release) -> None: + """The collector registers the US with its public repository; a US build + is published there, so it used no microdata whose licence keeps its + outputs private.""" + build = "populace-us-2024-20261201T000000Z" + + assert release_publication.collector_provenance( + release, build + ) == CollectorProvenance( + country_code="US", build_id=build, licensed_data=False, release=release + ) + + +def test_a_us_publication_names_its_build_for_the_collector(tmp_path) -> None: + from types import SimpleNamespace + + build = "populace-us-2024-20261201T000000Z" + manifest = tmp_path / "release_manifest.json" + manifest.write_text("{}") + prepared = SimpleNamespace( + repository="policyengine/populace-us", + release="microcosm-us-2024-national", + build=build, + release_role="national", + files=( + BuildFolderFile( + "release_manifest.json", "release_manifest", manifest, "0" * 64, 2 + ), + ), + ) + + request = release_publication.publication_request(prepared, make_current=True) + + assert request.collector == CollectorProvenance( + country_code="US", + build_id=build, + licensed_data=False, + release="microcosm-us-2024-national", + ) + + def _prepared(release_dir): from types import SimpleNamespace diff --git a/packages/microcosm-build/tests/installed_emitter/shared/test_installed_emitter_staging.py b/packages/microcosm-build/tests/installed_emitter/shared/test_installed_emitter_staging.py index 3186f66dd2..187c0d3cb1 100644 --- a/packages/microcosm-build/tests/installed_emitter/shared/test_installed_emitter_staging.py +++ b/packages/microcosm-build/tests/installed_emitter/shared/test_installed_emitter_staging.py @@ -4,11 +4,13 @@ start the separately installed ``microcosm-emitter`` command with ``start_bundle_emitter()``, as the UK re-stage command (``tools/stage_uk_rowwise_candidate.py``) starts it: the Hugging Face module -only, so the telemetry module never starts and nothing contacts the collector. -A build's own emitter also runs the telemetry and Orrery modules; its Hugging -Face module is the same code. The emitter's Hugging Face Hub requests go to the -loopback stand-in Hub (``HF_ENDPOINT``), which takes the dataset through the -LFS upload a real Hub requires for it, since Xet is turned off. +only, so the telemetry module never starts. A build's own emitter also runs +the telemetry and Orrery modules; its Hugging Face module is the same code. +The emitter's Hugging Face Hub requests go to the loopback stand-in Hub +(``HF_ENDPOINT``), which takes the dataset through the LFS upload a real Hub +requires for it, since Xet is turned off. The build switches the module's +collector submissions on; the fixture points them at a closed loopback port, +so nothing reaches a collector. ``tools/run_installed_emitter_tests.sh`` installs the minimum release builds accept and the newest pinned release, and runs this file once for each, with @@ -22,6 +24,7 @@ import json import os import shutil +import socket import subprocess import time from dataclasses import dataclass, field @@ -100,6 +103,13 @@ """ +def _closed_loopback_url() -> str: + with socket.socket() as probe: + probe.bind(("127.0.0.1", 0)) + port = probe.getsockname()[1] + return f"http://127.0.0.1:{port}" + + def _sha256(content: bytes) -> str: return hashlib.sha256(content).hexdigest() @@ -174,6 +184,12 @@ class InstalledEmitter: monkeypatch: pytest.MonkeyPatch processes: list[launcher.EmitterProcess] = field(default_factory=list) clients: list[EmitterClient] = field(default_factory=list) + #: The module settings the build gave each emitter it started, before + #: the fixture pointed collector submissions at ``closed_collector_url``. + configurations: list[dict[str, Any]] = field(default_factory=list) + #: A loopback port nothing listens on: a collector submission fails to + #: connect and stays queued, so nothing reaches the production collector. + closed_collector_url: str = field(default_factory=lambda: _closed_loopback_url()) def start(self, *, queue_directory: Path | None = None) -> EmitterClient: """``start_bundle_emitter()``, optionally with a queue of its own. @@ -188,8 +204,19 @@ def start(self, *, queue_directory: Path | None = None) -> EmitterClient: self.clients.append(client) return client - def record_start(self, *arguments: Any, **options: Any) -> launcher.EmitterProcess: - process = launcher.start_emitter(*arguments, **options) + def record_start( + self, modules: dict[str, dict[str, Any]], **options: Any + ) -> launcher.EmitterProcess: + """Start the emitter with the build's settings, collector submissions + sent to ``closed_collector_url`` unless the build named a collector.""" + self.configurations.append(json.loads(json.dumps(modules))) + started = {name: dict(settings) for name, settings in modules.items()} + hugging_face = started.get("huggingface") + if hugging_face is not None: + hugging_face.setdefault( + "development_collector_url", self.closed_collector_url + ) + process = launcher.start_emitter(started, **options) self.processes.append(process) return process @@ -301,6 +328,12 @@ def test_the_build_starts_the_installed_emitter_with_only_its_hub_module( assert client.emitter_version == installed_emitter.version assert client.modules == {"huggingface"} assert len(installed_emitter.processes) == 1 + # The build switches collector submissions on, and names no collector of + # its own, so they would go to the production collector. + (configuration,) = installed_emitter.configurations + hugging_face = configuration["huggingface"] + assert hugging_face.get("collector_submissions") is True + assert "development_collector_url" not in hugging_face def test_an_emitter_older_than_the_minimum_is_never_started( diff --git a/test_support/microcosm_build/emitter.py b/test_support/microcosm_build/emitter.py index 00de630c57..05ac3d5eb2 100644 --- a/test_support/microcosm_build/emitter.py +++ b/test_support/microcosm_build/emitter.py @@ -31,7 +31,11 @@ ``hub_files`` as the emitter's release writer documents it: the build folder and ``releases.json`` in one commit, after the interface's shared checks, or a ``refused`` receipt naming the first broken rule. - ``release_receipts`` scripts the answers instead. + ``release_receipts`` scripts the answers instead; +- ``collector_submission_receipt`` answers ``None``, as an emitter does + whose collector submissions are off, unless ``collector_receipts`` scripts + the answers for every hand-over (each ask takes the next one; the last one + repeats). The emitter's own tests cover the process, its queues and the Hub. """ @@ -178,7 +182,7 @@ class FakeEmitterClient: as the interface does after a timeout. """ - emitter_version = "0.14.0" + emitter_version = "0.15.0" def __init__( self, @@ -194,6 +198,7 @@ def __init__( deliver: bool = True, answer_receipts: bool = True, release_receipts: Sequence[Mapping[str, Any]] | None = None, + collector_receipts: Sequence[Mapping[str, Any]] | None = None, ) -> None: self._modules = frozenset(modules) self.accept_run_files = accept_run_files @@ -237,6 +242,13 @@ def __init__( #: Each release change handed over, and its latest receipt by ID. self.release_requests: list[ReleaseChange] = [] self._release_answers: dict[str, list[dict[str, Any]]] = {} + #: Scripted collector receipts, each hand-over's in turn (the last one + #: repeats), and the hand-over ID of every collector receipt asked for. + self.collector_receipts = ( + None if collector_receipts is None else list(collector_receipts) + ) + self.collector_receipt_requests: list[str] = [] + self._collector_answers: dict[str, list[dict[str, Any]]] = {} self._committed: dict[tuple[str, str], tuple[str, str]] = {} self._deliveries: dict[tuple[str, str], dict[str, Any]] = {} self.telemetry = TelemetryRecorder(self) @@ -757,6 +769,30 @@ def _apply_release_change(self, request: ReleaseChange) -> dict[str, Any]: commit = hashlib.sha1(str(len(self.release_requests)).encode()).hexdigest() return {"commit": commit, "current": after.releases[request.release].current} + # Collector submissions ----------------------------------------------------- + + def collector_submission_receipt(self, handover_id: str) -> dict[str, Any] | None: + self.calls.append("collector_submission_receipt") + self.collector_receipt_requests.append(handover_id) + if "huggingface" not in self.modules or self.collector_receipts is None: + return None + answers = self._collector_answers.setdefault( + handover_id, + [ + { + "handover_id": handover_id, + "destination": "collector", + "status": "pending", + "error_code": None, + "attempts": 0, + "submissions": [], + **dict(receipt), + } + for receipt in self.collector_receipts + ], + ) + return dict(answers.pop(0) if len(answers) > 1 else answers[0]) + def close(self) -> None: self.calls.append("close") self.closed = True diff --git a/test_support/microcosm_build/us_modal_stage_plan_tool.py b/test_support/microcosm_build/us_modal_stage_plan_tool.py index f08ecefb16..05f8db4e74 100644 --- a/test_support/microcosm_build/us_modal_stage_plan_tool.py +++ b/test_support/microcosm_build/us_modal_stage_plan_tool.py @@ -42,7 +42,7 @@ def _load(): #: What the image's emitter answers to ``microcosm-emitter version``. Tests #: get this answer instead of running a command at the image's emitter path. RECORDED_EMITTER_VERSION = { - "emitter_version": "0.14.0", + "emitter_version": "0.15.0", "protocol_versions": [1], "collector_origin": TEST_COLLECTOR_ORIGIN, } diff --git a/uv.lock b/uv.lock index eff3e0c519..ea26b19944 100644 --- a/uv.lock +++ b/uv.lock @@ -822,7 +822,7 @@ requires-dist = [ { name = "microcosm-data", marker = "extra == 'uk'", editable = "packages/microcosm-data" }, { name = "microcosm-data", marker = "extra == 'us'", editable = "packages/microcosm-data" }, { name = "microcosm-diagnostics", editable = "packages/microcosm-diagnostics" }, - { name = "microcosm-emitter-interface", specifier = ">=0.14.0,<1" }, + { name = "microcosm-emitter-interface", specifier = ">=0.15.0,<1" }, { name = "microcosm-fit", editable = "packages/microcosm-fit" }, { name = "microcosm-frame", editable = "packages/microcosm-frame" }, { name = "microcosm-graph", editable = "packages/microcosm-graph" }, @@ -943,11 +943,11 @@ dev = [ [[package]] name = "microcosm-emitter-interface" -version = "0.14.0" +version = "0.15.0" source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/e6/da/bb01ccc1738c63798df875af996a13f84872215d612e6504420549e22509/microcosm_emitter_interface-0.14.0.tar.gz", hash = "sha256:048d1cf5314cf9705fa7aeb797725569806fe438b54589687f83b92af0c03c59", size = 42700, upload-time = "2026-11-09T15:55:40.052Z" } +sdist = { url = "https://files.pythonhosted.org/packages/18/4f/104cfbf59a7d9c864b8c9ee7d39e4c892f96eacba191877d9960c41fbf3e/microcosm_emitter_interface-0.15.0.tar.gz", hash = "sha256:d4810e5f1d7a210ce653e3bc76b7cae5869e02dab0ca1653eac581a227aa9ff7", size = 44283, upload-time = "2026-11-12T20:02:41.336Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/ba/4d/68812412ffe1cac5620a5327703d5418d601ec3f869e6a5c02779c62817a/microcosm_emitter_interface-0.14.0-py3-none-any.whl", hash = "sha256:fec63dd29ca626b91e1cfcec6a52bce37e4bb2c248b0b25e3b4ac9042b6151a5", size = 67133, upload-time = "2026-11-09T15:55:38.726Z" }, + { url = "https://files.pythonhosted.org/packages/21/1d/08334f65ac81b24fcf3280139d05e789e765b82923d57f333c78aea1f32f/microcosm_emitter_interface-0.15.0-py3-none-any.whl", hash = "sha256:37ee5fbd8230ca010e172bf2655f4fcff1f890b2a9190e0e153953ecf8571997", size = 70076, upload-time = "2026-11-12T20:02:39.923Z" }, ] [[package]] From 83f12878f3600ca8f1ac70c1ff8f9152c6366e5d Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Fri, 13 Nov 2026 01:12:52 +0400 Subject: [PATCH 2/9] Switch collector submissions on and submit at staging and at release MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit microcosm#1599, tracker task 3a · 2: - Builds and the Modal image require microcosm-emitter 0.15.0, and the installed-emitter job's pin rises to it. 0.15.0 adds the setting that switches the Hugging Face module's collector submissions on, collector provenance on a release publication, and skipped collector receipts. - Every emitter Microcosm starts (a build's, the re-stage command's and the release command's) has its collector submissions on (telemetry_emitter.COLLECTOR_SUBMISSIONS), and a loopback collector given for telemetry takes the submissions too. - microcosm-publish-release-build names each build-folder release's build for the collector: UK builds licensed, US builds not, with the publication's own release and build. - After a described bundle or publication lands, the build or command waits up to ten minutes for the collector to accept the submissions, since a closing emitter starts no new one; an attempt after the commit that fails ends the wait. A hand-over that has not landed is asked about once. Skipped, rejected and failed receipts and submissions still queued are warnings and never fail a staging or a publication; the publication command prints the receipt as collector_submission. - Docs that said no emitter release can switch submissions on now describe the switch, the wait and the warnings; changelog fragment. The failed-submission test now expects the warning's final wording. Co-Authored-By: Claude Opus 5.5 --- README.md | 29 ++- .../1599-collector-submissions-on.added.md | 1 + docs/orrery-publication.md | 42 ++-- docs/uk-dense-release-assembly-runbook-762.md | 5 +- ...k-national-release-assembly-runbook-806.md | 6 +- docs/uk-staging-operations.md | 36 +++- docs/us-modal-stage-runbook.md | 9 +- .../build/minimum_emitter_version.json | 2 +- .../microcosm/build/release_publication.py | 108 +++++++++- .../src/microcosm/build/staging_dataset.py | 203 +++++++++++++++++- .../src/microcosm/build/telemetry_emitter.py | 81 +++++-- .../build/uk_runtime/rowwise_staging.py | 5 +- .../shared/test_staging_dataset.py | 26 ++- tools/installed-emitter/requirements.txt | 2 +- tools/stage_uk_rowwise_candidate.py | 8 +- 15 files changed, 476 insertions(+), 87 deletions(-) create mode 100644 changelog.d/1599-collector-submissions-on.added.md diff --git a/README.md b/README.md index 591d159f2c..eabf22d4e6 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ change: ```bash uv tool install microcosm-emitter # once per machine uv tool upgrade microcosm-emitter # to take a new release -microcosm-emitter version # the installed release; builds need 0.14.0 or later +microcosm-emitter version # the installed release; builds need 0.15.0 or later ``` The build finds the `microcosm-emitter` command through @@ -76,7 +76,12 @@ no remote staging, and queues no Orrery graph publication; a UK build given its dataset bundle remotely, as it is by default, is refused before it starts, since the emitter uploads the bundle. Before it starts the emitter, the build reads its version from `microcosm-emitter version` and does not -start one older than 0.14.0. That release adds the build machine's +start one older than 0.15.0. That release adds the setting that switches +the Hugging Face module's collector submissions on, which every emitter a +build starts sets, so staged bundles and release publications that name +their build reach the collector; collector provenance on a release +publication; and a `skipped` collector receipt when the emitter refuses its +collector settings. 0.14.0 added the build machine's readings: each heartbeat carries the machine's memory, CPU and disk use and the build's processes, a heartbeat after the machine wakes carries the sleep, the run's first event describes the machine, each stage's end says how long @@ -90,12 +95,12 @@ which builds read as package data and the Modal image's install step reads from the launching checkout. Releases before 0.10.0 send telemetry to the collector's Cloud Run address, which changes when the collector moves to another Google Cloud project; from 0.10.0 on, releases send to the -collector's hostname, which stays the same. 0.13.0 and 0.14.0 were each -the newest release when practically no machine ran the emitter yet, so +collector's hostname, which stays the same. 0.13.0, 0.14.0 and 0.15.0 were +each the newest release when practically no machine ran the emitter yet, so requiring them cost nothing (see [graph publication](docs/orrery-publication.md#emitter-dependency)). The build prints the installed and required versions, what it loses and the -upgrade command, `uv tool install --upgrade 'microcosm-emitter>=0.14.0'`, +upgrade command, `uv tool install --upgrade 'microcosm-emitter>=0.15.0'`, and continues as it does without the command. `uv tool upgrade` keeps any version constraint given at install time, such as `==0.7.0`; that `uv tool install --upgrade` command replaces it. Microcosm supplies build @@ -118,7 +123,7 @@ if the emitter cannot be prepared or is missing, its `microcosm-emitter version` times out or fails, it is older than the minimum, it lists no protocol version 1, its `hello` fails, it exits or times out before it is ready, or it starts without its telemetry module. -Every emitter a build starts (0.14.0 and later, the minimum) reads a given +Every emitter a build starts (0.15.0 and later, the minimum) reads a given collector token, and exits at that point when the collector-token variables it inherits (`MICROCOSM_COLLECTOR_TOKEN`, `MICROCOSM_COLLECTOR_TOKEN_EXPIRES_AT`, `MICROCOSM_COLLECTOR_ORIGIN`) are set @@ -531,7 +536,17 @@ three hours for a publication to land or be refused, which covers the emitter's one-hour expiry of a pending change and the upload of a US ACS local-area build of about 10 GB, and five minutes for a promotion. `--preflight-only` checks the build and lists what would be published, -offline, and starts no emitter. The calibration diagnostics dashboard posts +offline, and starts no emitter. A publication names its build for the +collector: country `UK` with licensed data for the UK releases, `US` +without for the US releases, and the release and build of its folder. The +emitter submits the build's calibration diagnostics, with its build and +release manifests, to the collector after the release commit, so once the +publication has landed the command waits up to ten minutes for the collector +to accept them before it closes the emitter. The printed outcome's +`collector_submission` gives the collector receipt's `status` and +`error_code`; a collector that receives nothing (`skipped`, for example +`COLLECTOR_SETTINGS_REFUSED`), rejects them or has not accepted them yet is a +warning and never fails the command. The calibration diagnostics dashboard posts these releases' Slack alerts from changes to `releases.json`. The UK assemblers, the US national builder and the US ACS package stage print the exact commands; the UK diff --git a/changelog.d/1599-collector-submissions-on.added.md b/changelog.d/1599-collector-submissions-on.added.md new file mode 100644 index 0000000000..12d91280cd --- /dev/null +++ b/changelog.d/1599-collector-submissions-on.added.md @@ -0,0 +1 @@ +Builds now send their calibration diagnostics to the collector, at staging and at release (microcosm#1599). Builds and the Modal image require microcosm-emitter 0.15.0 or later instead of 0.14.0: 0.15.0 adds the Hugging Face module's setting that switches collector submissions on, collector provenance on a release publication, and a `skipped` collector receipt with an error code when the emitter refuses its collector settings. microcosm-build's `microcosm-emitter-interface` pin rises from `>=0.14.0,<1` to `>=0.15.0,<1` (the lock moves from 0.14.0 to 0.15.0, and `APPROVED_UV_LOCK_SHA256` is re-pinned for the new lock), and the installed-emitter job's pin rises to 0.15.0. Every emitter a build, the UK re-stage command or the release publication command starts has its collector submissions on (`telemetry_emitter.COLLECTOR_SUBMISSIONS`); the emitter's own default leaves them off, so switching them off again is a Microcosm change. A loopback collector given for telemetry (`development_collector_url`) takes the submissions too. UK staged bundles, which already name their build, are submitted after their Hugging Face commit. `microcosm-publish-release-build` names each build for the collector, country `UK` with licensed data for the UK national, dense and local-area releases and `US` without for the US releases, with the publication's own release and build, so the emitter submits the build's calibration diagnostics and manifests after the release commit under `releases//`; the collector's calibration tree handler registers both countries' release repositories. Once a described bundle or publication has landed, the build or command waits up to ten minutes for the collector to accept the submissions, since an emitter that is closing starts no new submission; an attempt after the commit that fails ends the wait sooner, and a hand-over that has not landed is asked about once. A `skipped` receipt (`COLLECTOR_SETTINGS_REFUSED`, `COLLECTOR_FOLDER_TOO_LONG`, or Hugging Face's refusal), a rejected or failed submission, and submissions still queued when the wait ends are warnings, and never fail a staging or a publication; the publication command prints the collector receipt's `status` and `error_code` as `collector_submission`. The installed-emitter tests send the emitter's collector submissions to a closed loopback port. diff --git a/docs/orrery-publication.md b/docs/orrery-publication.md index 5093ccd456..87c8f4df98 100644 --- a/docs/orrery-publication.md +++ b/docs/orrery-publication.md @@ -150,7 +150,7 @@ retain a second delivery implementation or a compatibility wrapper. ## Emitter dependency `packages/microcosm-build` depends on `microcosm-emitter-interface` -(`>=0.14.0,<1`), the dependency-free package of typed calls, which `uv.lock` +(`>=0.15.0,<1`), the dependency-free package of typed calls, which `uv.lock` records with its hashes. The emitter itself, `microcosm-emitter`, is not a workspace dependency: each machine installs it on its own with `uv tool install microcosm-emitter`, and the Modal image installs the newest @@ -162,9 +162,9 @@ versions interfaces still send, and an emitter that lacks a module the build asks for starts without it. A build does not start an emitter older than `MINIMUM_EMITTER_VERSION` in -`microcosm.build.telemetry_emitter`, now 0.14.0, and the Modal image installs +`microcosm.build.telemetry_emitter`, now 0.15.0, and the Modal image installs at least the same release (`image_emitter_requirement()` in -`tools/modal_us_stage_plan.py`, `microcosm-emitter>=0.14.0`). The release is +`tools/modal_us_stage_plan.py`, `microcosm-emitter>=0.15.0`). The release is written once, in microcosm-build's package data, `packages/microcosm-build/src/microcosm/build/minimum_emitter_version.json`: the adapter reads it as package data, and the runner, which imports nothing @@ -179,20 +179,28 @@ changes when the collector moves to another Google Cloud project. From 0.10.0 on, the emitter's default collector address is the collector's hostname, which stays the same. Microcosm passes the emitter no collector address: the adapter's `development_collector_url` parameter, which no build command sets, -accepts only a loopback address. - -The minimum is 0.14.0, the newest release on 2026-11-09. 0.14.0 adds the -build machine's readings to each heartbeat, the sleeps the machine took, a -description of the machine in the run's first event, each stage's awake and -asleep time at its end, and a counter one level above a stage's progress, -which the US fiscal refresh's post-export scoring sends as the reform pass -each scoring batch belongs to (the interface's `OuterProgress`, from 0.14.0). -The minimum before it, 0.13.0, added `microcosm-emitter status`, which the -US Modal stage runner runs after each stage to record how many telemetry -events the stage's emitter left undelivered; builds require the same release -as the Modal image so that it is written once. Practically no machine ran -the separately installed emitter on either date, so refusing 0.11.9 to -0.13.0 cost nothing; the minimum before those, 0.11.9, came from the +accepts only a loopback address, and reaches telemetry, Orrery graph +publication and the Hugging Face module's collector submissions alike. + +The minimum is 0.15.0, the newest release on 2026-11-13. 0.15.0 adds the +Hugging Face module's setting that switches collector submissions on, which +every emitter a build starts sets (`telemetry_emitter.COLLECTOR_SUBMISSIONS`), +collector provenance on a release publication, which it submits after the +release commit, and a `skipped` collector receipt with an error code when it +refuses its collector settings. An older emitter accepts the setting but +drops a publication's provenance, so it would submit no release. The +minimum before it, 0.14.0, added the build machine's readings to each +heartbeat, the sleeps the machine took, a description of the machine in the +run's first event, each stage's awake and asleep time at its end, and a +counter one level above a stage's progress, which the US fiscal refresh's +post-export scoring sends as the reform pass each scoring batch belongs to +(the interface's `OuterProgress`, from 0.14.0). 0.13.0 added +`microcosm-emitter status`, which the US Modal stage runner runs after each +stage to record how many telemetry events the stage's emitter left +undelivered; builds require the same release as the Modal image so that it +is written once. Practically no machine ran the separately installed +emitter on any of these dates, so refusing 0.11.9 to 0.14.0 cost nothing; +the minimum before those, 0.11.9, came from the collector's hostname, for which 0.10.0 would have been enough. A refused emitter does cost the build: diff --git a/docs/uk-dense-release-assembly-runbook-762.md b/docs/uk-dense-release-assembly-runbook-762.md index 9d436dbd81..6790c5c224 100644 --- a/docs/uk-dense-release-assembly-runbook-762.md +++ b/docs/uk-dense-release-assembly-runbook-762.md @@ -38,9 +38,10 @@ the gates stood on. See [Optional diagnostics](#optional-diagnostics-microcosm13 bytes), which the publication command's release-contract check also reads. - For publication: `HF_TOKEN` (or `HUGGINGFACE_TOKEN`, or a token saved by `hf auth login`) with write access to `policyengine/populace-uk-private`, - and the separately installed `microcosm-emitter` 0.14.0 or later, which the + and the separately installed `microcosm-emitter` 0.15.0 or later, which the publication command starts as its child process and which uses the token it - inherits. These come from your shell: the command does not read + inherits, for the release commit and for submitting the build's calibration + diagnostics to the collector. These come from your shell: the command does not read `tools/release.env`, so if you keep the values there, `source tools/release.env` first. - The Ledger consumer artifact, the spine H5 with its sidecar, the OA ladder. diff --git a/docs/uk-national-release-assembly-runbook-806.md b/docs/uk-national-release-assembly-runbook-806.md index 32786cc2a4..a97f083455 100644 --- a/docs/uk-national-release-assembly-runbook-806.md +++ b/docs/uk-national-release-assembly-runbook-806.md @@ -21,8 +21,10 @@ Before starting, export: copied certification. - `HF_TOKEN` (or `HUGGINGFACE_TOKEN`, or a token saved by `hf auth login`), with write access to `policyengine/populace-uk-private`. The publication - command starts the separately installed `microcosm-emitter` (0.14.0 or - later) as its child process, and the emitter uses the token it inherits. + command starts the separately installed `microcosm-emitter` (0.15.0 or + later) as its child process, and the emitter uses the token it inherits, + for the release commit and for submitting the build's calibration + diagnostics to the collector. These come from your shell: the publication command does not read `tools/release.env`, so if you keep the values there, `source diff --git a/docs/uk-staging-operations.md b/docs/uk-staging-operations.md index 68d2b234f8..402967f944 100644 --- a/docs/uk-staging-operations.md +++ b/docs/uk-staging-operations.md @@ -245,15 +245,33 @@ The hand-over also names the build for the collector, with the interface's With that, the emitter submits the bundle's calibration diagnostics (with the build manifest as `build_manifest`) to the collector once the Hugging Face commit lands, as a `calibration-diagnostics` submission whose folder is -`staged/`, but only while its collector submissions are on. No -emitter release up to 0.14.0 (the newest released, which the installed-emitter -tests pin) can switch them on, so for now the emitter ignores the provenance -and the bundle goes to Hugging Face alone. Microcosm sets only a minimum -emitter version, so an emitter release that switches submissions on by -default would start these submissions with no change here. A different `collector` block gives the bundle a -different hand-over ID, so a bundle handed over before this change is not -the same hand-over as one handed over after it; the re-stage command resumes -a recorded hand-over by its recorded ID either way. +`staged/`, with the build's Hugging Face credential. Every emitter a +build or the re-stage command starts has its collector submissions switched +on (`telemetry_emitter.COLLECTOR_SUBMISSIONS`, through the setting emitter +0.15.0 added; the emitter's own default leaves them off, so switching them +off again is a Microcosm change). Once the bundle has landed, the build waits +up to ten minutes for the collector to accept the submissions +(`staging_dataset.follow_collector_submissions`), because an emitter that is +closing starts no new submission; an attempt after the commit that fails +ends the wait sooner. A bundle that has not landed is asked about once and +not waited for. The build carries on in every case, with a warning when: + +- the collector receives nothing (`skipped`): the emitter refused its + collector settings or the collector-token variables it inherits + (`COLLECTOR_SETTINGS_REFUSED`), Hugging Face refused the bundle + (`NOT_STAGED_ON_HUGGING_FACE`), or its folder is longer than the collector + accepts (`COLLECTOR_FOLDER_TOO_LONG`); +- the collector rejected the submissions, or they failed, with the code the + receipt gives; +- they were still queued when the build stopped waiting: the emitter, or the + next emitter started on this machine, sends them. + +The staged dataset record (`staged_dataset`) describes the Hugging Face +upload alone and does not change. A different `collector` block gives the +bundle a different hand-over ID, so a bundle handed over before the +provenance was added is not the same hand-over as one handed over after it; +the re-stage command resumes a recorded hand-over by its recorded ID either +way, and follows its collector receipt as the build does. Modes follow the staging switch. The default uploads telemetry and the bundle; `--staging-local-only` keeps both on disk (the sidecars are still written); diff --git a/docs/us-modal-stage-runbook.md b/docs/us-modal-stage-runbook.md index c9834db0f0..8f2f30add5 100644 --- a/docs/us-modal-stage-runbook.md +++ b/docs/us-modal-stage-runbook.md @@ -90,7 +90,7 @@ that release's current build. and asserts `HEAD` equals the commit. It then runs `uv sync --all-packages --extra us --frozen` against that tree's own `uv.lock` into `/opt/venv`, installs the newest `microcosm-emitter` - release (0.14.0 or later, the oldest a build starts) on its own with + release (0.15.0 or later, the oldest a build starts) on its own with `uv tool install` into `/usr/local/bin`, checks that `microcosm-emitter version` runs, and asserts `git status --porcelain` is empty. Emitter releases from 0.10.0 on send telemetry to the collector's @@ -108,7 +108,7 @@ that release's current build. (`/root/minimum_emitter_version.json`), and the copy reads that one: the check, which runs there, reports the install step the image was built with. The install step and its - `>=0.14.0` floor come from the checkout that launches the app + `>=0.15.0` floor come from the checkout that launches the app (`image_build_commands`, `image_emitter_requirement`), while the minimum the build enforces comes from the commit the plan pins, so a launch can combine an older checkout's floor with a newer commit's minimum, or the @@ -357,8 +357,9 @@ that release's current build. the newest emitter release when Modal builds its install step, and Modal reuses that step for a commit while the step's command is the same. Since #1455 (merged 2026-11-03), the command asks for at least - 0.11.9, since #1522 for `microcosm-emitter>=0.13.0`, and since #1556 for - `microcosm-emitter>=0.14.0`, so every image this runner builds has an + 0.11.9, since #1522 for `microcosm-emitter>=0.13.0`, since #1556 for + `microcosm-emitter>=0.14.0`, and since #1599 for + `microcosm-emitter>=0.15.0`, so every image this runner builds has an emitter that reports a collector origin and has `status`. An image whose install step an older checkout built (with `>=0.7.0`, possibly before 0.11.0) is not reused: the changed command rebuilds that step, for each commit, at its diff --git a/packages/microcosm-build/src/microcosm/build/minimum_emitter_version.json b/packages/microcosm-build/src/microcosm/build/minimum_emitter_version.json index 18abb58473..abc3e186e3 100644 --- a/packages/microcosm-build/src/microcosm/build/minimum_emitter_version.json +++ b/packages/microcosm-build/src/microcosm/build/minimum_emitter_version.json @@ -1,3 +1,3 @@ { - "minimum_emitter_version": "0.14.0" + "minimum_emitter_version": "0.15.0" } diff --git a/packages/microcosm-build/src/microcosm/build/release_publication.py b/packages/microcosm-build/src/microcosm/build/release_publication.py index 447732bfb0..f23bfe3d61 100644 --- a/packages/microcosm-build/src/microcosm/build/release_publication.py +++ b/packages/microcosm-build/src/microcosm/build/release_publication.py @@ -26,6 +26,16 @@ ``make_current`` can land without making its build current, when a change to the release's current build requested after it landed first. +A publication names its build for the collector (:func:`collector_provenance`), +so the emitter, whose collector submissions are on, submits the build's +calibration diagnostics, with its build and release manifests, to the +collector after the release commit, under the build's folder +``releases//``. Once the publication has landed, the command +waits for the collector to accept them before it closes its emitter, which +starts no new submission once it is closing, and prints the collector's +status; a collector that receives nothing or turns them down is a warning, +and never fails the publication. + The emitter finds its Hugging Face credential the way a build's emitter does: it is this command's child process and inherits its environment (``HF_TOKEN``, then ``HUGGINGFACE_TOKEN``, then the token saved by @@ -51,7 +61,12 @@ from pathlib import Path from typing import TYPE_CHECKING, Any, Protocol -from microcosm_emitter_interface import PromoteBuild, PublishRelease, ReleaseFile +from microcosm_emitter_interface import ( + CollectorProvenance, + PromoteBuild, + PublishRelease, + ReleaseFile, +) from microcosm_emitter_interface.publication import ( ReleaseChange, ReleaseReceipt, @@ -60,12 +75,14 @@ from microcosm_emitter_interface.releases import is_pointer_file from microcosm.build.staging_dataset import ( - RECEIPT_POLL_SECONDS, # noqa: F401 (used by the change) + COLLECTOR_SUBMISSION_WAIT_SECONDS, + RECEIPT_POLL_SECONDS, + follow_collector_submissions, hub_offline, write_access_problem, ) from microcosm.build.telemetry_emitter import start_bundle_emitter -from microcosm.data.contract import publishes_to_build_folder +from microcosm.data.contract import US_RELEASES, publishes_to_build_folder from microcosm.data.publish_cli import publication_refusal from microcosm.data.release import ( TAGGED_RELEASE_ADVICE, @@ -78,14 +95,19 @@ if TYPE_CHECKING: from microcosm_emitter_interface import EmitterStartupError, RequestFailure from microcosm_emitter_interface.bundles import WriteAccess + from microcosm_emitter_interface.submissions import CollectorSubmissionReceipt __all__ = [ "PROMOTION_WAIT_SECONDS", "PUBLICATION_WAIT_SECONDS", + "UK_COLLECTOR_COUNTRY_CODE", + "US_COLLECTOR_COUNTRY_CODE", "ReleaseEmitter", "ReleasePublication", + "collector_provenance", "main", "promote_release_build", + "publication_request", "publish_release_build", ] @@ -156,20 +178,51 @@ def promote_build( self, request: PromoteBuild, *, wait_seconds: float = 60.0 ) -> ReleaseReceipt: ... + def collector_submission_receipt( + self, handover_id: str + ) -> CollectorSubmissionReceipt | None: ... + def close(self) -> None: ... #: Starts the short-lived emitter a publication uses (only its Hugging Face #: module); tests replace it. _start_release_emitter = start_bundle_emitter +#: The clock and sleep of the wait for the collector; tests replace them. _clock = time.monotonic _sleep = time.sleep +#: The country codes a publication's collector provenance names: those the +#: collector's calibration tree handler registers each country's release +#: repository under. The UK's is ``UK``, as UK staged bundles name it +#: (``uk_runtime.rowwise_staging.UK_COLLECTOR_COUNTRY_CODE``), not the +#: telemetry's ``GB``. UK_COLLECTOR_COUNTRY_CODE = "UK" US_COLLECTOR_COUNTRY_CODE = "US" -def collector_provenance(release: str, build: str) -> Any: - return None +def collector_provenance(release: str, build: str) -> CollectorProvenance | None: + """The collector's provenance of a build of ``release``, or None. + + It names the publication's own release and build, as the interface + requires, since the collector refuses a build folder whose provenance + names another. A UK build (the national, dense and local-area releases) + used licensed microdata, so the collector keeps its Orrery outputs + private; a US build is published in the public US repository, so it used + none whose licence keeps its outputs private. None for a release whose + builds do not publish into their own folders. The interface raises + ``ValueError`` for a build ID it does not accept. + """ + if not publishes_to_build_folder(release): + return None + us_build = release in US_RELEASES + return CollectorProvenance( + country_code=US_COLLECTOR_COUNTRY_CODE + if us_build + else UK_COLLECTOR_COUNTRY_CODE, + build_id=build, + licensed_data=not us_build, + release=release, + ) @dataclass(frozen=True) @@ -180,6 +233,9 @@ class ReleasePublication: current: a promotion, or a publication with ``make_current``. ``problem`` says why nothing was handed over, when the emitter could not take the change or its write-access check refused it. + ``collector_receipt`` is the emitter's last collector receipt of a + publication, or None for a promotion, a change handed nothing, or a + publication the emitter has no collector row for. """ repository: str @@ -188,7 +244,7 @@ class ReleasePublication: wanted_current: bool receipt: ReleaseReceipt problem: str | None = None - collector_receipt: Any = None + collector_receipt: CollectorSubmissionReceipt | None = None @property def published(self) -> bool: @@ -248,7 +304,14 @@ def as_json(self) -> dict[str, Any]: "message": self.receipt.get("message"), "commit": self.receipt.get("commit"), "handover_id": self.receipt.get("handover_id"), - "collector_submission": None, + "collector_submission": ( + None + if self.collector_receipt is None + else { + "status": self.collector_receipt.get("status"), + "error_code": self.collector_receipt.get("error_code"), + } + ), } @@ -258,9 +321,11 @@ def _hand_over( client: ReleaseEmitter | None, wait_seconds: float, wanted_current: bool, + collector_wait_seconds: float = COLLECTOR_SUBMISSION_WAIT_SECONDS, ) -> ReleasePublication: owned = client is None emitter: ReleaseEmitter = _start_release_emitter() if owned else client + collector_receipt: CollectorSubmissionReceipt | None = None try: # The staged-bundle hand-over's check: the emitter is running with its # Hugging Face module, and its credential can write the repository. @@ -275,6 +340,22 @@ def _hand_over( receipt = unavailable_release_receipt(change) elif isinstance(change, PublishRelease): receipt = emitter.publish_release(change, wait_seconds=wait_seconds) + if change.collector is not None and receipt["status"] != "unavailable": + # Before the emitter closes: a closing emitter starts no new + # submission. + collector_receipt = follow_collector_submissions( + emitter, + change.handover_id(), + subject=f"build {change.build} of {change.release}", + wait_seconds=( + collector_wait_seconds + if receipt["status"] == "published" + else None + ), + poll_seconds=RECEIPT_POLL_SECONDS, + clock=_clock, + sleep=_sleep, + ) else: receipt = emitter.promote_build(change, wait_seconds=wait_seconds) finally: @@ -287,6 +368,7 @@ def _hand_over( wanted_current=wanted_current, receipt=receipt, problem=problem, + collector_receipt=collector_receipt, ) @@ -376,7 +458,10 @@ def _refuse_pointer_files(repository: str) -> None: def publication_request( prepared: BuildFolderRelease, *, make_current: bool ) -> PublishRelease: - """The ``publish_release`` request for a checked build.""" + """The ``publish_release`` request for a checked build. + + It names the build for the collector (:func:`collector_provenance`). + """ return PublishRelease( repository=prepared.repository, release=prepared.release, @@ -393,6 +478,7 @@ def publication_request( ) for item in prepared.files ], + collector=collector_provenance(prepared.release, prepared.build), ) @@ -424,6 +510,7 @@ def publish_release_build( wait_seconds: float = PUBLICATION_WAIT_SECONDS, parent_h5: Path | str | None = None, compatibility_wheels: tuple[Path | str, ...] = (), + collector_wait_seconds: float = COLLECTOR_SUBMISSION_WAIT_SECONDS, ) -> ReleasePublication: """Check a build and hand it to the emitter to publish into its folder. @@ -438,7 +525,9 @@ def publish_release_build( files; it hands nothing over unless the emitter's write-access check passes. A recertification is handed over only once the Hub shows its parent published with the manifest it carries, as the tagged publisher - required, and never with ``make_current``. + required, and never with ``make_current``. Once the publication has + landed, it waits at most ``collector_wait_seconds`` for the collector to + accept the build's submissions. """ if client is None: _refuse_offline() @@ -476,6 +565,7 @@ def publish_release_build( client=client, wait_seconds=wait_seconds, wanted_current=make_current, + collector_wait_seconds=collector_wait_seconds, ) diff --git a/packages/microcosm-build/src/microcosm/build/staging_dataset.py b/packages/microcosm-build/src/microcosm/build/staging_dataset.py index a33ea7fe9b..200657bd09 100644 --- a/packages/microcosm-build/src/microcosm/build/staging_dataset.py +++ b/packages/microcosm-build/src/microcosm/build/staging_dataset.py @@ -19,7 +19,10 @@ ``copied_files`` (:meth:`StagedBundleHandOver.may_rewrite`). A hand-over that names its build (``collector``, a ``CollectorProvenance``) also asks the emitter to submit the bundle's calibration diagnostics to the collector once -its commit lands, while the emitter's collector submissions are on. +its commit lands; every emitter a build starts has its collector submissions +on. Once the commit has landed, the build waits until the collector accepts +them (:func:`follow_collector_submissions`), since an emitter that is closing +starts no new submission. The module knows nothing about a country's manifest beyond the ``outputs`` mapping shape ``{name: {"path", "sha256", "bytes"}}``; callers pass the manifest @@ -39,7 +42,7 @@ from collections.abc import Callable, Mapping, Sequence from dataclasses import dataclass from pathlib import Path, PurePosixPath -from typing import Any, Final, Literal, TypedDict, cast, get_args +from typing import Any, Final, Literal, Protocol, TypedDict, cast, get_args from microcosm_emitter_interface import ( BundleFile, @@ -55,11 +58,13 @@ unavailable_bundle_receipt, ) from microcosm_emitter_interface.identifiers import repository_identifier +from microcosm_emitter_interface.submissions import CollectorSubmissionReceipt from microcosm.build.staging_storage import HuggingFaceDatasetStorage from microcosm.build.telemetry_emitter import BundleEmitter, emitter_problem __all__ = [ + "COLLECTOR_SUBMISSION_WAIT_SECONDS", "DEFAULT_STAGED_DATASET_PREFIX", "AT_BUILD_RECORD_KEY", "HANDOVER_RECORD_KEY", @@ -72,6 +77,7 @@ "STAGED_MANIFEST_FILENAME", "STAGED_MANIFEST_SCHEMA", "BundleEmitter", + "CollectorReceipts", "StagedBundleHandOver", "StagedDatasetBundle", "StagedDatasetDelivery", @@ -83,6 +89,7 @@ "delivery_covers_bundle", "disabled_staged_dataset", "fetch_bundle", + "follow_collector_submissions", "handover_record", "hub_offline", "local_only_staged_dataset", @@ -119,7 +126,37 @@ RESTAGE_WAIT_SECONDS = 10800.0 #: How often the build asks the emitter for the bundle's receipt meanwhile. RECEIPT_POLL_SECONDS = 1.0 +#: How long the build waits, once a described bundle or publication has +#: landed on Hugging Face, for the collector to accept its submissions. The +#: emitter's collector row may have retried every five minutes while it +#: waited for the commit, and its next attempt then uploads the files, so +#: ten minutes covers one attempt after the commit. The wait also ends at +#: that attempt when it fails. An emitter that is closing starts no new +#: submission; one still queued then is sent by the next emitter started on +#: the machine. COLLECTOR_SUBMISSION_WAIT_SECONDS = 600.0 +#: A collector receipt's ``pending`` code while the bundle's or publication's +#: Hugging Face commit has not landed. +_WAITING_FOR_HUGGING_FACE = "WAITING_FOR_HUGGING_FACE" +#: What each ``skipped`` code of a collector receipt means. +_SKIPPED_REASONS: Final[Mapping[str, str]] = { + "COLLECTOR_SETTINGS_REFUSED": ( + "the emitter refused its collector settings or the collector-token " + "variables it inherits" + ), + "COLLECTOR_FOLDER_TOO_LONG": ( + "its Hugging Face folder is longer than the collector accepts" + ), + "NOT_STAGED_ON_HUGGING_FACE": "Hugging Face refused it", + "NOT_PUBLISHED_ON_HUGGING_FACE": "Hugging Face refused it", +} +#: Added to a ``COLLECTOR_SETTINGS_REFUSED`` warning. +_SETTINGS_REFUSED_ADVICE = ( + " The emitter's own warning gives the error type. Check " + "MICROCOSM_COLLECTOR_TOKEN, MICROCOSM_COLLECTOR_TOKEN_EXPIRES_AT and " + "MICROCOSM_COLLECTOR_ORIGIN, which are set together or not at all; " + "without them the emitter uses the Hugging Face credential." +) _MODES = ("local_and_remote", "local_only", "disabled") _STATUSES = ("uploaded", "already_staged", "failed", "skipped") @@ -207,6 +244,10 @@ _HEXADECIMAL_TOKEN = re.compile(r"^(?=[0-9a-f]*[0-9])[0-9a-f]{8,}$") #: An emitter's own error code, printed only when it has this shape. _EMITTER_CODE = re.compile(r"^[A-Z][A-Z0-9_]{0,63}$") +#: A collector receipt's code, printed only when it has this shape: the +#: emitter's codes, or the collector's own, which are lower case +#: (``content_mismatch``). +_COLLECTOR_CODE = re.compile(r"^[A-Za-z][A-Za-z0-9_]{0,63}$") class StagedDatasetError(ValueError): @@ -824,7 +865,9 @@ class StagedBundleHandOver: handover_id: str | None = None #: The run directory the hand-over names its files in. run_dir: str | None = None - collector_receipt: Any = None + #: The emitter's last collector receipt of the hand-over, or None when + #: the build asked for none or the emitter has no collector row for it. + collector_receipt: CollectorSubmissionReceipt | None = None def may_rewrite(self, name: str) -> bool: """Whether the build may change ``name`` in the run directory now.""" @@ -996,6 +1039,126 @@ def _minutes(seconds: float) -> str: return f"{seconds / 60:g} minutes" +def _attempted_after_commit( + receipt: Mapping[str, Any], earlier_attempts: object +) -> bool: + """Whether an attempt that found the Hugging Face commit has finished.""" + attempts = receipt.get("attempts") + return ( + isinstance(attempts, int) + and isinstance(earlier_attempts, int) + and attempts > earlier_attempts + and receipt.get("error_code") != _WAITING_FOR_HUGGING_FACE + ) + + +def _collector_warning(receipt: Mapping[str, Any], subject: str) -> str | None: + """What the build says about a collector receipt, or None.""" + status = receipt.get("status") + raw_code = receipt.get("error_code") + code = ( + raw_code + if isinstance(raw_code, str) and _COLLECTOR_CODE.fullmatch(raw_code) + else None + ) + if status == "skipped": + reason = _SKIPPED_REASONS.get(str(code), "the emitter skipped them") + advice = ( + _SETTINGS_REFUSED_ADVICE if code == "COLLECTOR_SETTINGS_REFUSED" else "" + ) + return ( + f"the collector receives nothing of {subject}: {reason} " + f"({code or 'no code'}).{advice}" + ) + if status == "rejected": + return ( + f"the collector rejected the submissions of {subject} " + f"({code or 'no code'})." + ) + if status == "failed": + return ( + f"the submissions of {subject} to the collector failed " + f"({code or 'no code'})." + ) + if status == "pending": + detail = f" ({code})" if code else "" + return ( + f"the collector had not accepted the submissions of {subject} when " + f"the build stopped waiting{detail}; the emitter keeps them queued, " + "and it or the next emitter started on this machine sends them." + ) + return None + + +class CollectorReceipts(Protocol): + """The emitter calls :func:`follow_collector_submissions` makes.""" + + @property + def available(self) -> bool: ... + + def collector_submission_receipt( + self, handover_id: str + ) -> CollectorSubmissionReceipt | None: ... + + +def follow_collector_submissions( + emitter: CollectorReceipts, + handover_id: str, + *, + subject: str, + wait_seconds: float | None, + poll_seconds: float = RECEIPT_POLL_SECONDS, + clock: Callable[[], float] = time.monotonic, + sleep: Callable[[float], None] = time.sleep, +) -> CollectorSubmissionReceipt | None: + """The hand-over's collector receipt, once the collector has taken it. + + ``wait_seconds`` is None for a hand-over whose Hugging Face commit has + not landed: its submissions wait for the commit, so the build asks once, + and warns only when the collector will receive nothing. Otherwise the + build waits, at most ``wait_seconds``, while the receipt is ``pending``, + until an attempt that found the commit has finished: one that the + collector accepted ends ``pending``, and one that failed is retried by + the emitter. Any answer but an accepted or succeeded one is a warning + naming ``subject``. None, without a warning, when the emitter has no + collector row for the hand-over (it named no build, or no file the + collector takes) or does not answer. + """ + + if not emitter.available: + return None + receipt = emitter.collector_submission_receipt(handover_id) + if receipt is None: + return None + if wait_seconds is not None: + earlier_attempts = receipt.get("attempts") + deadline = clock() + max(0.0, float(wait_seconds)) + while ( + receipt.get("status") == "pending" + and not _attempted_after_commit(receipt, earlier_attempts) + and clock() < deadline + ): + sleep(poll_seconds) + latest = emitter.collector_submission_receipt(handover_id) + if latest is None: + break + receipt = latest + elif receipt.get("status") == "pending": + return receipt + warning = _collector_warning(receipt, subject) + if warning is not None: + _warn(warning) + return receipt + + +def _staged_subject(remote_prefix: str) -> str: + return f"the staged dataset bundle {remote_prefix}" + + +def _landed(delivery: Mapping[str, Any]) -> bool: + return delivery["status"] in ("uploaded", "already_staged") + + def _delivery_from_receipt( record: Mapping[str, Any], receipt: Mapping[str, Any], @@ -1150,7 +1313,10 @@ def stage_bundle( this run, if any; a ``REMOTE_DIFFERS`` warning then says when the folder may hold that bundle. ``collector`` names the build, so the emitter also submits the bundle's calibration diagnostics to the collector (see - :func:`bundle_request`). + :func:`bundle_request`); once the commit has landed, the build waits at + most ``collector_wait_seconds`` for the collector to accept them + (:func:`follow_collector_submissions`), and only asks whether it will + receive them otherwise. The emitter writes every file under ``//`` in one commit, idempotent on the outputs' digests (``already_staged``, or @@ -1217,12 +1383,25 @@ def stage_bundle( ) if answer.get("status") not in _QUEUED_STATUSES: return StagedBundleHandOver(delivery) + handover_id = _handover_id(answer) + collector_receipt = None + if collector is not None and emitter is not None and handover_id is not None: + collector_receipt = follow_collector_submissions( + emitter, + handover_id, + subject=_staged_subject(remote_prefix), + wait_seconds=collector_wait_seconds if _landed(delivery) else None, + poll_seconds=poll_seconds, + clock=clock, + sleep=sleep, + ) return StagedBundleHandOver( delivery, handed_over=frozenset(item.name for item in request.files), copied_files=_copied_files(answer, receipt), - handover_id=_handover_id(answer), + handover_id=handover_id, run_dir=str(bundle.run_dir), + collector_receipt=collector_receipt, ) @@ -1295,6 +1474,10 @@ def resume_hand_over( cache directory), or when a hand-over that has not landed can never finish: its files changed, or a file it reads is gone from the recorded run directory (the directory moved). + + The collector's receipt is followed as :func:`stage_bundle` follows it: + a hand-over that named its build and has landed waits at most + ``collector_wait_seconds`` for the collector to accept its submissions. """ handover_id = str(record.get("handover_id")) @@ -1342,12 +1525,22 @@ def resume_hand_over( if run_dir == str(bundle.run_dir) else frozenset() ) + collector_receipt = follow_collector_submissions( + emitter, + handover_id, + subject=_staged_subject(bundle.remote_prefix(prefix)), + wait_seconds=collector_wait_seconds if _landed(delivery) else None, + poll_seconds=poll_seconds, + clock=clock, + sleep=sleep, + ) return StagedBundleHandOver( delivery, handed_over=handed_over, copied_files=_copied_files(receipt, receipt), handover_id=handover_id, run_dir=run_dir, + collector_receipt=collector_receipt, ) diff --git a/packages/microcosm-build/src/microcosm/build/telemetry_emitter.py b/packages/microcosm-build/src/microcosm/build/telemetry_emitter.py index 5ea5a52b52..5e5750bfad 100644 --- a/packages/microcosm-build/src/microcosm/build/telemetry_emitter.py +++ b/packages/microcosm-build/src/microcosm/build/telemetry_emitter.py @@ -14,6 +14,13 @@ process arguments. No call raises into the build: a missing, slow, refusing or outdated emitter leaves the build running without it. +Every emitter the adapter starts has its Hugging Face module's collector +submissions switched on (``COLLECTOR_SUBMISSIONS``): a staged bundle or +release publication that names its build (``CollectorProvenance``) is also +submitted to the collector after its Hugging Face commit, with the same +credential. The emitter's own default leaves them off, so switching them +off again is a change here, not an emitter release. + Starting the adapter is the exception, and only through ``MICROCOSM_TELEMETRY_REQUIRED``. With ``1`` (a build that must send telemetry) it raises ``TelemetryRequiredError`` when the emitter cannot be @@ -67,6 +74,7 @@ unavailable_receipt, ) from microcosm_emitter_interface.protocol import HUGGING_FACE_MODULE, TELEMETRY_MODULE +from microcosm_emitter_interface.submissions import CollectorSubmissionReceipt from microcosm_emitter_interface.telemetry import ( DEFAULT_FAILURE_CLASS, DEFAULT_HEARTBEAT_SECONDS, @@ -78,6 +86,7 @@ from microcosm.build.telemetry_identity import runtime_identity __all__ = [ + "COLLECTOR_SUBMISSIONS", "DEFAULT_HEARTBEAT_SECONDS", "MINIMUM_EMITTER_VERSION", "TELEMETRY_REQUIRED_VARIABLE", @@ -88,6 +97,7 @@ "TelemetryRequiredError", "TelemetryRun", "emitter_problem", + "hugging_face_settings", "publication_inventory", "publish_graph", "start_bundle_emitter", @@ -128,15 +138,24 @@ def _packaged_minimum_emitter_version() -> str: return version -#: The oldest emitter release a build starts: 0.13.0 since 2026-11-05, the -#: newest release then. 0.13.0 added ``microcosm-emitter status``, which the -#: Modal stage runner runs in the container after a stage's tool to record how -#: many telemetry events each run left undelivered, so the image needs it; a -#: build requires the same release, so that the release is written once +#: The oldest emitter release a build starts: 0.15.0 since 2026-11-13, the +#: newest release then. 0.15.0 adds the Hugging Face module's setting that +#: switches collector submissions on (``hugging_face_settings``), collector +#: provenance on a release publication, which it submits after the release +#: commit, and a ``skipped`` collector receipt with an error code when it +#: refuses its collector settings. An older emitter accepts the setting but +#: drops a publication's provenance, so it would submit no release, and its +#: hand-over ID differs from the interface's. 0.14.0, from 2026-11-09, added +#: the build machine's readings. 0.13.0, from 2026-11-05, added +#: ``microcosm-emitter status``, which the Modal stage runner runs in the +#: container after a stage's tool to record how many telemetry events each +#: run left undelivered, so the image needs it; a build requires the same +#: release, so that the release is written once #: (``MINIMUM_EMITTER_VERSION_RESOURCE``). Practically no machine ran the -#: separately installed emitter yet, so refusing 0.11.9 to 0.12.5 cost -#: nothing then. Earlier floors: 0.11.9 from 2026-11-02, because since 0.10.0 -#: the emitter sends to the collector's hostname by default, which stays the +#: separately installed emitter at any of these rises, so refusing the +#: releases before them cost nothing. Earlier floors: 0.11.9 from +#: 2026-11-02, because since 0.10.0 the emitter sends to the collector's +#: hostname by default, which stays the #: same when the collector moves to another Google Cloud project, while #: earlier releases send to its Cloud Run address, which changes with the #: move; 0.11.1 fixed two cases in which the telemetry module stopped. A @@ -593,6 +612,10 @@ def dataset_bundle_receipt( self, handover_id: str ) -> DatasetBundleReceipt | None: ... + def collector_submission_receipt( + self, handover_id: str + ) -> CollectorSubmissionReceipt | None: ... + def check_write_access(self, repository: str) -> WriteAccess: ... def close(self) -> None: ... @@ -725,10 +748,7 @@ def start( heartbeat_seconds=heartbeat_seconds, ), orrery=OrrerySettings(development_collector_url=development_collector_url), - # Its queue is the hand-over database beside the spool database - # (``events.handovers.sqlite3``), so emitters of every release can - # share the spool database on one machine. - hugging_face=HuggingFaceSettings(), + hugging_face=hugging_face_settings(development_collector_url), spool_path=path, startup_timeout=startup_timeout_seconds, ) @@ -895,6 +915,31 @@ def publish_graph( ) +#: Whether the emitters a build starts submit described staged bundles and +#: release publications to the collector. On since emitter 0.15.0 +#: (2026-11-13), whose default leaves them off: switching them off again is +#: this change, not an emitter release. +COLLECTOR_SUBMISSIONS = True + + +def hugging_face_settings( + development_collector_url: str | None = None, +) -> HuggingFaceSettings: + """The Hugging Face module's settings for every emitter a build starts. + + Its queue is the hand-over database beside the spool database + (``events.handovers.sqlite3``), so emitters of every release can share + the spool database on one machine. Collector submissions are switched + on (``COLLECTOR_SUBMISSIONS``) and go to the production collector, or to + ``development_collector_url``, a loopback collector for tests and local + development, as telemetry and Orrery graph publication do. + """ + return HuggingFaceSettings( + collector_submissions=COLLECTOR_SUBMISSIONS, + development_collector_url=development_collector_url, + ) + + def _orrery_emitter() -> EmitterClient: """A short-lived emitter that runs only the Orrery module.""" return _start_emitter( @@ -907,13 +952,15 @@ def start_bundle_emitter( ) -> EmitterClient: """A short-lived emitter with only the Hugging Face module. - A command that stages a finished run's bundle, outside any build, uses - it; the caller closes it. Its hand-over queue is the one builds on this - machine share (``events.handovers.sqlite3``), so it also resumes their - queued hand-overs. + A command that stages a finished run's bundle or publishes a release, + outside any build, uses it; the caller closes it. Its hand-over queue is + the one builds on this machine share (``events.handovers.sqlite3``), so + it also resumes their queued hand-overs. Its collector submissions are on, + as a build's are (:func:`hugging_face_settings`). """ return _start_emitter( - hugging_face=HuggingFaceSettings(), startup_timeout=STARTUP_TIMEOUT_SECONDS + hugging_face=hugging_face_settings(development_collector_url), + startup_timeout=STARTUP_TIMEOUT_SECONDS, ) diff --git a/packages/microcosm-build/src/microcosm/build/uk_runtime/rowwise_staging.py b/packages/microcosm-build/src/microcosm/build/uk_runtime/rowwise_staging.py index 654f017f51..e7ef534168 100644 --- a/packages/microcosm-build/src/microcosm/build/uk_runtime/rowwise_staging.py +++ b/packages/microcosm-build/src/microcosm/build/uk_runtime/rowwise_staging.py @@ -13,8 +13,9 @@ module makes no Hugging Face call. A build whose environment switches the Hub off (``HF_HUB_OFFLINE``, as on Modal) keeps its bundle local. The bundle's hand-over names the build for the collector (:func:`collector_provenance`), -so the emitter submits its calibration diagnostics there once the bundle's -commit lands, while its collector submissions are on. +so the emitter, whose collector submissions are on, submits its calibration +diagnostics there once the bundle's commit lands, and the build waits for the +collector to accept them (``staging_dataset.follow_collector_submissions``). """ from __future__ import annotations diff --git a/packages/microcosm-build/tests/engine_free/shared/test_staging_dataset.py b/packages/microcosm-build/tests/engine_free/shared/test_staging_dataset.py index feff28fd03..6f50c58ed5 100644 --- a/packages/microcosm-build/tests/engine_free/shared/test_staging_dataset.py +++ b/packages/microcosm-build/tests/engine_free/shared/test_staging_dataset.py @@ -744,25 +744,35 @@ def test_submissions_not_accepted_when_the_wait_ends_stay_queued(tmp_path, capsy @pytest.mark.parametrize( - ("status", "warned"), - [("rejected", "rejected"), ("failed", "failed")], + ("status", "code", "warned"), + [ + ( + "rejected", + "content_mismatch", + "the collector rejected the submissions of the staged dataset bundle " + f"staged/{RUN_ID} (content_mismatch).", + ), + ( + "failed", + "COLLECTOR_REFUSED_422", + f"the submissions of the staged dataset bundle staged/{RUN_ID} to the " + "collector failed (COLLECTOR_REFUSED_422).", + ), + ], ) def test_a_submission_the_collector_turned_down_is_a_warning( - tmp_path, capsys, status, warned + tmp_path, capsys, status, code, warned ): bundle = _bundle(tmp_path) emitter = FakeEmitterClient( hub_api=FakeHub(tmp_path), - collector_receipts=[{"status": status, "error_code": "content_mismatch"}], + collector_receipts=[{"status": status, "error_code": code}], ) staged = _stage(bundle, emitter, collector=PROVENANCE) assert staged.delivery["status"] == "uploaded" - assert ( - f"warning: the collector {warned} the submissions of the staged dataset " - f"bundle staged/{RUN_ID} (content_mismatch)." in capsys.readouterr().err - ) + assert f"warning: {warned}" in capsys.readouterr().err def test_a_bundle_that_has_not_landed_is_asked_about_once_and_not_waited_for( diff --git a/tools/installed-emitter/requirements.txt b/tools/installed-emitter/requirements.txt index 910a692923..4890c25c80 100644 --- a/tools/installed-emitter/requirements.txt +++ b/tools/installed-emitter/requirements.txt @@ -4,4 +4,4 @@ # it, and tools/run_installed_emitter_tests.sh installs exactly this release and # warns when the package index has a newer one. Raise it in a pull request when # the emitter publishes a release. -microcosm-emitter==0.14.0 +microcosm-emitter==0.15.0 diff --git a/tools/stage_uk_rowwise_candidate.py b/tools/stage_uk_rowwise_candidate.py index e248cdce02..74f5ad40d9 100644 --- a/tools/stage_uk_rowwise_candidate.py +++ b/tools/stage_uk_rowwise_candidate.py @@ -69,9 +69,11 @@ the one ``staged_manifest.json`` records, else the same build ID; so ``--local-only`` stops on those rows too. The release is the manifest's ``release_id``. -The emitter then submits the bundle's calibration diagnostics to the -collector once the commit lands, while its collector submissions are on. A -hand-over the command resumes keeps what the build named. +The emitter, whose collector submissions are on, then submits the bundle's +calibration diagnostics to the collector once the commit lands, and the +command waits up to ten minutes for the collector to accept them before it +closes the emitter. A hand-over the command resumes keeps what the build +named, and its collector receipt is followed the same way. Staging is not publication: ``releases/`` and ``latest.json`` are untouched. """ From 520c3427c409956e95175336ab7bce67184e6a94 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Fri, 13 Nov 2026 01:22:00 +0400 Subject: [PATCH 3/9] Shorten the collector submissions changelog entry Co-Authored-By: Claude Opus 5.5 --- changelog.d/1599-collector-submissions-on.added.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/1599-collector-submissions-on.added.md b/changelog.d/1599-collector-submissions-on.added.md index 12d91280cd..da824518d1 100644 --- a/changelog.d/1599-collector-submissions-on.added.md +++ b/changelog.d/1599-collector-submissions-on.added.md @@ -1 +1 @@ -Builds now send their calibration diagnostics to the collector, at staging and at release (microcosm#1599). Builds and the Modal image require microcosm-emitter 0.15.0 or later instead of 0.14.0: 0.15.0 adds the Hugging Face module's setting that switches collector submissions on, collector provenance on a release publication, and a `skipped` collector receipt with an error code when the emitter refuses its collector settings. microcosm-build's `microcosm-emitter-interface` pin rises from `>=0.14.0,<1` to `>=0.15.0,<1` (the lock moves from 0.14.0 to 0.15.0, and `APPROVED_UV_LOCK_SHA256` is re-pinned for the new lock), and the installed-emitter job's pin rises to 0.15.0. Every emitter a build, the UK re-stage command or the release publication command starts has its collector submissions on (`telemetry_emitter.COLLECTOR_SUBMISSIONS`); the emitter's own default leaves them off, so switching them off again is a Microcosm change. A loopback collector given for telemetry (`development_collector_url`) takes the submissions too. UK staged bundles, which already name their build, are submitted after their Hugging Face commit. `microcosm-publish-release-build` names each build for the collector, country `UK` with licensed data for the UK national, dense and local-area releases and `US` without for the US releases, with the publication's own release and build, so the emitter submits the build's calibration diagnostics and manifests after the release commit under `releases//`; the collector's calibration tree handler registers both countries' release repositories. Once a described bundle or publication has landed, the build or command waits up to ten minutes for the collector to accept the submissions, since an emitter that is closing starts no new submission; an attempt after the commit that fails ends the wait sooner, and a hand-over that has not landed is asked about once. A `skipped` receipt (`COLLECTOR_SETTINGS_REFUSED`, `COLLECTOR_FOLDER_TOO_LONG`, or Hugging Face's refusal), a rejected or failed submission, and submissions still queued when the wait ends are warnings, and never fail a staging or a publication; the publication command prints the collector receipt's `status` and `error_code` as `collector_submission`. The installed-emitter tests send the emitter's collector submissions to a closed loopback port. +Builds now send their calibration diagnostics to the collector at staging and at release (microcosm#1599). Builds and the Modal image require microcosm-emitter 0.15.0 instead of 0.14.0, and microcosm-build's `microcosm-emitter-interface` pin rises to `>=0.15.0,<1` (the lock and `APPROVED_UV_LOCK_SHA256` follow, as does the installed-emitter job's pin). Every emitter Microcosm starts has its collector submissions on. `microcosm-publish-release-build` names each build for the collector (UK builds as licensed, US builds as not), so the emitter submits its calibration diagnostics after the release commit. Once a staged bundle or publication has landed, the build or command waits up to ten minutes for the collector to accept them, and warns without failing when the collector receives nothing (`skipped`), turns them down or has not accepted them yet; the publication command prints the collector's status as `collector_submission`. From f73357e964d8eb90187f55f10ea0b6b7cf7b2632 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Fri, 13 Nov 2026 01:56:09 +0400 Subject: [PATCH 4/9] Test review round 1's points on collector receipts Failing tests for microcosm#1600's review round 1: - the build and the release command say what they wait for once the bundle or publication is on Hugging Face; - the release command asks for the collector receipt by the hand-over ID the emitter's receipt names; - a timed-out submission is a warning; - the "not on Hugging Face" codes say the upload failed or was refused, and the COLLECTOR_SETTINGS_REFUSED advice says submissions use the Hugging Face credential, never a given collector token. Six cases fail, all on assertions. New coverage that passes already: an emitter that stops answering ends the wait, a receipt without a usable attempt count waits the whole time, a published build without a collector row is not waited for, and the installed-emitter re-stage test asserts that the closed collector port ended the wait. The fake emitter can now answer None for a collector receipt. Co-Authored-By: Claude Opus 5.5 --- .../shared/test_staging_dataset.py | 65 ++++++++++++++++++- .../uk/test_uk_release_publication.py | 46 ++++++++++++- .../shared/test_installed_emitter_staging.py | 14 +++- test_support/microcosm_build/emitter.py | 11 ++-- 4 files changed, 128 insertions(+), 8 deletions(-) diff --git a/packages/microcosm-build/tests/engine_free/shared/test_staging_dataset.py b/packages/microcosm-build/tests/engine_free/shared/test_staging_dataset.py index 6f50c58ed5..d9ff32795d 100644 --- a/packages/microcosm-build/tests/engine_free/shared/test_staging_dataset.py +++ b/packages/microcosm-build/tests/engine_free/shared/test_staging_dataset.py @@ -633,7 +633,13 @@ def test_a_described_bundle_waits_until_the_collector_accepts_its_submissions( assert clock.slept == [staging_dataset.RECEIPT_POLL_SECONDS] * 2 assert staged.collector_receipt is not None assert staged.collector_receipt["status"] == "awaiting_final_status" - assert "warning" not in capsys.readouterr().err + err = capsys.readouterr().err + # The build says what it waits for, since the bundle has already landed. + assert ( + f"the staged dataset bundle staged/{RUN_ID} is on Hugging Face; waiting " + "up to 10 minutes for the collector to accept its submissions..." in err + ) + assert "warning" not in err def test_the_first_failed_attempt_after_the_commit_ends_the_wait(tmp_path, capsys): @@ -683,7 +689,7 @@ def test_the_first_failed_attempt_after_the_commit_ends_the_wait(tmp_path, capsy "COLLECTOR_FOLDER_TOO_LONG", "its Hugging Face folder is longer than the collector accepts", ), - ("NOT_STAGED_ON_HUGGING_FACE", "Hugging Face refused it"), + ("NOT_STAGED_ON_HUGGING_FACE", "its Hugging Face upload failed or was refused"), ("A_CODE_FROM_A_LATER_EMITTER", "the emitter skipped them"), ], ) @@ -707,6 +713,15 @@ def test_a_skipped_collector_receipt_is_a_warning_and_the_bundle_stays_staged( f"warning: the collector receives nothing of the staged dataset bundle " f"staged/{RUN_ID}: {explanation} ({code})." in warning ) + # Submissions use the Hugging Face credential: a collector token given + # in the environment only sends telemetry, so the advice never says to + # set one. + advice = ( + "Collector submissions use the Hugging Face credential; a collector " + "token given in MICROCOSM_COLLECTOR_TOKEN only sends telemetry." + ) + assert (advice in warning) is (code == "COLLECTOR_SETTINGS_REFUSED") + assert "set together" not in warning def test_submissions_not_accepted_when_the_wait_ends_stay_queued(tmp_path, capsys): @@ -758,6 +773,13 @@ def test_submissions_not_accepted_when_the_wait_ends_stay_queued(tmp_path, capsy f"the submissions of the staged dataset bundle staged/{RUN_ID} to the " "collector failed (COLLECTOR_REFUSED_422).", ), + ( + "timed_out", + "FINAL_STATUS_TIMED_OUT", + "the collector gave no final status for the submissions of the staged " + f"dataset bundle staged/{RUN_ID} within a day of accepting them " + "(FINAL_STATUS_TIMED_OUT).", + ), ], ) def test_a_submission_the_collector_turned_down_is_a_warning( @@ -775,6 +797,45 @@ def test_a_submission_the_collector_turned_down_is_a_warning( assert f"warning: {warned}" in capsys.readouterr().err +def test_an_emitter_that_stops_answering_ends_the_wait(tmp_path, capsys): + bundle = _bundle(tmp_path) + emitter = FakeEmitterClient( + hub_api=FakeHub(tmp_path), + collector_receipts=[{"status": "pending", "attempts": 1}, None], + ) + + staged = _stage(bundle, emitter, collector=PROVENANCE) + + assert len(emitter.collector_receipt_requests) == 2 + assert staged.collector_receipt["status"] == "pending" + assert "the collector had not accepted the submissions" in capsys.readouterr().err + + +@pytest.mark.parametrize("attempts", [None, "1"], ids=["missing", "text"]) +def test_a_receipt_without_a_usable_attempt_count_waits_the_whole_time( + tmp_path, attempts +): + bundle = _bundle(tmp_path) + receipt = { + "status": "pending", + "error_code": "COLLECTOR_UNAVAILABLE", + "attempts": attempts, + } + emitter = FakeEmitterClient(hub_api=FakeHub(tmp_path), collector_receipts=[receipt]) + clock = Clock() + + staging_dataset.stage_bundle( + bundle, + emitter=emitter, + repository=REPOSITORY, + clock=clock, + sleep=clock.sleep, + collector=PROVENANCE, + ) + + assert sum(clock.slept) == 600 + + def test_a_bundle_that_has_not_landed_is_asked_about_once_and_not_waited_for( tmp_path, capsys ): diff --git a/packages/microcosm-build/tests/engine_free/uk/test_uk_release_publication.py b/packages/microcosm-build/tests/engine_free/uk/test_uk_release_publication.py index 6886ed2f10..1c7b8ebfe9 100644 --- a/packages/microcosm-build/tests/engine_free/uk/test_uk_release_publication.py +++ b/packages/microcosm-build/tests/engine_free/uk/test_uk_release_publication.py @@ -249,7 +249,51 @@ def test_a_published_build_waits_until_the_collector_accepts_its_submissions( "error_code": None, } assert outcome.succeeded - assert "warning" not in capsys.readouterr().err + err = capsys.readouterr().err + assert ( + f"build {UK_NATIONAL_BUILD} of {UK_NATIONAL_RELEASE_ID} is on Hugging Face; " + "waiting up to 10 minutes for the collector to accept its submissions..." in err + ) + assert "warning" not in err + + +def test_the_collector_receipt_is_asked_for_by_the_emitters_hand_over_id( + national: Path, + artifact_root: Path, # noqa: F811 + clock: Clock, +) -> None: + """The emitter keeps the collector row under the hand-over ID its receipt + names, so that is the ID the command asks about.""" + emitter_handover_id = "f" * 32 + client = FakeEmitterClient( + release_receipts=[{"handover_id": emitter_handover_id}], + collector_receipts=[{"status": "succeeded", "attempts": 1}], + ) + + outcome = release_publication.publish_release_build( + national, artifact_root=artifact_root, client=client + ) + + assert client.collector_receipt_requests == [emitter_handover_id] + assert outcome.collector_receipt["status"] == "succeeded" + + +def test_a_published_build_the_emitter_has_no_collector_row_for_is_not_waited_for( + national: Path, + artifact_root: Path, # noqa: F811 + clock: Clock, +) -> None: + client = FakeEmitterClient() + + outcome = release_publication.publish_release_build( + national, artifact_root=artifact_root, client=client + ) + + assert len(client.collector_receipt_requests) == 1 + assert clock.slept == [] + assert outcome.collector_receipt is None + assert outcome.as_json()["collector_submission"] is None + assert outcome.succeeded def test_refused_collector_settings_are_reported_and_the_publication_succeeds( diff --git a/packages/microcosm-build/tests/installed_emitter/shared/test_installed_emitter_staging.py b/packages/microcosm-build/tests/installed_emitter/shared/test_installed_emitter_staging.py index 187c0d3cb1..9a60ff4ff1 100644 --- a/packages/microcosm-build/tests/installed_emitter/shared/test_installed_emitter_staging.py +++ b/packages/microcosm-build/tests/installed_emitter/shared/test_installed_emitter_staging.py @@ -419,7 +419,10 @@ def test_the_installed_emitter_uploads_the_bundle_in_one_commit( def test_a_modal_runs_copied_back_outputs_are_staged_by_the_re_stage_command( - tmp_path: Path, stand_in_hub: StandInHub, installed_emitter: InstalledEmitter + tmp_path: Path, + stand_in_hub: StandInHub, + installed_emitter: InstalledEmitter, + capsys: pytest.CaptureFixture[str], ) -> None: """After ``modal volume get``, the UK re-stage command checks the build manifest and the outputs against the stage's receipt, starts the installed @@ -478,6 +481,15 @@ def test_a_modal_runs_copied_back_outputs_are_staged_by_the_re_stage_command( ) assert staged["run_id"] == RUN_ID assert manifest["staged_dataset_handover"]["run_dir"] == str(copied.resolve()) + # The hand-over names the build, so after the commit the command waited + # for the collector. The fixture's collector port is closed: the first + # attempt after the commit failed, which ended the wait, and the + # submissions stay queued. + assert ( + f"warning: the collector had not accepted the submissions of the staged " + f"dataset bundle {PREFIX} when the build stopped waiting " + "(COLLECTOR_UNAVAILABLE)" in capsys.readouterr().err + ) def test_a_commit_on_a_moved_head_is_refused_then_made_on_the_new_head( diff --git a/test_support/microcosm_build/emitter.py b/test_support/microcosm_build/emitter.py index 05ac3d5eb2..9f05685845 100644 --- a/test_support/microcosm_build/emitter.py +++ b/test_support/microcosm_build/emitter.py @@ -35,7 +35,7 @@ - ``collector_submission_receipt`` answers ``None``, as an emitter does whose collector submissions are off, unless ``collector_receipts`` scripts the answers for every hand-over (each ask takes the next one; the last one - repeats). + repeats; ``None`` stands for an emitter that does not answer). The emitter's own tests cover the process, its queues and the Hub. """ @@ -198,7 +198,7 @@ def __init__( deliver: bool = True, answer_receipts: bool = True, release_receipts: Sequence[Mapping[str, Any]] | None = None, - collector_receipts: Sequence[Mapping[str, Any]] | None = None, + collector_receipts: Sequence[Mapping[str, Any] | None] | None = None, ) -> None: self._modules = frozenset(modules) self.accept_run_files = accept_run_files @@ -779,7 +779,9 @@ def collector_submission_receipt(self, handover_id: str) -> dict[str, Any] | Non answers = self._collector_answers.setdefault( handover_id, [ - { + None + if receipt is None + else { "handover_id": handover_id, "destination": "collector", "status": "pending", @@ -791,7 +793,8 @@ def collector_submission_receipt(self, handover_id: str) -> dict[str, Any] | Non for receipt in self.collector_receipts ], ) - return dict(answers.pop(0) if len(answers) > 1 else answers[0]) + answer = answers.pop(0) if len(answers) > 1 else answers[0] + return None if answer is None else dict(answer) def close(self) -> None: self.calls.append("close") From 36b3bd1105e9cce402ff49d7166d5c3e8fb9122d Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Fri, 13 Nov 2026 02:04:03 +0400 Subject: [PATCH 5/9] Fix review round 1's points on collector receipts microcosm#1600 review round 1: - The collector-receipt follow-up moves from staging_dataset to its own module, collector_submissions, which also holds the UK and US collector country codes once; BundleEmitter and ReleaseEmitter share its CollectorReceipts protocol. - Once a bundle or publication is on Hugging Face, the wait says on stderr what it waits for and for how long. - The release command asks for the collector receipt by the hand-over ID the emitter's release receipt names. - A timed-out submission is a warning; the "not on Hugging Face" codes say the upload failed or was refused; the COLLECTOR_SETTINGS_REFUSED advice says submissions use the Hugging Face credential, since a collector token given in the environment only sends telemetry. - The README says the collector makes every UK national build it receives its latest tree, current or not; the agent guide says the installed-emitter tests send collector submissions to a closed port. The country-code lockstep test goes, since the code is defined once, and two tests name the constants' new module. Co-Authored-By: Claude Opus 5.5 --- README.md | 6 +- docs/agent-guide.md | 3 + docs/uk-staging-operations.md | 2 +- .../microcosm/build/collector_submissions.py | 201 ++++++++++++++++++ .../microcosm/build/release_publication.py | 50 +++-- .../src/microcosm/build/staging_dataset.py | 164 +------------- .../src/microcosm/build/telemetry_emitter.py | 11 +- .../build/uk_runtime/rowwise_staging.py | 9 +- .../shared/test_staging_dataset.py | 4 +- .../uk/test_uk_release_publication.py | 12 +- 10 files changed, 257 insertions(+), 205 deletions(-) create mode 100644 packages/microcosm-build/src/microcosm/build/collector_submissions.py diff --git a/README.md b/README.md index eabf22d4e6..46b3e843d1 100644 --- a/README.md +++ b/README.md @@ -546,7 +546,11 @@ to accept them before it closes the emitter. The printed outcome's `collector_submission` gives the collector receipt's `status` and `error_code`; a collector that receives nothing (`skipped`, for example `COLLECTOR_SETTINGS_REFUSED`), rejects them or has not accepted them yet is a -warning and never fails the command. The calibration diagnostics dashboard posts +warning and never fails the command. The collector makes every build of the +UK national release it receives the UK's latest calibration tree, whether or +not the build is current in `releases.json`, so a build published without +`--make-current` is the collector's latest from its publication on, and a +promotion sends the collector nothing. The calibration diagnostics dashboard posts these releases' Slack alerts from changes to `releases.json`. The UK assemblers, the US national builder and the US ACS package stage print the exact commands; the UK diff --git a/docs/agent-guide.md b/docs/agent-guide.md index b4cf5c74b0..17ad3113b8 100644 --- a/docs/agent-guide.md +++ b/docs/agent-guide.md @@ -181,6 +181,9 @@ start the installed command with `start_bundle_emitter()`, as the UK re-stage command does (the Hugging Face module only), and send its Hugging Face Hub requests through `HF_ENDPOINT` to a loopback stand-in server (`test_support/microcosm_build/stand_in_hub.py`), so the job needs no secret. +Builds switch the emitter's collector submissions on, so the tests' fixture +sends them to a closed loopback port: nothing reaches a collector, and a +build's wait for the collector ends at the first failed attempt. With Xet turned off, the stand-in takes the dataset through the LFS upload a real Hub requires for it, with the single-part `basic` transfer. It does not model Xet, which machines with `hf_xet` use, or the multipart transfer a real diff --git a/docs/uk-staging-operations.md b/docs/uk-staging-operations.md index 402967f944..9b5415ea40 100644 --- a/docs/uk-staging-operations.md +++ b/docs/uk-staging-operations.md @@ -251,7 +251,7 @@ on (`telemetry_emitter.COLLECTOR_SUBMISSIONS`, through the setting emitter 0.15.0 added; the emitter's own default leaves them off, so switching them off again is a Microcosm change). Once the bundle has landed, the build waits up to ten minutes for the collector to accept the submissions -(`staging_dataset.follow_collector_submissions`), because an emitter that is +(`collector_submissions.follow_collector_submissions`), because an emitter that is closing starts no new submission; an attempt after the commit that fails ends the wait sooner. A bundle that has not landed is asked about once and not waited for. The build carries on in every case, with a warning when: diff --git a/packages/microcosm-build/src/microcosm/build/collector_submissions.py b/packages/microcosm-build/src/microcosm/build/collector_submissions.py new file mode 100644 index 0000000000..154f835d66 --- /dev/null +++ b/packages/microcosm-build/src/microcosm/build/collector_submissions.py @@ -0,0 +1,201 @@ +"""What becomes of a staged bundle's or release publication's collector submissions. + +Every emitter a build starts has its Hugging Face module's collector +submissions on (``telemetry_emitter.COLLECTOR_SUBMISSIONS``). A staged bundle +or release publication that names its build (``CollectorProvenance``) is then +also submitted to the collector, from the emitter's own worker, once its +Hugging Face commit lands. An emitter that is closing starts no new +submission, so a build or command that closes its emitter straight after the +commit would leave them queued for the next emitter started on the machine. +:func:`follow_collector_submissions` waits, after the commit, until the +collector has accepted them, and says what became of them. Nothing here +raises into the build or fails a staging or a publication. +""" + +from __future__ import annotations + +import re +import sys +import time +from collections.abc import Callable, Mapping +from typing import Any, Final, Protocol + +from microcosm_emitter_interface.submissions import CollectorSubmissionReceipt + +__all__ = [ + "COLLECTOR_RECEIPT_POLL_SECONDS", + "COLLECTOR_SUBMISSION_WAIT_SECONDS", + "UK_COLLECTOR_COUNTRY_CODE", + "US_COLLECTOR_COUNTRY_CODE", + "CollectorReceipts", + "follow_collector_submissions", +] + +#: The country code a UK build's collector provenance names. Staging +#: telemetry registers UK runs as ``GB``, but the collector's calibration +#: tree handler knows the country as ``UK`` and builds no tree from a +#: submission naming another code. Its Orrery graph handler records whatever +#: code it is given. +UK_COLLECTOR_COUNTRY_CODE: Final = "UK" +#: The country code a US build's collector provenance names. +US_COLLECTOR_COUNTRY_CODE: Final = "US" +#: How long a build or command waits, once a described bundle or publication +#: has landed on Hugging Face, for the collector to accept its submissions. +#: The emitter's collector row may have retried every five minutes while it +#: waited for the commit, and its next attempt then uploads the files, so ten +#: minutes covers one attempt after the commit. The wait also ends at that +#: attempt when it fails. +COLLECTOR_SUBMISSION_WAIT_SECONDS: Final = 600.0 +#: How often the receipt is asked for meanwhile. +COLLECTOR_RECEIPT_POLL_SECONDS: Final = 1.0 +#: A receipt's ``pending`` code while the Hugging Face commit has not landed. +_WAITING_FOR_HUGGING_FACE: Final = "WAITING_FOR_HUGGING_FACE" +#: What each ``skipped`` code means. +_NOT_ON_HUGGING_FACE: Final = "its Hugging Face upload failed or was refused" +_SKIPPED_REASONS: Final[Mapping[str, str]] = { + "COLLECTOR_SETTINGS_REFUSED": ( + "the emitter refused its collector settings or the collector-token " + "variables it inherits" + ), + "COLLECTOR_FOLDER_TOO_LONG": ( + "its Hugging Face folder is longer than the collector accepts" + ), + "NOT_STAGED_ON_HUGGING_FACE": _NOT_ON_HUGGING_FACE, + "NOT_PUBLISHED_ON_HUGGING_FACE": _NOT_ON_HUGGING_FACE, +} +#: Added to a ``COLLECTOR_SETTINGS_REFUSED`` warning. The emitter's +#: collector session uses a token given in the environment for telemetry +#: only, so it never makes submissions work. +_SETTINGS_REFUSED_ADVICE: Final = ( + " The emitter's own warning gives the error type: a collector origin or" + " development collector it does not trust, or collector-token variables" + " it cannot use. Collector submissions use the Hugging Face credential; a" + " collector token given in MICROCOSM_COLLECTOR_TOKEN only sends telemetry." +) +#: A receipt's code, printed only when it has this shape: the emitter's codes, +#: or the collector's own, which are lower case (``content_mismatch``). +_CODE: Final = re.compile(r"^[A-Za-z][A-Za-z0-9_]{0,63}$") + + +class CollectorReceipts(Protocol): + """The emitter calls :func:`follow_collector_submissions` makes.""" + + @property + def available(self) -> bool: ... + + def collector_submission_receipt( + self, handover_id: str + ) -> CollectorSubmissionReceipt | None: ... + + +def _warn(message: str) -> None: + print(f"warning: {message}", file=sys.stderr, flush=True) + + +def _minutes(seconds: float) -> str: + return f"{seconds / 60:g} minutes" + + +def _attempted_after_commit( + receipt: Mapping[str, Any], earlier_attempts: object +) -> bool: + """Whether an attempt that found the Hugging Face commit has finished.""" + attempts = receipt.get("attempts") + return ( + isinstance(attempts, int) + and isinstance(earlier_attempts, int) + and attempts > earlier_attempts + and receipt.get("error_code") != _WAITING_FOR_HUGGING_FACE + ) + + +def _collector_warning(receipt: Mapping[str, Any], subject: str) -> str | None: + """What the build says about a collector receipt, or None.""" + status = receipt.get("status") + raw_code = receipt.get("error_code") + code = raw_code if isinstance(raw_code, str) and _CODE.fullmatch(raw_code) else None + shown = code or "no code" + if status == "skipped": + reason = _SKIPPED_REASONS.get(shown, "the emitter skipped them") + advice = ( + _SETTINGS_REFUSED_ADVICE if code == "COLLECTOR_SETTINGS_REFUSED" else "" + ) + return ( + f"the collector receives nothing of {subject}: {reason} ({shown}).{advice}" + ) + if status == "rejected": + return f"the collector rejected the submissions of {subject} ({shown})." + if status == "failed": + return f"the submissions of {subject} to the collector failed ({shown})." + if status == "timed_out": + return ( + f"the collector gave no final status for the submissions of {subject} " + f"within a day of accepting them ({shown})." + ) + if status == "pending": + detail = f" ({code})" if code else "" + return ( + f"the collector had not accepted the submissions of {subject} when " + f"the build stopped waiting{detail}; the emitter keeps them queued, " + "and it or the next emitter started on this machine sends them." + ) + return None + + +def follow_collector_submissions( + emitter: CollectorReceipts, + handover_id: str, + *, + subject: str, + wait_seconds: float | None, + poll_seconds: float = COLLECTOR_RECEIPT_POLL_SECONDS, + clock: Callable[[], float] = time.monotonic, + sleep: Callable[[float], None] = time.sleep, +) -> CollectorSubmissionReceipt | None: + """The hand-over's collector receipt, once the collector has taken it. + + ``wait_seconds`` is None for a hand-over whose Hugging Face commit has + not landed: its submissions wait for the commit, so this asks once, and + warns only when the collector will receive nothing or turned them down. + Otherwise it says, on stderr, that ``subject`` is on Hugging Face and + waits, at most ``wait_seconds``, while the receipt is ``pending``, until + an attempt that found the commit has finished: one that the collector + accepted ends ``pending``, and one that failed is retried by the + emitter. Any answer but an accepted or succeeded one is a warning naming + ``subject``. None, without a warning, when the emitter has no collector + row for the hand-over (it named no build, or no file the collector + takes) or does not answer. + """ + + if not emitter.available: + return None + receipt = emitter.collector_submission_receipt(handover_id) + if receipt is None: + return None + if wait_seconds is not None: + if receipt.get("status") == "pending": + print( + f"{subject} is on Hugging Face; waiting up to " + f"{_minutes(wait_seconds)} for the collector to accept its " + "submissions...", + file=sys.stderr, + flush=True, + ) + earlier_attempts = receipt.get("attempts") + deadline = clock() + max(0.0, float(wait_seconds)) + while ( + receipt.get("status") == "pending" + and not _attempted_after_commit(receipt, earlier_attempts) + and clock() < deadline + ): + sleep(poll_seconds) + latest = emitter.collector_submission_receipt(handover_id) + if latest is None: + break + receipt = latest + elif receipt.get("status") == "pending": + return receipt + warning = _collector_warning(receipt, subject) + if warning is not None: + _warn(warning) + return receipt diff --git a/packages/microcosm-build/src/microcosm/build/release_publication.py b/packages/microcosm-build/src/microcosm/build/release_publication.py index f23bfe3d61..5cc3f5023a 100644 --- a/packages/microcosm-build/src/microcosm/build/release_publication.py +++ b/packages/microcosm-build/src/microcosm/build/release_publication.py @@ -54,6 +54,7 @@ import argparse import json import os +import re import sys import time from collections.abc import Mapping @@ -74,13 +75,15 @@ ) from microcosm_emitter_interface.releases import is_pointer_file -from microcosm.build.staging_dataset import ( +from microcosm.build.collector_submissions import ( + COLLECTOR_RECEIPT_POLL_SECONDS, COLLECTOR_SUBMISSION_WAIT_SECONDS, - RECEIPT_POLL_SECONDS, + UK_COLLECTOR_COUNTRY_CODE, + US_COLLECTOR_COUNTRY_CODE, + CollectorReceipts, follow_collector_submissions, - hub_offline, - write_access_problem, ) +from microcosm.build.staging_dataset import hub_offline, write_access_problem from microcosm.build.telemetry_emitter import start_bundle_emitter from microcosm.data.contract import US_RELEASES, publishes_to_build_folder from microcosm.data.publish_cli import publication_refusal @@ -100,8 +103,6 @@ __all__ = [ "PROMOTION_WAIT_SECONDS", "PUBLICATION_WAIT_SECONDS", - "UK_COLLECTOR_COUNTRY_CODE", - "US_COLLECTOR_COUNTRY_CODE", "ReleaseEmitter", "ReleasePublication", "collector_provenance", @@ -156,8 +157,11 @@ ) -class ReleaseEmitter(Protocol): - """The interface ``EmitterClient``'s release calls and state.""" +class ReleaseEmitter(CollectorReceipts, Protocol): + """The interface ``EmitterClient``'s release calls and state. + + Its collector receipts come from ``CollectorReceipts``. + """ startup_error: EmitterStartupError | None last_failure: RequestFailure | None @@ -178,26 +182,17 @@ def promote_build( self, request: PromoteBuild, *, wait_seconds: float = 60.0 ) -> ReleaseReceipt: ... - def collector_submission_receipt( - self, handover_id: str - ) -> CollectorSubmissionReceipt | None: ... - def close(self) -> None: ... +#: The shape of an emitter's hand-over ID. +_HANDOVER_ID = re.compile(r"^[0-9a-f]{32}$") #: Starts the short-lived emitter a publication uses (only its Hugging Face #: module); tests replace it. _start_release_emitter = start_bundle_emitter #: The clock and sleep of the wait for the collector; tests replace them. _clock = time.monotonic _sleep = time.sleep -#: The country codes a publication's collector provenance names: those the -#: collector's calibration tree handler registers each country's release -#: repository under. The UK's is ``UK``, as UK staged bundles name it -#: (``uk_runtime.rowwise_staging.UK_COLLECTOR_COUNTRY_CODE``), not the -#: telemetry's ``GB``. -UK_COLLECTOR_COUNTRY_CODE = "UK" -US_COLLECTOR_COUNTRY_CODE = "US" def collector_provenance(release: str, build: str) -> CollectorProvenance | None: @@ -342,17 +337,18 @@ def _hand_over( receipt = emitter.publish_release(change, wait_seconds=wait_seconds) if change.collector is not None and receipt["status"] != "unavailable": # Before the emitter closes: a closing emitter starts no new - # submission. + # submission. The emitter keeps the collector row under the + # hand-over ID its receipt names. collector_receipt = follow_collector_submissions( emitter, - change.handover_id(), + _receipt_handover_id(receipt) or change.handover_id(), subject=f"build {change.build} of {change.release}", wait_seconds=( collector_wait_seconds if receipt["status"] == "published" else None ), - poll_seconds=RECEIPT_POLL_SECONDS, + poll_seconds=COLLECTOR_RECEIPT_POLL_SECONDS, clock=_clock, sleep=_sleep, ) @@ -372,6 +368,16 @@ def _hand_over( ) +def _receipt_handover_id(receipt: ReleaseReceipt) -> str | None: + """The hand-over ID a release receipt names, when it has the emitter's shape.""" + handover_id = receipt.get("handover_id") + return ( + handover_id + if isinstance(handover_id, str) and _HANDOVER_ID.fullmatch(handover_id) + else None + ) + + def _refuse_offline() -> None: """Refuse before an emitter starts when it could not reach the Hub.""" if hub_offline(): diff --git a/packages/microcosm-build/src/microcosm/build/staging_dataset.py b/packages/microcosm-build/src/microcosm/build/staging_dataset.py index 200657bd09..616e5662f8 100644 --- a/packages/microcosm-build/src/microcosm/build/staging_dataset.py +++ b/packages/microcosm-build/src/microcosm/build/staging_dataset.py @@ -21,8 +21,8 @@ emitter to submit the bundle's calibration diagnostics to the collector once its commit lands; every emitter a build starts has its collector submissions on. Once the commit has landed, the build waits until the collector accepts -them (:func:`follow_collector_submissions`), since an emitter that is closing -starts no new submission. +them (``collector_submissions.follow_collector_submissions``), since an +emitter that is closing starts no new submission. The module knows nothing about a country's manifest beyond the ``outputs`` mapping shape ``{name: {"path", "sha256", "bytes"}}``; callers pass the manifest @@ -42,7 +42,7 @@ from collections.abc import Callable, Mapping, Sequence from dataclasses import dataclass from pathlib import Path, PurePosixPath -from typing import Any, Final, Literal, Protocol, TypedDict, cast, get_args +from typing import Any, Final, Literal, TypedDict, cast, get_args from microcosm_emitter_interface import ( BundleFile, @@ -60,11 +60,14 @@ from microcosm_emitter_interface.identifiers import repository_identifier from microcosm_emitter_interface.submissions import CollectorSubmissionReceipt +from microcosm.build.collector_submissions import ( + COLLECTOR_SUBMISSION_WAIT_SECONDS, + follow_collector_submissions, +) from microcosm.build.staging_storage import HuggingFaceDatasetStorage from microcosm.build.telemetry_emitter import BundleEmitter, emitter_problem __all__ = [ - "COLLECTOR_SUBMISSION_WAIT_SECONDS", "DEFAULT_STAGED_DATASET_PREFIX", "AT_BUILD_RECORD_KEY", "HANDOVER_RECORD_KEY", @@ -77,7 +80,6 @@ "STAGED_MANIFEST_FILENAME", "STAGED_MANIFEST_SCHEMA", "BundleEmitter", - "CollectorReceipts", "StagedBundleHandOver", "StagedDatasetBundle", "StagedDatasetDelivery", @@ -89,7 +91,6 @@ "delivery_covers_bundle", "disabled_staged_dataset", "fetch_bundle", - "follow_collector_submissions", "handover_record", "hub_offline", "local_only_staged_dataset", @@ -126,37 +127,6 @@ RESTAGE_WAIT_SECONDS = 10800.0 #: How often the build asks the emitter for the bundle's receipt meanwhile. RECEIPT_POLL_SECONDS = 1.0 -#: How long the build waits, once a described bundle or publication has -#: landed on Hugging Face, for the collector to accept its submissions. The -#: emitter's collector row may have retried every five minutes while it -#: waited for the commit, and its next attempt then uploads the files, so -#: ten minutes covers one attempt after the commit. The wait also ends at -#: that attempt when it fails. An emitter that is closing starts no new -#: submission; one still queued then is sent by the next emitter started on -#: the machine. -COLLECTOR_SUBMISSION_WAIT_SECONDS = 600.0 -#: A collector receipt's ``pending`` code while the bundle's or publication's -#: Hugging Face commit has not landed. -_WAITING_FOR_HUGGING_FACE = "WAITING_FOR_HUGGING_FACE" -#: What each ``skipped`` code of a collector receipt means. -_SKIPPED_REASONS: Final[Mapping[str, str]] = { - "COLLECTOR_SETTINGS_REFUSED": ( - "the emitter refused its collector settings or the collector-token " - "variables it inherits" - ), - "COLLECTOR_FOLDER_TOO_LONG": ( - "its Hugging Face folder is longer than the collector accepts" - ), - "NOT_STAGED_ON_HUGGING_FACE": "Hugging Face refused it", - "NOT_PUBLISHED_ON_HUGGING_FACE": "Hugging Face refused it", -} -#: Added to a ``COLLECTOR_SETTINGS_REFUSED`` warning. -_SETTINGS_REFUSED_ADVICE = ( - " The emitter's own warning gives the error type. Check " - "MICROCOSM_COLLECTOR_TOKEN, MICROCOSM_COLLECTOR_TOKEN_EXPIRES_AT and " - "MICROCOSM_COLLECTOR_ORIGIN, which are set together or not at all; " - "without them the emitter uses the Hugging Face credential." -) _MODES = ("local_and_remote", "local_only", "disabled") _STATUSES = ("uploaded", "already_staged", "failed", "skipped") @@ -244,10 +214,6 @@ _HEXADECIMAL_TOKEN = re.compile(r"^(?=[0-9a-f]*[0-9])[0-9a-f]{8,}$") #: An emitter's own error code, printed only when it has this shape. _EMITTER_CODE = re.compile(r"^[A-Z][A-Z0-9_]{0,63}$") -#: A collector receipt's code, printed only when it has this shape: the -#: emitter's codes, or the collector's own, which are lower case -#: (``content_mismatch``). -_COLLECTOR_CODE = re.compile(r"^[A-Za-z][A-Za-z0-9_]{0,63}$") class StagedDatasetError(ValueError): @@ -1039,118 +1005,6 @@ def _minutes(seconds: float) -> str: return f"{seconds / 60:g} minutes" -def _attempted_after_commit( - receipt: Mapping[str, Any], earlier_attempts: object -) -> bool: - """Whether an attempt that found the Hugging Face commit has finished.""" - attempts = receipt.get("attempts") - return ( - isinstance(attempts, int) - and isinstance(earlier_attempts, int) - and attempts > earlier_attempts - and receipt.get("error_code") != _WAITING_FOR_HUGGING_FACE - ) - - -def _collector_warning(receipt: Mapping[str, Any], subject: str) -> str | None: - """What the build says about a collector receipt, or None.""" - status = receipt.get("status") - raw_code = receipt.get("error_code") - code = ( - raw_code - if isinstance(raw_code, str) and _COLLECTOR_CODE.fullmatch(raw_code) - else None - ) - if status == "skipped": - reason = _SKIPPED_REASONS.get(str(code), "the emitter skipped them") - advice = ( - _SETTINGS_REFUSED_ADVICE if code == "COLLECTOR_SETTINGS_REFUSED" else "" - ) - return ( - f"the collector receives nothing of {subject}: {reason} " - f"({code or 'no code'}).{advice}" - ) - if status == "rejected": - return ( - f"the collector rejected the submissions of {subject} " - f"({code or 'no code'})." - ) - if status == "failed": - return ( - f"the submissions of {subject} to the collector failed " - f"({code or 'no code'})." - ) - if status == "pending": - detail = f" ({code})" if code else "" - return ( - f"the collector had not accepted the submissions of {subject} when " - f"the build stopped waiting{detail}; the emitter keeps them queued, " - "and it or the next emitter started on this machine sends them." - ) - return None - - -class CollectorReceipts(Protocol): - """The emitter calls :func:`follow_collector_submissions` makes.""" - - @property - def available(self) -> bool: ... - - def collector_submission_receipt( - self, handover_id: str - ) -> CollectorSubmissionReceipt | None: ... - - -def follow_collector_submissions( - emitter: CollectorReceipts, - handover_id: str, - *, - subject: str, - wait_seconds: float | None, - poll_seconds: float = RECEIPT_POLL_SECONDS, - clock: Callable[[], float] = time.monotonic, - sleep: Callable[[float], None] = time.sleep, -) -> CollectorSubmissionReceipt | None: - """The hand-over's collector receipt, once the collector has taken it. - - ``wait_seconds`` is None for a hand-over whose Hugging Face commit has - not landed: its submissions wait for the commit, so the build asks once, - and warns only when the collector will receive nothing. Otherwise the - build waits, at most ``wait_seconds``, while the receipt is ``pending``, - until an attempt that found the commit has finished: one that the - collector accepted ends ``pending``, and one that failed is retried by - the emitter. Any answer but an accepted or succeeded one is a warning - naming ``subject``. None, without a warning, when the emitter has no - collector row for the hand-over (it named no build, or no file the - collector takes) or does not answer. - """ - - if not emitter.available: - return None - receipt = emitter.collector_submission_receipt(handover_id) - if receipt is None: - return None - if wait_seconds is not None: - earlier_attempts = receipt.get("attempts") - deadline = clock() + max(0.0, float(wait_seconds)) - while ( - receipt.get("status") == "pending" - and not _attempted_after_commit(receipt, earlier_attempts) - and clock() < deadline - ): - sleep(poll_seconds) - latest = emitter.collector_submission_receipt(handover_id) - if latest is None: - break - receipt = latest - elif receipt.get("status") == "pending": - return receipt - warning = _collector_warning(receipt, subject) - if warning is not None: - _warn(warning) - return receipt - - def _staged_subject(remote_prefix: str) -> str: return f"the staged dataset bundle {remote_prefix}" @@ -1315,8 +1169,8 @@ def stage_bundle( submits the bundle's calibration diagnostics to the collector (see :func:`bundle_request`); once the commit has landed, the build waits at most ``collector_wait_seconds`` for the collector to accept them - (:func:`follow_collector_submissions`), and only asks whether it will - receive them otherwise. + (``collector_submissions.follow_collector_submissions``), and only asks + whether it will receive them otherwise. The emitter writes every file under ``//`` in one commit, idempotent on the outputs' digests (``already_staged``, or diff --git a/packages/microcosm-build/src/microcosm/build/telemetry_emitter.py b/packages/microcosm-build/src/microcosm/build/telemetry_emitter.py index 5e5750bfad..ef01c2ca78 100644 --- a/packages/microcosm-build/src/microcosm/build/telemetry_emitter.py +++ b/packages/microcosm-build/src/microcosm/build/telemetry_emitter.py @@ -74,7 +74,6 @@ unavailable_receipt, ) from microcosm_emitter_interface.protocol import HUGGING_FACE_MODULE, TELEMETRY_MODULE -from microcosm_emitter_interface.submissions import CollectorSubmissionReceipt from microcosm_emitter_interface.telemetry import ( DEFAULT_FAILURE_CLASS, DEFAULT_HEARTBEAT_SECONDS, @@ -83,6 +82,7 @@ TelemetryStatus, ) +from microcosm.build.collector_submissions import CollectorReceipts from microcosm.build.telemetry_identity import runtime_identity __all__ = [ @@ -588,11 +588,12 @@ def __init__(self, reported: str) -> None: self.reported = reported -class BundleEmitter(Protocol): +class BundleEmitter(CollectorReceipts, Protocol): """The interface ``EmitterClient``'s staged-bundle calls and state. ``startup_error`` says why an emitter did not start, and ``last_failure`` - why its latest call reported failure. + why its latest call reported failure. Its collector receipts come from + ``CollectorReceipts``. """ startup_error: EmitterStartupError | None @@ -612,10 +613,6 @@ def dataset_bundle_receipt( self, handover_id: str ) -> DatasetBundleReceipt | None: ... - def collector_submission_receipt( - self, handover_id: str - ) -> CollectorSubmissionReceipt | None: ... - def check_write_access(self, repository: str) -> WriteAccess: ... def close(self) -> None: ... diff --git a/packages/microcosm-build/src/microcosm/build/uk_runtime/rowwise_staging.py b/packages/microcosm-build/src/microcosm/build/uk_runtime/rowwise_staging.py index e7ef534168..4e3713bfb6 100644 --- a/packages/microcosm-build/src/microcosm/build/uk_runtime/rowwise_staging.py +++ b/packages/microcosm-build/src/microcosm/build/uk_runtime/rowwise_staging.py @@ -15,7 +15,7 @@ hand-over names the build for the collector (:func:`collector_provenance`), so the emitter, whose collector submissions are on, submits its calibration diagnostics there once the bundle's commit lands, and the build waits for the -collector to accept them (``staging_dataset.follow_collector_submissions``). +collector to accept them (``collector_submissions.follow_collector_submissions``). """ from __future__ import annotations @@ -35,6 +35,7 @@ calibration_epoch_stride, forwards_calibration_epoch, ) +from microcosm.build.collector_submissions import UK_COLLECTOR_COUNTRY_CODE from microcosm.build.run_outcome import ( UNRECORDED_GATE_BLOCK, GateBlock, @@ -114,12 +115,6 @@ _STAGING_UPLOAD_INTERVAL_SECONDS = STAGING_UPLOAD_INTERVAL_SECONDS _STAGED_DATASET_PHASES = STAGED_DATASET_PHASES _ACTIVE_EMITTER: LocalTelemetryEmitter | None = None -#: The country code a UK bundle's collector provenance names. Staging -#: telemetry registers UK runs as ``GB``, but the collector's calibration -#: tree handler knows the country as ``UK`` and builds no tree from a -#: submission naming another code. Its Orrery graph handler records whatever -#: code it is given. -UK_COLLECTOR_COUNTRY_CODE = "UK" #: The releases a staged UK build can be a candidate for: each release role's #: release, whose builds publish into their own folders. _CANDIDATE_RELEASES = frozenset( diff --git a/packages/microcosm-build/tests/engine_free/shared/test_staging_dataset.py b/packages/microcosm-build/tests/engine_free/shared/test_staging_dataset.py index d9ff32795d..369de55ec1 100644 --- a/packages/microcosm-build/tests/engine_free/shared/test_staging_dataset.py +++ b/packages/microcosm-build/tests/engine_free/shared/test_staging_dataset.py @@ -10,7 +10,7 @@ import pytest from microcosm_emitter_interface import CollectorProvenance -from microcosm.build import staging_dataset +from microcosm.build import collector_submissions, staging_dataset from microcosm.build.staging_dataset import ( SHA256SUMS_FILENAME, STAGED_MANIFEST_FILENAME, @@ -746,7 +746,7 @@ def test_submissions_not_accepted_when_the_wait_ends_stay_queued(tmp_path, capsy ) assert staged.delivery["status"] == "uploaded" - assert staging_dataset.COLLECTOR_SUBMISSION_WAIT_SECONDS == 600 + assert collector_submissions.COLLECTOR_SUBMISSION_WAIT_SECONDS == 600 assert sum(clock.slept) == 600 assert staged.collector_receipt["status"] == "pending" warning = capsys.readouterr().err diff --git a/packages/microcosm-build/tests/engine_free/uk/test_uk_release_publication.py b/packages/microcosm-build/tests/engine_free/uk/test_uk_release_publication.py index 1c7b8ebfe9..965198dbe8 100644 --- a/packages/microcosm-build/tests/engine_free/uk/test_uk_release_publication.py +++ b/packages/microcosm-build/tests/engine_free/uk/test_uk_release_publication.py @@ -19,8 +19,7 @@ from microcosm_emitter_interface import CollectorProvenance from microcosm_emitter_interface.releases import ReleaseRecordError, ReleasesRecord -from microcosm.build import release_publication -from microcosm.build.uk_runtime import rowwise_staging +from microcosm.build import collector_submissions, release_publication from microcosm.data import release as release_module from microcosm.data.releases_record import parse_releases_record from test_support.microcosm_build.emitter import FakeEmitterClient @@ -207,13 +206,6 @@ def test_every_uk_release_names_its_builds_as_licensed_uk_builds(release) -> Non ) -def test_the_uk_country_code_is_the_one_staged_bundles_name() -> None: - assert ( - release_publication.UK_COLLECTOR_COUNTRY_CODE - == rowwise_staging.UK_COLLECTOR_COUNTRY_CODE - ) - - def test_a_release_that_publishes_with_tags_names_no_build() -> None: assert ( release_publication.collector_provenance( @@ -241,7 +233,7 @@ def test_a_published_build_waits_until_the_collector_accepts_its_submissions( (request,) = client.release_requests assert client.collector_receipt_requests == [request.handover_id()] * 2 - assert clock.slept == [release_publication.RECEIPT_POLL_SECONDS] + assert clock.slept == [collector_submissions.COLLECTOR_RECEIPT_POLL_SECONDS] assert outcome.collector_receipt is not None assert outcome.collector_receipt["status"] == "awaiting_final_status" assert outcome.as_json()["collector_submission"] == { From 8ef27ea01741ea7ba2c1cb4165317ea29e49c8b3 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Fri, 13 Nov 2026 02:34:10 +0400 Subject: [PATCH 6/9] Test review round 2's points on collector warnings Failing tests for microcosm#1600's review round 2: - the COLLECTOR_SETTINGS_REFUSED advice says to unset the three collector-token variables, since an emitter given a token uses it instead of the Hugging Face credential and it only sends telemetry; - the warning for submissions still queued says an emitter running on the machine later sends them, and that files the emitter did not copy must stay unchanged until then. Three cases and the installed-emitter re-stage test fail, all on assertions. New coverage that passes already: a release receipt without a hand-over ID falls back to the request's own, and no wait is announced when the first collector receipt is settled. Co-Authored-By: Claude Opus 5.5 --- .../shared/test_staging_dataset.py | 44 ++++++++++++++----- .../uk/test_uk_release_publication.py | 19 ++++++++ .../shared/test_installed_emitter_staging.py | 4 +- 3 files changed, 54 insertions(+), 13 deletions(-) diff --git a/packages/microcosm-build/tests/engine_free/shared/test_staging_dataset.py b/packages/microcosm-build/tests/engine_free/shared/test_staging_dataset.py index 369de55ec1..2fcf28f2fd 100644 --- a/packages/microcosm-build/tests/engine_free/shared/test_staging_dataset.py +++ b/packages/microcosm-build/tests/engine_free/shared/test_staging_dataset.py @@ -671,9 +671,11 @@ def test_the_first_failed_attempt_after_the_commit_ends_the_wait(tmp_path, capsy assert staged.collector_receipt["error_code"] == "COLLECTOR_UNAVAILABLE" assert ( f"warning: the collector had not accepted the submissions of the staged " - f"dataset bundle staged/{RUN_ID} when the build stopped waiting " - "(COLLECTOR_UNAVAILABLE); the emitter keeps them queued, and it or the " - "next emitter started on this machine sends them." in capsys.readouterr().err + f"dataset bundle staged/{RUN_ID} when the wait ended " + "(COLLECTOR_UNAVAILABLE); the emitter keeps them queued on this machine, " + "and an emitter running here later sends them. Until then, leave " + "unchanged any of their files the emitter did not copy at hand-over." + in capsys.readouterr().err ) @@ -713,12 +715,15 @@ def test_a_skipped_collector_receipt_is_a_warning_and_the_bundle_stays_staged( f"warning: the collector receives nothing of the staged dataset bundle " f"staged/{RUN_ID}: {explanation} ({code})." in warning ) - # Submissions use the Hugging Face credential: a collector token given - # in the environment only sends telemetry, so the advice never says to - # set one. + # Submissions use the Hugging Face credential, which an emitter given a + # collector token never reads, and a given token only sends telemetry: + # the advice is to unset the variables, never to complete them. advice = ( - "Collector submissions use the Hugging Face credential; a collector " - "token given in MICROCOSM_COLLECTOR_TOKEN only sends telemetry." + "Collector submissions use the Hugging Face credential, and an emitter " + "given a collector token uses that token instead, which only sends " + "telemetry: unset MICROCOSM_COLLECTOR_TOKEN, " + "MICROCOSM_COLLECTOR_TOKEN_EXPIRES_AT and MICROCOSM_COLLECTOR_ORIGIN " + "for a staging or publication that should reach the collector." ) assert (advice in warning) is (code == "COLLECTOR_SETTINGS_REFUSED") assert "set together" not in warning @@ -752,9 +757,10 @@ def test_submissions_not_accepted_when_the_wait_ends_stay_queued(tmp_path, capsy warning = capsys.readouterr().err assert ( f"warning: the collector had not accepted the submissions of the staged " - f"dataset bundle staged/{RUN_ID} when the build stopped waiting " - "(COLLECTOR_UNAVAILABLE); the emitter keeps them queued, and it or the " - "next emitter started on this machine sends them." in warning + f"dataset bundle staged/{RUN_ID} when the wait ended " + "(COLLECTOR_UNAVAILABLE); the emitter keeps them queued on this machine, " + "and an emitter running here later sends them. Until then, leave " + "unchanged any of their files the emitter did not copy at hand-over." in warning ) @@ -797,6 +803,22 @@ def test_a_submission_the_collector_turned_down_is_a_warning( assert f"warning: {warned}" in capsys.readouterr().err +@pytest.mark.parametrize("status", ["succeeded", "skipped"]) +def test_no_wait_is_announced_when_the_first_receipt_is_settled( + tmp_path, capsys, status +): + bundle = _bundle(tmp_path) + emitter = FakeEmitterClient( + hub_api=FakeHub(tmp_path), + collector_receipts=[{"status": status, "attempts": 1}], + ) + + _stage(bundle, emitter, collector=PROVENANCE) + + assert len(emitter.collector_receipt_requests) == 1 + assert "waiting up to" not in capsys.readouterr().err.split("upload...")[-1] + + def test_an_emitter_that_stops_answering_ends_the_wait(tmp_path, capsys): bundle = _bundle(tmp_path) emitter = FakeEmitterClient( diff --git a/packages/microcosm-build/tests/engine_free/uk/test_uk_release_publication.py b/packages/microcosm-build/tests/engine_free/uk/test_uk_release_publication.py index 965198dbe8..1f10a9ba36 100644 --- a/packages/microcosm-build/tests/engine_free/uk/test_uk_release_publication.py +++ b/packages/microcosm-build/tests/engine_free/uk/test_uk_release_publication.py @@ -270,6 +270,25 @@ def test_the_collector_receipt_is_asked_for_by_the_emitters_hand_over_id( assert outcome.collector_receipt["status"] == "succeeded" +def test_a_receipt_without_a_hand_over_id_falls_back_to_the_requests_own( + national: Path, + artifact_root: Path, # noqa: F811 + clock: Clock, +) -> None: + client = FakeEmitterClient( + release_receipts=[{"handover_id": ""}], + collector_receipts=[{"status": "succeeded", "attempts": 1}], + ) + + outcome = release_publication.publish_release_build( + national, artifact_root=artifact_root, client=client + ) + + (request,) = client.release_requests + assert client.collector_receipt_requests == [request.handover_id()] + assert outcome.collector_receipt["status"] == "succeeded" + + def test_a_published_build_the_emitter_has_no_collector_row_for_is_not_waited_for( national: Path, artifact_root: Path, # noqa: F811 diff --git a/packages/microcosm-build/tests/installed_emitter/shared/test_installed_emitter_staging.py b/packages/microcosm-build/tests/installed_emitter/shared/test_installed_emitter_staging.py index 9a60ff4ff1..5a897043c5 100644 --- a/packages/microcosm-build/tests/installed_emitter/shared/test_installed_emitter_staging.py +++ b/packages/microcosm-build/tests/installed_emitter/shared/test_installed_emitter_staging.py @@ -487,8 +487,8 @@ def test_a_modal_runs_copied_back_outputs_are_staged_by_the_re_stage_command( # submissions stay queued. assert ( f"warning: the collector had not accepted the submissions of the staged " - f"dataset bundle {PREFIX} when the build stopped waiting " - "(COLLECTOR_UNAVAILABLE)" in capsys.readouterr().err + f"dataset bundle {PREFIX} when the wait ended (COLLECTOR_UNAVAILABLE)" + in capsys.readouterr().err ) From 59ab99de80067456aef4905e33c51d64511d049d Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Fri, 13 Nov 2026 02:35:34 +0400 Subject: [PATCH 7/9] Fix review round 2's points on collector warnings microcosm#1600 review round 2: - The COLLECTOR_SETTINGS_REFUSED advice says to unset MICROCOSM_COLLECTOR_TOKEN, MICROCOSM_COLLECTOR_TOKEN_EXPIRES_AT and MICROCOSM_COLLECTOR_ORIGIN: an emitter given a token uses it instead of the Hugging Face credential, and it only sends telemetry. - The warning for submissions still queued says an emitter running on the machine later sends them, and that files the emitter did not copy must stay unchanged until then. - The UK staging guide and the README list timed-out and failed submissions, and say the "not staged" code covers a failed or refused upload; the changelog says submissions are on in every emitter with a Hugging Face module. Co-Authored-By: Claude Opus 5.5 --- README.md | 7 ++++--- .../1599-collector-submissions-on.added.md | 2 +- docs/uk-staging-operations.md | 17 +++++++++------- .../microcosm/build/collector_submissions.py | 20 ++++++++++++------- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 46b3e843d1..53a49a7773 100644 --- a/README.md +++ b/README.md @@ -544,9 +544,10 @@ release manifests, to the collector after the release commit, so once the publication has landed the command waits up to ten minutes for the collector to accept them before it closes the emitter. The printed outcome's `collector_submission` gives the collector receipt's `status` and -`error_code`; a collector that receives nothing (`skipped`, for example -`COLLECTOR_SETTINGS_REFUSED`), rejects them or has not accepted them yet is a -warning and never fails the command. The collector makes every build of the +`error_code`. A collector that receives nothing (`skipped`, for example +`COLLECTOR_SETTINGS_REFUSED`), submissions that are rejected, fail or time +out (`timed_out`), and submissions not yet accepted when the wait ends are +warnings and never fail the command. The collector makes every build of the UK national release it receives the UK's latest calibration tree, whether or not the build is current in `releases.json`, so a build published without `--make-current` is the collector's latest from its publication on, and a diff --git a/changelog.d/1599-collector-submissions-on.added.md b/changelog.d/1599-collector-submissions-on.added.md index da824518d1..68aa24b3a7 100644 --- a/changelog.d/1599-collector-submissions-on.added.md +++ b/changelog.d/1599-collector-submissions-on.added.md @@ -1 +1 @@ -Builds now send their calibration diagnostics to the collector at staging and at release (microcosm#1599). Builds and the Modal image require microcosm-emitter 0.15.0 instead of 0.14.0, and microcosm-build's `microcosm-emitter-interface` pin rises to `>=0.15.0,<1` (the lock and `APPROVED_UV_LOCK_SHA256` follow, as does the installed-emitter job's pin). Every emitter Microcosm starts has its collector submissions on. `microcosm-publish-release-build` names each build for the collector (UK builds as licensed, US builds as not), so the emitter submits its calibration diagnostics after the release commit. Once a staged bundle or publication has landed, the build or command waits up to ten minutes for the collector to accept them, and warns without failing when the collector receives nothing (`skipped`), turns them down or has not accepted them yet; the publication command prints the collector's status as `collector_submission`. +Builds now send their calibration diagnostics to the collector at staging and at release (microcosm#1599). Builds and the Modal image require microcosm-emitter 0.15.0 instead of 0.14.0, and microcosm-build's `microcosm-emitter-interface` pin rises to `>=0.15.0,<1` (the lock and `APPROVED_UV_LOCK_SHA256` follow, as does the installed-emitter job's pin). Every emitter Microcosm starts with its Hugging Face module has its collector submissions on. `microcosm-publish-release-build` names each build for the collector (UK builds as licensed, US builds as not), so the emitter submits its calibration diagnostics after the release commit. Once a staged bundle or publication has landed, the build or command waits up to ten minutes for the collector to accept them, and warns without failing when the collector receives nothing (`skipped`), turns them down or has not accepted them yet; the publication command prints the collector's status as `collector_submission`. diff --git a/docs/uk-staging-operations.md b/docs/uk-staging-operations.md index 9b5415ea40..387f8706b5 100644 --- a/docs/uk-staging-operations.md +++ b/docs/uk-staging-operations.md @@ -258,13 +258,16 @@ not waited for. The build carries on in every case, with a warning when: - the collector receives nothing (`skipped`): the emitter refused its collector settings or the collector-token variables it inherits - (`COLLECTOR_SETTINGS_REFUSED`), Hugging Face refused the bundle - (`NOT_STAGED_ON_HUGGING_FACE`), or its folder is longer than the collector - accepts (`COLLECTOR_FOLDER_TOO_LONG`); -- the collector rejected the submissions, or they failed, with the code the - receipt gives; -- they were still queued when the build stopped waiting: the emitter, or the - next emitter started on this machine, sends them. + (`COLLECTOR_SETTINGS_REFUSED`; an emitter given a collector token uses it + instead of the Hugging Face credential, and it only sends telemetry, so + unset those variables), the bundle's Hugging Face upload failed or was + refused (`NOT_STAGED_ON_HUGGING_FACE`), or its folder is longer than the + collector accepts (`COLLECTOR_FOLDER_TOO_LONG`); +- the collector rejected the submissions, they failed, or the collector gave + no final status within a day (`timed_out`), with the code the receipt gives; +- they were still queued when the wait ended: an emitter running on this + machine later sends them, and files the emitter did not copy at hand-over + must stay unchanged until then. The staged dataset record (`staged_dataset`) describes the Hugging Face upload alone and does not change. A different `collector` block gives the diff --git a/packages/microcosm-build/src/microcosm/build/collector_submissions.py b/packages/microcosm-build/src/microcosm/build/collector_submissions.py index 154f835d66..b5405bb5d2 100644 --- a/packages/microcosm-build/src/microcosm/build/collector_submissions.py +++ b/packages/microcosm-build/src/microcosm/build/collector_submissions.py @@ -63,14 +63,18 @@ "NOT_STAGED_ON_HUGGING_FACE": _NOT_ON_HUGGING_FACE, "NOT_PUBLISHED_ON_HUGGING_FACE": _NOT_ON_HUGGING_FACE, } -#: Added to a ``COLLECTOR_SETTINGS_REFUSED`` warning. The emitter's -#: collector session uses a token given in the environment for telemetry -#: only, so it never makes submissions work. +#: Added to a ``COLLECTOR_SETTINGS_REFUSED`` warning. An emitter given a +#: collector token in the environment uses it instead of the Hugging Face +#: credential, and the token only sends telemetry, so its submissions never +#: have a credential: the variables are to be unset, not completed. _SETTINGS_REFUSED_ADVICE: Final = ( " The emitter's own warning gives the error type: a collector origin or" " development collector it does not trust, or collector-token variables" - " it cannot use. Collector submissions use the Hugging Face credential; a" - " collector token given in MICROCOSM_COLLECTOR_TOKEN only sends telemetry." + " it cannot use. Collector submissions use the Hugging Face credential," + " and an emitter given a collector token uses that token instead, which" + " only sends telemetry: unset MICROCOSM_COLLECTOR_TOKEN," + " MICROCOSM_COLLECTOR_TOKEN_EXPIRES_AT and MICROCOSM_COLLECTOR_ORIGIN for a" + " staging or publication that should reach the collector." ) #: A receipt's code, printed only when it has this shape: the emitter's codes, #: or the collector's own, which are lower case (``content_mismatch``). @@ -136,8 +140,10 @@ def _collector_warning(receipt: Mapping[str, Any], subject: str) -> str | None: detail = f" ({code})" if code else "" return ( f"the collector had not accepted the submissions of {subject} when " - f"the build stopped waiting{detail}; the emitter keeps them queued, " - "and it or the next emitter started on this machine sends them." + f"the wait ended{detail}; the emitter keeps them queued on this " + "machine, and an emitter running here later sends them. Until then, " + "leave unchanged any of their files the emitter did not copy at " + "hand-over." ) return None From 8be98be04c210e9aa331413594d3adb2b22484af Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Fri, 13 Nov 2026 03:07:44 +0400 Subject: [PATCH 8/9] Test review round 3's points on queued collector submissions Failing tests for microcosm#1600's review round 3: submissions left pending with CREDENTIAL_MISSING say the emitter has no credential and how to give it the Hugging Face one, instead of promising a later emitter sends them; the still-queued warning says uncopied files stay unchanged until the hand-over settles. Three cases fail, all on assertions. Co-Authored-By: Claude Opus 5.5 --- .../shared/test_staging_dataset.py | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/packages/microcosm-build/tests/engine_free/shared/test_staging_dataset.py b/packages/microcosm-build/tests/engine_free/shared/test_staging_dataset.py index 2fcf28f2fd..002ee83dd6 100644 --- a/packages/microcosm-build/tests/engine_free/shared/test_staging_dataset.py +++ b/packages/microcosm-build/tests/engine_free/shared/test_staging_dataset.py @@ -673,9 +673,9 @@ def test_the_first_failed_attempt_after_the_commit_ends_the_wait(tmp_path, capsy f"warning: the collector had not accepted the submissions of the staged " f"dataset bundle staged/{RUN_ID} when the wait ended " "(COLLECTOR_UNAVAILABLE); the emitter keeps them queued on this machine, " - "and an emitter running here later sends them. Until then, leave " - "unchanged any of their files the emitter did not copy at hand-over." - in capsys.readouterr().err + "and an emitter running here later sends them. Leave unchanged any of " + "their files the emitter did not copy at hand-over until the hand-over " + "settles." in capsys.readouterr().err ) @@ -759,8 +759,9 @@ def test_submissions_not_accepted_when_the_wait_ends_stay_queued(tmp_path, capsy f"warning: the collector had not accepted the submissions of the staged " f"dataset bundle staged/{RUN_ID} when the wait ended " "(COLLECTOR_UNAVAILABLE); the emitter keeps them queued on this machine, " - "and an emitter running here later sends them. Until then, leave " - "unchanged any of their files the emitter did not copy at hand-over." in warning + "and an emitter running here later sends them. Leave unchanged any of " + "their files the emitter did not copy at hand-over until the hand-over " + "settles." in warning ) @@ -819,6 +820,36 @@ def test_no_wait_is_announced_when_the_first_receipt_is_settled( assert "waiting up to" not in capsys.readouterr().err.split("upload...")[-1] +def test_a_submission_without_a_credential_says_how_to_give_it_one(tmp_path, capsys): + """An emitter given a telemetry-only collector token, or finding no + Hugging Face credential, keeps the submissions pending with + CREDENTIAL_MISSING; a later emitter sends them only with the credential.""" + bundle = _bundle(tmp_path) + emitter = FakeEmitterClient( + hub_api=FakeHub(tmp_path), + collector_receipts=[ + { + "status": "pending", + "error_code": "WAITING_FOR_HUGGING_FACE", + "attempts": 1, + }, + {"status": "pending", "error_code": "CREDENTIAL_MISSING", "attempts": 2}, + ], + ) + + _stage(bundle, emitter, collector=PROVENANCE) + + warning = capsys.readouterr().err + assert ( + f"warning: the collector had not accepted the submissions of the staged " + f"dataset bundle staged/{RUN_ID} when the wait ended (CREDENTIAL_MISSING): " + "the emitter has no credential to submit them with." in warning + ) + assert "unset MICROCOSM_COLLECTOR_TOKEN" in warning + assert "`hf auth login`" in warning + assert "an emitter running here later sends them" not in warning + + def test_an_emitter_that_stops_answering_ends_the_wait(tmp_path, capsys): bundle = _bundle(tmp_path) emitter = FakeEmitterClient( From d76efd3f5402cf112e06de47036b5c8603d986ae Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Fri, 13 Nov 2026 03:09:56 +0400 Subject: [PATCH 9/9] Fix review round 3's points on collector warnings and docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit microcosm#1600 review round 3, which found no bugs: - Submissions left pending with CREDENTIAL_MISSING say the emitter has no credential for them and how to give it the Hugging Face one, instead of promising that a later emitter sends them; uncopied files stay unchanged until the hand-over settles. - The README, the UK staging guide and the changelog say the build waits until the collector accepts the submissions, not for its later verdict. The README no longer describes the collector's choice of the latest UK tree, which tracker task 2b · 12 changes before this merges. - The Orrery guide's workstation section names 0.15.0, and the re-stage command's docstring and --wait-seconds help mention the collector wait. Co-Authored-By: Claude Opus 5.5 --- README.md | 12 +++--- .../1599-collector-submissions-on.added.md | 2 +- docs/orrery-publication.md | 6 +-- docs/uk-staging-operations.md | 12 ++++-- .../microcosm/build/collector_submissions.py | 40 +++++++++++++------ tools/stage_uk_rowwise_candidate.py | 11 +++-- 6 files changed, 53 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 53a49a7773..e3dfc6d630 100644 --- a/README.md +++ b/README.md @@ -545,13 +545,11 @@ publication has landed the command waits up to ten minutes for the collector to accept them before it closes the emitter. The printed outcome's `collector_submission` gives the collector receipt's `status` and `error_code`. A collector that receives nothing (`skipped`, for example -`COLLECTOR_SETTINGS_REFUSED`), submissions that are rejected, fail or time -out (`timed_out`), and submissions not yet accepted when the wait ends are -warnings and never fail the command. The collector makes every build of the -UK national release it receives the UK's latest calibration tree, whether or -not the build is current in `releases.json`, so a build published without -`--make-current` is the collector's latest from its publication on, and a -promotion sends the collector nothing. The calibration diagnostics dashboard posts +`COLLECTOR_SETTINGS_REFUSED`) or refuses the submissions at intake, and +submissions not yet accepted when the wait ends, are warnings and never fail +the command. Once the collector has accepted them, its own processing decides +whether it builds a tree from them or rejects them (for example +`provenance_mismatch`); the command doesn't wait for that. The calibration diagnostics dashboard posts these releases' Slack alerts from changes to `releases.json`. The UK assemblers, the US national builder and the US ACS package stage print the exact commands; the UK diff --git a/changelog.d/1599-collector-submissions-on.added.md b/changelog.d/1599-collector-submissions-on.added.md index 68aa24b3a7..b34068aedc 100644 --- a/changelog.d/1599-collector-submissions-on.added.md +++ b/changelog.d/1599-collector-submissions-on.added.md @@ -1 +1 @@ -Builds now send their calibration diagnostics to the collector at staging and at release (microcosm#1599). Builds and the Modal image require microcosm-emitter 0.15.0 instead of 0.14.0, and microcosm-build's `microcosm-emitter-interface` pin rises to `>=0.15.0,<1` (the lock and `APPROVED_UV_LOCK_SHA256` follow, as does the installed-emitter job's pin). Every emitter Microcosm starts with its Hugging Face module has its collector submissions on. `microcosm-publish-release-build` names each build for the collector (UK builds as licensed, US builds as not), so the emitter submits its calibration diagnostics after the release commit. Once a staged bundle or publication has landed, the build or command waits up to ten minutes for the collector to accept them, and warns without failing when the collector receives nothing (`skipped`), turns them down or has not accepted them yet; the publication command prints the collector's status as `collector_submission`. +Builds now send their calibration diagnostics to the collector at staging and at release (microcosm#1599). Builds and the Modal image require microcosm-emitter 0.15.0 instead of 0.14.0, and microcosm-build's `microcosm-emitter-interface` pin rises to `>=0.15.0,<1` (the lock and `APPROVED_UV_LOCK_SHA256` follow, as does the installed-emitter job's pin). Every emitter Microcosm starts with its Hugging Face module has its collector submissions on. `microcosm-publish-release-build` names each build for the collector (UK builds as licensed, US builds as not), so the emitter submits its calibration diagnostics after the release commit. Once a staged bundle or publication has landed, the build or command waits up to ten minutes for the collector to accept them, and warns without failing when the collector receives nothing (`skipped`), refuses them at intake or has not accepted them yet; the publication command prints the collector's status as `collector_submission`. diff --git a/docs/orrery-publication.md b/docs/orrery-publication.md index 87c8f4df98..a892ae7cb8 100644 --- a/docs/orrery-publication.md +++ b/docs/orrery-publication.md @@ -227,7 +227,7 @@ the new lockfile digest and rerun the tests and wheel checks. ## Migrating an existing workstation -Install the emitter once with `uv tool install microcosm-emitter` (0.13.0 or +Install the emitter once with `uv tool install microcosm-emitter` (0.15.0 or later; a build does not start an older emitter, says how to upgrade it and continues without it). It keeps using the existing spool database, `$XDG_CACHE_HOME/microcosm/telemetry/events.sqlite3`, at the same Alembic @@ -240,7 +240,7 @@ modification. The emitter's README describes the repair for a machine that ran an earlier, unreleased build of the hand-over queue. No new credential, hosted service or infrastructure is required by this migration. -To upgrade a machine whose emitter is older than 0.13.0, run -`uv tool install --upgrade 'microcosm-emitter>=0.13.0'`; it also replaces a +To upgrade a machine whose emitter is older than 0.15.0, run +`uv tool install --upgrade 'microcosm-emitter>=0.15.0'`; it also replaces a version constraint given at install time, which `uv tool upgrade` keeps. `microcosm-emitter version` prints the installed release. diff --git a/docs/uk-staging-operations.md b/docs/uk-staging-operations.md index 387f8706b5..c151496538 100644 --- a/docs/uk-staging-operations.md +++ b/docs/uk-staging-operations.md @@ -263,11 +263,17 @@ not waited for. The build carries on in every case, with a warning when: unset those variables), the bundle's Hugging Face upload failed or was refused (`NOT_STAGED_ON_HUGGING_FACE`), or its folder is longer than the collector accepts (`COLLECTOR_FOLDER_TOO_LONG`); -- the collector rejected the submissions, they failed, or the collector gave - no final status within a day (`timed_out`), with the code the receipt gives; +- the collector refused the submissions at intake (`rejected` or `failed`), + with the code the receipt gives. Once it has accepted them, its own + processing decides whether it builds a tree or rejects them, and the build + doesn't wait for that; a re-stage that resumes an older hand-over can show + that later result, or `timed_out`; +- the emitter had no credential for them (`CREDENTIAL_MISSING`): it was given + a collector token, which only sends telemetry, or found no Hugging Face + credential; - they were still queued when the wait ended: an emitter running on this machine later sends them, and files the emitter did not copy at hand-over - must stay unchanged until then. + must stay unchanged until the hand-over settles. The staged dataset record (`staged_dataset`) describes the Hugging Face upload alone and does not change. A different `collector` block gives the diff --git a/packages/microcosm-build/src/microcosm/build/collector_submissions.py b/packages/microcosm-build/src/microcosm/build/collector_submissions.py index b5405bb5d2..77cbed714d 100644 --- a/packages/microcosm-build/src/microcosm/build/collector_submissions.py +++ b/packages/microcosm-build/src/microcosm/build/collector_submissions.py @@ -63,19 +63,27 @@ "NOT_STAGED_ON_HUGGING_FACE": _NOT_ON_HUGGING_FACE, "NOT_PUBLISHED_ON_HUGGING_FACE": _NOT_ON_HUGGING_FACE, } -#: Added to a ``COLLECTOR_SETTINGS_REFUSED`` warning. An emitter given a -#: collector token in the environment uses it instead of the Hugging Face -#: credential, and the token only sends telemetry, so its submissions never -#: have a credential: the variables are to be unset, not completed. +#: Which credential collector submissions use. An emitter given a collector +#: token in the environment uses it instead of the Hugging Face credential, +#: and the token only sends telemetry, so its submissions never have a +#: credential: the variables are to be unset, not completed. +_CREDENTIAL_ADVICE: Final = ( + "Collector submissions use the Hugging Face credential, and an emitter" + " given a collector token uses that token instead, which only sends" + " telemetry: unset MICROCOSM_COLLECTOR_TOKEN," + " MICROCOSM_COLLECTOR_TOKEN_EXPIRES_AT and MICROCOSM_COLLECTOR_ORIGIN for a" + " staging or publication that should reach the collector." +) +#: Added to a ``COLLECTOR_SETTINGS_REFUSED`` warning. _SETTINGS_REFUSED_ADVICE: Final = ( " The emitter's own warning gives the error type: a collector origin or" " development collector it does not trust, or collector-token variables" - " it cannot use. Collector submissions use the Hugging Face credential," - " and an emitter given a collector token uses that token instead, which" - " only sends telemetry: unset MICROCOSM_COLLECTOR_TOKEN," - " MICROCOSM_COLLECTOR_TOKEN_EXPIRES_AT and MICROCOSM_COLLECTOR_ORIGIN for a" - " staging or publication that should reach the collector." + f" it cannot use. {_CREDENTIAL_ADVICE}" ) +#: A ``pending`` code: the emitter has no credential for the submissions, +#: because it was given a telemetry-only collector token or finds no Hugging +#: Face credential. A later emitter sends them only once it has one. +_CREDENTIAL_MISSING: Final = "CREDENTIAL_MISSING" #: A receipt's code, printed only when it has this shape: the emitter's codes, #: or the collector's own, which are lower case (``content_mismatch``). _CODE: Final = re.compile(r"^[A-Za-z][A-Za-z0-9_]{0,63}$") @@ -136,14 +144,22 @@ def _collector_warning(receipt: Mapping[str, Any], subject: str) -> str | None: f"the collector gave no final status for the submissions of {subject} " f"within a day of accepting them ({shown})." ) + if status == "pending" and code == _CREDENTIAL_MISSING: + return ( + f"the collector had not accepted the submissions of {subject} when " + f"the wait ended ({code}): the emitter has no credential to submit " + f"them with. {_CREDENTIAL_ADVICE} A build with no Hugging Face " + "credential needs HF_TOKEN or `hf auth login`. The emitter keeps them " + "queued on this machine for a later emitter that has the credential." + ) if status == "pending": detail = f" ({code})" if code else "" return ( f"the collector had not accepted the submissions of {subject} when " f"the wait ended{detail}; the emitter keeps them queued on this " - "machine, and an emitter running here later sends them. Until then, " - "leave unchanged any of their files the emitter did not copy at " - "hand-over." + "machine, and an emitter running here later sends them. Leave " + "unchanged any of their files the emitter did not copy at hand-over " + "until the hand-over settles." ) return None diff --git a/tools/stage_uk_rowwise_candidate.py b/tools/stage_uk_rowwise_candidate.py index 74f5ad40d9..d9328b485c 100644 --- a/tools/stage_uk_rowwise_candidate.py +++ b/tools/stage_uk_rowwise_candidate.py @@ -9,9 +9,11 @@ and ``sha256sums.txt``, which the emitter commits in one commit under ``staged//``. The command starts a short-lived emitter of its own, with only its Hugging Face module, and waits for its first upload attempt, -for up to three hours by default (``--wait-seconds``). When it stops waiting -it closes its emitter, which abandons an upload still running; the next -emitter started on the machine retries it. +for up to three hours by default (``--wait-seconds``). Once the upload has +landed it waits up to ten more minutes for the collector to accept the +bundle's submissions. When it stops waiting it closes its emitter, which +abandons an upload still running; the next emitter started on the machine +retries it. When the manifest names the build's own hand-over (``staged_dataset_handover``) and this machine's emitter still holds it, the @@ -213,7 +215,8 @@ def _parse_args(argv: list[str] | None = None) -> argparse.Namespace: "How long to wait for the emitter's upload attempt before closing it " f"(default {RESTAGE_WAIT_SECONDS:g}: a 2.4 GB bundle at 2 Mbit/s). " "Closing the emitter abandons an upload still running; the next " - "emitter started on this machine retries it." + "emitter started on this machine retries it. After an upload lands, " + "the command also waits up to ten minutes for the collector." ), ) parser.add_argument(