Skip to content

feat(usage): surface Codex code-review weekly window + additional_rate_limits fallback - #4494

Merged
diegosouzapw merged 1 commit into
release/v3.8.33from
feat/port-pr-836-codex-review-quota
Jun 21, 2026
Merged

diegosouzapw merged 1 commit into
release/v3.8.33from
feat/port-pr-836-codex-review-quota

Conversation

@diegosouzapw

@diegosouzapw diegosouzapw commented Jun 21, 2026 •

Copy link
Copy Markdown
Owner

Summary

Ports the review-quota plumbing half of an upstream fix (author @hiepau1231) into OmniRoute. The Codex usage dashboard only emitted the primary code_review_rate_limit window as quotas.code_review and dropped review descriptors that arrive via the additional_rate_limits array (the shape some ChatGPT Codex plans report).

buildCodexUsageQuotas now:

  • Emits the secondary window as quotas.code_review_weekly (mirrors the existing session/weekly pair for the normal rate limit).
  • Falls back to the matching additional_rate_limits[] entry when the dedicated code_review_rate_limit block is empty — matched on limit_name, metered_feature, limit_id, id, or name containing code_review, codex_review, or review.

The dedicated block stays preferred when both are present. The existing quotas.code_review key is preserved (back-compat for the dashboard rendering and the usage-service-hardening regression). The new code_review_weekly → "Code Review Weekly" label is registered in ProviderLimits/utils.tsx.

What we did NOT port

  • Virtual <model>-review chat-model variants — OmniRoute already exposes codex-auto-review as a dedicated native review model (CODEX_NATIVE_UNPREFIXED_MODELS), so per-model -review aliases would duplicate that surface.
  • idToken removal — OmniRoute actively parses the id_token JWT to extract the workspace id used for chatgpt-account-id binding on the usage endpoint (src/lib/oauth/providers/codex.ts::parseIdToken); removing it would break workspace selection.
  • max_completion_tokens / max_output_tokens stripping — the Codex executor already enforces an allowlist (RESPONSES_API_ALLOWLIST) that rejects unknown chat-completions fields before they reach upstream.

Test plan

  • TDD-RED → GREEN: node --import tsx/esm --test tests/unit/codex-usage-quotas-review-window.test.ts (4 new assertions: secondary-window surfacing, additional_rate_limits fallback, silent-payload back-compat, dedicated-block preference)
  • Label parity assertion appended to tests/unit/provider-limits-ui.test.ts
  • Full codex-usage regression: node --import tsx/esm --test tests/unit/codex-usage-quotas-review-window.test.ts tests/unit/provider-limits-ui.test.ts tests/unit/usage-service-hardening.test.ts tests/unit/codex-quota-fetcher.test.ts tests/unit/codex-quota-sync-no-proactive-refresh.test.ts — all 55 green
  • npm run typecheck:core — clean
  • npx eslint on touched files — clean

Inspired-by: upstream contribution by

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for extracting and displaying the secondary (weekly) window of Codex code-review rate limits, and adds a fallback mechanism to detect these limits within additional_rate_limits when the dedicated code_review_rate_limit block is missing. It also updates the UI label mapping and adds comprehensive unit tests. The reviewer suggested simplifying the descriptor matching logic to handle hyphenated variants and eliminate redundant checks, as well as checking the title field of entries for better coverage.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +116 to +130
function isCodexReviewLimitDescriptor(...values: unknown[]): boolean {
return values.some((value) => {
if (typeof value !== "string") return false;
const normalized = value.trim().toLowerCase();
if (!normalized) return false;
return (
normalized === "code_review" ||
normalized === "codex_review" ||
normalized === "review" ||
normalized.includes("code_review") ||
normalized.includes("codex_review") ||
normalized.includes("code review")
);
});
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The current implementation of isCodexReviewLimitDescriptor contains redundant checks (e.g., normalized === "code_review" is fully covered by normalized.includes("code_review")). Additionally, it does not support hyphenated variants like code-review or codex-review which are common in API payloads.

We can simplify and make this check more robust by replacing underscores and hyphens with spaces, then performing a clean match. This handles all common formats (code_review, code-review, code review, etc.) while safely avoiding false positives like preview.

function isCodexReviewLimitDescriptor(...values: unknown[]): boolean {
  return values.some((value) => {
    if (typeof value !== "string") return false;
    const normalized = value.trim().toLowerCase();
    if (!normalized) return false;
    const clean = normalized.replace(/[-_]/g, " ");
    return (
      clean === "review" ||
      clean.includes("code review") ||
      clean.includes("codex review")
    );
  });
}

Comment on lines +142 to +150
if (
isCodexReviewLimitDescriptor(
getFieldValue(entry, "limit_name", "limitName"),
getFieldValue(entry, "metered_feature", "meteredFeature"),
getFieldValue(entry, "limit_id", "limitId"),
entry["id"],
entry["name"]
)
) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

To align with findCodexSparkRateLimit and ensure defensive coverage, we should also check entry["title"] when identifying the review rate limit descriptor. Some plans or upstream variants might report the user-friendly name in the title field.

Suggested change
if (
isCodexReviewLimitDescriptor(
getFieldValue(entry, "limit_name", "limitName"),
getFieldValue(entry, "metered_feature", "meteredFeature"),
getFieldValue(entry, "limit_id", "limitId"),
entry["id"],
entry["name"]
)
) {
if (
isCodexReviewLimitDescriptor(
getFieldValue(entry, "limit_name", "limitName"),
getFieldValue(entry, "metered_feature", "meteredFeature"),
getFieldValue(entry, "limit_id", "limitId"),
entry["id"],
entry["name"],
entry["title"]
)
) {

@diegosouzapw
diegosouzapw changed the base branch from release/v3.8.32 to release/v3.8.33 June 21, 2026 14:02
…e_limits fallback

The Codex usage dashboard only emitted the primary `code_review_rate_limit`
window as `quotas.code_review` and dropped review descriptors that arrive via
the `additional_rate_limits` array (the shape some ChatGPT Codex plans report).

`buildCodexUsageQuotas` now:

- Emits the secondary window as `quotas.code_review_weekly` (mirrors the
  existing `session`/`weekly` pair for the normal rate limit).
- Falls back to the matching `additional_rate_limits[]` entry when the dedicated
  `code_review_rate_limit` block is empty — matched on `limit_name`,
  `metered_feature`, `limit_id`, `id`, or `name` containing `code_review`,
  `codex_review`, or `review`.

The dedicated block stays preferred when both are present. The existing
`quotas.code_review` key is preserved (back-compat for the dashboard
rendering and the `usage-service-hardening` regression test).

The new `code_review_weekly → "Code Review Weekly"` label is registered in
`ProviderLimits/utils.tsx` so the card renders both windows side-by-side.

TDD: 4 new assertions in `tests/unit/codex-usage-quotas-review-window.test.ts`
(secondary-window surfacing, `additional_rate_limits` fallback, silent-payload
back-compat, dedicated-block preference) + 1 label assertion appended to
`tests/unit/provider-limits-ui.test.ts`. All 46 codex-usage-related tests pass.

What we did NOT port from upstream:
- The virtual `<model>-review` chat-model variants — OmniRoute already exposes
  `codex-auto-review` as a dedicated native review model
  (`CODEX_NATIVE_UNPREFIXED_MODELS`), so per-model `-review` aliases would
  duplicate that surface.
- The `idToken` removal — OmniRoute actively parses the `id_token` JWT to
  extract the workspace id used for `chatgpt-account-id` binding on the
  usage endpoint (`src/lib/oauth/providers/codex.ts::parseIdToken`); removing
  it would break workspace selection.
- The `max_completion_tokens` / `max_output_tokens` stripping — the Codex
  executor already enforces an allowlist (`RESPONSES_API_ALLOWLIST`) that
  rejects unknown chat-completions fields before they reach upstream.

Inspired-by: decolua/9router#836 (review-quota plumbing pattern)

Co-authored-by: Rezky Hamid <hiepau1231@gmail.com>
@diegosouzapw
diegosouzapw force-pushed the feat/port-pr-836-codex-review-quota branch from b7dfaa0 to 61cbd9b Compare June 21, 2026 17:06
@diegosouzapw
diegosouzapw merged commit a37ee2f into release/v3.8.33 Jun 21, 2026
3 checks passed
diegosouzapw added a commit that referenced this pull request Jun 21, 2026
…4512)

Rebuilt onto release/v3.8.33; usage.ts baseline reconciled for the #4493/#4494/#4512 quota trio. Integrated into release/v3.8.33.
@diegosouzapw diegosouzapw mentioned this pull request Jun 22, 2026
@diegosouzapw
diegosouzapw deleted the feat/port-pr-836-codex-review-quota branch June 22, 2026 02:48
tkgo11 pushed a commit to tkgo11/OmniRoute that referenced this pull request Sep 23, 2026
…e_limits fallback (diegosouzapw#4494)

Rebuilt onto release/v3.8.33 (squash-base-stale). Integrated into release/v3.8.33.
tkgo11 pushed a commit to tkgo11/OmniRoute that referenced this pull request Sep 23, 2026
…iegosouzapw#4512)

Rebuilt onto release/v3.8.33; usage.ts baseline reconciled for the diegosouzapw#4493/diegosouzapw#4494/diegosouzapw#4512 quota trio. Integrated into release/v3.8.33.
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