Skip to content

fix(health): clamp analytics uptime_ratio below 1#2045

Open
philluiz2323 wants to merge 2 commits into
JSONbored:mainfrom
philluiz2323:fix/analytics-uptime-ratio-clamp
Open

fix(health): clamp analytics uptime_ratio below 1#2045
philluiz2323 wants to merge 2 commits into
JSONbored:mainfrom
philluiz2323:fix/analytics-uptime-ratio-clamp

Conversation

@philluiz2323

Copy link
Copy Markdown
Contributor

Summary

What Changed

  • Export displayUptimeRatio from reliability.mjs.
  • Route all uptime_ratio emission in formatTrends, subnet uptime trends, incidents SLA, leaderboards, and uptime history through displayUptimeRatio.
  • Regression test: 24999/25000 -> 0.9999, not 1.

Fixes #2025

Registry Safety

  • No secrets, PATs, wallet data, private dashboards, private URLs, or validator-local state.
  • Generated artifacts were produced by repo scripts, not hand-edited.
  • R2-only/high-churn detail artifacts are not committed.
  • Public API/OpenAPI/schema changes are intentional and documented. (None.)

Validation

  • npx vitest run tests/health-serving.test.mjs -t \"clamps a sub-perfect uptime_ratio\"
  • git diff --check

@philluiz2323 philluiz2323 requested a review from JSONbored as a code owner June 26, 2026 23:11
@superagent-security

Copy link
Copy Markdown

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

@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 93.26%. Comparing base (2bcd5c1) to head (e1c5f55).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2045      +/-   ##
==========================================
+ Coverage   93.23%   93.26%   +0.03%     
==========================================
  Files          48       48              
  Lines        7626     7755     +129     
  Branches     2804     2839      +35     
==========================================
+ Hits         7110     7233     +123     
- Misses         90       92       +2     
- Partials      426      430       +4     
Files with missing lines Coverage Δ
src/health-serving.mjs 89.79% <100.00%> (ø)
src/reliability.mjs 98.11% <ø> (ø)

... and 6 files with indirect coverage changes

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

@gittensory-orb

gittensory-orb Bot commented Jun 27, 2026

Copy link
Copy Markdown

Tip

🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩

✅ Gittensory review — safe to merge

3 files · 1 AI reviewers · no blockers · readiness 73/100 · CI green · clean

✅ Approved — safe to merge

Review summary
This PR exports `displayUptimeRatio` from `reliability.mjs` and routes all `uptime_ratio` emissions across seven call sites in `health-serving.mjs` (`formatTrends` ×2, `formatBulkTrends` ×2, `formatIncidents`, `formatLeaderboards`, `formatUptime`) through it, replacing naive `toFixed(4)` / `round4` calls. The logic is correct: sub-perfect ratios that floating-point round to exactly `1` are clamped to `0.9999`, while a genuinely perfect ratio (`okCount === total`) passes through as `1`. The regression test in `health-serving.test.mjs` validates both cases through `formatTrends`.

Signal Result Evidence
Code review ✅ No blockers 1 reviewers, synthesized
Linked issue ✅ Linked #2025
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Review load ✅ 20/20 Readiness component derived from cached public PR metadata and labels.
Validation evidence ❌ 5/25 Cached preflight status is hold.
Open PR queue ❌ 3/10 20 open PR(s), 15 likely reviewable, 5 unlinked.
Contributor context ✅ Confirmed Gittensor contributor philluiz2323; Gittensor profile; 773 PR(s), 177 issue(s).
Gate result ✅ Passing No configured blocker found.
Nits — 4 non-blocking
  • tests/health-serving.test.mjs: the new clamping test only exercises `formatTrends`; `formatBulkTrends`, `formatIncidents`, `formatLeaderboards`, and `formatUptime` are not directly tested for this behavior — since `displayUptimeRatio` is the single logic point this is low-risk, but a coverage gap remains for those data paths.
  • The full `health-serving.mjs` was not provided, so it cannot be confirmed that no other `uptime_ratio` emitters still use raw `toFixed(4)` or `round4` elsewhere in the file; a grep pass before merge would close that loop.
  • Add one clamping test for `formatBulkTrends` targeting the per-entry aggregation path (the second hunk at ~line 420), since it accumulates `okCount/samples` across a different data-flow shape than `formatTrends` and is the next most likely source of a silent regression.
  • Run `grep -n 'uptime_ratio' src/health-serving.mjs | grep -E 'toFixed|round4'` to confirm no emitter was missed before closing issue health-serving: formatTrends and analytics uptime_ratio still round sub-perfect ratios up to 1 #2025.
Review context
  • Author: philluiz2323
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository registration is not available in the local Gittensory cache.
  • Public profile languages: not available
  • Official Gittensor activity: 773 PR(s), 177 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Fix blocker.
  • Expect slower review.
  • Refresh registry data or choose a registered active repo.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Review load = cached public PR metadata such as size labels, changed paths, and preflight status.
  • Open PR queue = repo-wide review pressure; it is not a PR quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
Review details

Generated from public PR metadata and the diff. Advisory only; deterministic signals remain authoritative.

This PR exports `displayUptimeRatio` from `reliability.mjs` and routes all `uptime_ratio` emissions across seven call sites in `health-serving.mjs` (`formatTrends` ×2, `formatBulkTrends` ×2, `formatIncidents`, `formatLeaderboards`, `formatUptime`) through it, replacing naive `toFixed(4)` / `round4` calls. The logic is correct: sub-perfect ratios that floating-point round to exactly `1` are clamped to `0.9999`, while a genuinely perfect ratio (`okCount === total`) passes through as `1`. The regression test in `health-serving.test.mjs` validates both cases through `formatTrends`.

Nits (4)

  • tests/health-serving.test.mjs: the new clamping test only exercises `formatTrends`; `formatBulkTrends`, `formatIncidents`, `formatLeaderboards`, and `formatUptime` are not directly tested for this behavior — since `displayUptimeRatio` is the single logic point this is low-risk, but a coverage gap remains for those data paths.
  • The full `health-serving.mjs` was not provided, so it cannot be confirmed that no other `uptime_ratio` emitters still use raw `toFixed(4)` or `round4` elsewhere in the file; a grep pass before merge would close that loop.
  • Add one clamping test for `formatBulkTrends` targeting the per-entry aggregation path (the second hunk at ~line 420), since it accumulates `okCount/samples` across a different data-flow shape than `formatTrends` and is the next most likely source of a silent regression.
  • Run `grep -n 'uptime_ratio' src/health-serving.mjs | grep -E 'toFixed|round4'` to confirm no emitter was missed before closing issue health-serving: formatTrends and analytics uptime_ratio still round sub-perfect ratios up to 1 #2025.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 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.

  • Re-run Gittensory review

@gittensory-orb gittensory-orb Bot added gittensor Gittensor contributor context gittensor:bug Bug labels Jun 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Bug gittensor Gittensor contributor context

Projects

None yet

Development

Successfully merging this pull request may close these issues.

health-serving: formatTrends and analytics uptime_ratio still round sub-perfect ratios up to 1

1 participant