fix(stats): refresh plan status for build-only apps and after cycle rollover

Merged
RI
7h ago
+247-0

Problem

Follow-up to PR #4212. A 48h production check after that deploy showed:

  • EquiFarmX is fixed: user:upgrade_to_team was sent on 2026-11-28 and is_good_plan=false.
  • UnPurchase still shows is_above_plan=true and plan_usage=270. That status is from 2026-10-04: org_stats_refresh_state.plan_calculated_at has not changed since then.

process_cron_stats_jobs only queues apps with recent bundles, MAU, device usage or bandwidth, or apps of paying orgs that have stored bundles. An app that only runs native builds matches none of these. Its stats never refresh, so its org's plan status stays frozen.

  • UnPurchase built every few days from 5 to 26 October and was never re-evaluated or warned during that time.
  • It has had no usage since its cycle rolled over on 12 November, yet it still counts in "Above Plan Without Credits".

In prod right now, 48 apps have builds in the last 30 days but no recent bundle or MAU. 43 apps of paying orgs had their plan last calculated before their current cycle started.

Fix

In process_cron_stats_jobs, active_apps now also includes:

  1. Apps with daily_build_time rows in the last 30 days.
  2. Apps of paying orgs whose plan_calculated_at is older than subscription_anchor_start. This gives one refresh after a billing-cycle rollover, so an idle org drops the previous cycle's overage flags. The existing 20-hour guard still applies.

Build-only apps refresh on the same 6-hour stats_jobs cadence as other active apps: about 48 apps Ɨ 4 runs ā‰ˆ 190 refreshes a day, plus one refresh per rollover app (43 today). The queue is still staggered at 25 per minute.

Tests

Two new cases in tests/process-cron-stats-jobs.test.ts:

  • a build-only app is queued only after it has build time;
  • after a rollover the app is queued, and once the plan has been calculated in the current cycle it is not queued again.

eslint passes. I could not run the DB tests locally because the docker compose plugin is not installed here, so they run in CI (local-db-sql-tests).

šŸ¤– Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Statistics now refresh for apps with recent build activity, even when they have no bundle or device usage.
    • Eligible apps on yearly plans can have their statistics refreshed when their billing-cycle information is out of date. Updates are queued in controlled batches to avoid duplicate refresh requests.