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

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

Fix: accounts were marked as quota_exceeded as soon as the 7d window hit 100%, even when paid credits were available.#237
mws-weekend-projects wants to merge 10 commits intoSoju06: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
Copy link
Copy Markdown
Owner

Soju06 commented Mar 21, 2026

@codex review

Copy link
Copy Markdown

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

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 👍 / 👎.

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