From 0678d1dcb7a2e6d41f645dbd79d2e0166953835d Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Thu, 26 Nov 2026 20:53:13 +0100 Subject: [PATCH 1/3] Stop the merged baseline pass at a refused post-export batch file _baseline_for caught every error from the merged baseline pass with `except Exception`, PostExportBatchFileError included, then logged a fallback and let each consumer score its own plan. The batch-file PR said whichever of it and the merged-pass PR landed second should re-raise the refusal there, as the two held-out writers do; neither did. A changed file still stopped certification one pass later, and a file that failed one read and passed the next let certification finish without the merged pass. Re-raise PostExportBatchFileError before the broad handler, say so in the docstring, and test both cases: a changed file (no fallback log, no fallback pass) and a file that fails one read only (now raises; main returned values through the fallback). Co-Authored-By: Claude Opus 5.5 --- ...-merged-baseline-batch-file-error.fixed.md | 1 + .../us/test_us_post_export_batch_files.py | 53 +++++++++++++++++++ tools/build_us_fiscal_refresh_release.py | 9 +++- 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 changelog.d/us-merged-baseline-batch-file-error.fixed.md diff --git a/changelog.d/us-merged-baseline-batch-file-error.fixed.md b/changelog.d/us-merged-baseline-batch-file-error.fixed.md new file mode 100644 index 0000000000..2593b6bdf6 --- /dev/null +++ b/changelog.d/us-merged-baseline-batch-file-error.fixed.md @@ -0,0 +1 @@ +A refused post-export batch file now stops the merged baseline pass at once. Before, the pass treated the refusal as an ordinary failure and let each consumer score its own baseline plan instead. A file that changed still stopped certification, one pass later. A file that failed one read and passed the next let certification finish without the merged pass. Scored values do not change. diff --git a/packages/microcosm-build/tests/engine_free/us/test_us_post_export_batch_files.py b/packages/microcosm-build/tests/engine_free/us/test_us_post_export_batch_files.py index e2a108560a..e54a1e96f0 100644 --- a/packages/microcosm-build/tests/engine_free/us/test_us_post_export_batch_files.py +++ b/packages/microcosm-build/tests/engine_free/us/test_us_post_export_batch_files.py @@ -284,6 +284,59 @@ def test_a_holdout_raises_a_refused_batch_file_instead_of_reporting_it( assert not (release_dir / filename).exists() +_MERGED_PLANS = {"first_consumer": (_AGE_KEY,), "second_consumer": (_AGE_KEY,)} + + +def test_the_merged_baseline_pass_raises_a_changed_batch_file_without_falling_back( + builder, tmp_path, capsys +) -> None: + """A batch file that changed stops the merged baseline pass at once: the + scorer neither logs a fallback nor scores each consumer's plan again.""" + + scorer = _open_scorer( + builder, _nested_frame(), tmp_path, baseline_plans=_MERGED_PLANS + ) + try: + first_file = sorted(scorer.batch_directory.iterdir())[0] + first_file.write_bytes(first_file.read_bytes() + b"changed") + capsys.readouterr() + with pytest.raises(builder.PostExportBatchFileError, match="SHA-256"): + scorer.open_consumer("first_consumer", _MERGED_PLANS["first_consumer"]) + assert "merged baseline plan failed" not in capsys.readouterr().out + assert not scorer._merged_baseline_failed + finally: + scorer.close() + + +def test_the_merged_baseline_pass_raises_a_batch_file_it_could_not_read_once( + builder, tmp_path, monkeypatch +) -> None: + """A batch file the merged pass could not read stops certification, even + when a later read of the same file would succeed: the per-consumer plans + do not score it again in a fallback pass.""" + + scorer = _open_scorer( + builder, _nested_frame(), tmp_path, baseline_plans=_MERGED_PLANS + ) + try: + first_file = sorted(scorer.batch_directory.iterdir())[0] + real_read_bytes = Path.read_bytes + failed_reads = [] + + def read_bytes_failing_once(path): + if path == first_file and not failed_reads: + failed_reads.append(path) + raise OSError("fixture read error") + return real_read_bytes(path) + + monkeypatch.setattr(Path, "read_bytes", read_bytes_failing_once) + with pytest.raises(builder.PostExportBatchFileError, match="cannot be read"): + scorer.open_consumer("first_consumer", _MERGED_PLANS["first_consumer"]) + assert failed_reads == [first_file] + finally: + scorer.close() + + def test_a_pass_frees_each_batch_before_it_reads_the_next( builder, tmp_path, monkeypatch ) -> None: diff --git a/tools/build_us_fiscal_refresh_release.py b/tools/build_us_fiscal_refresh_release.py index 7d544a5041..0231c25ae8 100644 --- a/tools/build_us_fiscal_refresh_release.py +++ b/tools/build_us_fiscal_refresh_release.py @@ -6129,7 +6129,10 @@ def _baseline_for( opened again, scores its own plan in a pass of its own. If the merged pass raises, every consumer scores its own plan, so a key that only one consumer planned fails that consumer alone, with the error it - raised before the merge (the holdout reports catch it). + raised before the merge (the holdout reports catch it). A refused + batch file (:class:`PostExportBatchFileError`) is the exception: it + stops certification at once, as it does in every other post-export + stage, and no consumer scores its own plan. """ registered = self._registered_baseline_plans.get(name) if registered is not None and registered != baseline_plan: @@ -6149,6 +6152,10 @@ def _baseline_for( ) try: self._merged_baseline = self._score(union, label="merged baseline plan") + except PostExportBatchFileError: + # The scored file's integrity, not a key one consumer planned: + # it stops certification. + raise except Exception as error: self._merged_baseline_failed = True try: From 8f3a4a147273d67515e21146ad214b8b0c8610d7 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Thu, 26 Nov 2026 22:09:31 +0100 Subject: [PATCH 2/3] Say in the release rule that a refused batch file stops the shared pass The rule still said every stage runs its own pass when the shared pass raises. A refused batch file is now the exception: it stops certification there, and the cost is a rerun. Co-Authored-By: Claude Opus 5.5 --- docs/us-release-build-rule.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/us-release-build-rule.md b/docs/us-release-build-rule.md index b63d1297ef..56effe8246 100644 --- a/docs/us-release-build-rule.md +++ b/docs/us-release-build-rule.md @@ -462,7 +462,9 @@ one Microsimulation over the whole file. smoke, reform validation, demographics and the two held-out reports) ran a pass of its own: five passes over 177 batches on a national export. If the shared pass raises, every stage runs its own pass as before, so a key that - only one held-out report asks for still fails that report alone. Each + only one held-out report asks for still fails that report alone. A refused + batch file does not fall back: it stops certification in the shared pass, + and no stage runs its own. Each stage's recorded `baseline_passes` stays 1: the one pass its baseline came from, shared unless the shared pass failed. Only the build log tells the two apart: it prints `Post-export merged baseline plan failed` on a fallback, @@ -485,7 +487,8 @@ one Microsimulation over the whole file. stage now includes every stage's baseline work, and the later stages' times include none. - A shared pass that fails costs the time it ran in addition to every - stage's own pass. + stage's own pass. A shared pass stopped by a refused batch file costs a + rerun of certification instead. - `_record_post_export_request_descriptors` runs the same dry run and returns every request, baseline and reform, as a picklable `PostExportRequest` (`microcosm.build.us_runtime.post_export_requests`), which a process started From 020c9857377c6f85750b984921c28cc7ac0dddc6 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Thu, 26 Nov 2026 22:35:18 +0100 Subject: [PATCH 3/3] Note the refused-batch-file exception in the plan comment and test it directly The scoring-plan comment still said every consumer scores its own plan once the merged pass fails; a refused batch file is raised at once instead. The _baseline_for docstring now names the guard sweep's baseline worker, which registers its plans too. The changed-file test asserts that no consumer scored its own plan. Co-Authored-By: Claude Opus 5.5 --- .../engine_free/us/test_us_post_export_batch_files.py | 4 +++- tools/build_us_fiscal_refresh_release.py | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/microcosm-build/tests/engine_free/us/test_us_post_export_batch_files.py b/packages/microcosm-build/tests/engine_free/us/test_us_post_export_batch_files.py index e54a1e96f0..4854648327 100644 --- a/packages/microcosm-build/tests/engine_free/us/test_us_post_export_batch_files.py +++ b/packages/microcosm-build/tests/engine_free/us/test_us_post_export_batch_files.py @@ -302,7 +302,9 @@ def test_the_merged_baseline_pass_raises_a_changed_batch_file_without_falling_ba capsys.readouterr() with pytest.raises(builder.PostExportBatchFileError, match="SHA-256"): scorer.open_consumer("first_consumer", _MERGED_PLANS["first_consumer"]) - assert "merged baseline plan failed" not in capsys.readouterr().out + out = capsys.readouterr().out + assert "merged baseline plan failed" not in out + assert "first_consumer baseline plan" not in out assert not scorer._merged_baseline_failed finally: scorer.close() diff --git a/tools/build_us_fiscal_refresh_release.py b/tools/build_us_fiscal_refresh_release.py index 0231c25ae8..771e8d35fa 100644 --- a/tools/build_us_fiscal_refresh_release.py +++ b/tools/build_us_fiscal_refresh_release.py @@ -5089,8 +5089,9 @@ def _select_households_by_position(frame: Frame, positions: np.ndarray) -> Frame # in ONE batch-outer pass, in ascending period order, serving each consumer # its own keys (microcosm#1595). A consumer without a registered plan, and # every consumer once that pass has failed, scores its own plan in a pass -# of its own. The served baseline refuses any key outside the consumer's -# recorded plan; +# of its own; a refused batch file (``PostExportBatchFileError``) is raised +# at once instead. The served baseline refuses any key outside the +# consumer's recorded plan; # * each reform builds ONE tax-benefit system (microcosm#456) and scores each # key, or each set of keys it is asked to ``prefetch``, in one pass, batch # by batch; every batch engine is released before the next; @@ -6131,8 +6132,9 @@ def _baseline_for( one consumer planned fails that consumer alone, with the error it raised before the merge (the holdout reports catch it). A refused batch file (:class:`PostExportBatchFileError`) is the exception: it - stops certification at once, as it does in every other post-export - stage, and no consumer scores its own plan. + propagates at once, as it does from every other post-export pass, so + it stops certification (or the guard sweep's baseline worker) and no + consumer scores its own plan. """ registered = self._registered_baseline_plans.get(name) if registered is not None and registered != baseline_plan: