Skip to content

fix(review): sum per-PR review-effort minutes with fallback in public-stats (#2070) - #4060

Merged
JSONbored merged 3 commits into
JSONbored:mainfrom
RealDiligent:fix/public-stats-per-pr-effort-sum-2070
Jul 7, 2026
Merged

fix(review): sum per-PR review-effort minutes with fallback in public-stats (#2070)#4060
JSONbored merged 3 commits into
JSONbored:mainfrom
RealDiligent:fix/public-stats-per-pr-effort-sum-2070

Conversation

@RealDiligent

Copy link
Copy Markdown
Contributor

Summary

Closes #2070

Supersedes closed #4058 (CI was green; auto-closed on Orb/own-ledger interaction feedback — addressed here).

Completes the public-stats ROI fix: minutesSaved now sums each distinct published PR's reviewEffortMinutes with MINUTES_SAVED_PER_PR per-PR fallback for missing metadata. Orb fleet outcomes (no persisted effort metadata) still credit the flat constant separately so the counter scales with fleet growth.

Root cause

#1955 persisted per-PR estimates, but getPublicStats used reviewed * AVG(minutes). SQLite AVG skips NULLs, so mixed ledgers under-reported (e.g. 4 min + missing estimate -> 8 instead of 24).

Fix

  • SQL: SUM(COALESCE(minutes, MINUTES_SAVED_PER_PR)) at per-PR grain
  • minutesSaved = ownLedgerSum + orb.total * MINUTES_SAVED_PER_PR (own-ledger scoped; Orb flat credit preserved)

Test plan

  • npm run typecheck
  • npx vitest run test/unit/public-stats.test.ts (20/20)
  • Mixed-effort D1 regression + Orb interaction test

@RealDiligent
RealDiligent requested a review from JSONbored as a code owner July 7, 2026 18:59
@superagent-security

Copy link
Copy Markdown
Contributor

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

@loopover-orb loopover-orb Bot added the gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier. label Jul 7, 2026
@loopover-orb

loopover-orb Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Tip

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

✅ Gittensory review result - approve/merge recommended

Review updated: 2026-07-07 23:04:32 UTC

2 files · 1 AI reviewer · no blockers · readiness 100/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This PR correctly finishes the #1955/#2070 ROI fix: it replaces the buggy `reviewed * AVG(minutes)` computation (which silently zeroed out contributions from PRs missing persisted effort estimates, since SQLite's AVG skips NULLs) with a `SUM(COALESCE(per-PR-minutes, MINUTES_SAVED_PER_PR))` at per-PR grain, and separates the own-ledger sum from the Orb fleet's flat MINUTES_SAVED_PER_PR credit via a newly-captured `ownLedgerReviewed` snapshot taken before the Orb merge. The bind-parameter order for the new `?` (MINUTES_SAVED_PER_PR) matches its position in the SQL text (ahead of the projects `IN` list), and the extensive new/updated unit tests — including two real-D1 tests — correctly exercise both the COALESCE-fallback and Orb-separation branches with matching expected values I verified by hand.

Nits — 4 non-blocking
  • src/review/public-stats.ts: the `reviewed === 0 ? 0 : Math.round(...)` guard is redundant — when reviewed is 0, ownLedgerReviewed and orb.total are both 0, so the round() branch already evaluates to 0; consider dropping the ternary for one less branch to reason about (and to cover with coverage tooling).
  • src/review/public-stats.ts: `ownLedgerReviewed` and the top-level `reviewed` (post-Orb-merge) now diverge in meaning but share very similar names — a short comment at the `ownLedgerReviewed` declaration noting it's captured pre-Orb-merge specifically for the effort fallback would help future readers avoid conflating the two.
  • Consider renaming `ownLedgerReviewed` to something like `ownLedgerReviewedBeforeOrb` or moving the Orb merge earlier isn't an option (order matters), so a one-line comment at its declaration is the cheapest clarity win.
  • The per-PR dedup subquery (`GROUP BY repo, number` with inner `AVG(minutes)`) is unchanged from the prior version and continues to correctly collapse republish events before the outer SUM — worth calling out in the header comment as still load-bearing for the new SUM path, since a naive reviewer might assume SUM alone would double-count re-publishes if this subquery were ever removed.
Signal Result Evidence
Code review ✅ No blockers 1 reviewer
Linked issue ✅ Linked #2070, #4058
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (2 linked issues).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 285 registered-repo PR(s), 92 merged, 1 issue(s).
Contributor context ✅ Confirmed Gittensor contributor RealDiligent; Gittensor profile; 285 PR(s), 1 issue(s).
Gate result ✅ Passing No configured blocker found.
Review context
  • Author: RealDiligent
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: JavaScript, Ruby, Svelte, TypeScript, Cuda, Markdown
  • Official Gittensor activity: 285 PR(s), 1 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Keep the PR focused and include validation evidence before maintainer review.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.

🟩 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

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.59%. Comparing base (1deb96c) to head (d3d8874).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4060   +/-   ##
=======================================
  Coverage   93.59%   93.59%           
=======================================
  Files         380      380           
  Lines       35596    35599    +3     
  Branches    13050    13051    +1     
=======================================
+ Hits        33316    33319    +3     
  Misses       1618     1618           
  Partials      662      662           
Files with missing lines Coverage Δ
src/review/public-stats.ts 96.66% <100.00%> (+0.17%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@loopover-orb loopover-orb Bot added the manual-review Gittensor contributor context label Jul 7, 2026
@RealDiligent
RealDiligent force-pushed the fix/public-stats-per-pr-effort-sum-2070 branch from 47fd706 to d3d8874 Compare July 7, 2026 20:30
@RealDiligent

Copy link
Copy Markdown
Contributor Author

Rebased onto latest \main\ (includes #4061) and added a clarifying comment on \ownLedgerReviewed\ per Gittensory review nits. Ready for maintainer merge — \Closes #2070.

RealDiligent and others added 3 commits July 8, 2026 04:34
…-stats

Closes JSONbored#2070

Replace reviewed * AVG(reviewEffortMinutes) with SUM(COALESCE(minutes,
MINUTES_SAVED_PER_PR)) so mixed ledgers credit missing per-PR estimates
with the documented flat fallback instead of under-reporting ROI.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@JSONbored
JSONbored merged commit a32a1bb into JSONbored:main Jul 7, 2026
8 checks passed
@loopover-orb loopover-orb Bot added gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. and removed gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier. labels Jul 7, 2026
@JSONbored JSONbored added gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier. and removed gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. labels Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier. manual-review Gittensor contributor context

Development

Successfully merging this pull request may close these issues.

feat(review): replace flat MINUTES_SAVED_PER_PR with the per-PR effort estimate in public-stats ROI

2 participants