Skip to content

feat(balancer): bypass QUOTA_EXCEEDED filter for gated models with additional quota#855

Open
zwd0313 wants to merge 8 commits into
Soju06:mainfrom
zwd0313:feat/allow-gated-model-quota-exceeded-bypass
Open

feat(balancer): bypass QUOTA_EXCEEDED filter for gated models with additional quota#855
zwd0313 wants to merge 8 commits into
Soju06:mainfrom
zwd0313:feat/allow-gated-model-quota-exceeded-bypass

Conversation

@zwd0313
Copy link
Copy Markdown

@zwd0313 zwd0313 commented May 30, 2026

Problem

When a model is routed through an additional (gated) quota (e.g. `GPT-5.3-Codex-Spark`), `select_account()` unconditionally filters out all accounts with `QUOTA_EXCEEDED` status — even when the additional (independent) quota is available and the account is otherwise healthy. This causes legitimate gated-model requests to fail with "No available accounts".

The root cause: the `QUOTA_EXCEEDED` branch in `select_account()` does `continue` without checking whether an additional quota gate has already determined the account is eligible.

Change

Add a `bypass_quota_exceeded=False` keyword parameter to `select_account()` that, when `True`, skips the `QUOTA_EXCEEDED continue` branch while still respecting all other status checks (PAUSED, DEACTIVATED, RATE_LIMITED, cooldown, error backoff).

At the `LoadBalancer.select_account()` entry point, automatically compute:

```python
_effective_bypass_quota_exceeded = additional_limit_name is not None
```

so bypass is enabled for any gated-model request. The parameter flows through the full call chain:

  • `LoadBalancer.select_account()` → `_select_account_preferring_budget_safe()` → `select_account()`
  • `LoadBalancer.select_account()` → `_select_with_stickiness()` → `select_account()`

Impact scope: Only affects requests routed through an additional quota gate. Standard (non-gated) requests are unaffected (`additional_limit_name=None` → bypass stays `False`).

Testing

84/84 pass (82 existing + 2 new):

  • `test_bypass_quota_exceeded_keeps_account_in_pool`: confirms QUOTA_EXCEEDED account stays in pool when bypass=True
  • `test_bypass_quota_exceeded_does_not_affect_other_statuses`: confirms PAUSED/DEACTIVATED still filtered when bypass=True

Files changed (3 files, +65/-1)

File Change
`app/core/balancer/logic.py` New `bypass_quota_exceeded` param + skip logic
`app/modules/proxy/load_balancer.py` Param forwarding + entry-point computation
`tests/unit/test_load_balancer.py` 2 regression tests

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: 551facccdc

ℹ️ 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 thread app/modules/proxy/load_balancer.py Outdated
@Soju06 Soju06 added 🤖 codex: needs work [@codex review] raised an issue and removed 🤖 codex: needs work [@codex review] raised an issue labels May 31, 2026
@Komzpa
Copy link
Copy Markdown
Collaborator

Komzpa commented May 31, 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: 934ca0635e

ℹ️ 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 thread app/core/balancer/logic.py Outdated
Comment thread app/modules/proxy/load_balancer.py Outdated
@Komzpa Komzpa added the 🤖 codex: needs work [@codex review] raised an issue label May 31, 2026
@Komzpa Komzpa force-pushed the feat/allow-gated-model-quota-exceeded-bypass branch from 934ca06 to 295705f Compare May 31, 2026 20:14
@Soju06 Soju06 removed the 🤖 codex: needs work [@codex review] raised an issue label May 31, 2026
@Komzpa
Copy link
Copy Markdown
Collaborator

Komzpa commented May 31, 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: 295705f392

ℹ️ 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 thread app/modules/proxy/load_balancer.py Outdated
@Komzpa Komzpa added the 🤖 codex: needs work [@codex review] raised an issue label May 31, 2026
@Komzpa Komzpa force-pushed the feat/allow-gated-model-quota-exceeded-bypass branch from 295705f to 24971c2 Compare May 31, 2026 20:32
@Komzpa
Copy link
Copy Markdown
Collaborator

Komzpa commented May 31, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

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

@Komzpa Komzpa added 🤖 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 31, 2026
@Komzpa Komzpa force-pushed the feat/allow-gated-model-quota-exceeded-bypass branch 4 times, most recently from 3f99a17 to c51efb7 Compare May 31, 2026 22:03
@Soju06
Copy link
Copy Markdown
Owner

Soju06 commented May 31, 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: c51efb7fed

ℹ️ 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 thread app/core/balancer/logic.py
@Soju06 Soju06 added the 🤖 codex: needs work [@codex review] raised an issue label May 31, 2026
@Komzpa Komzpa force-pushed the feat/allow-gated-model-quota-exceeded-bypass branch from c51efb7 to 7266350 Compare May 31, 2026 22:46
@Soju06 Soju06 removed the 🤖 codex: needs work [@codex review] raised an issue label May 31, 2026
@Komzpa
Copy link
Copy Markdown
Collaborator

Komzpa commented May 31, 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: 72663507ba

ℹ️ 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 thread app/modules/usage/repository.py Outdated
@Komzpa Komzpa added the 🤖 codex: needs work [@codex review] raised an issue label May 31, 2026
@Komzpa Komzpa force-pushed the feat/allow-gated-model-quota-exceeded-bypass branch from 7266350 to 9752e3e Compare May 31, 2026 23:07
@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 Jun 1, 2026
zwd0313 and others added 4 commits June 1, 2026 08:13
…ditional quota

When a model is routed through an additional (gated) quota, the
primary-window QUOTA_EXCEEDED status on an account may be stale or
irrelevant — the additional quota gate has already verified
eligibility independently.  Previously, select_account() unconditionally
filtered out QUOTA_EXCEEDED accounts via `continue`, causing legitimate
gated-model requests to fail with 'No available accounts' even though
the additional quota was available.

Add a `bypass_quota_exceeded=False` parameter to select_account()
that, when True, skips the QUOTA_EXCEEDED continue branch while still
respecting all other status checks (PAUSED, DEACTIVATED, RATE_LIMITED,
cooldown, error backoff).

At the LoadBalancer.select_account() entry point, compute
`_effective_bypass_quota_exceeded = additional_limit_name is not None`
so bypass is automatically enabled for any gated-model request.  The
parameter flows through _select_account_preferring_budget_safe() and
_select_with_stickiness() to all internal select_account() call sites.

Two unit tests:
- bypass_quota_exceeded=True keeps QUOTA_EXCEEDED account in pool
- bypass_quota_exceeded=True does not affect PAUSED/DEACTIVATED filtering
@Komzpa Komzpa force-pushed the feat/allow-gated-model-quota-exceeded-bypass branch from 9752e3e to 882ec9b Compare June 1, 2026 04:21
@Komzpa
Copy link
Copy Markdown
Collaborator

Komzpa commented Jun 1, 2026

@codex review

@Komzpa
Copy link
Copy Markdown
Collaborator

Komzpa commented Jun 1, 2026

Addressed in 882ec9b5.

  • Added OpenSpec change fix-gated-model-requested-limit-bypass-semantics with strict validation for the gated/requested-limit quota semantics.
  • Requested-limit ranking now keeps requested additional secondary usage separate: missing requested secondary rows no longer borrow ordinary account secondary usage for requested-limit ranking, budget checks, or relative-availability scoring.
  • QUOTA_EXCEEDED bypass no longer bypasses active cooldown_until; cooldown/backoff gates remain enforced while the quota-status bypass still works for cooled eligible accounts.

Validation:

  • uv run openspec validate fix-gated-model-requested-limit-bypass-semantics --strict
  • uv run ruff check app/core/balancer/logic.py app/modules/proxy/load_balancer.py tests/unit/test_load_balancer.py
  • uv run pytest tests/unit/test_load_balancer.py tests/unit/test_proxy_load_balancer_refresh.py tests/unit/test_proxy_service_additional_limits.py tests/integration/test_additional_usage_flow.py tests/integration/test_load_balancer_integration.py -q
  • CI is green on 882ec9b5: https://github.com/Soju06/codex-lb/actions/runs/26734991097

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: 882ec9b556

ℹ️ 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 thread app/modules/proxy/load_balancer.py
@Komzpa Komzpa added the 🤖 codex: needs work [@codex review] raised an issue label Jun 1, 2026
@Soju06 Soju06 removed the 🤖 codex: needs work [@codex review] raised an issue label Jun 1, 2026
@Soju06
Copy link
Copy Markdown
Owner

Soju06 commented Jun 1, 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: ae519914e0

ℹ️ 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 thread app/core/balancer/logic.py
@Soju06 Soju06 added the 🤖 codex: needs work [@codex review] raised an issue label Jun 1, 2026
@Soju06 Soju06 removed the 🤖 codex: needs work [@codex review] raised an issue label Jun 1, 2026
@Komzpa
Copy link
Copy Markdown
Collaborator

Komzpa commented Jun 1, 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: 58a8cbe4c2

ℹ️ 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 thread app/modules/proxy/load_balancer.py
@Komzpa Komzpa added the 🤖 codex: needs work [@codex review] raised an issue label Jun 1, 2026
@Komzpa Komzpa force-pushed the feat/allow-gated-model-quota-exceeded-bypass branch from b13a5e2 to ca9e470 Compare June 1, 2026 07:04
@Komzpa
Copy link
Copy Markdown
Collaborator

Komzpa commented Jun 1, 2026

@codex review

@Komzpa Komzpa removed 🤖 codex: needs work [@codex review] raised an issue hermes: needs-followup Hermes left a blocker/comment that needs follow-up observation labels Jun 1, 2026
@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 🤖 codex: ok [@codex review] says no issues found. and removed 🤖 codex: ok [@codex review] says no issues found. labels Jun 1, 2026
# Conflicts:
#	app/core/balancer/logic.py
#	app/modules/proxy/load_balancer.py
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.

3 participants