feat(scripts): expire internal team free credits#4279
Open
iscekic wants to merge 1 commit into
Open
Conversation
Add a one-off script that expires every free, personal, positive credit grant (with or without an existing expiry date) for users whose email ends in @kilocode.ai or @kilo.ai. Each targeted grant is tagged with expiry_date = now and expired via processLocalExpirations, so the accounting matches the production expiration cron. Fully-spent grants expire $0 (no-op); partially-spent grants expire their unspent remainder. If expiring a user's grants would drive their balance negative, a one-off accounting_adjustment credit restores the balance to exactly $0. Dry run by default; --execute performs writes. Emits per-user JSONL, a mutation log, and an error log.
Contributor
Code Review SummaryStatus: 2 Issues Found | Recommendation: Address before merge Overview
Fix these issues in Kilo Cloud Issue Details (click to expand)WARNING
Files Reviewed (1 files)
Reviewed by gpt-5.4-20260305 · Input: 77.3K · Output: 10.3K · Cached: 695.6K Review guidance: REVIEW.md from base branch |
Contributor
Author
|
Script already ran against prod. @pedroheyerdahl has run output details in Slack DMs. |
Contributor
|
Approved in concept, DNR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
One-off maintenance script (
apps/web/src/scripts/d2026-06-26_expire-internal-free-credits.ts) that expires free credit grants belonging to internal team accounts.Selection
Users whose
kilocode_users.google_user_emailends in@kilocode.aior@kilo.ai(case-insensitive suffix match, so it's independent of the nullable backfilledemail_domaincolumn). Per matched user, the affected set is every credit transaction that is:is_free = trueorganization_id IS NULL(personal)amount_microdollars > 0(a grant, not an adjustment/expiration row)credits_expired/orb_credit_expired/orb_credit_voidedrecord referencing it)This includes grants with or without an existing
expiry_date.Behavior
For each affected grant, set
expiry_date = nowand expire it throughprocessLocalExpirations(), so balance accounting matches the production expiration cron exactly:$0→ effectively left untouched.If expiring a user's grants drives their balance below zero (e.g. spend previously clawed back via
total_microdollars_acquired), a one-offaccounting_adjustmentcredit (is_free, positive) restores the balance to exactly$0. No user ends negative.Mechanics
--executeperforms writes.--yesskips the confirmation prompt;--batch-size/--concurrencytunable.src/scripts/output/.computeExpiration/processLocalExpirationsfrom@/lib/creditExpiration.Notes
accounting_adjustmentis itself a free, non-expiring credit, so re-running the script would re-target it. Intended as a one-off.