From 10fa8507e14ab08b981a532bab8e5f265da0976f Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Thu, 26 Nov 2026 23:57:22 +0400 Subject: [PATCH 1/3] Test that the merged baseline pass raises a refused batch file at once Fails on main: when a batch file changed, the merged baseline pass (#1725) catches PostExportBatchFileError like any other error, prints that each consumer will score its own baseline plan, and the consumer's own pass then reads the same changed file and raises the same error. The merged pass must raise it after one read, with no fall-back. Co-Authored-By: Claude Opus 5.5 --- .../us/test_us_post_export_batch_files.py | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) 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..ab827fcbf9 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 @@ -473,3 +473,40 @@ def test_certification_removes_an_earlier_attempts_batch_files( builder._place_build_for_certification(record, release_root / "releases" / "r") assert sorted(path.name for path in stale.iterdir()) == ["notes.txt"] assert kept.read_text() == "not a scorer's" + + +def test_the_merged_baseline_pass_raises_a_refused_batch_file_at_once( + builder, tmp_path, monkeypatch, capsys +) -> None: + """The merged baseline pass, one pass over every registered consumer's + keys, falls back to each consumer's own pass when it raises, so a key only + one consumer planned fails that consumer alone. A refused batch file is + not such a key: every pass reads the same files. The merged pass raises + it, having read the changed file once, and nothing falls back.""" + + plans = { + "demographics": builder._record_post_export_baseline_plan( + builder._demographics_consumer + ), + "ssi_social_security_holdout": builder._record_post_export_baseline_plan( + builder._ssi_social_security_holdout_consumer + ), + } + read_batch = builder._PostExportBatchFiles.__getitem__ + positions_read: list[int] = [] + + def counted_read(self, position): + positions_read.append(position) + return read_batch(self, position) + + monkeypatch.setattr(builder._PostExportBatchFiles, "__getitem__", counted_read) + scorer = _open_scorer(builder, _nested_frame(), tmp_path, baseline_plans=plans) + try: + first_file = sorted(scorer.batch_directory.iterdir())[0] + first_file.write_bytes(first_file.read_bytes() + b"changed") + with pytest.raises(builder.PostExportBatchFileError, match="SHA-256"): + scorer.open_consumer("demographics", plans["demographics"]) + finally: + scorer.close() + assert positions_read == [0] + assert "scores its own baseline plan instead" not in capsys.readouterr().out From dcb82eb03650d147a82123512ba412829c9201fe Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Thu, 26 Nov 2026 23:58:48 +0400 Subject: [PATCH 2/3] Raise a refused batch file from the merged baseline pass at once _baseline_for re-raises PostExportBatchFileError before its broad handler, which makes every consumer fall back to scoring its own baseline plan. A key only one consumer planned still fails that consumer alone; a refused batch file now stops certification in the merged pass, since every consumer's own pass would read the same files. Scored values are unchanged. Co-Authored-By: Claude Opus 5.5 --- .../us-post-export-merged-pass-batch-refusal.fixed.md | 1 + docs/us-release-build-rule.md | 4 +++- tools/build_us_fiscal_refresh_release.py | 8 +++++++- 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 changelog.d/us-post-export-merged-pass-batch-refusal.fixed.md diff --git a/changelog.d/us-post-export-merged-pass-batch-refusal.fixed.md b/changelog.d/us-post-export-merged-pass-batch-refusal.fixed.md new file mode 100644 index 0000000000..dcac6c1c12 --- /dev/null +++ b/changelog.d/us-post-export-merged-pass-batch-refusal.fixed.md @@ -0,0 +1 @@ +US post-export scoring's merged baseline pass now raises a refused household batch file (one whose bytes changed or that cannot be read) at once. Before, it caught that error like any other, printed that each stage would score its own baseline plan, and the first stage's own pass then read the same file and raised the same error, so certification stopped one pass later than it needed to. Scored values are unchanged. diff --git a/docs/us-release-build-rule.md b/docs/us-release-build-rule.md index b63d1297ef..816f775ee2 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 is the exception: the shared pass raises it, and certification + stops there, since every stage's own pass would read the same files. 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, diff --git a/tools/build_us_fiscal_refresh_release.py b/tools/build_us_fiscal_refresh_release.py index 7d544a5041..6eae5863ec 100644 --- a/tools/build_us_fiscal_refresh_release.py +++ b/tools/build_us_fiscal_refresh_release.py @@ -6129,7 +6129,9 @@ 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 (``PostExportBatchFileError``) is raised instead: every + consumer's pass would read the same batch files. """ registered = self._registered_baseline_plans.get(name) if registered is not None and registered != baseline_plan: @@ -6149,6 +6151,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 here, before any consumer's own pass. + raise except Exception as error: self._merged_baseline_failed = True try: From 23d6030f2b964f60ae142fb556eaf96b0e59cd5e Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Fri, 27 Nov 2026 00:13:28 +0400 Subject: [PATCH 3/3] Cover an unreadable batch file in the merged pass and correct the changelog Review found that the test covered only a batch file whose bytes changed, so a fix that re-raised only on a digest mismatch would pass. The test now also deletes the file and expects the "cannot be read" refusal after one attempt, with no fall-back. The changelog (and the previous commit's message) said the fall-back pass always raised the same error. That holds for a changed file. A read error that did not happen again on the fall-back's second read used to let certification go on; it now stops certification, as a refused batch file does in every other post-export stage. Co-Authored-By: Claude Opus 5.5 --- ...-export-merged-pass-batch-refusal.fixed.md | 2 +- .../us/test_us_post_export_batch_files.py | 20 +++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/changelog.d/us-post-export-merged-pass-batch-refusal.fixed.md b/changelog.d/us-post-export-merged-pass-batch-refusal.fixed.md index dcac6c1c12..48fecbc0fb 100644 --- a/changelog.d/us-post-export-merged-pass-batch-refusal.fixed.md +++ b/changelog.d/us-post-export-merged-pass-batch-refusal.fixed.md @@ -1 +1 @@ -US post-export scoring's merged baseline pass now raises a refused household batch file (one whose bytes changed or that cannot be read) at once. Before, it caught that error like any other, printed that each stage would score its own baseline plan, and the first stage's own pass then read the same file and raised the same error, so certification stopped one pass later than it needed to. Scored values are unchanged. +US post-export scoring's merged baseline pass now raises a refused household batch file, one whose bytes changed or that cannot be read, at once, so certification stops there. Before, it caught that error like any other, printed that each stage would score its own baseline plan, and the first stage's own pass read the same file again. A file whose bytes changed raised the same error one pass later. A read error that did not happen again on that second read let certification go on; it now stops certification, as a refused batch file does in every other post-export stage. Scored values are unchanged whenever certification completes. 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 ab827fcbf9..a8edaf30e4 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 @@ -475,14 +475,19 @@ def test_certification_removes_an_earlier_attempts_batch_files( assert kept.read_text() == "not a scorer's" +@pytest.mark.parametrize( + ("damage", "refusal"), + [("changed", "SHA-256"), ("missing", "cannot be read")], +) def test_the_merged_baseline_pass_raises_a_refused_batch_file_at_once( - builder, tmp_path, monkeypatch, capsys + builder, tmp_path, monkeypatch, capsys, damage, refusal ) -> None: """The merged baseline pass, one pass over every registered consumer's keys, falls back to each consumer's own pass when it raises, so a key only - one consumer planned fails that consumer alone. A refused batch file is - not such a key: every pass reads the same files. The merged pass raises - it, having read the changed file once, and nothing falls back.""" + one consumer planned fails that consumer alone. A refused batch file, one + whose bytes changed or that cannot be read, is not such a key: every pass + reads the same files. The merged pass raises it, having tried the file + once, and nothing falls back.""" plans = { "demographics": builder._record_post_export_baseline_plan( @@ -503,8 +508,11 @@ def counted_read(self, position): scorer = _open_scorer(builder, _nested_frame(), tmp_path, baseline_plans=plans) try: first_file = sorted(scorer.batch_directory.iterdir())[0] - first_file.write_bytes(first_file.read_bytes() + b"changed") - with pytest.raises(builder.PostExportBatchFileError, match="SHA-256"): + if damage == "changed": + first_file.write_bytes(first_file.read_bytes() + b"changed") + else: + first_file.unlink() + with pytest.raises(builder.PostExportBatchFileError, match=refusal): scorer.open_consumer("demographics", plans["demographics"]) finally: scorer.close()