Skip to content

Fix: accounts were marked as quota_exceeded as soon as the 7d window hit 100%, even when paid credits were available. - #237

Closed
mws-weekend-projects wants to merge 10 commits into
Soju06:mainfrom
mws-weekend-projects:fix/credits-aware-quota-and-no-account-logs
Closed

mws-weekend-projects wants to merge 10 commits into
Soju06:mainfrom
mws-weekend-projects:fix/credits-aware-quota-and-no-account-logs

Conversation

@mws-weekend-projects

Copy link
Copy Markdown
Contributor
  • Quota decision now checks credits (has, unlimited, balance) before blocking an account.
  • If credits are usable, the account stays/returns active.
  • Added unit tests for both cases (with credits vs without credits).

Result:
Accounts with valid credits are no longer falsely blocked, while true quota-exhausted accounts are still blocked correctly.

@Soju06

Soju06 commented Mar 21, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 36160fffb4

ℹ️ 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".

Comment on lines +142 to +143
except sa_exc.SQLAlchemyError:
return None, None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Roll back failed burn-rate query before continuing

latest_projected_burn_rates swallows SQLAlchemyError and returns (None, None) without rolling back the session, but ProxyService._write_request_log then calls add_log in the same session immediately after this fallback. In PostgreSQL, a statement error leaves the transaction aborted until rollback, so the subsequent insert can fail and drop request logs whenever this lookup errors (for example during partial migration rollout or transient query errors).

Useful? React with 👍 / 👎.

) -> BurnRateSnapshot:
primary_rows, secondary_rows = _normalize_latest_windows(latest_primary_usage, latest_secondary_usage)
accounts_by_id = {account.id: account for account in accounts}
now_epoch = int(now.timestamp())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Convert burn-rate timestamp as UTC, not local time

compute_burn_rate_snapshot is passed now from utcnow() (a naive UTC datetime in this codebase), but int(now.timestamp()) interprets naive datetimes in the host's local timezone. On non-UTC hosts this offsets now_epoch, which skews seconds_until_reset/elapsed_seconds and therefore projected burn-rate values.

Useful? React with 👍 / 👎.

@L1st3r

L1st3r commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

Is this something we still want? I can try to pick it up and get it ready for merging if so...

@mws-weekend-projects

mws-weekend-projects commented Apr 6, 2026 •

Copy link
Copy Markdown
Contributor Author

I still think this would be very useful. Without it, it’s a bit like driving through a traffic-calmed street in the city with speed cameras but no dashboard — you really want to know your actual speed.

That said, the implementation is a bit tricky in practice. So for now, it might be better to leave this as a feature request unless someone comes up with a cleaner implementation. I may also improve it later on.

Also, the current logic is still pretty limited because until now I had only used Plus accounts. I’m now also using token-based billing (1000 for USD 40), and there are also USD 200 Pro accounts, so there are clearly more account/usage models to consider.

@Komzpa Komzpa added 🤖 codex: needs work [@codex review] raised an issue 🤖 codex: ok [@codex review] says no issues found. and removed 🤖 codex: needs work [@codex review] raised an issue 🤖 codex: ok [@codex review] says no issues found. labels May 16, 2026
@Soju06

Soju06 commented May 21, 2026

Copy link
Copy Markdown
Owner

Maintainer cleanup: closing this as stale / no longer merge-ready against the current main.

This PR has been open across substantial main-branch churn and is currently carrying at least one stale signal (conflicts/blocked or failing checks, outstanding codex: needs work, draft/old branch state, or overlap with newer/current implementation). Keeping it open is making the PR queue harder to reason about.

If the change is still needed, please open a fresh, focused PR rebased on current main with green CI and a clean Codex review.

@Soju06 Soju06 closed this May 21, 2026
@Komzpa Komzpa added needs rebase Needs rebase or conflict repair against current main stale No response from reporter; scheduled for close labels May 21, 2026
@Komzpa

Komzpa commented May 21, 2026

Copy link
Copy Markdown
Collaborator

Revived on a maintainer-owned branch as #764 because this PR head has maintainerCanModify=false and cannot be updated here. Keeping credit to the original implementation in the replacement PR.

@Komzpa Komzpa added superseded Replaced by another PR, issue track, or merged implementation and removed 🤖 codex: needs work [@codex review] raised an issue needs rebase Needs rebase or conflict repair against current main labels May 21, 2026
@Soju06 Soju06 added the 🤖 codex: needs work [@codex review] raised an issue label May 21, 2026
@Komzpa Komzpa removed the 🤖 codex: needs work [@codex review] raised an issue label May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale No response from reporter; scheduled for close superseded Replaced by another PR, issue track, or merged implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants