Skip to content

💰 fix: Load app config in set-balance script to respect balance settings#12669

Open
ucodia wants to merge 1 commit intodanny-avila:mainfrom
ucodia:claude/fix-librechat-12413-yjfRm
Open

💰 fix: Load app config in set-balance script to respect balance settings#12669
ucodia wants to merge 1 commit intodanny-avila:mainfrom
ucodia:claude/fix-librechat-12413-yjfRm

Conversation

@ucodia
Copy link
Copy Markdown
Contributor

@ucodia ucodia commented Apr 15, 2026

Summary

The npm run set-balance command always errored with Error: Balance is not enabled. Use librechat.yaml to enable it even when balance was correctly configured in librechat.yaml.

Root cause: config/set-balance.js called getBalanceConfig() without the app config argument, so it couldn't read balance settings. The sibling config/add-balance.js script already does this correctly by loading the app config first and passing it in.

This PR aligns set-balance.js with add-balance.js:

  • Imports getAppConfig from ~/server/services/Config
  • Awaits getAppConfig() before checking balance config
  • Passes the resolved appConfig into getBalanceConfig(appConfig)

Fixes #12413 and #12412

Change Type

  • Bug fix (non-breaking change which fixes an issue)

Testing

Verified against a locally built Docker image:

  1. Build the image locally from this branch.
  2. Configure balance in librechat.yaml:
    balance:
      enabled: true
      startBalance: 50000
  3. Run npm run set-balance <email> <amount> inside the container.
  4. Before the fix: the script exits with Error: Balance is not enabled. Use librechat.yaml to enable it.
  5. After the fix: the script proceeds, locates the user, updates the balance via Balance.findOneAndUpdate, and prints Balance set successfully! along with the new balance.
  6. Verified behavior parity with npm run add-balance, which was already working correctly with the same config loading pattern.

Test Configuration:

  • Locally built Docker image from this branch
  • Node.js v20.19.0
  • MongoDB (local)
  • librechat.yaml with balance.enabled: true

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • My changes do not introduce new warnings
  • Local unit tests pass with my changes

…tings

The `set-balance` script called `getBalanceConfig()` without the app
config, so it always reported balance as disabled regardless of the
librechat.yaml configuration. Mirror the working `add-balance` script
by loading the app config first and passing it into `getBalanceConfig`.

Fixes danny-avila#12413
@ucodia ucodia marked this pull request as ready for review April 15, 2026 09:17
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