Skip to content

fix(scoring): parse underscores in fractional upstream constants - #1039

Merged
JSONbored merged 3 commits into
JSONbored:mainfrom
bohdansolovie:fix/fractional-underscore-upstream-constants
Jun 22, 2026
Merged

fix(scoring): parse underscores in fractional upstream constants#1039
JSONbored merged 3 commits into
JSONbored:mainfrom
bohdansolovie:fix/fractional-underscore-upstream-constants

Conversation

@bohdansolovie

Copy link
Copy Markdown
Contributor

Closes #992

Summary

#969 added underscore support to parsePythonNumberConstants for integer parts (1_500_000) and scientific notation (1e-9), but the fractional digit classes still rejected _. Per PEP 515, underscores are valid between digits in any part of a numeric literal.

A valid upstream constant like RATE = 0.000_001 was truncated at the first fractional underscore and read as 0, silently skewing score previews and breakdowns that depend on the fetched scoring snapshot.

Root cause

// src/scoring/model.ts — before
const match = line.match(/^([A-Z][A-Z0-9_]+)\s*=\s*([-+]?(?:\d[\d_]*\.?\d*|\.\d+)(?:[eE][-+]?\d+)?)/);
//                                                          ^ int allows _     ^ frac: no _   ^ bare decimal: no _
Python literal (PEP 515) True value Before (bug) After (fix)
RATE = 0.000_001 0.000001 0 0.000001
SCALE = 3.14_15 3.1415 3.14 3.1415
VAL = 1_000.000_5 1000.0005 1000 1000.0005
BARE = .5_0 0.5 0.5 (unchanged) 0.5

Integer grouping (1_500_000), plain floats (0.90), and exponents (5.8e1, 1e-9) continue to parse as before.

Changes

  • src/scoring/model.ts — extend fractional digit classes to allow _ in both 123.456_789 and .5_0 forms.
  • test/unit/scoring.test.ts — regression test for fractional underscore literals (#992).

Number(raw.replace(/_/g, "")) already strips underscores before parsing; no other logic changes.

Reachability

refreshScoringModelSnapshot fetches upstream gittensor/constants.py and runs it through parsePythonNumberConstants, merging results into scoring constants used by buildScorePreview, score breakdown, and unmodeled-constant detection. Any upstream maintainer using fractional digit-grouping for readability hits this path.

API / OpenAPI / MCP contract

No schema changes. Parsed upstream constant values may change when fractional underscores are present in constants.py.

Migration / deploy / secrets

None.

Security / privacy

None.

Validation

Run from repo root (Node >= 22):

npm run test:ci

All gates passed locally on branch fix/fractional-underscore-upstream-constants.

Distinct from #994

Unrelated to label multiplier selection (#994). This completes the fractional-underscore gap left by #969.

Closes JSONbored#992

Co-authored-by: Cursor <cursoragent@cursor.com>
@bohdansolovie
bohdansolovie requested a review from JSONbored as a code owner June 22, 2026 14:28
@dosubot dosubot Bot added the size:XS label Jun 22, 2026
@ghost ghost added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jun 22, 2026
@ghost

ghost commented Jun 22, 2026

Copy link
Copy Markdown

🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨

🛠️ Maintainer review — Held for maintainer review

Reviewed 2 changed file(s) — two independent AI reviewers, synthesized. ✅ Safe to merge — both reviewers found no blocking issues.

ℹ️ Correct and all CI green — held for maintainer review.

Merge readiness: ✅ Mergeable · all CI checks green/neutral/skipped.

Summary

The change updates the regex in parsePythonNumberConstants to correctly handle underscore separators in both integer and fractional parts of Python numeric literals, fixing a parsing bug. Added unit test verifies the new behavior. No security concerns, build passes, and existing tests remain green. The modification is limited to parsing logic and does not introduce regressions.

💡 Nits — non-blocking, optional

  • Regex could be refined to more strictly follow Python numeric literal rules.
  • Consider tightening the regex to reject trailing underscores (e.g., 123_) which are not valid Python literals.
  • Add a test case for an invalid constant (e.g., BAD = 1_) to ensure it is ignored.
  • Consider adding a comment explaining why the regex change is necessary and what specific issues it addresses.

@ghost ghost added the reviewbot-review label Jun 22, 2026
@ghost

ghost commented Jun 22, 2026

Copy link
Copy Markdown

Note

🟦🟦🟦🟦🟦🟦🟦🟦🟦🟦🟦🟦

💡 Gittensory review — advisory only

0 files · no blockers · readiness 0/100

💡 Advisory only — no action taken

Signal Result Evidence
Code review ✅ No blockers synthesized
Gate result ⚠️ Skipped #1039 is no longer open.

💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.

@ghost ghost added the gittensory:reviewed label Jun 22, 2026
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Held for maintainer (guardrail_area) — correct + CI green

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.85%. Comparing base (3425026) to head (f9074aa).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1039   +/-   ##
=======================================
  Coverage   96.85%   96.85%           
=======================================
  Files         141      141           
  Lines       17501    17501           
  Branches     6334     6334           
=======================================
  Hits        16951    16951           
  Misses        104      104           
  Partials      446      446           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JSONbored
JSONbored merged commit f1f7ce1 into JSONbored:main Jun 22, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: upstream-constant parser truncates fractional digit-grouping (0.000_001 -> 0)

2 participants