Skip to content

fix(stats): preserve completed global stats shards on dispatcher retries#2581

Open
riderx wants to merge 2 commits into
mainfrom
fix/global-stats-retry-reset
Open

fix(stats): preserve completed global stats shards on dispatcher retries#2581
riderx wants to merge 2 commits into
mainfrom
fix/global-stats-retry-reset

Conversation

@riderx

@riderx riderx commented Jun 24, 2026

Copy link
Copy Markdown
Member

Summary

  • Fixes global stats and LogSnag admin dashboard data stalling since the June 17 sharded snapshot pipeline (fix(cron): keep global stats snapshots running #2484).
  • Dispatcher retries no longer call resetGlobalStatsCompletedShards() and re-queue every shard; they now queue only missing shards and keep existing completed_shards progress.
  • Added a unit test covering partial-retry shard selection.

Root cause

Cloudflare Workers logs (via GraphQL analytics) show no elevated worker error rates, but code review of the new sharded pipeline shows this failure mode:

  1. Daily logsnag_insights dispatcher queues shard jobs and reserves a delayed retry message.
  2. Shards run asynchronously and mark themselves complete in global_stats.completed_shards.
  3. When the dispatcher retry runs (timeout, cancel failure, or partial completion), it previously reset completed_shards to [] and re-queued all shards.
  4. The admin dashboard only reads rows where all required shards are present (completed_shards @> required), so partial snapshots never appear.

Test plan

  • bun test tests/logsnag-insights-revenue.unit.test.ts
  • After deploy, confirm new global_stats rows after 2026-06-17 get all required shards and appear in admin global stats trend
  • Confirm LogSnag daily insights resume posting

Made with Cursor

Summary by CodeRabbit

  • Refactor

    • Optimized insights processing retry mechanism to intelligently queue only missing components instead of reprocessing all components, improving system efficiency and reducing unnecessary load.
  • Tests

    • Added unit tests validating correct identification of missing required components in global statistics processing.
  • Chores

    • Updated project build configuration files.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0f67f891-4de8-4f9c-aa7e-1aefd02847ae

📥 Commits

Reviewing files that changed from the base of the PR and between a52498a and 8c028cf.

📒 Files selected for processing (3)
  • knip.json
  • supabase/functions/_backend/triggers/logsnag_insights.ts
  • tests/logsnag-insights-revenue.unit.test.ts
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • Cap-go/capacitor-updater (manual)

📝 Walkthrough

Walkthrough

Adds two helpers (queueMissingLogsnagInsightsShards, dispatchMissingLogsnagInsightsShards) that enqueue only shards absent from completed_shards rather than all shards. runLogsnagInsightsUpdate is updated to call the missing-shard dispatcher and exit early on retries. A unit test covers partial-completion shard derivation. knip.json adds a Playwright config to the exports-ignore list.

Changes

Logsnag Insights Missing-Shard Retry Dispatch

Layer / File(s) Summary
queueMissingLogsnagInsightsShards and dispatchMissingLogsnagInsightsShards helpers
supabase/functions/_backend/triggers/logsnag_insights.ts
Adds queueMissingLogsnagInsightsShards to compute and enqueue only shards absent from completedShards, and adds dispatchMissingLogsnagInsightsShards to initialize the snapshot row, read completed shards, and delegate to that helper. Updates dispatchLogsnagInsightsShards to use queueMissingLogsnagInsightsShards with an empty set instead of an explicit loop.
Retry path wiring and unit test
supabase/functions/_backend/triggers/logsnag_insights.ts, tests/logsnag-insights-revenue.unit.test.ts
Updates runLogsnagInsightsUpdate to call dispatchMissingLogsnagInsightsShards and return early when retryCount > 0. Adds a unit test asserting that a partial completed-shards set (core, usage, revenue) correctly derives remaining required shards and missing global-stats shards (including notifications).

knip.json Playwright Config Ignore

Layer / File(s) Summary
ignoreExportsUsedInFile update
knip.json
Adds playwright/visual-diff.config.ts with an exports ignore rule to ignoreExportsUsedInFile.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Cap-go/capgo#2484: Established the sharded global_stats.completed_shards pipeline and retry infrastructure in logsnag_insights.ts that this PR's missing-shard helpers and retry dispatch directly extend.

Suggested labels

codex

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main fix: preserving completed global stats shards during dispatcher retries, which directly addresses the root cause of the data stalling issue.
Description check ✅ Passed The description covers all required sections: a clear summary explaining the fix and its context, a detailed root cause analysis, and a test plan with checkboxes. The description is comprehensive and directly addresses the PR objectives.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands.

@cursor cursor Bot requested a review from WcaleNieWolny June 24, 2026 00:02

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale comment

Risk: medium. Cursor Bugbot check passed, but no Bugbot review comment was posted, so I'm not auto-approving. Requesting human review for this global stats dispatcher retry fix.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver External

@codspeed-hq

codspeed-hq Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 43 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing fix/global-stats-retry-reset (8c028cf) with main (a52498a)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Dispatcher retries were resetting completed_shards and re-queuing every shard, wiping partial daily snapshot progress introduced by the June sharded logsnag pipeline.

Co-authored-by: Cursor <cursoragent@cursor.com>
@cursor cursor Bot requested a review from Dalanir June 24, 2026 00:03

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale comment

Risk: medium. Cursor Bugbot check passed, but no Bugbot review comment was posted, so I'm not auto-approving. Requesting human review for this global stats dispatcher retry fix.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

The visual diff routes are loaded dynamically after git checkout, so knip cannot trace their usage and was failing the dead code check on main.

Co-authored-by: Cursor <cursoragent@cursor.com>
@riderx riderx force-pushed the fix/global-stats-retry-reset branch from a8f9d9a to 8c028cf Compare June 24, 2026 00:05
@coderabbitai coderabbitai Bot added the codex label Jun 24, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Risk: medium. Cursor Bugbot check passed, but no Bugbot review comment was posted, so I'm not auto-approving. Human reviewers WcaleNieWolny and Dalanir are already assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver External

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Risk: medium. Cursor Bugbot check passed, but no Bugbot review comment was posted, so I'm not auto-approving. Human reviewers WcaleNieWolny and Dalanir are already assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant