Skip to content

draws.py: the docstring lied about S, and the code lied about empty payloads - #329

Merged
Polichinel merged 4 commits into
developmentfrom
docs/draws-docstring-stale-sample-width
Nov 12, 2026
Merged

Polichinel merged 4 commits into
developmentfrom
docs/draws-docstring-stale-sample-width

Conversation

@Polichinel

Copy link
Copy Markdown
Collaborator

What

views_postprocessing/delivery/draws.py's module docstring claimed that FAO receives the full posterior mixture — (N, S≈1024) draws per cell. Two things wrong in one sentence:

  1. It stated a design target as delivered fact. S≈1024 is ADR-015's aspiration on the produced count, not a width any FAO delivery has carried.
  2. It named the wrong consumer, exclusively. The ADR-013 §6 gate is partner-neutral and has run for CRAF'd as well as FAO since S5 — Separate partner declarations from delivery machinery #153 — sink.deliver_run takes s_min and consumer_name as parameters and reaches for neither partner's facts.

Why remove the number rather than correct it

The delivered width is a property of the run. It is declared in the §2 header and floored per product by S_MIN — those are its two homes. A value written into this docstring is a third copy of a fact nothing checks, and it is the copy that had already drifted.

Correcting 1024 to a current number would reintroduce exactly the thing that failed: ADR-015 expects the width to move upward (512–1024 per constituent), so any number written here is scheduled to go stale. The docstring now says what S is — header-declared, pooled across the ensemble's members, differing per ensemble — and points at where to read it.

This follows the repo's one-home-per-fact rule: reasoning lives in the register, docstrings point at it, and declarations are the authority.

Evidence

Measured this turn, from the staged chrome_box wire:

  • sample_count = 1024 in all 108 shard headers, one distinct value
  • num_rows / 64,742 = 1,024 on first and last shard
  • one provenance block throughout: {"ensemble": "chrome_box", "pipeline_core_version": "3.4.0", "reconciled": true}

So 1,024 is one ensemble's pooled width, not a constant — which is the point.

Deliberately not changed

docs/ADRs/013_sampled_forecast_wire_contract.md:74 reads "Production aims at S≈1024." That is true as an aim and stays. The docstring's error was restating an aim as a measurement, not the aim itself.

Verification

  • ruff check views_postprocessing/delivery/draws.py — all checks passed
  • pytest -k "draws or collapse" — 11 passed, 0 failed
  • Grep confirmed no test or doc asserts on this docstring's text. The 1024 literals in tests/test_draws.py:44-46 and tests/test_track_a_source.py:105-106 are fixtures for a header-declares-1024-vs-payload-mismatch case, untouched by this change.

Docstring only — no behaviour change.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ANY1CCy9Xo7zjMY4XJ69v9

Polichinel and others added 3 commits November 12, 2026 01:51
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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ANY1CCy9Xo7zjMY4XJ69v9
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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ANY1CCy9Xo7zjMY4XJ69v9
… is not a verdict

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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ANY1CCy9Xo7zjMY4XJ69v9
@Polichinel Polichinel changed the title docs(draws): S has two homes, and neither is this docstring draws.py: the docstring lied about S, and the code lied about empty payloads Nov 12, 2026
@Polichinel

Copy link
Copy Markdown
Collaborator Author

Scope changed: this PR is no longer docs-only

/code-review max's Phase 3 sweep landed after the first review and found a correctness bug in the same function. I've added the fix here rather than on a separate branch, because the two are the same defect: the docstring on this branch asserts that check 4 fails "only [when] every row is draw-degenerate", and for an empty payload the code did not honour that. Fixing the prose alone would have left the file self-contradictory in a new way.

PR retitled accordingly.

Added in 2190bd6

An empty payload was reported as a collapse. 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 sent the reader to the summarizer and the ADR-013 §6 contract when the real fault was a target that resolved to no rows — which would have shipped zero cells to a partner. Now refused as what it is, pointing upstream at the resolution step. 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 raised numpy's bare ValueError. Because DrawsCollapseError subclasses ValueError, a caller catching the narrow type missed it entirely, while a caller catching ValueError blamed the §6 policy gate for malformed input. Now wrapped, stating that nothing about the draws has been checked.

Both are documented as sitting outside §6's four rules, since in neither case is there a payload to judge. The four-rule numbering is deliberately left intact — ADR-013 counts four, and renumbering would widen a drift that already exists (see below).

Two tests, both asserting the old message cannot come back

test_an_empty_payload_is_refused_as_empty_and_not_as_collapsed asserts "degenerate" not in str(excinfo.value), so the misdiagnosis is pinned out, not just the new behaviour pinned in.

Verification

  • ruff check — clean on both files
  • pytest tests/test_draws.py — 12 passed
  • Full suite — 529 passed, 3 skipped, 41 xfailed, 0 failed (excluding tests/test_falsify_coverage_region_is_declared.py, which is untracked and in no commit)

Flagged for the maintainer, not fixed here

docs/ADRs/013_sampled_forecast_wire_contract.md:1126 carries an open maintainer item: "(2) §6 "region-pinned" production S_min: the term was never defined". Commit 5d6262e on this branch removed that exact phrase from the docstring — it was measurably false, since nothing region-pins a sample width — but removing an undefined term is not the same as defining it, and the ADR's open item stands. The ADR is now the stale copy: :730 still scopes the gate to "the FAO delivery" and promises the wiring "lands with the #91 sink leg (not yet built)" when it is built and reached from both managers, and :1201 still asserts the four rules "all match delivery/draws.py exactly".

That is a two-place ADR amendment plus a maintainer decision, so it is deliberately out of this PR.

…verclaim

/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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ANY1CCy9Xo7zjMY4XJ69v9
@Polichinel
Polichinel merged commit db42863 into development Nov 12, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant