Fix: accounts were marked as quota_exceeded as soon as the 7d window hit 100%, even when paid credits were available.#237
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 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".
| except sa_exc.SQLAlchemyError: | ||
| return None, None |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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 👍 / 👎.
Result:
Accounts with valid credits are no longer falsely blocked, while true quota-exhausted accounts are still blocked correctly.