Skip to content

fix(proxy): support Pro Lite account routing - #558

Merged
Soju06 merged 4 commits into
Soju06:mainfrom
aruis:codex/support-prolite-plan-capacity
May 15, 2026
Merged

Soju06 merged 4 commits into
Soju06:mainfrom
aruis:codex/support-prolite-plan-capacity

Conversation

@aruis

@aruis aruis commented May 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Recognize upstream prolite account plan values without rewriting stored account rows.
  • Map Pro Lite accounts to Pro-equivalent primary and secondary usage capacities for dashboard totals and capacity-weighted routing.
  • Treat Pro Lite as Pro-equivalent when model registry plan gates allow pro, so Pro-gated models can select Pro Lite accounts.
  • Add OpenSpec change artifacts and regression coverage for auth normalization, usage summaries, dashboard overview, and proxy account selection.

Fixes #557

Validation

  • uv run pytest -q tests/unit/test_auth.py tests/unit/test_usage.py tests/unit/test_proxy_load_balancer_refresh.py tests/integration/test_dashboard_overview.py
  • uv run ruff check app/core/plan_types.py app/core/usage/__init__.py app/modules/proxy/load_balancer.py tests/unit/test_auth.py tests/unit/test_usage.py tests/unit/test_proxy_load_balancer_refresh.py tests/integration/test_dashboard_overview.py
  • uv run ty check app/core/plan_types.py app/core/usage/__init__.py app/modules/proxy/load_balancer.py tests/unit/test_auth.py tests/unit/test_usage.py tests/unit/test_proxy_load_balancer_refresh.py tests/integration/test_dashboard_overview.py

Notes

  • uv run openspec validate --specs could not run locally because the openspec executable is not installed in this environment.
  • A local amd64 Docker test image was exercised against the reported Pro Lite account, confirming dashboard quota totals and gpt-5.4 request routing after proxy configuration was corrected.

@Soju06

Soju06 commented May 8, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

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: 5419de7772

ℹ️ 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/plan_types.py Outdated
Comment on lines +73 to +75
normalized = normalize_account_plan_type(value)
if normalized is None:
return False

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve direct matching for unknown account plans

account_plan_matches_allowed now rejects any plan string that is not in ACCOUNT_PLAN_TYPES because normalize_account_plan_type returns None, so accounts with a new upstream plan (for example, any future plan value) will never pass model gating even when the model registry explicitly allows that same plan. This is a regression from the previous _filter_accounts_for_model behavior (a.plan_type in allowed_plans) and can cause modeled requests to fail with NO_PLAN_SUPPORT_FOR_MODEL until code is updated for each new plan string; keep a fallback direct membership check before applying equivalence mapping.

Useful? React with 👍 / 👎.

@Soju06

Soju06 commented May 8, 2026

Copy link
Copy Markdown
Owner

Thanks @aruis -- the prolite plumbing looks right and Fixes #557 is on the money. Codex review flagged one real regression that I think we should address before merge:

P1 -- account_plan_matches_allowed rejects unknown plans

The old _filter_accounts_for_model did a direct string comparison:

allowed_plans = ...  # from upstream model.available_in_plans
return [a for a in accounts if a.plan_type in allowed_plans]

The new helper short-circuits to False when normalize_account_plan_type(value) returns None:

def account_plan_matches_allowed(value, allowed_plans):
    normalized = normalize_account_plan_type(value)
    if normalized is None:
        return False  # <-- regression
    ...

normalize_account_plan_type only knows the values currently in ACCOUNT_PLAN_TYPES. So if OpenAI later ships a new plan slug (the next prolite-style addition), accounts on that plan will silently fail model gating for every model, including ones whose registry entry explicitly lists the new plan in available_in_plans. This is the regression direction.

Suggested shape -- preserve a direct string fallback so unknown-but-explicitly-allowed plans still work:

def account_plan_matches_allowed(value, allowed_plans):
    cleaned = _clean_plan_type(value)
    if not cleaned:
        return False
    normalized = canonicalize_account_plan_type(cleaned)
    normalized_allowed = {plan.lower() for plan in allowed_plans}
    candidate = (normalized or cleaned.lower())
    if candidate in normalized_allowed:
        return True
    if normalized is not None and ACCOUNT_PLAN_EQUIVALENTS.get(normalized, frozenset()) & normalized_allowed:
        return True
    return False

(I.e. fall through to the lowercased raw string when normalization can't resolve it, instead of dropping the account.)

A quick regression test in tests/unit/test_plan_types.py would help -- something like:

def test_unknown_plan_passes_when_explicitly_allowed():
    assert account_plan_matches_allowed("future_plan", {"future_plan", "plus"})

def test_unknown_plan_blocked_when_not_in_allowed():
    assert not account_plan_matches_allowed("future_plan", {"plus"})

Once that's in I'll re-run @codex review and if it lands clean we can merge. The rest of the PR (capacity entries, equivalents map, openspec deltas) is fine.

Heads-up that I dropped a couple of follow-up notes on #557 too:

  • The current prolite -> pro capacity values mean prolite accounts get the same routing weight as Pro, even though their actual quotas may be smaller. If routing telemetry shows prolite over-utilization later, calibrating capacity values down (or treating prolite as roughly plus * 5) would be a clean follow-up.
  • sharenla's point chore(main): release 0.1.3 #4 (stale quota_exceeded / rate_limited not auto-recovering) looks like a separate issue from prolite -- the recovery logic in _compute_account_state already runs on every selection. If anyone has a concrete repro it deserves its own ticket.

Will re-trigger review after the regression fix.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

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: 5419de7772

ℹ️ 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/plan_types.py Outdated
Comment on lines +74 to +75
if normalized is None:
return False

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Allow unknown plans when explicitly listed

account_plan_matches_allowed now returns False whenever normalize_account_plan_type cannot resolve the account plan, which regresses the previous behavior of _filter_accounts_for_model (direct string membership). If the model registry starts emitting a new slug (for example a future plan type) and available_in_plans includes that same slug, those accounts will still be filtered out and selection can fail with no_accounts until code is updated. This should fall back to comparing the cleaned raw plan string against allowed_plans when normalization returns None so explicitly-allowed unknown plans continue to work.

Useful? React with 👍 / 👎.

@aruis

aruis commented May 10, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the P1 regression in eaa044d:

  • account_plan_matches_allowed now falls back to the lowercased raw plan slug when normalization does not recognize a future upstream plan.
  • Unknown plans still remain blocked unless the model registry explicitly lists that exact plan.
  • Added tests/unit/test_plan_types.py coverage for explicitly allowed and blocked unknown plans, plus Pro Lite equivalence.

Local validation:

  • uv run pytest -q tests/unit/test_auth.py tests/unit/test_plan_types.py tests/unit/test_usage.py tests/unit/test_proxy_load_balancer_refresh.py tests/integration/test_dashboard_overview.py
  • uv run ruff check app/core/plan_types.py tests/unit/test_plan_types.py tests/unit/test_usage.py tests/unit/test_proxy_load_balancer_refresh.py tests/integration/test_dashboard_overview.py
  • uv run ty check app/core/plan_types.py tests/unit/test_plan_types.py tests/unit/test_usage.py tests/unit/test_proxy_load_balancer_refresh.py tests/integration/test_dashboard_overview.py

@Soju06

Soju06 commented May 10, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

ℹ️ 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 commented May 11, 2026

Copy link
Copy Markdown
Owner

Thanks @aruis -- the P1 fix and the raw-fallback for unknown plans both look correct, codex review is clean across the latest commit, and the local docker repro you mentioned is a strong signal. Before merging I'd like to fold one capacity nuance @sharenla raised in #557 so we don't ship Pro Lite with an over-provisioned weight.

What I'd like changed

# app/core/usage/__init__.py
PRIMARY_CAPACITY = {
    ...,
    "pro": 1500.0,
-   "prolite": 1500.0,
+   "prolite": 1125.0,   # plus x5 long-term level
    "enterprise": 1500.0,
}

SECONDARY_CAPACITY = {
    ...,
    "pro": 50400.0,
-   "prolite": 50400.0,
+   "prolite": 37800.0,  # plus x5 long-term level
    "enterprise": 50400.0,
}

Why

Per @sharenla's #557 follow-up, Pro Lite Codex usage is product-documented as roughly Plus x5 long-term:

  • prolite_primary = plus_primary x 5 = 225 x 5 = 1125
  • prolite_secondary = plus_secondary x 5 = 7560 x 5 = 37800

There is also a Pro Lite / Pro mid-tier promo running through May 31 with Codex usage closer to Plus x10, but as @sharenla notes, baking the temporary promo into the long-term default is product-maintenance debt -- the conservative default is the permanent Plus x5 baseline. Operators who want to track the promo can override the constants out-of-band; defaulting to Pro (1500 / 50400) is x6.7 over the long-term Pro Lite ceiling and x10+ over what Plus customers would expect parity with.

This only affects derived credit totals / remaining-credit donuts and capacity-weighted routing weights -- upstream used_percent is still the source of truth for how much of the account window is consumed (sharenla's wording), so percent-based routing decisions stay correct either way. But for the dashboard math and capacity-weighted routing this is worth getting right at merge.

Tests

The two existing tests that exercise capacity will need their expected numbers updated to the new values:

  • tests/unit/test_usage.py -- prolite capacity assertions
  • tests/integration/test_dashboard_overview.py -- aggregate dashboard numbers when a Pro Lite account is present

The plan-matching / model-gating tests stay the same -- those don't depend on the capacity numbers, only on ACCOUNT_PLAN_EQUIVALENTS.

After this push

I'll re-run @codex review once and merge. Sorry for one more round; the rest of the PR is in great shape.

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create an environment for this repo.

@aruis

aruis commented May 11, 2026

Copy link
Copy Markdown
Contributor Author

Updated the PR to fold in the Pro Lite capacity nuance from #557:

  • prolite capacity is now Plus x5: 1125.0 primary / 37800.0 secondary.
  • Dashboard and usage regression expectations now assert those values.
  • Model eligibility remains Pro-equivalent for Pro-gated models.
  • OpenSpec change text now distinguishes Plus x5 capacity from Pro-equivalent model eligibility.

Local validation:

uv run pytest -q tests/unit/test_auth.py tests/unit/test_usage.py tests/unit/test_plan_types.py tests/unit/test_proxy_load_balancer_refresh.py tests/integration/test_dashboard_overview.py
uv run ruff check app/core/usage/__init__.py tests/unit/test_auth.py tests/unit/test_usage.py tests/unit/test_plan_types.py tests/unit/test_proxy_load_balancer_refresh.py tests/integration/test_dashboard_overview.py
uv run ty check app/core/usage/__init__.py tests/unit/test_auth.py tests/unit/test_usage.py tests/unit/test_plan_types.py tests/unit/test_proxy_load_balancer_refresh.py tests/integration/test_dashboard_overview.py

All passed locally. openspec validate --specs still cannot run in my local environment because the openspec executable is not installed.

@Soju06

Soju06 commented May 15, 2026

Copy link
Copy Markdown
Owner

@codex review

1 similar comment
@Soju06

Soju06 commented May 15, 2026

Copy link
Copy Markdown
Owner

@codex review

@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 merged commit a737c7e into Soju06:main May 15, 2026
18 checks passed
@Soju06

Soju06 commented May 15, 2026

Copy link
Copy Markdown
Owner

@all-contributors please add @aruis for code, test, bug

@allcontributors

Copy link
Copy Markdown
Contributor

@Soju06

I've put up a pull request to add @aruis! 🎉

@allcontributors

Copy link
Copy Markdown
Contributor

@Soju06

@aruis already contributed before to code

@aruis
aruis deleted the codex/support-prolite-plan-capacity branch May 15, 2026 13:32
Soju06 added a commit that referenced this pull request May 17, 2026
Release 1.18.0 — v1.17.0 → main, 27 PR.

## Pre-merge verification (release-gate e2e)

- ✅ CI 18/18 (mergeStateStatus CLEAN)
- ✅ baseline release-gate-smoke: 10/10 (`v1.models`, chat non-stream/stream/tool_call, responses non-stream/stream, unknown-msg-key drop, transient codes, dashboard 72-byte, alembic index)
- ✅ per-PR e2e extra: 14/14 (#658 strict tool × chat valid/invalid/type-omitted + responses invalid, #650-652 trim replay markers, #516 prev-resp miss mask, #558 prolite plan, #600 token_expired, #635 device poll, #647 frontend 72B, #594 account selection, #640 alembic head, #653/#654 conv archive, #655/#656 weekly pace)
- ✅ pytest 562 passed / 3 PG-only skip (unit + integration suite)
- ✅ SDK e2e 20/20 (`tests/e2e/test_openai_sdk_compat.py` + `tests/e2e/test_v1_responses_openai_sdk.py`)
- ✅ `scripts/verify_v1_responses_openai_sdk.py` 5/5 against live container with real account
- ✅ ruff check + ruff format --check + uv run ty check — All clean
- ✅ prod parity probe: #637 (unknown-key drop) + #658 (strict tool 400) both confirmed fixed vs prod 1.17.0

## Behavior change to note in announcements

- **#658**: `strict: true` function tool schemas missing `additionalProperties: false` (or other strict-mode requirements) now return a local **400 `invalid_function_parameters`** with `param=tools[N].function.parameters` (chat) / `tools[N].parameters` (responses). Pre-1.18.0 these were silently forwarded upstream; 1.18.0 enforces OpenAI's documented strict-mode contract locally before forwarding.

OpenSpec changes shipped in this release (to be archived after tag publish):
- deactivate-on-token-expired (#600)
- drop-unknown-message-fields (#637)
- mask-single-http-previous-response-miss (#516)
- normalize-v1-responses-openai-sdk-stream (#639)
- start-device-oauth-polling (#635)
- support-prolite-plan-capacity (#558)
- treat-upstream-overloaded-as-retryable (#601)
- validate-password-length (#598)
- validate-strict-function-tool-schema (#658)
Soju06 added a commit that referenced this pull request May 17, 2026
Archive changes shipped in v1.18.0 and v1.18.1 per AGENTS.md
"release 이후 archive" workflow. All 12 changes verified shipped in
production at 10.0.0.113 (image 1.18.1, sha256:0431a474432d).

1.18.0 (9 changes):
- deactivate-on-token-expired (#600)
- drop-unknown-message-fields (#637)
- mask-single-http-previous-response-miss (#516)
- normalize-v1-responses-openai-sdk-stream (#639)
- start-device-oauth-polling (#635) [delta header fixed: MODIFIED -> ADDED]
- support-prolite-plan-capacity (#558) [delta header fixed: MODIFIED -> ADDED]
- treat-upstream-overloaded-as-retryable (#601)
- validate-password-length (#598)
- validate-strict-function-tool-schema (#658)

1.18.1 (3 changes):
- harden-long-codex-websocket-turns (#586)
- suppress-duplicate-side-effect-tool-calls (#586)
- hotfix-db-pool-pre-ping-and-firewall-cache-ttl (#679)

Specs updated: 9 capabilities (admin-auth, api-firewall, chat-completions-compat,
chat-completions-extensions, database-backends, frontend-architecture,
responses-api-compat, usage-refresh-policy).

openspec validate --specs: 19/19 passed.

Co-authored-by: Hermes Agent <[email protected]>
vitalNohj pushed a commit to vitalNohj/codex-lb that referenced this pull request Jul 17, 2026
* fix(proxy): support Pro Lite account routing

* fix(proxy): preserve explicit unknown plan matching

* test(proxy): refine plan matching coverage

* fix(usage): calibrate Pro Lite capacity
vitalNohj pushed a commit to vitalNohj/codex-lb that referenced this pull request Jul 17, 2026
Release 1.18.0 — v1.17.0 → main, 27 PR.

## Pre-merge verification (release-gate e2e)

- ✅ CI 18/18 (mergeStateStatus CLEAN)
- ✅ baseline release-gate-smoke: 10/10 (`v1.models`, chat non-stream/stream/tool_call, responses non-stream/stream, unknown-msg-key drop, transient codes, dashboard 72-byte, alembic index)
- ✅ per-PR e2e extra: 14/14 (Soju06#658 strict tool × chat valid/invalid/type-omitted + responses invalid, Soju06#650-652 trim replay markers, Soju06#516 prev-resp miss mask, Soju06#558 prolite plan, Soju06#600 token_expired, Soju06#635 device poll, Soju06#647 frontend 72B, Soju06#594 account selection, Soju06#640 alembic head, Soju06#653/Soju06#654 conv archive, Soju06#655/Soju06#656 weekly pace)
- ✅ pytest 562 passed / 3 PG-only skip (unit + integration suite)
- ✅ SDK e2e 20/20 (`tests/e2e/test_openai_sdk_compat.py` + `tests/e2e/test_v1_responses_openai_sdk.py`)
- ✅ `scripts/verify_v1_responses_openai_sdk.py` 5/5 against live container with real account
- ✅ ruff check + ruff format --check + uv run ty check — All clean
- ✅ prod parity probe: Soju06#637 (unknown-key drop) + Soju06#658 (strict tool 400) both confirmed fixed vs prod 1.17.0

## Behavior change to note in announcements

- **Soju06#658**: `strict: true` function tool schemas missing `additionalProperties: false` (or other strict-mode requirements) now return a local **400 `invalid_function_parameters`** with `param=tools[N].function.parameters` (chat) / `tools[N].parameters` (responses). Pre-1.18.0 these were silently forwarded upstream; 1.18.0 enforces OpenAI's documented strict-mode contract locally before forwarding.

OpenSpec changes shipped in this release (to be archived after tag publish):
- deactivate-on-token-expired (Soju06#600)
- drop-unknown-message-fields (Soju06#637)
- mask-single-http-previous-response-miss (Soju06#516)
- normalize-v1-responses-openai-sdk-stream (Soju06#639)
- start-device-oauth-polling (Soju06#635)
- support-prolite-plan-capacity (Soju06#558)
- treat-upstream-overloaded-as-retryable (Soju06#601)
- validate-password-length (Soju06#598)
- validate-strict-function-tool-schema (Soju06#658)
vitalNohj pushed a commit to vitalNohj/codex-lb that referenced this pull request Jul 17, 2026
…u06#682)

Archive changes shipped in v1.18.0 and v1.18.1 per AGENTS.md
"release 이후 archive" workflow. All 12 changes verified shipped in
production at 10.0.0.113 (image 1.18.1, sha256:0431a474432d).

1.18.0 (9 changes):
- deactivate-on-token-expired (Soju06#600)
- drop-unknown-message-fields (Soju06#637)
- mask-single-http-previous-response-miss (Soju06#516)
- normalize-v1-responses-openai-sdk-stream (Soju06#639)
- start-device-oauth-polling (Soju06#635) [delta header fixed: MODIFIED -> ADDED]
- support-prolite-plan-capacity (Soju06#558) [delta header fixed: MODIFIED -> ADDED]
- treat-upstream-overloaded-as-retryable (Soju06#601)
- validate-password-length (Soju06#598)
- validate-strict-function-tool-schema (Soju06#658)

1.18.1 (3 changes):
- harden-long-codex-websocket-turns (Soju06#586)
- suppress-duplicate-side-effect-tool-calls (Soju06#586)
- hotfix-db-pool-pre-ping-and-firewall-cache-ttl (Soju06#679)

Specs updated: 9 capabilities (admin-auth, api-firewall, chat-completions-compat,
chat-completions-extensions, database-backends, frontend-architecture,
responses-api-compat, usage-refresh-policy).

openspec validate --specs: 19/19 passed.

Co-authored-by: Hermes Agent <[email protected]>
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.

Prolite accounts show zero aggregate remaining credits

2 participants