Bug Fix: CRM Health Scoring No Longer Scores Cancelled Customers
Bug Fix: CRM Health Scoring No Longer Scores Cancelled Customers
Version: 1.0.37
Overview
A bug in the crmHealthScoringCron job caused cancelled customers to be included in health scoring runs. This has been resolved by filtering out cancelled customers directly in the database query, consistent with how the churn prediction cron was fixed in a prior release.
Background
The CRM health scoring cron is responsible for periodically evaluating the health of active customer accounts and persisting scores used by the platform's AI-powered customer management features — including proactive engagement triggers, churn risk overlays, and customer success dashboards.
The Problem
The crmHealthScoringCron query used an empty and() condition with a comment:
// We exclude cancelled manually in logic but include them for record-keeping
In practice, the downstream logic did not reliably exclude cancelled customers. All customers — including those with a cancelled status — were fetched from the database and passed into scoreAndPersistHealth. This meant:
- Cancelled accounts consumed compute resources during each scoring cycle.
- Stale or misleading health scores could be written back to cancelled customer records.
- Health score dashboards and downstream automations could surface data for accounts that were no longer active.
The Fix
A .where() clause was added directly to the database query:
.where(sql`${customers.status} != 'cancelled'`)
This ensures cancelled customers are excluded at the SQL level — before any application logic runs — rather than relying on fragile in-memory filtering downstream.
What This Means
| Scenario | Before Fix | After Fix |
|---|---|---|
| Cancelled customer fetched by cron | ✅ Yes | ❌ No |
scoreAndPersistHealth called for cancelled customer | ✅ Yes | ❌ No |
| Health score persisted for cancelled customer | ✅ Yes | ❌ No |
| Active customer health scoring | ✅ Yes | ✅ Yes |
Relation to Churn Cron Fix
This is the same class of bug that was previously fixed in the churn prediction cron. Both crons shared an identical pattern: an empty and() condition in the query with a comment suggesting downstream exclusion — but without reliable enforcement. Both have now been resolved with the same approach: push the exclusion into the WHERE clause.
No Action Required
This is an internal infrastructure fix. No configuration changes, API changes, or user-facing behaviour changes are required. Cancelled customer records will simply no longer receive health score updates going forward.