Skip to content

fix(quota): keep credit-backed accounts usable - #764

Merged
Soju06 merged 3 commits into
Soju06:mainfrom
Komzpa:revive/pr-237
Jun 1, 2026
Merged

Soju06 merged 3 commits into
Soju06:mainfrom
Komzpa:revive/pr-237

Conversation

@Komzpa

@Komzpa Komzpa commented May 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

Revives the useful quota-handling slice of #237 on a maintainer-owned branch because the original PR head has maintainerCanModify=false.

Credit: original implementation by @mws-weekend-projects in #237; this branch keeps only the current-main-compatible credit-backed quota fix.

  • Keeps credit-backed accounts usable when paid credits are present on secondary usage data.
  • Drops the stale burn-rate/request-log stack that carried the old Codex needs-work comments.

Validation

  • uv run pytest tests/unit/test_load_balancer.py -q passed: 67 passed
  • uv run ruff check app/core/usage/quota.py app/modules/proxy/load_balancer.py tests/unit/test_load_balancer.py passed
  • uv run ty check app/core/usage/quota.py app/modules/proxy/load_balancer.py tests/unit/test_load_balancer.py passed
  • git diff --check origin/main..HEAD passed

Revives #237

@Soju06

Soju06 commented May 22, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Soju06 Soju06 added the 🤖 codex: ok [@codex review] says no issues found. label May 22, 2026
@Soju06

Soju06 commented May 24, 2026

Copy link
Copy Markdown
Owner

Hermes review found one blocker before merge:

  • app/modules/accounts/mappers.py:151-159 still calls apply_usage_quota(...) without passing the credits_has / credits_unlimited / credits_balance fields from the selected primary/secondary UsageHistory rows. The load-balancer path now reactivates a quota-exceeded account with usable secondary credits, but the accounts/dashboard summary path still reports the same account as quota_exceeded.

Reproducer on the PR merged onto current main:

uv run python - <<'PY'
from app.db.models import Account, AccountStatus, UsageHistory
from app.modules.accounts.mappers import _effective_status_from_usage
acc = Account(id='a', email='[email protected]', status=AccountStatus.QUOTA_EXCEEDED, reset_at=1700003600)
primary = UsageHistory(account_id='a', window='primary', used_percent=40.0, reset_at=None, window_minutes=300)
secondary = UsageHistory(account_id='a', window='secondary', used_percent=100.0, reset_at=1700003600, window_minutes=10080, credits_has=False, credits_unlimited=False, credits_balance=25.0)
print(_effective_status_from_usage(acc, primary, primary.used_percent, secondary, secondary.used_percent).value)
PY
# => quota_exceeded

Expected: propagate the same usable-credit snapshot into the account-summary effective-status path (and add a regression test) so credit-backed accounts are not displayed/treated as quota-exceeded there while the proxy path considers them active.

@Soju06 Soju06 added hermes: needs-followup Hermes left a blocker/comment that needs follow-up observation and removed 🤖 codex: ok [@codex review] says no issues found. labels May 24, 2026
@Soju06

Soju06 commented May 24, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Soju06 Soju06 added the 🤖 codex: ok [@codex review] says no issues found. label May 24, 2026
@Komzpa Komzpa removed the hermes: needs-followup Hermes left a blocker/comment that needs follow-up observation label May 24, 2026
@Soju06

Soju06 commented May 27, 2026

Copy link
Copy Markdown
Owner

Merge-gate hold: code/CI/Codex look good, but this changes quota/status behavior for credit-backed accounts and the PR has no active openspec/changes/<slug>/ artifact.

Please add the OpenSpec delta, or explicitly waive the OpenSpec gate for this small bugfix. Code-wise I did not find a remaining blocker; the previous status/dashboard mismatch appears addressed.

@Soju06 Soju06 added the hermes: needs-followup Hermes left a blocker/comment that needs follow-up observation label May 27, 2026
@Soju06 Soju06 removed the 🤖 codex: ok [@codex review] says no issues found. label May 27, 2026
@Soju06

Soju06 commented May 27, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@Komzpa Komzpa removed the hermes: needs-followup Hermes left a blocker/comment that needs follow-up observation label May 27, 2026
@Komzpa

Komzpa commented May 31, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Soju06 Soju06 added the 🤖 codex: ok [@codex review] says no issues found. label May 31, 2026
@Soju06
Soju06 merged commit 6da403a into Soju06:main Jun 1, 2026
22 checks passed
vitalNohj pushed a commit to vitalNohj/codex-lb that referenced this pull request Jul 17, 2026
Keep credit-backed accounts available when their secondary usage window is exhausted but usable credits remain.

Apply the same credit-aware quota interpretation to proxy selection and account-summary status mapping while preserving primary-window rate-limit precedence and paused/deactivated states.

Includes regression tests and OpenSpec coverage for the behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤖 codex: ok [@codex review] says no issues found.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants