Repository navigation
fix(python): align local score rounding with the reference - #672
Open
yousizaitianqiong wants to merge 1 commit into
Open
yousizaitianqiong wants to merge 1 commit into
yousizaitianqiong wants to merge 1 commit into
Conversation
yousizaitianqiong
requested review from
AsperforMias,
KurosawaGeeker and
hikariming
as code owners
November 24, 2026 05:23
This branch has not been deployed
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.
Problem
The Python SDK can report a mismatch for a scan produced by the TypeScript scorer because Python's built-in
roundand the reference's scaled half-even rule differ at some boundaries. With synthetic metrics and no active contribution years, an account age of0.9produces maturity1.1in the current Python scorer and1.0in the reference; at2.7, Python produces3.1and the reference produces3.2. The corrected Python scorer matches the reference in both cases.Change
Use a shared Python helper for the existing reference rule in the scoring and risk paths, and add cross-runtime fixtures for score and risk boundaries. Preserve the previous Python behavior when scaling a finite value overflows. The tested finite inputs also retain the reference's signed-zero behavior. This follows up the rounding discussion in #231, authored by 4evour; that prior work is not part of this contribution.
The TypeScript and Go scoring implementations and the server's scoring weights are unchanged. The separate
_math_roundhelpers and the fields compared byverify_scanare also unchanged. The implementation does not claim complete cross-language equivalence for all floats: for example, finite values whose scaling overflows retain the existing Python result while the TypeScript and Go helpers can return infinity.Impact and versioning
The examples above are synthetic. I recomputed the full Python score and risk output for 13 public, anonymized historical fixture snapshots representing 11 fixture aliases; baseline and candidate outputs were identical for those snapshots. This is not a live scan and does not establish how many real accounts are affected.
I also replayed my own public cached scan (
scanned_at=1795385705753) offline. The baseline and candidate returned identical full Python scoring outputs, including the risk assessment, with a final score of 67.4. This single snapshot does not establish the wider impact.scoring/README.mdrequires a backend score-version bump when outputs change. This patch changes the Python mirror at demonstrated boundaries while leaving the canonical TypeScript scorer unchanged. Could maintainers confirm whether this mirror-only correction needs a coordinated backend version change?Validation
go test ./...andgo vet ./...passed; the independent review also ran 11 shared parity subtests and a separate boundary probe. Existing Go/TypeScript differences at extreme values and signed zero remain outside this Python patch.pnpm scoring:boundarypassed; pnpm reported an existingnode_modules/lockfile setting warning.The first Windows pytest collection failed because the default GBK encoding could not decode a UTF-8 fixture; the full run passed with UTF-8 enabled. The initial offline pnpm installation lacked package metadata; the successful run reused previously fetched packages. AI assistance was used to investigate, prepare, and test this change.