From e3a461b5adffa1bcc634840565733a3f422e8a68 Mon Sep 17 00:00:00 2001 From: Polichinl Date: Thu, 12 Nov 2026 01:51:19 +0100 Subject: [PATCH 1/4] docs(draws): S has two homes, and neither is this docstring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The module docstring claimed FAO receives ``(N, S≈1024)`` draws per cell. That was a design target stated as delivered fact, and it named the wrong consumer: ADR-013 §6's gate is partner-neutral and has run for CRAF'd as well as FAO since #153. Rather than correct the number, remove it. The delivered width is a property of the run, declared in the §2 header and floored per product by ``S_MIN``; a value written into this docstring is a third copy of a fact with two homes, and it is the copy nothing checks. It had already drifted once. Measured today: the staged chrome_box wire's headers declare ``sample_count = 1024`` in all 108 shards, with ``num_rows / 64,742 = 1,024`` — one ensemble's pooled width, not a constant. ``docs/ADRs/013`` §74 is left alone: it says production *aims* at S≈1024, which is true as an aim. The docstring's error was restating an aim as a measurement. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01ANY1CCy9Xo7zjMY4XJ69v9 --- views_postprocessing/delivery/draws.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/views_postprocessing/delivery/draws.py b/views_postprocessing/delivery/draws.py index 799537a..57ae030 100644 --- a/views_postprocessing/delivery/draws.py +++ b/views_postprocessing/delivery/draws.py @@ -7,12 +7,19 @@ lives here. Declare-don't-guess: nothing is inferred from the payload — the caller states what the payload claims to be, and this invariant fails loud if it is not. -Why this matters: the whole point of the sampled-forecast wire (ADR-013) is that FAO -receives the full posterior mixture — ``(N, S≈1024)`` draws per cell — collapsed to a -point exactly once, downstream, in the summarizer. Any hop that bakes out a mean/median -or ships a mislabeled point payload silently flattens the mixture. This is the single -**policy** gate (the per-hop emission/ingest asserts are mechanism guards); it runs -before every FAO-facing forecast upload. +Why this matters: the whole point of the sampled-forecast wire (ADR-013) is that a +partner receives the full posterior mixture — ``(N, S)`` draws per cell — collapsed to +a point exactly once, downstream, in the summarizer. Any hop that bakes out a +mean/median or ships a mislabeled point payload silently flattens the mixture. This is +the single **policy** gate (the per-hop emission/ingest asserts are mechanism guards); +it runs before every partner-facing forecast upload — FAO's and CRAF'd's alike, since +the sink is partner-neutral (#153). + +``S`` is deliberately not given a value here. It is whatever the run's §2 header +declares — the width pooled across the ensemble's members, which differs per ensemble — +and the floor a delivery will accept is its product's own ``S_MIN``. Those are its two +homes. The ``S≈1024`` that stood in this paragraph until 2026-11-12 was a third copy +and had gone stale: it stated a design target as though it were the delivered width. """ from __future__ import annotations From 5d6262e849eee98717c7d0d2670cdc7f8b747993 Mon Sep 17 00:00:00 2001 From: Polichinl Date: Thu, 12 Nov 2026 03:01:44 +0100 Subject: [PATCH 2/4] docs(draws): the floor had a stale third copy too, nine lines down MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review of the previous commit caught that it asserted the floor has exactly two declared homes while check 3's own description, unchanged in the same docstring, named a third: "the consumer-facing floor (2 for the walking skeleton; region-pinned for production)". Measured: nothing region-pins the draw width. Neither product module mentions ``region`` at all, and ``delivery/coverage.py`` pins cell counts, not sample widths. The floor is a plain per-product constant. So the fix for one stale copy of a fact shipped beside another stale copy of the same fact. Also tightened the paragraph the previous commit added: it said the header and ``S_MIN`` were "its two homes", eliding that the header declares the width while ``S_MIN`` declares the floor — two facts, not one with two homes, which is the distinction the paragraph exists to draw. ruff clean; 41 passed on -k "draws or collapse or doc_accuracy". Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01ANY1CCy9Xo7zjMY4XJ69v9 --- views_postprocessing/delivery/draws.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/views_postprocessing/delivery/draws.py b/views_postprocessing/delivery/draws.py index 57ae030..40b0fef 100644 --- a/views_postprocessing/delivery/draws.py +++ b/views_postprocessing/delivery/draws.py @@ -15,11 +15,12 @@ it runs before every partner-facing forecast upload — FAO's and CRAF'd's alike, since the sink is partner-neutral (#153). -``S`` is deliberately not given a value here. It is whatever the run's §2 header -declares — the width pooled across the ensemble's members, which differs per ensemble — -and the floor a delivery will accept is its product's own ``S_MIN``. Those are its two -homes. The ``S≈1024`` that stood in this paragraph until 2026-11-12 was a third copy -and had gone stale: it stated a design target as though it were the delivered width. +``S`` is deliberately not given a value here. The run's §2 header declares what the +width is — pooled across the ensemble's members, so it differs per ensemble — and each +product's ``S_MIN`` declares the least a delivery will accept. Those two declarations +are the authority. The ``S≈1024`` that stood in this paragraph until 2026-11-12 was +neither, and had gone stale: it stated a design target as though it were the delivered +width. """ from __future__ import annotations @@ -45,9 +46,9 @@ def assert_draws_uncollapsed( 1. ``values`` is 2-D ``(N, S)`` — a collapsed 1-D column or a stacked 3-D block is not a sampled forecast payload. 2. payload ``S == sample_count`` — the header's declaration must match the bytes. - 3. ``sample_count >= s_min`` — the consumer-facing floor (2 for the walking - skeleton; region-pinned for production). Declared by the caller from config, - never guessed here. + 3. ``sample_count >= s_min`` — the consumer-facing floor, declared per product in + its own ``S_MIN`` (2 while the deliveries are walking skeletons). Declared by + the caller from config, never guessed here. 4. **Global** non-degeneracy — at least one row carries more than one distinct draw value. Per-row zero variance is explicitly **legal** (zero-conflict cells dominate PGM); only a payload where *every* row is draw-degenerate fails — that From 2190bd6aa27efefb2e642724784ca7a29eeafe83 Mon Sep 17 00:00:00 2001 From: Polichinl Date: Thu, 12 Nov 2026 03:12:01 +0100 Subject: [PATCH 3/4] fix(draws): an empty payload is not a collapsed one, and ragged input is not a verdict MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The docstring work on this branch asserted that check 4 fails "only [when] *every* row is draw-degenerate". For an empty payload the code did not honour that, so fixing the prose without fixing the code would have left the file self-contradictory in a new way. Both found by /code-review max's sweep. **Empty payload, misdiagnosed.** `np.any(arr != arr[:, :1], axis=1).any()` over zero rows is False, so the degeneracy branch fired. Measured before the fix: (0, 8) -> "every one of the 0 rows is draw-degenerate (all 8 draws identical per row)" (3, 0) -> "every one of the 3 rows is draw-degenerate (all 0 draws identical per row)" Vacuously true, and it pointed the reader at the summarizer and the ADR-013 §6 contract when the real fault was a target that resolved to no rows — which would have delivered zero cells to a partner. Now refused as what it is, naming the resolution step upstream. (The `(3, 0)` shape is unreachable in production: check 2 or check 3 catches a zero width first, since S_MIN is 2.) **Ragged input, mislabelled.** `np.asarray([[1,2],[3]])` raises numpy's bare `ValueError`, and because `DrawsCollapseError` subclasses `ValueError` a caller catching the narrow type missed it while a caller catching `ValueError` blamed the §6 policy gate for malformed input. Now wrapped, saying that nothing about the draws has been checked. Both refusals are documented as sitting **outside** §6's four rules, because in both cases there is no payload to judge. The four-rule numbering is deliberately left intact: ADR-013 counts four, and renumbering would widen the drift that review finding (c) already records. ruff clean; tests/test_draws.py 12 passed; full suite 529 passed, 3 skipped, 41 xfailed, 0 failed (excluding the untracked stub, which is in no commit). Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01ANY1CCy9Xo7zjMY4XJ69v9 --- tests/test_draws.py | 27 ++++++++++++++++++++++ views_postprocessing/delivery/draws.py | 32 +++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/tests/test_draws.py b/tests/test_draws.py index 1724b9f..4a4867f 100644 --- a/tests/test_draws.py +++ b/tests/test_draws.py @@ -77,3 +77,30 @@ def test_nan_rows_count_as_varied_documented_behavior(): def test_label_appears_in_message(): with pytest.raises(DrawsCollapseError, match="second-store"): assert_draws_uncollapsed(np.zeros(3), 8, s_min=2, label="second-store") + + +def test_an_empty_payload_is_refused_as_empty_and_not_as_collapsed(): + """0 rows is not a collapse, and saying so sent readers to the wrong place. + + `np.any(arr != arr[:, :1], axis=1).any()` over zero rows is False, so the + degeneracy branch fired and reported "every one of the 0 rows is + draw-degenerate (all 8 draws identical per row)" — vacuously true. It pointed + the reader at the summarizer and the ADR-013 §6 contract when the real fault was + a target that resolved to no rows, which would have delivered zero cells to a + partner. Found by `/code-review max`, 2026-11-12. + """ + with pytest.raises(DrawsCollapseError, match="0 rows") as excinfo: + assert_draws_uncollapsed(np.zeros((0, 8), dtype="float32"), 8, s_min=2) + # The old message is the thing under test: it must not come back. + assert "degenerate" not in str(excinfo.value) + + +def test_input_that_is_not_an_array_at_all_is_refused_as_malformed(): + """Ragged input raised numpy's bare ValueError, which reads as a §6 verdict. + + `DrawsCollapseError` subclasses `ValueError`, so a caller catching the narrow + type missed this entirely while a caller catching `ValueError` blamed the policy + gate for malformed input. Nothing about the draws has been checked at that point. + """ + with pytest.raises(DrawsCollapseError, match="could not be read as an array"): + assert_draws_uncollapsed([[1, 2], [3]], 2, s_min=2) diff --git a/views_postprocessing/delivery/draws.py b/views_postprocessing/delivery/draws.py index 40b0fef..64dbcf6 100644 --- a/views_postprocessing/delivery/draws.py +++ b/views_postprocessing/delivery/draws.py @@ -54,6 +54,14 @@ def assert_draws_uncollapsed( dominate PGM); only a payload where *every* row is draw-degenerate fails — that is a collapsed forecast wearing a sampled header, not an edge case. + Two refusals sit **outside** those four rules, because in both cases there is no + payload for §6 to judge: input ``np.asarray`` cannot read at all (ragged input, + which used to surface as a bare ``ValueError`` appearing to blame this gate), and + a payload with zero rows (which check 4 reported as "every one of the 0 rows is + draw-degenerate" — vacuously true, and a diagnosis pointing at the summarizer + when the frame simply resolved empty). Both raise ``DrawsCollapseError`` naming + the real fault, so the ``Raises`` contract below holds for every input. + NaN note: a NaN draw compares unequal to everything (including another NaN), so a NaN-carrying row counts as non-degenerate here. That is deliberate — NaN payloads are not this invariant's job; they fail loud at the delivery null gates. @@ -68,7 +76,18 @@ def assert_draws_uncollapsed( Raises: DrawsCollapseError: naming the failed check, expected vs found. """ - arr = np.asarray(values) + try: + arr = np.asarray(values) + except Exception as exc: + # `np.asarray` raises on ragged input, and the raw ValueError reads as though + # the §6 policy gate had rejected the draws. It had not — it never got a + # payload to look at. `DrawsCollapseError` subclasses ValueError, so a caller + # catching the narrow type used to miss this entirely. + raise DrawsCollapseError( + f"{label}: the payload could not be read as an array at all " + f"({type(exc).__name__}: {exc}) — this is malformed input, not a collapsed " + f"forecast. Nothing about the draws has been checked." + ) from exc if arr.ndim != 2: raise DrawsCollapseError( f"{label}: payload is {arr.ndim}-D, expected 2-D (N, S) draws — a collapsed " @@ -85,6 +104,17 @@ def assert_draws_uncollapsed( f"{label}: sample_count={sample_count} is below the delivery floor " f"s_min={s_min} — a (near-)point payload must not ship as a sampled forecast." ) + if arr.shape[0] == 0: + # Check 4 below cannot speak for an empty payload: `np.any(...).any()` over + # zero rows is False, so the degeneracy branch fired and reported "every one + # of the 0 rows is draw-degenerate" — vacuously true, and a diagnosis that + # sends the reader to the summarizer and the §6 contract when the real fault + # is that this target resolved to no rows at all. + raise DrawsCollapseError( + f"{label}: payload has 0 rows — an empty frame is not a collapsed " + f"forecast, and shipping it would deliver zero cells. The fault is " + f"upstream of this gate, where the target's frame was resolved." + ) varied_rows = np.any(arr != arr[:, :1], axis=1) if not bool(varied_rows.any()): raise DrawsCollapseError( From b80bd3d0e22c9014e64c25ac72664b75d30b3575 Mon Sep 17 00:00:00 2001 From: Polichinl Date: Thu, 12 Nov 2026 03:22:11 +0100 Subject: [PATCH 4/4] docs(draws): the fix overclaimed in the same sentence that fixed an overclaim MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit /falsify, claim mode, on "ready to merge": FALSIFIED by the prose added in 2190bd6. It said the two new refusals mean "the Raises contract below holds for every input". Measured: s_min=None -> TypeError (escapes DrawsCollapseError) s_min="2" -> TypeError (escapes DrawsCollapseError) Both from check 3's `sample_count < s_min`. Since DrawsCollapseError subclasses ValueError, neither is catchable as a draws failure, so "every input" was false on the third probe that looked for it. Narrowed to what was measured: no *payload* can now reach a caller as a bare ValueError, and the declared ints remain unenforced — stated explicitly, with the reason it is tolerable (sink.py passes a product constant) rather than left for the next reader to discover. This is the third stale or overstated claim in this one docstring, and the second one introduced while fixing the previous. Recorded in the commit rather than the prose, because the file does not need a changelog of its own prose. ruff clean; full suite 529 passed, 3 skipped, 41 xfailed, 0 failed. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01ANY1CCy9Xo7zjMY4XJ69v9 --- views_postprocessing/delivery/draws.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/views_postprocessing/delivery/draws.py b/views_postprocessing/delivery/draws.py index 64dbcf6..791c338 100644 --- a/views_postprocessing/delivery/draws.py +++ b/views_postprocessing/delivery/draws.py @@ -60,7 +60,11 @@ def assert_draws_uncollapsed( a payload with zero rows (which check 4 reported as "every one of the 0 rows is draw-degenerate" — vacuously true, and a diagnosis pointing at the summarizer when the frame simply resolved empty). Both raise ``DrawsCollapseError`` naming - the real fault, so the ``Raises`` contract below holds for every input. + the real fault, so no *payload* can now reach a caller as a bare ``ValueError``. + The declared ints are a separate matter and are still unenforced: a non-int + ``s_min`` escapes as a ``TypeError`` from check 3. Unreachable from + ``wire/sink.py``, which passes a product constant, and measured rather than + assumed — but not a claim this docstring should make for every input. NaN note: a NaN draw compares unequal to everything (including another NaN), so a NaN-carrying row counts as non-degenerate here. That is deliberate — NaN payloads