test(dash): compare prices with a tolerance so the suite passes on arm64 - #61
Merged
OsherElhadad merged 1 commit intoAug 12, 2026
Merged
Conversation
TestPriceNeverReportsUnknownCostAsFree fails on darwin/arm64 at origin/main (e4ad3b5), before any local change: cost = 0.00327; want 0.0032700000000000003. Both sides call the same Price.Cost with the same arguments, and nothing rounds. The difference is FMA: Price.Cost is a sum of four products, and Go permits the compiler to contract x*y + z into a fused multiply-add, which rounds once rather than twice. The contraction is applied inconsistently between the two evaluations here — the literal arguments in the test fold differently from the struct-field loads inside Price — so the two mathematically identical sums land one bit apart and == fails. amd64 does not contract this shape, so CI is green and the failure is only visible on Apple Silicon. Compare within 1e-12 instead. The property under test is the accounting (a cost we cannot compute must never read as free), which a 1-ULP difference does not affect; the surrounding exact assertions on TokenAccounting and the baseline > actual ordering are untouched. Separable from the rest of this branch — it fixes an upstream test on a platform upstream CI does not run, and touches no production code. Assisted-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Itay-Nakash <itay.nakash@ibm.com>
OsherElhadad
approved these changes
Aug 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TestPriceNeverReportsUnknownCostAsFree fails on darwin/arm64 at current main,
before any other change:
Both sides call the same modelinfo.Price.Cost with the same arguments, and
nothing in Price or Event.Price rounds. The difference is FMA. Price.Cost is a sum
of four products:
and the Go spec PERMITS an implementation to contract x*y + z into a fused
multiply-add, which rounds once instead of twice. The contraction is applied
inconsistently between the two evaluations in the test -- the literal arguments in
the assertion fold differently from the struct-field loads inside Price -- so the
two mathematically identical sums land one bit apart, and == fails.
arm64 has an FMA instruction the compiler will use for this shape; amd64 does not
contract it. So the failure is invisible in CI (ubuntu-latest, amd64) and
reproduces for every contributor on Apple Silicon. Confirmed both ways:
The fix compares within 1e-12 instead of exact equality, with the reason recorded
in a comment so nobody "simplifies" it back. The property under test is the
accounting -- a cost we cannot compute must read as unknown, never as zero -- and a
1-ULP difference does not affect it. The surrounding exact assertions are left
alone: TokenAccounting is still compared with ==, and the ordering assertion
(baseline must exceed actual when tokens were removed) is untouched, so the test
still fails if the accounting logic regresses.
Test-only change, 12 insertions, 2 deletions, no production code. make lint,
go test -race ./... and go test -race -tags cg_skeleton ./... all pass on arm64
after it; before it, ./dash/ fails.
Worth noting for whoever owns pricing: the same pattern (comparing a float64
against a re-computation of the same expression) will keep producing
platform-dependent failures wherever it appears. This PR only fixes the one
occurrence that is failing today.