Initial AI quota (qontakchat_ai_credit) stops resetting monthly (Billing V1 & V3)
Jira: TBD — to be minted as a Story under Epic BIF-8695 · Epic: BIF-8695
Overview
- Before: The monthly reset job overwrites each package's initial AI quota
(
qontakchat_ai_credit, thecreditfield) back toInitialChatbotAiPackage.credit(e.g. 1000) on the 1st of every month, discarding the prior month's running balance. A customer who used only 300 is topped back to 1000; unused quota never carries. - After: For billing V1 and V3, the monthly reset no longer touches the initial
AI quota — the
creditbalance persists: it carries over month to month and only depletes with real usage. No monthly refill is added and no leftover is discarded. The initial quota is granted at activation/renewal (its existing lifecycle) and is not refreshed monthly.
Scope Changes
- Backend (moderator-be) — the monthly reset stops resetting the initial
creditportion; add-on/top-up (extra) handling is untouched.
Technical notes (grounding)
- Reset:
Core::Repositories::Billing::ChatbotAi::Reset(app/domains/core/repositories/billing/chatbot_ai/reset.rb), run bychatbot_ai_reset_monthly_taskat 00:00 on the 1st, Asia/Jakarta (config/schedule.yml). - Today it sets
package.credit = initial_package.credit - usage_gap(≈ the full initial amount on the 1st, when the gap is ~0) — this is the monthly overwrite to remove for the initial quota.package.extra(add-on/top-up,chatbot_ai_extra), the postpaid branch, theis_reset_holdminus-usage hold, and the outstanding/conversation-log handling are separate concerns that stay as-is. - The change targets the initial quota only (the
creditfield /qontakchat_ai_creditcomponent), for billing V1 and V3.
Out of scope
- Add-on / top-up (
extra) quota behaviour — unchanged. - Any component other than the initial AI quota.
- No change to how the initial quota is first granted at activation/renewal.
8. User Stories + Acceptance Criteria
| User Story | Importance | Mockup / Technical Notes | Acceptance Criteria |
|---|---|---|---|
| [AIQUOTA-S01] — Initial AI quota persists instead of resetting monthly As the billing system, I want the monthly reset to stop resetting the initial AI quota ( qontakchat_ai_credit / the credit field) for billing V1 and V3, so that the initial quota balance persists — carrying over and only depleting with usage — instead of being refilled to the initial amount every month. | Should Have | Reset job runs 1st of month (chatbot_ai_reset_monthly_task). Remove only the credit (initial) overwrite; keep extra / postpaid / is_reset_hold / outstanding logic. Applies to V1 and V3. | — Happy Path — • AC-1: Given a ChatbotAiPackage on billing V1 or V3 with a running credit balance, when the monthly reset runs, then package.credit (initial AI quota) is not reset or refilled — it keeps its current running balance (no monthly grant added, no leftover discarded).• AC-2: Given the initial quota now persists, when the customer consumes AI usage during the month, then deductions reduce the persisted credit as today until it reaches 0, after which existing extra / top-up overflow behaviour applies unchanged.— Guard-rails — • NEG-1: Given the add-on / top-up quota ( extra), when the reset runs, then its existing behaviour — postpaid handling, is_reset_hold minus-usage hold, and outstanding/conversation logs — is unchanged; only the initial credit stops resetting.• NEG-2: Given any component other than the initial AI quota, when the reset runs, then it is unaffected. |
Open questions
- Grant lifecycle — the initial quota is (re)granted at subscription activation /
contract renewal (
suite_packages/activate,chatbots/renew_package), correct? We are removing only the monthly refresh, not the activation grant — confirm. - Billing-version gating — "V1 and V3" effectively means all
ChatbotAiPackages; should the code gate on abilling_versionfield, or does removing the monthly credit reset apply universally? Is there a V2 to consider? - Rollout — hard behaviour change at the next monthly run for all packages, or behind a config/flag for staged enablement?
- Reset audit log — with the initial-credit reset removed, should the monthly
ChatbotAiPackageLog/resetconversation log still be written forcredit(now a no-op), or skipped? Preserve an audit trail either way. - Negative-credit path — today the reset can spill negative
creditintoextra. Withcreditno longer overwritten, confirm theextrareconciliation still behaves correctly whencreditis already 0/negative from in-month deductions.