fix(orb): degrade getOrbGlobalStats to zeros on a DB error - #8936
Conversation
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8936 +/- ##
==========================================
- Coverage 90.56% 90.55% -0.01%
==========================================
Files 96 97 +1
Lines 22490 22508 +18
Branches 3884 3893 +9
==========================================
+ Hits 20367 20383 +16
Misses 1945 1945
- Partials 178 180 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
|
|
Tip ✅ LoopOver review result - approve/merge recommendedReview updated: 2026-07-26 13:59:18 UTC
Review summary Nits — 4 non-blocking
Decision drivers
Context & advisory signals — never blocks the verdict
Linked issue satisfactionAddressed Review context
Contributor next steps
Signal definitions
🧪 Chat with LoopOverAsk LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.
Full command reference: https://loopover.ai/docs/loopover-commands 🧪 Experimental — new and may change. 🟩 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 LoopOver, a quiet PR intelligence layer for OSS maintainers.
|
What
getOrbGlobalStats(src/orb/outcomes.ts) runs inPromise.all([getOrbGlobalStats(env), computeFleetAnalytics(env)])insrc/review/public-stats.ts. Its siblingcomputeFleetAnalyticswraps its DB reads in try/catch anddegrades to an all-null/zero report on any D1 error — but
getOrbGlobalStatshad no such guard, so aD1 error on its join query (the exact "exceeded its CPU time limit and was reset" failure the function's
own header documents) threw straight out of the
Promise.all. The only net was the route-level catch,which then 503s the entire
/v1/public/statspayload (accuracyTrend, reuseRateTrend,reviewVolumeTrend, rulePrecision all lost) instead of degrading just the orb aggregate.
Change
Wrap the query in try/catch, returning
{ merged: 0, closed: 0, total: 0 }on failure — matchingcomputeFleetAnalytics's degrade-gracefully posture exactly, so a D1 error drops only the orb aggregaterather than the whole stats payload.
Validation
test/integration/orb-outcomes.test.ts: an injected DB whosefirst()rejects makesgetOrbGlobalStatsresolve to{ merged: 0, closed: 0, total: 0 }rather than throw.npx vitest run test/integration/orb-outcomes.test.ts→ 11/11 pass; the new catch branch is covered(lcov-verified), the existing success paths remain covered.
Closes #8879