Skip to content

fix(api): preserve monthly free credit refreshes - #128

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-cac3
Draft

fix(api): preserve monthly free credit refreshes#128
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-cac3

Conversation

@cursor

@cursor cursor Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

Free-tier agents below the monthly credit floor could be silently skipped by the monthly refresh job if any unrelated account update happened after the month started. Authenticated API calls update Agent.lastSeenAt, which also advances Prisma's updatedAt, so a delayed or retried monthly job could treat active users as already refreshed and withhold their free credits.

Root cause

refreshMonthlyCredits used Agent.updatedAt >= startOfMonth as its idempotency guard even though updatedAt is a broad account mutation timestamp, not a refresh marker.

Fix

Use an explicit AuditLog marker (monthly_free_credit_refresh) for per-month idempotency. The job now records both granted and skipped high-balance accounts, keeps the existing top-up-only guard so purchased balances are never lowered, and sends refresh email copy using the actual credits added.

Validation

  • npm run build
  • node tests/tools-credits-hardening.test.mjs
  • node tests/critical-regressions.test.mjs
Open in Web View Automation 

Co-authored-by: Deesmo <Deesmo@users.noreply.github.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.

1 participant