fix!: reject non-finite weights at ingestion

Measured, a NaN weight behaved exactly as `0.0`:

  weight NaN -> Ok, converged: true, 1 iteration, step (0.0, 0.0)
                skill pi 0.027777777777777776, tau 0.0
  weight 0.0 -> Ok, same skill, bit for bit

So a NaN arriving from a division or a parse was indistinguishable from
a deliberate zero, and the fit reported itself as cleanly converged.

Worth correcting an earlier description of this: the event does not
vanish. The member contributes nothing, which is precisely what weight
zero means, and that equivalence is what makes it undetectable rather
than merely wrong.

Zero and negative weights stay accepted. Both are expressible choices
about how much a member contributes, and tests/degenerate_inputs.rs pins
their behaviour deliberately; only values that are not quantities at all
are rejected. A test asserts they still ingest, so the new check cannot
quietly widen.

This completes the boundary: every malformed input that previously
produced a plausible answer — a one-team event, an empty team, a
non-finite score, a non-finite weight — now fails where it enters.

BREAKING CHANGE: an event carrying a non-finite weight returns
`InvalidParameter` instead of silently treating that member as weightless.

Refs #18

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011hcFjNDmHXZF8URGLku5zZ
This commit is contained in:
2026-09-08 21:03:16 +02:00
co-authored by Claude Opus 5
parent 862779ae34
commit 8b20e0c560
2 changed files with 66 additions and 0 deletions
+23
View File
@@ -1753,6 +1753,29 @@ impl<T: Time, D: Drift<T>, O: Observer<T>, K: Eq + Hash + Clone> History<T, D, O
}
}
// A non-finite weight is not a weight. Measured, it behaves exactly as
// `0.0` — the member contributes nothing — while `converge` reports
// `converged: true` after one iteration with a step of `(0.0, 0.0)`.
// So a NaN arriving from a division or a parse is indistinguishable
// from a deliberate zero, and looks like a clean fit.
//
// Zero and negative weights stay accepted: both are expressible
// choices about how much a member contributes, and
// `tests/degenerate_inputs.rs` pins them deliberately. Only the values
// that are not quantities at all are rejected.
if let Some(weights) = weights.as_ref() {
for team_weights in weights.iter().flatten() {
for weight in team_weights {
if !weight.is_finite() {
return Err(InferenceError::InvalidParameter {
name: "weight",
value: *weight,
});
}
}
}
}
// Chokepoint for tie validation: every ingestion route lands here,
// including `record_draw`, which builds its results directly rather
// than going through `Outcome`.