Repository navigation
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3aa828fda5
ℹ️ 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".
|
Thanks @huzky-v -- the design itself is clean: reusing I checked merge-tree against current main (post-#559) and there is no text or semantic conflict -- the two paths are complementary (sync vs periodic / single-process vs cross-process). So functionally we're good to land this once one P1 is addressed. P1 -- AsyncSession concurrent useCodex review caught this and it's correct: # app/core/usage/refresh_scheduler.py:130
latest_primary, latest_secondary = await asyncio.gather(
usage_repo.latest_by_account(window="primary"),
usage_repo.latest_by_account(window="secondary"),
)
When this hits, the failure mode is one of two SQLAlchemy errors:
Either way the surrounding Suggested fixSequential calls are the simplest and match the SQLAlchemy contract: latest_primary = await usage_repo.latest_by_account(window="primary")
latest_secondary = await usage_repo.latest_by_account(window="secondary")The two queries don't share a critical section that benefits from parallelism (no cross-DB joins, no upstream calls in between), and If we ever do want parallelism on a future variant -- for example to also pull additional-quota windows in the same cycle -- the right pattern is per-task sessions: async with get_background_session() as session_primary, get_background_session() as session_secondary:
primary_repo = UsageRepository(session_primary)
secondary_repo = UsageRepository(session_secondary)
latest_primary, latest_secondary = await asyncio.gather(
primary_repo.latest_by_account(window="primary"),
secondary_repo.latest_by_account(window="secondary"),
)But that is overkill for two small reads -- the sequential pattern above is fine. Tests to updateThe existing
Whichever is easier on your side. Not blocking otherwiseThe rest of the PR is in good shape and the merge-tree against main is clean. Once you push the sequential read I'll re-run |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3aa828fda5
ℹ️ 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".
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b958b79f6f
ℹ️ 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".
|
Thanks @huzky-v -- the AsyncSession P1 ( P1 -- rate-limit cooldown is bypassed in recovery stateIn runtime.cooldown_until = blocked_at # in the past as soon as we evaluate itThis causes the RATE_LIMITED branch of
The intent of the recovery scheduler is the opposite -- only flip an account back to Suggested fixSeed # app/modules/proxy/load_balancer.py:~1169
runtime.cooldown_until = (
account.rate_limit_reset_at # if a hard reset timestamp is known
or (account.blocked_at + retry_delay) # else derive from blocked_at + delay
)(Exact field names depend on what If the recovery state has no notion of "how long the cooldown is" because that info lives elsewhere, then the recovery path should not clear Tests to adddef test_recovery_state_preserves_rate_limit_cooldown_when_block_recent():
account = _make_account(
status=AccountStatus.RATE_LIMITED,
blocked_at=now - timedelta(minutes=5),
rate_limit_reset_at=now + timedelta(minutes=25),
)
state = background_recovery_state_from_account(account)
runtime = _state_from_account(account, state)
assert runtime.status == AccountStatus.RATE_LIMITED # not ACTIVE
assert runtime.cooldown_until > now
def test_recovery_state_recovers_account_after_cooldown_elapsed():
account = _make_account(
status=AccountStatus.RATE_LIMITED,
blocked_at=now - timedelta(hours=2),
rate_limit_reset_at=now - timedelta(minutes=5), # already past reset
)
state = background_recovery_state_from_account(account)
runtime = _state_from_account(account, state)
assert runtime.status == AccountStatus.ACTIVENot blocking otherwise
Once this is fixed I'll re-run |
|
To use Codex here, create an environment for this repo. |
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
6efd07d to
19fff75
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
c40cac3 to
7608bf8
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Current-main smoke failure before mergeLive PR gates are green ( Repro I ran: git fetch origin main pull/529/head:refs/remotes/origin/pr-529 --prune
git worktree add --detach .worktree/review-pr-529 refs/remotes/origin/pr-529
cd .worktree/review-pr-529
git merge --no-commit --no-ff origin/main
uv run --locked openspec validate reconcile-background-account-status --strict
uv run --locked ruff check \
app/core/usage/refresh_scheduler.py \
app/modules/proxy/load_balancer.py \
tests/integration/test_accounts_api_extended.py \
tests/unit/test_load_balancer.py \
tests/unit/test_request_locality.py \
tests/unit/test_usage_refresh_scheduler_recovery.py
uv run --locked ty check \
app/core/usage/refresh_scheduler.py \
app/modules/proxy/load_balancer.py \
tests/integration/test_accounts_api_extended.py \
tests/unit/test_load_balancer.py \
tests/unit/test_request_locality.py \
tests/unit/test_usage_refresh_scheduler_recovery.py
uv run --locked pytest -q -ra \
tests/integration/test_accounts_api_extended.py \
tests/unit/test_load_balancer.py \
tests/unit/test_request_locality.py \
tests/unit/test_usage_refresh_scheduler_recovery.py \
--durations=20OpenSpec / ruff / ty pass, but pytest fails: This looks like drift against current Could you rebase/merge current |
7608bf8 to
f09b655
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b7fd132fcd
ℹ️ 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".
| account.status == AccountStatus.RATE_LIMITED | ||
| and blocked_at is not None |
There was a problem hiding this comment.
Require freshness when recovering markerless rate limits
When a persisted rate_limited row has no blocked_at marker, this guard is skipped entirely, so _state_from_account() can return ACTIVE solely because reset_at is in the past and the latest primary row is below 100%, even if that row predates the rate-limit event or the background refresh just failed. This makes the new scheduler reconciliation clear legacy/markerless rate-limit rows without the fresh post-block usage proof required by the recovery path, potentially re-enabling an account before a successful usage refresh confirms recovery.
Useful? React with 👍 / 👎.
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…on will roll it to ACTIVE
f46b0d6 to
7535ad1
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7535ad11e1
ℹ️ 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".
| account.status == AccountStatus.RATE_LIMITED | ||
| and blocked_at is not None | ||
| and reset_at is not None | ||
| and reset_at <= time.time() | ||
| and not _usage_entry_recorded_after_block(primary_entry, blocked_at) | ||
| ): |
There was a problem hiding this comment.
Require post-block secondary evidence before quota recovery
The background recovery path only enforces a post-block freshness check for RATE_LIMITED accounts; QUOTA_EXCEEDED accounts can still be returned as ACTIVE by _state_from_account when reset_at has elapsed even if the latest secondary usage row predates blocked_at. Because this commit now persists that recovery in reconcile_recoverable_account_statuses, a stale pre-block secondary snapshot can incorrectly reactivate an account and send traffic to an actually exhausted quota window.
Useful? React with 👍 / 👎.
| if account.status in (AccountStatus.RATE_LIMITED, AccountStatus.QUOTA_EXCEEDED) and status == AccountStatus.ACTIVE: | ||
| return account.status |
There was a problem hiding this comment.
Avoid hard-coupling UI status recovery to refresh scheduler
This override prevents the API mapper from ever showing ACTIVE for persisted rate_limited/quota_exceeded rows, even when apply_usage_quota computes recovery from usage data. If background refresh is disabled or not running (it is gated by usage_refresh_enabled and leader acquisition), statuses remain permanently stale in /api/accounts, which is a functional regression from the previous on-read recovery behavior.
Useful? React with 👍 / 👎.
|
Maintainer cleanup: closing this as stale / no longer merge-ready against the current 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 If the change is still needed, please open a fresh, focused PR rebased on current |
|
Revived on a maintainer-owned branch as #754 because this PR head has maintainerCanModify=false and cannot be updated here. Keeping credit to the original implementation in the replacement PR. |
Address #479
Probably fix the issue that the UI still show the stale status after the time resets
As currently the status update is more like
lazy update, if there is no request tocodex-lbor the account does not tide to any API, the status shown in UI will never be updated.Not sure why the request does not get routed, but this would best effort reset the status, as a fallback, with the help of scheduler
This fix is to introduce the account status for those account status = rate-limit/ quota exceed in the scheduler