Skip to content

refactor(backend): remove BetaUserCredit monthly credit refill (hotfix) - #12969

Merged
kcze merged 3 commits into
masterfrom
hotfix/remove-beta-monthly-credit-refill
May 1, 2026
Merged

refactor(backend): remove BetaUserCredit monthly credit refill (hotfix)#12969
kcze merged 3 commits into
masterfrom
hotfix/remove-beta-monthly-credit-refill

Conversation

@Torantulino

Copy link
Copy Markdown
Member

Hotfix against master. Equivalent to PR #12966 (against dev); see that PR for the full review thread. PR #12966 will be closed in favor of this one. Branch named hotfix/... so repo-pr-enforce-base-branch does not redirect it back to dev.

Why / What / How

Why

Beta-cohort users have been receiving $15 of free credits at the start of every calendar month via a MONTHLY-CREDIT-TOP-UP-{date} GRANT transaction. The BetaUserCredit class that implemented this perk was always documented as temporary — its own docstring at credit.py:1157-1161 (master) reads:

This is a temporary class to handle the test user utilizing monthly credit refill.
TODO: Remove this class & its feature toggle.

The free-credit perk is being retired. Removing it also removes a quiet bifurcation in the credit system that has accumulated downstream branches (paywall, onboarding, rate-limits) — the cleanest path forward is to close out the beta cohort.

What

This PR is intentionally surgical — it removes the monthly-refill mechanism only:

  • Deletes BetaUserCredit (master credit.py:1157-1187).
  • Simplifies get_user_credit_model() (master credit.py:1223-1248) to always return UserCredit (or DisabledUserCredit when credits are disabled).
  • Drops two now-unused settings fields: enable_beta_monthly_credit (never read in production code, only by two test monkeypatches) and num_user_credits_refill (only consumed by the deleted class's __init__).
  • Drops a now-unused import of is_feature_enabled from credit.py.
  • Updates tests:
    • Deletes the two tests that exercised monthly-refill behavior specifically (test_block_credit_reset and test_credit_refill in credit_test.py).
    • Cleans the dead updatedAt = 35-days-ago setup from disable_test_user_transactions() (it was specifically there to trigger the now-gone monthly check).
    • Swaps BetaUserCredit(1000)UserCredit() in credit_test.py, credit_integration_test.py (4 sites), and credit_metadata_test.py (2 sites). All swapped tests exercise behavior that lived on the parent class — class choice was incidental.
    • Drops the four stale enable_beta_monthly_credit / num_user_credits_refill monkeypatches from credit_integration_test.py.
    • Removes a stale comment in credit_concurrency_test.py.
    • Adds test_get_user_credit_model_returns_usercredit_unconditionally — a regression guard that asserts the factory returns exactly UserCredit (using __class__ is UserCredit, not isinstance, so any future class BetaFoo(UserCredit) resurrection trips the test instead of silently passing).

How

Flag.ENABLE_PLATFORM_PAYMENT and its three remaining downstream consumers (backend/copilot/rate_limit.py, backend/api/features/v1.py, frontend/src/app/(platform)/PaywallGate/PaywallGate.tsx, frontend/src/app/(no-navbar)/onboarding/useOnboardingPage.ts) are deliberately left in place. A user who currently has the flag off will, post-merge, get UserCredit from the factory but no longer see the paywall engage on NO_TIER (because rate_limit.py still falls back to BASIC multipliers when the flag is off, and PaywallGate skips when the flag is off). The soft-brick risk this creates for flag-off users without payment configured is being addressed by other moving parts in flight — out of scope for this PR by design.

A follow-up PR can clean up the flag and its gates once that parallel work lands.

Existing data: MONTHLY-CREDIT-TOP-UP-* GRANT rows already in the database are unaffected. They remain valid historical ledger entries; nothing depends on them and nothing cleans them up. No migration needed.

Rollback: pure code change. git revert of the squash commit fully restores prior behavior.

Notes for review

  • This is the same single commit as PR refactor(backend): remove BetaUserCredit monthly credit refill #12966 (d8c18f119), cherry-picked onto master. The cherry-pick was clean — no manual conflict resolution. master and dev differ around this code (dev has unrelated InvoiceListItem, grant_credits, list_invoices, admin_export_user_history additions in credit.py and max_workspace_storage_mb in settings.py), but the exact regions this PR deletes are byte-identical between master and dev. The four test files are 100% identical between master and dev.
  • After this lands on master, the standard master → dev backmerge will carry the change to dev automatically.

Changes 🏗️

  • autogpt_platform/backend/backend/data/credit.py
    • Delete BetaUserCredit class.
    • Simplify get_user_credit_model() to UserCredit / DisabledUserCredit only.
    • Drop unused is_feature_enabled import.
  • autogpt_platform/backend/backend/util/settings.py
    • Delete enable_beta_monthly_credit and num_user_credits_refill fields.
  • autogpt_platform/backend/backend/data/credit_test.py
    • Swap module-level BetaUserCredit(REFILL_VALUE)UserCredit(). Drop REFILL_VALUE constant. Clean dead updatedAt reset in disable_test_user_transactions.
    • Delete test_block_credit_reset (monthly-refill behavioral test).
    • Delete test_credit_refill (asserted post-reset balance equals refill value).
    • Drop now-unused datetime / timedelta / timezone imports.
  • autogpt_platform/backend/backend/data/credit_integration_test.py
    • Swap 4 instances of BetaUserCredit(1000)UserCredit().
    • Drop 4 monkeypatches of enable_beta_monthly_credit / num_user_credits_refill.
    • Add test_get_user_credit_model_returns_usercredit_unconditionally regression test.
  • autogpt_platform/backend/backend/data/credit_metadata_test.py
    • Swap 2 instances of BetaUserCredit(1000)UserCredit().
  • autogpt_platform/backend/backend/data/credit_concurrency_test.py
    • Delete stale comment referencing BetaUserCredit.

Net: −149 LoC across 6 files.

Checklist 📋

For code changes:

  • I have clearly listed my changes in the PR description
  • I have made a test plan
  • I have tested my changes according to the test plan:
    • CI: poetry run pytest backend/data/credit_test.py backend/data/credit_integration_test.py backend/data/credit_metadata_test.py backend/data/credit_concurrency_test.py -v
    • CI: poetry run pytest backend/data/credit_integration_test.py::test_get_user_credit_model_returns_usercredit_unconditionally -v (new regression test)
    • CI: full backend test suite remains green
    • Manual (post-merge, dev DB): existing beta users no longer see new MONTHLY-CREDIT-TOP-UP-* rows on the 1st of next month
    • Manual: grep -rn "BetaUserCredit\|num_user_credits_refill\|enable_beta_monthly_credit" autogpt_platform/backend/ returns zero hits

For configuration changes:

  • .env.default is updated or already compatible with my changes — neither removed setting was in .env.default (they were Pydantic defaults only)
  • docker-compose.yml is updated or already compatible — no references
  • I have included a list of my configuration changes in the PR description (under Changes) — enable_beta_monthly_credit and num_user_credits_refill removed from Settings

Note on local test execution

The reporter's local Windows env has a poetry install blocker on the stagehand wheel ([Errno 22] extracting from poetry's artifact cache) that is unrelated to this branch and reproduces on master HEAD. All 6 edited files pass python -m ast parse, and grep confirms zero residual references to BetaUserCredit, num_user_credits_refill, enable_beta_monthly_credit, MONTHLY-CREDIT-TOP-UP, or REFILL_VALUE anywhere in autogpt_platform/backend/. CI is the source of truth for the test runs.

Out of scope (deliberate)

  • Flag.ENABLE_PLATFORM_PAYMENT and its 3 downstream consumers — soft-brick risk handled separately.
  • Backfill / cleanup of historical MONTHLY-CREDIT-TOP-UP-* ledger rows.
  • LaunchDarkly-side flag deletion.
  • User-facing announcement copy.

The BetaUserCredit class auto-granted beta-cohort users $15 of credits per
calendar month via a MONTHLY-CREDIT-TOP-UP-{date} GRANT transaction. The
class's own docstring marked it for removal as a temporary feature; the
free-credit perk is being retired.

This PR is intentionally surgical:

- Deletes `BetaUserCredit` and the two now-unused settings fields it
  consumed (`enable_beta_monthly_credit`, `num_user_credits_refill`).
- Simplifies `get_user_credit_model()` to always return `UserCredit` (or
  `DisabledUserCredit` when credits are disabled).
- Drops the dead refill-trigger setup in test fixtures and deletes the
  two tests that exercised monthly-refill behavior specifically; swaps
  remaining `BetaUserCredit(...)` instantiations for `UserCredit()` in
  test files where the class choice was incidental.
- Adds an integration test that asserts the factory's exact return class
  to catch any future re-introduction of beta-cohort branching.

`Flag.ENABLE_PLATFORM_PAYMENT` and its three other downstream consumers
(`rate_limit.py`, `v1.py` subscription routing, frontend `PaywallGate`,
frontend onboarding) are intentionally untouched — the soft-brick risk
for flag-off users without payment configured is being handled by other
moving parts in flight. A follow-up PR can clean up the flag and its
gates once that work lands.

Existing `MONTHLY-CREDIT-TOP-UP-*` ledger rows in the DB are unaffected;
they remain valid historical GRANT entries.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Torantulino
Torantulino requested a review from a team as a code owner April 30, 2026 20:15
@Torantulino
Torantulino requested review from Bentlybro and majdyz and removed request for a team April 30, 2026 20:15
@github-project-automation github-project-automation Bot moved this to 🆕 Needs initial review in AutoGPT development kanban Apr 30, 2026
@coderabbitai

coderabbitai Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5ffa282f-e174-4bf3-93cf-848c30ab8944

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)

Walkthrough

This PR removes the BetaUserCredit model class and LaunchDarkly flag-driven credit model selection logic. The get_user_credit_model() function is simplified to return UserCredit() based solely on settings.config.enable_credit, and beta credit configuration fields are removed from settings.

Changes

Cohort / File(s) Summary
Core Credit Model
autogpt_platform/backend/backend/data/credit.py
Removes BetaUserCredit class and feature flag-based branching logic; get_user_credit_model() now unconditionally returns UserCredit() when credit is enabled, otherwise DisabledUserCredit().
Configuration Settings
autogpt_platform/backend/backend/util/settings.py
Removes enable_beta_monthly_credit and num_user_credits_refill fields from Config class.
Test Suite Updates
autogpt_platform/backend/backend/data/credit_*_test.py
Updates all test files to use UserCredit() instead of BetaUserCredit(1000); removes beta credit monkeypatching and monthly refill/reset test cases; adds regression test for model selection behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

size/m, platform/backend

Suggested reviewers

  • Bentlybro
  • kcze

Poem

🐰 Beta credits hop away,
Flags no longer guide the day,
Simple paths now light the way,
One model rules—hip hip hooray! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 61.54% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: removing BetaUserCredit monthly credit refill functionality, matching the primary objective of the PR.
Description check ✅ Passed The description is comprehensive and directly addresses the changeset, explaining the why, what, and how of removing the BetaUserCredit monthly refill mechanism, with detailed context about affected files and design decisions.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hotfix/remove-beta-monthly-credit-refill

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added size/l platform/backend AutoGPT Platform - Back end and removed size/l labels Apr 30, 2026
@Torantulino
Torantulino marked this pull request as draft April 30, 2026 20:16
@Torantulino
Torantulino requested review from kcze and removed request for Bentlybro and majdyz April 30, 2026 20:16
@codecov

codecov Bot commented Apr 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.58%. Comparing base (f0a5097) to head (b9beb1d).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #12969      +/-   ##
==========================================
+ Coverage   69.57%   69.58%   +0.01%     
==========================================
  Files        2114     2114              
  Lines      157419   157368      -51     
  Branches    16220    16219       -1     
==========================================
- Hits       109524   109505      -19     
+ Misses      44684    44652      -32     
  Partials     3211     3211              
Flag Coverage Δ
platform-backend 78.60% <100.00%> (+<0.01%) ⬆️
platform-frontend-e2e 30.89% <ø> (+0.22%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Platform Backend 78.60% <100.00%> (+<0.01%) ⬆️
Platform Frontend 37.32% <ø> (+0.05%) ⬆️
AutoGPT Libs ∅ <ø> (∅)
Classic AutoGPT 28.43% <ø> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot added the size/l label May 1, 2026
@kcze
kcze marked this pull request as ready for review May 1, 2026 09:35
@kcze
kcze enabled auto-merge (squash) May 1, 2026 09:44

@kcze kcze left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good

@github-project-automation github-project-automation Bot moved this from 🆕 Needs initial review to 👍🏼 Mergeable in AutoGPT development kanban May 1, 2026
@kcze
kcze merged commit 9e41726 into master May 1, 2026
41 checks passed
@kcze
kcze deleted the hotfix/remove-beta-monthly-credit-refill branch May 1, 2026 09:58
@github-project-automation github-project-automation Bot moved this from 👍🏼 Mergeable to ✅ Done in AutoGPT development kanban May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform/backend AutoGPT Platform - Back end size/l

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants