Skip to content

fix(pioneer): derive cycle figures from ledger + ledger-trail the pool reset#33

Merged
WayforthOfficial merged 1 commit into
mainfrom
fix/pioneer-counter-ledger-derive
Jun 21, 2026
Merged

fix(pioneer): derive cycle figures from ledger + ledger-trail the pool reset#33
WayforthOfficial merged 1 commit into
mainfrom
fix/pioneer-counter-ledger-derive

Conversation

@WayforthOfficial

Copy link
Copy Markdown
Owner

Pioneer cycle counters could orphan: a full-account reset wiped the pioneer_drip ledger + zeroed the pool but left users.pioneer_drip_* — so the dashboard showed +15,600 (13 drips) with 0 ledger rows and a 0 pool.

  1. /account/pioneer/status derives drip_credits_this_cycle / drip_days_this_cycle from the pioneer_drip ledger (same source as credits_earned_this_month), not the denormalized users.pioneer_drip_* columns → can't orphan again.
  2. Monthly cycle-reset writes a pioneer_reset ledger row for the forfeited pool when it zeroes pioneer_credits_balance (CTE captures pre-zero value; RETURNING gates it to real resets) → pool never hits 0 without a trail.
  3. The orphaned 15,600/13 counter on the affected account was zeroed in the DB to match its empty ledger.

🤖 Generated with Claude Code

…l reset

The Pioneer drip cycle counters could orphan: a full-account reset wiped the
pioneer_drip ledger + zeroed pioneer_credits_balance, but left
users.pioneer_drip_credits_this_cycle / _days_this_cycle untouched — so
/account/pioneer/status reported "+15,600 this cycle (13 drips)" with ZERO
pioneer_drip ledger rows and a 0 pool. Same denormalized-counter drift class as
the monthly_calls_count / invoice issue.

1. /account/pioneer/status now DERIVES drip_credits_this_cycle (= the pioneer_drip
   ledger sum this cycle, same source as credits_earned_this_month) and
   drip_days_this_cycle (= distinct Pacific drip days from the ledger) instead of
   reading the denormalized users.pioneer_drip_* columns. The displayed figure
   can no longer disagree with the credits actually dripped.

2. The monthly cycle-reset now writes a 'pioneer_reset' credit_transactions row
   for the forfeited pool when it zeroes pioneer_credits_balance — the pool never
   drops to 0 without a ledger trail. Uses a CTE to capture the pre-zero balance;
   RETURNING fires only when the month-gate matches, so a no-op reset writes no
   row and zeroes no counters (also fixes latent over-zeroing of the counters).

(The orphaned 15,600/13 counter on the affected account was separately zeroed in
the DB to match its empty ledger.)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants