fix(email): correct weekly/monthly/24h stats email calculations#2754
Conversation
Weekly success/failure rates wrongly used install-fail instead of install/(install+fail). Monthly stats truncated the last day of the month. Deploy 24h emails could stringify Analytics Engine Float64 counts into trash values, then permanently skip sending after a premature claim when installs looked too low. Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 16 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughCron email statistics now use centralized numeric, UTC date-range, aggregation, and retry helpers. Analytics Engine conversion supports additional numeric types, the weekly SQL window covers seven days, and unit tests cover the new utility behavior. ChangesAnalytics and cron statistics
Estimated code review effort: 3 (Moderate) | ~25 minutes Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
Merging this PR will not alter performance
Comparing Footnotes
|
Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_3843b23c-8336-448a-a9b3-12d16c631dbc) |
There was a problem hiding this comment.
Stale comment
Risk: medium. Not approving: Cursor Bugbot skipped (usage limit reached), so automated review is incomplete, and this PR includes a SQL migration plus user-facing email stat fixes above the low-risk approval threshold. Assigned reviewers for human review.
Sent by Cursor Approval Agent: Pull Request Approver External
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@supabase/functions/_backend/triggers/cron_email.ts`:
- Around line 245-257: Handle query errors in the appVersions and deployHistory
fetches instead of discarding them. After each Supabase query, check its error
result and throw simpleError() when either query fails; only continue to monthly
activity processing when both queries succeed.
- Around line 362-379: Update the release-error branch in the deploy install
stats email retry flow to throw after cloudlogErr records releaseError, instead
of continuing to return the successful 200 response. Ensure the exception
propagates to the caller so the same cron job is retried while preserving the
existing success branch.
- Around line 211-217: Replace the weekNumber calculation near the
now/startOfYear logic with a true ISO-8601 week calculation, using UTC dates and
Thursday-based week-year boundaries so dates such as January 1, 2021 resolve to
week 53 of 2020. Keep the existing monthName calculation unchanged and ensure
the resulting metadata uses the computed ISO week number.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 3bd30dbf-4e1c-48c0-bcc6-dd9d564fa9ea
📒 Files selected for processing (6)
supabase/functions/_backend/plugin_runtime/utils/cloudflare.tssupabase/functions/_backend/triggers/cron_email.tssupabase/functions/_backend/utils/cloudflare.tssupabase/functions/_backend/utils/cron_email_stats.tssupabase/migrations/20260725113045_fix_weekly_stats_date_window.sqltests/cron-email-stats.unit.test.ts
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
Cap-go/capacitor-updater(manual)
There was a problem hiding this comment.
All reported issues were addressed across 6 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Add regression backtests proving weekly rates match admin install/(install+fail), monthly windows include the last day, 24h install sums never string-concatenate, and "flawless" copy is never used when failures are non-zero. Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_f9f75321-0b9d-44a4-8375-01a1757d3dc7) |
There was a problem hiding this comment.
Stale comment
Risk: medium. Not approving: Cursor Bugbot skipped (usage limit reached), this PR exceeds the low-risk threshold (SQL migration plus user-facing email stat logic), and automated reviewers reported unresolved findings. Human reviewers are already assigned.
Sent by Cursor Approval Agent: Pull Request Approver External
There was a problem hiding this comment.
Stale comment
Risk: medium. Not approving: Cursor Bugbot skipped (usage limit reached) and did not complete review. CodeRabbit and cubic also flagged unresolved cron email error-handling and stats issues; human review is still needed. Reviewers are already assigned.
Sent by Cursor Approval Agent: Pull Request Approver
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_bd4f0291-9043-4f07-800c-951c3dd1ce91) |
There was a problem hiding this comment.
Stale comment
Risk: medium. Not approving: Cursor Bugbot skipped (usage limit reached) and did not complete review. This PR exceeds the low-risk threshold (SQL migration plus user-facing email stat logic). Human reviewers are already assigned.
Sent by Cursor Approval Agent: Pull Request Approver External
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_e4b873cf-b044-44fd-b1c0-e83607e1eeca) |
Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_761ebace-0556-4c77-ad63-572a05ebbdb3) |
There was a problem hiding this comment.
Stale comment
Risk: medium. Not approving: Cursor Bugbot skipped (usage limit reached) and did not complete automated review. This PR exceeds the low-risk threshold (SQL migration plus user-facing email stat logic). Human reviewers are already assigned.
Sent by Cursor Approval Agent: Pull Request Approver External
Use "About one in ten" for the <=10% band and isolate the get_weekly_stats window fixture under com.test.*. Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_6b95183c-0de3-4ed9-bc19-ff3538c96ba4) |
There was a problem hiding this comment.
Stale comment
Risk: medium. Not approving: Cursor Bugbot skipped (usage limit reached) and did not complete automated review. This PR exceeds the low-risk threshold (SQL migration plus user-facing email stat logic). Human reviewers are already assigned.
Sent by Cursor Approval Agent: Pull Request Approver External
Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_0ffb78fc-0f84-4f74-82f0-0b7037d39bd8) |
There was a problem hiding this comment.
Stale comment
Risk: medium. Not approving: Cursor Bugbot skipped (usage limit reached) and did not complete automated review. This PR exceeds the low-risk threshold (SQL migration plus user-facing email stat logic). Human reviewers are already assigned.
Sent by Cursor Approval Agent: Pull Request Approver External
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@supabase/tests/36_test_get_weekly_stats_window.sql`:
- Line 9: Wrap the long INSERT statements in the weekly stats SQL test,
including the referenced lines, so each line stays within SQLFluff’s
80-character LT05 limit. Preserve the existing columns, values, and SQL behavior
while formatting the statement across multiple lines.
In `@tests/cron-email-stats-backtest.unit.test.ts`:
- Line 61: Update all five test cases in this block, including the case titled
“never reproduces the old install-fail negative/wrong-rate bug across
production-like weeks,” to use the concurrent test variant. Keep their existing
fixtures, inputs, assertions, and test bodies unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: eccd5fd7-ebb4-4e99-b195-a2f1d6a6cd29
📒 Files selected for processing (5)
supabase/functions/_backend/triggers/cron_email.tssupabase/functions/_backend/utils/cron_email_stats.tssupabase/tests/36_test_get_weekly_stats_window.sqltests/cron-email-stats-backtest.unit.test.tstests/cron-email-stats.unit.test.ts
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
Cap-go/capacitor-updater(manual)
Wrap weekly stats SQL fixture lines and mark backtest cases concurrent for faster CI. Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_8d172ab8-be40-438f-9ed9-94447793df2a) |
There was a problem hiding this comment.
Stale comment
Risk: medium. Not approving: Cursor Bugbot skipped (usage limit reached) and did not complete automated review. This PR exceeds the low-risk threshold (SQL migration plus user-facing email stat logic). Human reviewers are already assigned.
Sent by Cursor Approval Agent: Pull Request Approver External
Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_7ede1d32-4324-4b45-8c3f-95ee23bad1d1) |
There was a problem hiding this comment.
Risk: medium. Not approving: Cursor Bugbot skipped (usage limit reached) and did not complete automated review. This PR exceeds the low-risk threshold (SQL migration plus user-facing email stat logic). Human reviewers are already assigned.
Sent by Cursor Approval Agent: Pull Request Approver External
|





Summary (AI generated)
installandfailare independent counters, so success/failure rates now useinstall / (install + fail)instead of the brokeninstall - failformulabundle:install_stats_24htrash counts by coercing Analytics EngineFloat64aggregates to numbers (string concat bug)get_weekly_statsto a true 7-day inclusive window (was 8 days)Motivation (AI generated)
Weekly and monthly Capgo stats emails were reporting incorrect numbers, and
bundle:install_stats_24happeared to stop sending. Root cause was bad calculation/window logic plus Analytics Engine numeric values being left as strings and then concatenated, combined with permanently claiminginstall_stats_email_sent_atbefore a successful send.Business Impact (AI generated)
Customers get trustworthy weekly/monthly activity emails again, and 24h post-deploy install emails can resume instead of being silently skipped after bad/empty analytics reads.
Test Plan (AI generated)
bun test:unit -- tests/cron-email-stats.unit.test.ts)bundle:install_stats_24hGenerated with AI
Summary by CodeRabbit
Bug Fixes
Improvements
Tests