Skip to content

fix(029): the selection gate compares tolerance boundaries in exact decimal (#474) - #479

Merged
bartekus merged 1 commit into
mainfrom
fix/474-selection-decimal
Nov 3, 2026
Merged

bartekus merged 1 commit into
mainfrom
fix/474-selection-decimal

Conversation

@bartekus

@bartekus bartekus commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor
  • Spec 029, 3.12.3: every clause comparison, with within: { absolute: t } or a noise band, is computed in exact decimal over the shortest round-trip decimals of b, c and the band; a candidate exactly on a boundary is decided by the comparison as written (passes >=/<=, fails >/<). Band computation (3.5) is unchanged. Dated 2026-11-03 Implementation record paragraph cites Selection gate: a candidate exactly at a decimal tolerance boundary passes or fails on binary rounding (spec 029) #474 and the owner's decision.
  • metric_clause (crates/rustev-eval/src/selection.rs) no longer forms a binary64 threshold; a small local exact digit sum does the comparison (no new dependency). A non-finite value or band is refused, leaving the clause unknown (3.12.4), never panicking.
  • Coverage minima were already exact integer comparisons.
  • New tests: absolute_tolerance_edges_compare_in_exact_decimal (the four rows of Selection gate: a candidate exactly at a decimal tolerance boundary passes or fails on binary rounding (spec 029) #474 qualify, the next binary64 value past each boundary is rejected), noise_band_edges_compare_in_exact_decimal (87.5/87.6 with a 0.1 band, both directions, not_worse_than and better_than), and unit tests for the exact sum and for NaN and the infinities. No golden or fixture changes.

Fixes #474.

Checks run locally: cargo test -p rustev-eval --locked, cargo clippy -p rustev-eval --all-targets -- -D warnings, cargo fmt --all --check, make gate, spec-spine verify 029.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

AI review (findings)

Reviewing the three changed files. The core logic is the new exact_sum_cmp path for Within::Absolute tolerances.

shortest panics on NaN and infinity

shortest(v: f64) calls format!("{v:e}") and then split_once('e').expect("exponent form"). Rust's {:e} formatter produces NaN, inf, and -inf for the corresponding f64 special values — none of which contain e. The expect will panic.

shortest is called with bv and cv, which come from value(bm, …) and value(cm, …). If those functions do not already reject NaN and infinity (they are not visible in the diff), a metric value of positive or negative infinity — plausible for e.g. log-loss when a probability of zero is assigned — reaches shortest and panics rather than producing an Err.

The module unit tests exercise f64::MAX, f64::MIN_POSITIVE, and the smallest subnormal, but not f64::NAN or f64::INFINITY.

Everything else looks correct

  • add_digits: carry propagation is correct; the early-break on carry == 0 && i >= m.len() fires only after carry has been recomputed for that position.
  • exact_sum_cmp: sign dispatch via t.negative != subtract is correct; trim removes trailing (most-significant) zeros before the length-then-MSB comparison.
  • The higher/lower-is-better rewrites (c + t >= b and b + t >= c) are algebraically correct.
  • The spec text and change note match the implementation.
  • -0.0 is handled correctly: it contributes a zero digit that trim removes, leaving both sides zero.
{"head": "86b36e2e786a0414126fd94b779515ac89eecf38", "verdict": "findings", "findings": [{"path": "crates/rustev-eval/src/selection.rs", "line": 536, "summary": "shortest() panics on NaN and infinity because format!(\"{v:e}\") produces \"NaN\", \"inf\", or \"-inf\" (no 'e'), causing split_once('e').expect() to panic; there is no guard in the function or at the call sites visible in the diff."}]}

Subject: cf3ae8d...86b36e2, diff digest 51619015200c4312b2a4caa1e332a5387fe681fa8aa07d9cd7cade016f5792c1, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus temporarily deployed to statecraft-review-exception November 3, 2026 19:10 — with GitHub Actions Inactive
@bartekus
bartekus force-pushed the fix/474-selection-decimal branch from 86b36e2 to 41dd8b8 Compare November 3, 2026 19:15
…ecimal (#474)

Every selection clause comparison, with an absolute tolerance or a noise
band, is computed in exact decimal over the shortest round-trip decimals
of the baseline, candidate and band, so a candidate exactly on a
non-dyadic boundary is decided by the rule as written. A non-finite value
is refused, leaving the clause unknown. Spec 029 3.12.3 states the rule;
band computation is unchanged.
@bartekus
bartekus force-pushed the fix/474-selection-decimal branch from 41dd8b8 to f4d06f5 Compare November 3, 2026 19:16
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the three changed files: the core arithmetic in selection.rs, the new integration tests, and the spec update.

crates/rustev-eval/src/selection.rs

shortest parses format!("{v:e}"). Rust's {:e} always produces one digit before the decimal point in normalized scientific notation, so split_once('e') correctly separates mantissa from exponent. The digit extraction (filter(u8::is_ascii_digit)) skips the decimal point, and exponent - fraction correctly adjusts for it. The non-finite guard covers NaN and infinities before any parsing.

add_digits carries correctly: with each digit in 0–9 and carry in {0,1}, sum ≤ 19 < 256, so u8 never overflows; the final push(carry) handles propagation past the high end.

exact_sum_cmp builds parallel positive/negative accumulators where the sign of each term (t.negative XOR subtract) routes it correctly, giving sign(pos − neg) = sign(sum(lhs) − sum(rhs)) after trimming trailing (high-order) zero digits. Length comparison before lexicographic comparison is valid because both arrays are normalized (no leading zero in the big-endian view) and aligned to the same low exponent.

The four cases in metric_clause correctly rephrase each comparison as a >= or > between non-negative sums:

case intended code equivalent
(true,true) c > b+band cmp([c],[b,tol]).is_gt() ✓
(false,true) c < b−band cmp([b],[c,tol]).is_gt() ✓
(true,false) c >= b−band cmp([c,tol],[b]).is_ge() ✓
(false,false) c <= b+band cmp([b,tol],[c]).is_ge() ✓

exact() for Decimal uses the integer units representation at fixed scale; the digits are MSB-first (matching shortest), so both representations feed into the same alignment logic correctly.

The -0.0 edge case: format!("{:e}", -0.0) = "-0e0" → {negative:true, digits:[0], exponent:0}. The digit zero routed to neg contributes nothing, so -0.0 and 0.0 compare as equal. The inline test confirms this.

crates/rustev-eval/tests/selection.rs

The two new tests (absolute_tolerance_edges_compare_in_exact_decimal, noise_band_edges_compare_in_exact_decimal) cover all four (higher, better) combinations, verify boundary equality and then that one ULP step in each direction flips the result. The sequential f.loss(true, …) calls rely on the fixture replacing the candidate datum, which is consistent with how the pre-existing tests use the same fixture.

specs/029-evaluation-repeatability/spec.md

The normative addition to §3.12.3 is consistent with the implementation: shortest round-trip decimals for binary64 values, exact decimal for t, no binary64 arithmetic on the comparison. The revision note accurately records the fix, the owner decision date (2026-11-03), and the test names. "Band computation (3.5) is unchanged" is accurate — the PR still calls band() to get an f64, then converts it via shortest.

No concrete defects found.

{"head": "f4d06f50249dc942a023776d190b4cfd095d9e24", "verdict": "no-findings", "findings": []}

Subject: cf3ae8d...f4d06f5, diff digest be62b8d9ed03e31d51d35c57bc90202620968cd722a5b5ef569b8289598b0c16, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus added this pull request to the merge queue Nov 3, 2026
bartekus added a commit that referenced this pull request Nov 3, 2026
…A-76); every PlanId changes, re-derive PlanId-keyed baselines, ledgers and caches

The release family moves from 0.3.0 to 0.4.0 in lockstep, within the
0.4.0 scope the owner decided on 2026-11-02 (no service image, no spec
011). No behavior changes from the bump itself.

- Version sites: the workspace version and its internal =0.4.0 pins,
  Cargo.lock, the nine npm package.json files, and
  tools/rustev-release/release-set.json (version and tag).
- Regenerated fixtures: every PlanId embeds the compiler identity
  rustev-core/<crate version> (spec 002 3.3.4), so every golden,
  conformance case and fixture carrying one is regenerated through its
  bless or harvest path, with byte copies where a file mirrors another.
  The rustev-serve Sigstore fixture is re-signed with its throwaway
  local keys.
- Archive policy (spec 021 3.5): a reviewed raise of rustev-runtime's
  unpacked bound from 524,288 (512 KiB) to 589,824 (576 KiB); it unpacks
  to 542,825 after specs 044 and 043 (release dry run 41628699504 and
  the local candidate refused it); and rustev-eval's from 720,896
  (704 KiB) to 786,432 (768 KiB), since #479 (spec 029's exact-decimal
  comparison) takes it from 719,021 to 724,041, measured by packaging
  the release set with that change. Archives (128,868 of 160 KiB;
  180,011 of 192 KiB), file lists and every other bound are unchanged.
  Spec 021 records the candidate run.
- Spec 058: a dated Implementation record entry for the version move,
  with the consumer note: every PlanId changes from 0.3.0 to 0.4.0, so
  baselines, ledgers and cache keys keyed by a PlanId are re-derived on
  upgrade.

Includes spec 060's ratification by the owner on 2026-11-03 (A-76: "I
ratify 060") and its first increment (3.7.2): status approved,
implementation in-progress; 060 also amends 056; publish_release leaves
present qualification- assets out of its comparison (058 3.5.2) and
refuses a run's own asset with that prefix, with the test
qualification_assets_beside_a_release_are_ignored_never_published; the
A-76 row in docs/decisions/00-founding-decisions.md. 0.4.0 still ships
without the image.

Spec-Drift-Waiver: family version bump to 0.4.0 (release 0.4.0, scope
decided by the owner on 2026-11-02). Every PlanId embeds the compiler
crate version (spec 002 3.3.4), so fixtures are regenerated mechanically
through their bless and harvest paths; no behavior changes. Approved by
the owner on 2026-11-03 ("everything necessary for the 0.4.0 release").
Merged via the queue into main with commit f1f08cd Nov 3, 2026
33 checks passed
@bartekus
bartekus deleted the fix/474-selection-decimal branch November 3, 2026 21:25
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.

Selection gate: a candidate exactly at a decimal tolerance boundary passes or fails on binary rounding (spec 029)

1 participant