Skip to content

feat(proxy): restore opportunistic traffic class on main#716

Open
Komzpa wants to merge 122 commits into
Soju06:mainfrom
Komzpa:fix/opportunistic-traffic-class-main
Open

feat(proxy): restore opportunistic traffic class on main#716
Komzpa wants to merge 122 commits into
Soju06:mainfrom
Komzpa:fix/opportunistic-traffic-class-main

Conversation

@Komzpa
Copy link
Copy Markdown
Collaborator

@Komzpa Komzpa commented May 19, 2026

Summary

This is now the consolidated routing/quota/account-dashboard branch based directly on main.

The branch keeps the original opportunistic traffic-class restoration and folds the overlapping routing/quota work that was otherwise split across several open PRs. The goal is one reviewable main-based PR for account identity, additional-quota routing, sticky/fill-first selection, manual account routing policy, reset-window preference, single-account/drain behavior, security-work account authorization, live credits display, and quota phase planning.

Current head: 1aea7b33c42b3040d09383af392bbeb3ad0bb351
Base: main

Folded here:

Kept separate:

Notable consolidation fixes:

  • Account import/deduplication uses the account key model instead of treating duplicate emails as duplicate accounts.
  • Additional-quota routing policy is exposed consistently through backend schemas, service mappings, account detail UI, and registry-default routing policies.
  • Opportunistic admission now applies the dashboard single-account scope before probing burn capacity, so preflight matches real request routing.
  • Reset-window and sticky-threshold settings preserve older settings objects without forcing undefined frontend values into API payloads.
  • Required file/account pins are honored before dashboard single-account routing, so file finalize/input-file requests stay on the account that owns the pinned upload.
  • Security-work authorized routing preserves additional-quota metadata, so gated-model retries keep using the quota scope and routing policy selected before the security filter.
  • Quota planner request costs are applied after hard eligibility filters without dropping routing policy, traffic class, sticky threshold, or additional-quota semantics.
  • The migration graph has a merge revision for the folded quota-planner and routing-consolidation heads, so head upgrades stay single-headed.

Validation

Local validation for the current head:

  • uv run ruff check .
  • uv run ruff format --check .
  • uv run ty check
  • uv run pytest tests/unit/test_load_balancer.py tests/unit/test_select_with_stickiness.py tests/unit/test_quota_planner.py tests/integration/test_quota_planner_api.py -q
  • uv run pytest tests/unit/test_db_migrate.py tests/unit/test_db_rate_limiter.py tests/integration/test_migrations.py -q
  • uv run pytest tests/unit tests/integration -q (3094 passed, 43 skipped)
  • bun run typecheck
  • bun run lint
  • bun run test -- --run (490 passed)
  • bun run build

Additional validation for the latest Codex review fixes:

  • uv run pytest tests/integration/test_additional_usage_flow.py::test_accounts_list_returns_additional_quotas tests/integration/test_proxy_chat_completions.py::test_responses_compact_opportunistic_denial_runs_before_api_key_reservation -q (2 passed)
  • uv run pytest tests/integration/test_additional_usage_flow.py tests/integration/test_proxy_chat_completions.py -q (14 passed)
  • uv run ruff check app/modules/accounts/repository.py app/modules/accounts/service.py app/modules/proxy/api.py tests/integration/test_additional_usage_flow.py tests/integration/test_proxy_chat_completions.py
  • uv run ruff format --check app/modules/accounts/repository.py app/modules/accounts/service.py app/modules/proxy/api.py tests/integration/test_additional_usage_flow.py tests/integration/test_proxy_chat_completions.py
  • uv run ty check app/modules/accounts app/modules/proxy tests/integration/test_additional_usage_flow.py tests/integration/test_proxy_chat_completions.py
  • uv run pytest tests/unit/test_proxy_utils.py::test_opportunistic_admission_scopes_single_account_to_selected_account tests/unit/test_proxy_utils.py::test_opportunistic_admission_empty_scope_when_single_account_is_outside_api_key_scope tests/integration/test_settings_api.py::test_settings_api_returns_known_additional_quota_policies -q (3 passed)
  • uv run ruff check app/modules/proxy/service.py app/modules/settings/api.py app/modules/settings/schemas.py tests/unit/test_proxy_utils.py tests/integration/test_settings_api.py
  • uv run pytest tests/unit/test_load_balancer.py -q (169 passed)
  • uv run ruff check app/modules/proxy/load_balancer.py tests/unit/test_load_balancer.py
  • uv run ty check

Current-head GitHub CI run:

  • pending for 1aea7b33c42b3040d09383af392bbeb3ad0bb351 (https://github.com/Soju06/codex-lb/actions/runs/26793720749)
  • uv run pytest tests/unit/test_proxy_utils.py::test_stream_responses_retries_security_work_warning_on_authorized_account tests/unit/test_proxy_utils.py::test_stream_responses_treats_missing_security_work_pool_as_optional tests/unit/test_proxy_utils.py::test_stream_responses_missing_security_work_pool_preserves_failover_budget -q (3 passed)
  • uv run pytest tests/unit/test_proxy_utils.py::test_stream_responses_retries_security_work_warning_on_authorized_account tests/unit/test_proxy_utils.py::test_stream_responses_treats_missing_security_work_pool_as_optional tests/unit/test_proxy_utils.py::test_stream_responses_missing_security_work_pool_preserves_failover_budget tests/integration/test_additional_usage_flow.py::test_accounts_list_returns_additional_quotas tests/integration/test_proxy_chat_completions.py::test_responses_compact_opportunistic_denial_runs_before_api_key_reservation -q (5 passed)
  • uv run ruff check app/modules/proxy/service.py tests/unit/test_proxy_utils.py
  • uv run ruff format --check app/modules/proxy/service.py tests/unit/test_proxy_utils.py
  • uv run ty check app/modules/proxy/service.py tests/unit/test_proxy_utils.py
  • uv run pytest tests/unit/test_load_balancer.py::test_drain_budget_safe_selection_filters_over_threshold_accounts tests/unit/test_load_balancer.py::test_burn_first_selection_honors_primary_reset_preference tests/unit/test_load_balancer.py::test_all_primary_pressured_fallback_honors_primary_reset_preference tests/unit/test_load_balancer.py::test_primary_pressured_fallback_honors_reset_bucket_before_primary_usage tests/unit/test_load_balancer.py::test_budget_safe_selection_keeps_burn_first_ahead_of_threshold -q (5 passed)
  • uv run ruff check app/modules/proxy/load_balancer.py tests/unit/test_load_balancer.py
  • uv run ruff format --check app/modules/proxy/load_balancer.py tests/unit/test_load_balancer.py
  • uv run ty check app/modules/proxy/load_balancer.py tests/unit/test_load_balancer.py

Current-head CI is pending after the latest push. Codex review labels are managed by the repository synchronizer; this PR should not carry 🤖 codex: ok until the synchronizer proves green current-head CI plus a clean current-head Codex review.

@Komzpa Komzpa force-pushed the fix/opportunistic-traffic-class-main branch from 42a6cff to 5a3b7be Compare May 19, 2026 19:37
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: 42a6cff511

ℹ️ 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
Copy link
Copy Markdown
Collaborator Author

Komzpa commented May 19, 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: 5a3b7be84f

ℹ️ 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 force-pushed the fix/opportunistic-traffic-class-main branch 3 times, most recently from fa13a43 to bad03a4 Compare May 20, 2026 13:57
@Komzpa
Copy link
Copy Markdown
Collaborator Author

Komzpa commented May 20, 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: bad03a4b42

ℹ️ 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 force-pushed the fix/opportunistic-traffic-class-main branch from bad03a4 to f411de9 Compare May 20, 2026 15:50
@Komzpa
Copy link
Copy Markdown
Collaborator Author

Komzpa commented May 20, 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: f411de94d3

ℹ️ 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 20, 2026
@Komzpa Komzpa force-pushed the fix/opportunistic-traffic-class-main branch from f411de9 to 7327639 Compare May 20, 2026 16:27
@Komzpa Komzpa removed the 🤖 codex: needs work [@codex review] raised an issue label May 20, 2026
@Soju06 Soju06 added the 🤖 codex: needs work [@codex review] raised an issue label May 21, 2026
@Komzpa Komzpa force-pushed the fix/opportunistic-traffic-class-main branch 2 times, most recently from b8c5b02 to 7f80220 Compare May 21, 2026 10:27
@Soju06
Copy link
Copy Markdown
Owner

Soju06 commented May 21, 2026

@codex review

1 similar comment
@Soju06
Copy link
Copy Markdown
Owner

Soju06 commented May 21, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

ℹ️ 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 labels May 21, 2026
@Soju06 Soju06 added 🤖 codex: needs work [@codex review] raised an issue and removed 🤖 codex: ok [@codex review] says no issues found. labels May 21, 2026
@Komzpa Komzpa added 🤖 codex: ok [@codex review] says no issues found. and removed 🤖 codex: needs work [@codex review] raised an issue labels May 21, 2026
@Soju06 Soju06 added 🤖 codex: needs work [@codex review] raised an issue and removed 🤖 codex: ok [@codex review] says no issues found. labels May 21, 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: 589edbdd95

ℹ️ 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 added 2 commits June 2, 2026 03:22
…idate/routing-quota

# Conflicts:
#	app/core/balancer/__init__.py
#	app/core/balancer/logic.py
#	app/modules/proxy/load_balancer.py
#	frontend/src/test/mocks/handlers.ts
#	tests/unit/test_load_balancer.py
@Komzpa
Copy link
Copy Markdown
Collaborator Author

Komzpa commented Jun 1, 2026

@codex review

1 similar comment
@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: 43b1b17433

ℹ️ 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/service.py
Comment thread app/modules/settings/api.py
@Komzpa
Copy link
Copy Markdown
Collaborator Author

Komzpa commented Jun 2, 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: c8a0f30f48

ℹ️ 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/accounts/service.py Outdated
Comment thread app/modules/proxy/api.py
@Soju06
Copy link
Copy Markdown
Owner

Soju06 commented Jun 2, 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: 2d66af05d5

ℹ️ 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/service.py
@Soju06
Copy link
Copy Markdown
Owner

Soju06 commented Jun 2, 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: a9e9180d50

ℹ️ 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
Comment thread app/modules/proxy/load_balancer.py
@Soju06
Copy link
Copy Markdown
Owner

Soju06 commented Jun 2, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

ℹ️ 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
Copy link
Copy Markdown
Owner

Soju06 commented Jun 2, 2026

Hermes follow-up while checking the folded #737 quota-planner content: I still see merge blockers on the surviving #716 branch.

  1. Warmup decisions are not atomically claimed before synthetic traffic is sent. QuotaWarmupService.warm_now() reads a planned decision and then sends the upstream probe before any status transition (app/modules/quota_planner/warmup.py:81-100, :157-164). Final status is then overwritten to executed unconditionally (warmup.py:194-199). cancel_decision() can set the same planned row to canceled (warmup.py:273-285), but QuotaPlannerRepository.update_decision_status() has no expected-status/CAS guard (app/modules/quota_planner/repository.py:126-148). So an admin cancel or concurrent scheduler/worker race can still result in duplicate or canceled synthetic warmups executing and then overwriting the cancellation. Please add a narrow atomic claim state such as planned -> executing with WHERE id = ... AND status = 'planned', execute only after a successful claim, and make final/cancel updates conditional on that in-flight state.

  2. The quota-planner behavior change still lacks an OpenSpec change folder. The folded feat(quota-planner): add phase-aware routing planner #737 diff adds dashboard/API/schema/scheduler/migration behavior, but only adds stable specs (openspec/specs/quota-phase-planner/context.md, openspec/specs/quota-phase-planner/spec.md) and no openspec/changes/<slug>/ entry. The repo gate requires one for non-exempt behavior changes (AGENTS.md:24-28, AGENTS.md:90-96, .github/CONTRIBUTING.md:235-239). openspec validate --specs passing is not enough for this merge gate.

  3. feat(proxy): restore opportunistic traffic class on main #716 is currently not mergeable against current main. GitHub reports mergeable_state=dirty / CONFLICTING; local current-main probe conflicts in tests/integration/test_proxy_chat_completions.py. CI is green for the old head/base, but the live merge gate is not clean.

I verified #737 itself is closed/unmerged and is an ancestor of #716, so I’m leaving this on #716 rather than the closed PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

db migration PR changes Alembic database migrations; maintainer must coordinate merge order hermes: needs-followup Hermes left a blocker/comment that needs follow-up observation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants