Skip to content

feat(proxy): add opportunistic traffic class#567

Open
Komzpa wants to merge 10 commits intoSoju06:mainfrom
Komzpa:codex/opportunistic-traffic-class
Open

feat(proxy): add opportunistic traffic class#567
Komzpa wants to merge 10 commits intoSoju06:mainfrom
Komzpa:codex/opportunistic-traffic-class

Conversation

@Komzpa
Copy link
Copy Markdown
Contributor

@Komzpa Komzpa commented May 9, 2026

Summary

  • Add API-key traffic_class with foreground default and opportunistic routing.
  • Add Codex opportunistic admission preflight at /backend-api/codex/opportunistic/admission.
  • Return OpenAI-style 429 denials with Retry-After when the opportunistic burn window is closed.
  • Add dynamic opportunistic burn floors for burn_first, normal, and preserve accounts.
  • Route real opportunistic Codex requests through the existing Codex proxy path while keeping Fixer-style preflight as a scheduling hint.

Stack

Tests

  • uv run ty check
  • /home/kom/proj/codex-lb/.venv/bin/python -m ruff check app/core/balancer app/db/models.py app/db/alembic/versions/20260509_000000_add_api_key_traffic_class.py app/modules/api_keys app/modules/proxy/api.py app/modules/proxy/load_balancer.py app/modules/proxy/service.py tests/unit/test_api_keys_service.py tests/unit/test_load_balancer.py
  • openspec validate add-opportunistic-traffic-class --strict --no-interactive
  • /home/kom/proj/codex-lb/.venv/bin/python -m pytest tests/unit/test_load_balancer.py tests/unit/test_api_keys_service.py tests/integration/test_load_balancer_integration.py tests/integration/test_settings_api.py tests/integration/test_additional_usage_flow.py tests/integration/test_migrations.py -q
  • /home/kom/proj/codex-lb/.venv/bin/python -m ruff format --check app/core/balancer app/db/models.py app/db/alembic/versions/20260509_000000_add_api_key_traffic_class.py app/modules/api_keys app/modules/proxy/api.py app/modules/proxy/load_balancer.py app/modules/proxy/service.py tests/unit/test_api_keys_service.py tests/unit/test_load_balancer.py && git diff --check

@Komzpa Komzpa force-pushed the codex/opportunistic-traffic-class branch from c21f588 to 288ab6a Compare May 9, 2026 08:42
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: c21f58874b

ℹ️ 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 on lines +189 to +191
if _routing_policy(other) == ROUTING_POLICY_PRESERVE:
if _preserve_allows_opportunistic_burn(other, current, preserve_count=preserve_count):
return True
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 Treat preserve capacity as foreground in zero-burn eligibility

The zero-burn guard for normal/burn-first accounts only counts preserve peers when _preserve_allows_opportunistic_burn(...) returns true. That conflates “foreground capacity exists” with “preserve is also opportunistically burnable”: a preserve account at its opportunistic floor can still retain foreground reserve, but this code treats it as unavailable and blocks draining expendable accounts to zero. As a result, opportunistic admission can close earlier than intended whenever the only remaining foreground reserve is on preserve accounts.

Useful? React with 👍 / 👎.

@Komzpa Komzpa force-pushed the codex/opportunistic-traffic-class branch 2 times, most recently from 1c72cbd to e4a5f8f Compare May 9, 2026 09:07
@Komzpa Komzpa force-pushed the codex/opportunistic-traffic-class branch from e4a5f8f to 42d3f9f Compare May 9, 2026 09:17
@Komzpa Komzpa force-pushed the codex/opportunistic-traffic-class branch 3 times, most recently from a7adecf to 61cdd1c Compare May 9, 2026 16:52
@Komzpa Komzpa force-pushed the codex/opportunistic-traffic-class branch from 61cdd1c to 8f7a0e2 Compare May 9, 2026 16:54
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.

1 participant