Skip to content

Sum legacy probability totals in a fixed order in both readers - #5

Open
0xkaushik-ai wants to merge 1 commit into
RightNow-AI:mainfrom
0xkaushik-ai:fix/legacy-distribution-sum-order
Open

0xkaushik-ai wants to merge 1 commit into
RightNow-AI:mainfrom
0xkaushik-ai:fix/legacy-distribution-sum-order

Conversation

@0xkaushik-ai

Copy link
Copy Markdown

decision_for and decisionFor check that a legacy answer's probabilities sum to 1 within 1e-6. The total was built differently on each side, so the two SDKs disagree on answers that land exactly on that edge, and so does the Python package across interpreter versions.

  • Python used sum(), which has been compensated since 3.12. [0.060817, 0.532085, 0.407097] adds to 0.9999990000000001 sequentially (accepted) but to 0.999999 under sum() (rejected). The same wheel accepts this answer on 3.11 and rejects it on 3.12+.
  • TypeScript added in Object.entries order, which puts integer-like keys first, so {"b", "1", "a"} is summed in a different order than the JSON lists it.

Both readers now add sequentially in UTF-8 key order, which the reader already uses for ties. Two legacy fixtures pin the edge: before this change the first fails on Python 3.12+ and the second fails in both SDKs.

Found by feeding the same random answers to both readers and diffing the results. The v1 path is unaffected since those totals are integers.

Python used sum(), which is compensated since 3.12, so the same legacy
answer passes the 1e-6 total check on 3.11 and fails it on 3.12+.
TypeScript added in Object.entries order, which moves integer-like keys
first. Both now add sequentially in the reader's existing tie order.

This branch has not been deployed

No deployments
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