Skip to content

fix(scoring): truncate per-repo grace_period_hours to int for upstream parity - #1326

Merged
JSONbored merged 6 commits into
JSONbored:mainfrom
joaovictor91123:fix/time-decay-grace-period-int-truncation
Jun 26, 2026
Merged

fix(scoring): truncate per-repo grace_period_hours to int for upstream parity#1326
JSONbored merged 6 commits into
JSONbored:mainfrom
joaovictor91123:fix/time-decay-grace-period-int-truncation

Conversation

@joaovictor91123

Copy link
Copy Markdown
Contributor

Summary

Fixes #1320. resolveTimeDecay (src/scoring/preview.ts) advertises that it "Mirrors upstream's resolve_time_decay", but it did not reproduce upstream's integer coercion of the grace period. Upstream coerces only grace_period_hours to an integer while the three curve params stay floats:

# gittensor/validator/utils/load_weights.py — resolve_time_decay
grace_period_hours=int(pick(cfg.grace_period_hours, TIME_DECAY_GRACE_PERIOD_HOURS)),   # int() — truncates
sigmoid_midpoint_days=float(pick(cfg.sigmoid_midpoint_days, TIME_DECAY_SIGMOID_MIDPOINT)),
sigmoid_steepness=float(pick(cfg.sigmoid_steepness, TIME_DECAY_SIGMOID_STEEPNESS_SCALAR)),
min_multiplier=float(pick(cfg.min_multiplier, TIME_DECAY_MIN_MULTIPLIER)),

Upstream's range check permits 0 <= grace_period_hours <= 168, so a maintainer may legally configure a fractional grace (e.g. 13.9), which upstream truncates to 13. The TS port passed the raw float through, so a PR aged between trunc(grace) and grace (e.g. 13.5h with grace 13.9) was reported as fresh (multiplier 1.0) in the preview while the validator already applies decay — silently over-stating the score. Same class of parity drift as #806/#807/#808/#812.

The fix wraps the resolved grace in Math.trunc (truncate-toward-zero, the literal translation of Python int()); it is a no-op on the already-integer default 12, so no existing fixture changes. A regression test pins both the truncation and the boundary-decay behavior.

Scope

  • The PR title follows type(scope): short summary Conventional Commit format, for example fix(api): restore profile access checks.
  • This PR is focused and does not mix unrelated backend, UI, MCP, docs, dependency, and deploy changes.
  • This follows CONTRIBUTING.md and does not reintroduce GitHub Pages, VitePress, site/, or CNAME.
  • I linked an issue, or this is small enough that the summary explains why an issue is not needed.

Validation

  • git diff --check
  • npm run actionlint
  • npm run typecheck
  • npm run test:coverage locally; the one changed src/** line (Math.trunc(...)) introduces no new branch and is exercised by the time-decay suite; the new regression test covers both the truncation and the boundary-decay path.
  • npm run test:workers
  • npm run build:mcp
  • npm run test:mcp-pack
  • npm run ui:openapi:check
  • npm run ui:lint
  • npm run ui:typecheck
  • npm run ui:build
  • npm audit --audit-level=moderate
  • New or changed behavior has unit/integration tests for new branches, fallback paths, and sanitizer boundaries

If any required check was skipped, explain why:

  • Ran the full npm run test:ci gate locally; all checks green.

Safety

  • No secrets, wallet details, hotkeys, coldkeys, user PATs, private keys, raw trust scores, private rankings, or private maintainer evidence are exposed.
  • Public GitHub text stays sanitized, low-noise, and does not imply compensation guarantees or optimization tactics.
  • Auth, cookie, CORS, GitHub App, Cloudflare, or session changes include negative-path tests.
  • API/OpenAPI/MCP behavior is updated and tested where needed.
  • UI changes use live API data or real empty/error/loading states, not production mock/demo fallbacks.
  • Visible UI changes include a UI Evidence section below with JPG/JPEG or PNG screenshots arranged as organized, captioned, clickable thumbnails. SVG screenshots are not used as review evidence. Review-only screenshots or recordings are not committed to the repository.
  • Public docs/changelogs are updated where needed; changelogs are only edited for release-prep PRs.

This is a backend scoring-logic change with no UI/API surface impact, so the UI Evidence section is omitted.

Notes

  • Pure, deterministic, self-contained change to resolveTimeDecay; no schema, OpenAPI, wrangler, or migration impact.

…m parity (JSONbored#1320)

Upstream resolve_time_decay coerces only grace_period_hours to an integer (grace_period_hours=int(pick(...))) while the curve params stay floats. A repo may legally configure a fractional grace (upstream validates 0..168), so the un-truncated TS value left a PR aged between trunc(grace) and grace looking fresh in the preview while it was already decaying upstream. Wrap the resolved grace in Math.trunc to match, and pin the truncation + boundary-decay behavior with a regression test.
@dosubot dosubot Bot added the size:XS label Jun 25, 2026
@superagent-security

Copy link
Copy Markdown
Contributor

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

@JSONbored JSONbored added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jun 25, 2026
@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.42%. Comparing base (0574c0f) to head (7f9db87).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1326   +/-   ##
=======================================
  Coverage   95.42%   95.42%           
=======================================
  Files         193      193           
  Lines       21026    21026           
  Branches     7614     7614           
=======================================
  Hits        20064    20064           
  Misses        383      383           
  Partials      579      579           
Files with missing lines Coverage Δ
src/scoring/preview.ts 99.02% <ø> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JSONbored JSONbored left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Verdict: MERGE — fork CI never ran (code correct) · gittensor:bug on merge. action_required, only Superagent posted. Approve the run; green ⇒ merge, #1320 slop-closed → no multiplier.

@dosubot dosubot Bot added the lgtm label Jun 26, 2026
@JSONbored
JSONbored merged commit 839ed47 into JSONbored:main Jun 26, 2026
15 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]: per-repo scoring.time_decay.grace_period_hours is not truncated to an integer (drifts from upstream resolve_time_decay)

2 participants