Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/us-merged-baseline-batch-file-error.fixed.md
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 5 additions & 2 deletions docs/us-release-build-rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,61 @@ 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"])
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()


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:
Expand Down
15 changes: 12 additions & 3 deletions tools/build_us_fiscal_refresh_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -6129,7 +6130,11 @@ 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
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:
Expand All @@ -6149,6 +6154,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:
Expand Down
Loading