Skip to content

fix(catalog): apply providerContextCaps.openai to native OpenAI rows - #1435

Merged
Wibias merged 2 commits into
lidge-jun:devfrom
Yuxin-Qiao:fix/native-context-cap-openai
Aug 11, 2026
Merged

fix(catalog): apply providerContextCaps.openai to native OpenAI rows#1435
Wibias merged 2 commits into
lidge-jun:devfrom
Yuxin-Qiao:fix/native-context-cap-openai

Conversation

@Yuxin-Qiao

@Yuxin-Qiao Yuxin-Qiao commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • providerContextCaps.openai is now a ceiling for native OpenAI catalog rows, the live Codex discovery endpoint, management model rows, and routing capability evidence.
  • Hardcoded native context overrides are decoupled from cap application: overrides are applied first when present, then known context_window / max_context_window values are capped regardless of origin. Auto-compaction is recomputed from the capped window.
  • Preserved native rows without a hardcoded override, including gpt-5.4-mini, now receive the same OpenAI cap. With no cap configured, the existing 372k native default is unchanged.

Closes #1430

Verification

  • bun run typecheck passes.
  • bun run privacy:scan passes; git diff --check is clean.
  • Focused suites pass: 235 tests, 0 fail across tests/codex-catalog.test.ts, tests/claude-models-discovery.test.ts, tests/native-model-toggle.test.ts, tests/route-explainability.test.ts, tests/grok-sync.test.ts, tests/claude-context-windows.test.ts, and tests/claude-desktop-native-context.test.ts.
  • The endpoint regression exercises GET /v1/models?client_version=1.0.0 and asserts native GPT-5.6 output of 272000 / 272000 / 244800; catalog, preserved-row, runtime, and routing regressions remain covered.
  • Rebased onto the current dev head e2f7f2ba; the pushed PR head is e266f799.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed (existing providerContextCaps documentation covers this behavior).
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • All CI tests are green on my local testing.

  • I pushed my PR to the latest dev commit.

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

@github-actions

Copy link
Copy Markdown
Contributor

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Aug 10, 2026
@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

⏳ DRAFT

  • review readiness checklist open (3/4 boxes ticked).

What to do

  • Tick all four boxes in the PR description once you're done (currently 3/4).
  • CodeRabbit has 1 unresolved finding; the Codex/CodeRabbit findings box has been unticked.
  • Resolve every open review conversation on this pull request, then re-tick the box.
  • The checklist has been reset: re-test against the latest code and tick the boxes again.

Review readiness checklist

  • ✅ All CI tests are green on my local testing.
  • ✅ I pushed my PR to the latest dev commit.
  • ⬜ I resolved all correct Codex and CodeRabbit findings.
  • ✅ My PR is ready for review.

3/4 boxes ticked.

CodeRabbit has 1 unresolved finding; the Codex/CodeRabbit findings box has been unticked.
Resolve every open review conversation on this pull request, then re-tick the box.
The checklist has been reset: re-test against the latest code and tick the boxes again.
Automatic draft conversion failed. Please convert this pull request to a draft manually until every box above is ticked.

@github-actions
github-actions Bot marked this pull request as draft August 10, 2026 19:02
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Native OpenAI provider context caps now constrain native model metadata, catalog construction and synchronization, and routing capability evidence. GPT-5.6 uses shared API context metadata, with regression coverage for capped and uncapped behavior.

Changes

Native OpenAI context-cap handling

Layer / File(s) Summary
Context-cap resolution and native metadata
src/codex/catalog/metadata.ts, src/codex/catalog/parsing.ts, src/codex/catalog/provider-fetch.ts
Native context windows and overrides apply providerContextCaps.openai as a ceiling. Auto-compaction limits use the capped context window.
Catalog construction and synchronization
src/codex/catalog/sync.ts, src/server/index.ts
Catalog builders, observed-state merges, retained sync, native-entry derivation, backfills, and final normalization propagate the OpenAI context cap.
Routing capability evidence
src/routing/capability.ts
Native OpenAI detection uses OPENAI_CODEX_PROVIDER_ID. Capability evidence applies the configured OpenAI context cap and preserves the default when no cap exists.
Context-cap regression coverage
tests/codex-catalog.test.ts, tests/native-model-toggle.test.ts, tests/route-explainability.test.ts, tests/claude-models-discovery.test.ts
Tests cover catalog construction, synchronization, native model rows, discovery, direct context resolution, and capped or uncapped routing evidence.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related issues

  • lidge-jun/opencodex#1430 — Applies providerContextCaps.openai to native GPT-5.6 catalog context windows and related limits.

Possibly related PRs

Suggested labels: review-ready

Suggested reviewers: lidge-jun, ingwannu

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes applying the OpenAI provider context cap to native catalog rows, which is the primary change.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mkarolczyk

Copy link
Copy Markdown

I found one remaining Codex-facing path that still bypasses the OpenAI provider cap.

In src/server/index.ts:914, GET /v1/models?client_version=… calls buildCatalogEntries() without passing providerContextCap(config, OPENAI_CODEX_PROVIDER_ID).

I reproduced this on the PR head with providerContextCaps.openai = 272000: the endpoint still returns 372000 / 372000 / 334800 for gpt-5.6-sol, instead of 272000 / 272000 / 244800.

Please pass the cap through this call and add an integration test in tests/claude-models-discovery.test.ts. The current focused tests do not exercise the live Codex discovery endpoint with a provider cap.

@Wibias Wibias left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Request changes based on a full review of the current head.

Merge blocker:

The PR claims providerContextCaps.openai is now a ceiling for native OpenAI rows, but the persisted-catalog normalizer still returns early unless the native slug has an entry in NATIVE_OPENAI_CONTEXT_OVERRIDES:

const override = NATIVE_OPENAI_CONTEXT_OVERRIDES[nativeSlug]; if (!override) return;

That means supported native rows without a hardcoded override can still bypass the cap. gpt-5.4-mini is in NATIVE_OPENAI_MODELS but has no NATIVE_OPENAI_CONTEXT_OVERRIDES entry, so a genuine/preserved native gpt-5.4-mini row can remain uncapped even though runtime/synthetic metadata paths use nativeOpenAiContextWindow(..., cap) and are capped. This leaves cross-surface catalog/routing disagreement.

Please decouple hardcoded native overrides from provider-cap application: first apply an override if one exists, then apply the OpenAI provider cap to the resulting known context_window / max_context_window values regardless of where those values came from, and recompute auto-compaction from the capped context where applicable.

Add a regression for a preserved genuine gpt-5.4-mini native row with an OpenAI cap lower than its existing context window, verifying context/max-context/auto-compact all reflect the cap.

The GPT-5.6 paths added by this PR otherwise look correct and I did not find a security issue. This PR also overlaps newer dev work in central catalog files, so after the fix it should be refreshed onto current dev and rerun with exact-head CI.

@Yuxin-Qiao
Yuxin-Qiao force-pushed the fix/native-context-cap-openai branch from 2e6099b to 16e6342 Compare August 11, 2026 03:49
@Yuxin-Qiao

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review. Both points are addressed on the refreshed head 16e6342b, rebased onto current dev (da8ebd31).

1. Hardcoded overrides and the provider cap are decoupled

applyNativeOpenAiContextOverride in src/codex/catalog/parsing.ts no longer returns early when NATIVE_OPENAI_CONTEXT_OVERRIDES[nativeSlug] is absent. The flow is now:

  • If an override exists, its contextWindow / maxContextWindow are applied first, each passed through applyProviderContextCap.
  • Afterwards the cap is applied to the resulting context_window / max_context_window regardless of where those values came from (hardcoded override, preserved disk row, or pinned upstream snapshot).
  • auto_compact_token_limit is recomputed as floor(context_window * 0.9) from the capped window. The equality guard means preserved rows are only rewritten when the cap actually lowers the advertised window, so behavior is unchanged when no cap is configured or the cap does not bind (a preserved gpt-5.4-mini row at 272k with no cap stays exactly as it was).

2. Regression for preserved gpt-5.4-mini

Added in tests/codex-catalog.test.ts: "preserved gpt-5.4-mini rows get the openai cap without a hardcoded override (#1430)". A preserved genuine gpt-5.4-mini row (272_000 context/max) goes through mergeCatalogEntriesForSync with openaiContextCap = 200_000 and must come out with context_window = 200_000, max_context_window = 200_000, auto_compact_token_limit = 180_000.

3. Refresh onto current dev and verification

  • Rebased onto da8ebd31 (current dev), single squashed commit, no conflicts.
  • bun run typecheck: clean.
  • Focused suites (codex-catalog, native-model-toggle, route-explainability, grok-sync, claude-context-windows, claude-desktop-native-context): 226 pass / 0 fail, including the new regression.
  • Full suite: the failing set was compared against a clean dev baseline on the same files; they are identical except one crash-guard breadcrumb test that passes on rerun (load flake during the full run). No failures come from this PR.
  • bun run privacy:scan and git diff --check: clean.
  • Gate checks on the exact head (enforce-target, label, hygiene, resolve-pr) are green. Cross-platform CI and React Doctor still need maintainer approval to run on this fork PR (they were action_required on the previous head for the same reason).

No security issue was introduced; the GPT-5.6 paths are untouched by this revision.

@github-actions
github-actions Bot marked this pull request as ready for review August 11, 2026 03:53
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot]: The PR is marked ready for review. I will review pull request #1435 at head 16e6342b86904319545cf3f9205ee086331c09bd.

⚠️ Action not completed

Already reviewed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] Pull request #1435 is marked ready at 16e6342b86904319545cf3f9205ee086331c09bd. I will review the current head.

⚠️ Action not completed

Already reviewed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/codex/catalog/sync.ts (1)

363-377: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Pass the OpenAI context cap to Codex discovery.

At src/server/index.ts:914, pass providerContextCap(config, OPENAI_CODEX_PROVIDER_ID) as the final argument to buildCatalogEntries. Otherwise, /v1/models?client_version=... returns uncapped native context_window and max_context_window values. Add a regression test in tests/claude-models-discovery.test.ts for the capped response.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/codex/catalog/sync.ts` around lines 363 - 377, Update the Codex discovery
call in src/server/index.ts around buildCatalogEntries to pass
providerContextCap(config, OPENAI_CODEX_PROVIDER_ID) as its final argument.
Ensure the capped value is reflected in native context_window and
max_context_window responses, and add a regression test in
claude-models-discovery.test.ts covering the capped response.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/codex/catalog/sync.ts`:
- Around line 363-377: Update the Codex discovery call in src/server/index.ts
around buildCatalogEntries to pass providerContextCap(config,
OPENAI_CODEX_PROVIDER_ID) as its final argument. Ensure the capped value is
reflected in native context_window and max_context_window responses, and add a
regression test in claude-models-discovery.test.ts covering the capped response.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: e7523212-be04-47c7-a733-8833c94c7b92

📥 Commits

Reviewing files that changed from the base of the PR and between 2e6099b and 16e6342.

📒 Files selected for processing (4)
  • src/codex/catalog/parsing.ts
  • src/codex/catalog/sync.ts
  • src/providers/registry.ts
  • tests/codex-catalog.test.ts

@Ingwannu Ingwannu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The refreshed head fixes the earlier preserved-row blocker, but one merge blocker remains on exact head 16e6342b.

src/server/index.ts:914 serves the live Codex discovery route (GET /v1/models?client_version=...) by calling buildCatalogEntries(...) without the new OpenAI context-cap argument. With providerContextCaps.openai = 272000, that route can therefore still emit native GPT-5.6 rows at 372000 / 372000 / 334800, while the synchronized catalog and routing evidence are capped. This leaves the user-visible runtime surface inconsistent with the paths this PR fixed.

Please pass providerContextCap(config, OPENAI_CODEX_PROVIDER_ID) through this call and add an endpoint-level regression in tests/claude-models-discovery.test.ts (or the nearest existing server discovery suite) that asserts the live response is 272000 / 272000 / 244800 for a native GPT-5.6 row.

The branch is also five commits behind current dev (7779c057), so refresh it and run exact-head cross-platform CI after the endpoint fix. The rest of the revised cap propagation, including the preserved gpt-5.4-mini case, looks sound.

@Wibias
Wibias marked this pull request as draft August 11, 2026 05:48
@Yuxin-Qiao
Yuxin-Qiao force-pushed the fix/native-context-cap-openai branch from 16e6342 to 1a31c7b Compare August 11, 2026 06:22
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '== Changed files at PR head =='
git diff --name-status HEAD^ HEAD

printf '%s\n' '== src/server/index.ts outline =='
ast-grep outline src/server/index.ts --items all --match 'models|Catalog|providerContextCap|OPENAI_CODEX_PROVIDER_ID' || true

printf '%s\n' '== buildCatalogEntries call sites and cap-related imports =='
rg -n -C 5 '\bbuildCatalogEntries\s*\(|\bproviderContextCap\s*\(|\bOPENAI_CODEX_PROVIDER_ID\b' src/server/index.ts src tests

printf '%s\n' '== Discovery test outline and provider-cap references =='
ast-grep outline tests/claude-models-discovery.test.ts --items all || true
rg -n -C 6 'providerContextCaps|context_window|max_context_window|auto_compact_token_limit|/v1/models|client_version|gpt-5\.6' tests/claude-models-discovery.test.ts

printf '%s\n' '== Relevant PR diff =='
git diff HEAD^ HEAD -- src/server/index.ts tests/claude-models-discovery.test.ts

Length of output: 169447


@github-actions[bot] Verified. The earlier Codex discovery finding is addressed.

  • src/server/index.ts passes providerContextCap(config, OPENAI_CODEX_PROVIDER_ID) to buildCatalogEntries() at Line 926.
  • tests/claude-models-discovery.test.ts adds an endpoint regression test.
  • The test configures providerContextCaps.openai = 272_000 and verifies that GET /v1/models?client_version=1.0.0 returns 272_000 / 272_000 / 244_800 for gpt-5.6-sol.

This covers the previously uncapped discovery path.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

You are interacting with an AI system.

Native OpenAI catalog rows ignored providerContextCaps.openai: the fixed
native context overrides in metadata.ts stayed at 372k while routed models
were capped. Thread the openai provider cap through the catalog entry
builders (finishUpstreamNativeEntry, deriveEntry, buildCatalogEntries,
mergeCatalogEntriesForSync), the runtime native metadata accessors
(nativeOpenAiContextWindow, nativeModelRows), and routing capability
evidence so the catalog, management rows, and proxy routing agree.
Preserved native rows without a hardcoded override (e.g. gpt-5.4-mini) are
capped the same way, and auto-compaction follows the capped window.

The 372k native value remains the default when no cap is configured.

Closes lidge-jun#1430
@Wibias
Wibias marked this pull request as ready for review August 11, 2026 06:55
@github-actions
github-actions Bot marked this pull request as draft August 11, 2026 06:56
@Yuxin-Qiao
Yuxin-Qiao force-pushed the fix/native-context-cap-openai branch from 1a31c7b to e266f79 Compare August 11, 2026 06:58
@Wibias
Wibias marked this pull request as ready for review August 11, 2026 06:59
@github-actions
github-actions Bot marked this pull request as draft August 11, 2026 06:59
@github-actions
github-actions Bot marked this pull request as ready for review August 11, 2026 07:02
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

@github-actions The PR is ready for review. I will review the current head of #1435.

⚠️ Action not completed

Already reviewed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] The PR readiness gate passed. I will review the current pull request head.

⚠️ Action not completed

Already reviewed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/providers/registry.ts (1)

322-323: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Correct the Daybreak endpoint-support note.

At src/providers/registry.ts:322-323, state that OpenAI lists both v1/chat/completions and v1/responses for daybreak-red-latest and daybreak-blue-latest. If OpenCodex intentionally routes these aliases through openai-responses, describe that local routing policy instead of claiming that Chat Completions is unsupported.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/providers/registry.ts` around lines 322 - 323, Update the Daybreak
endpoint-support note in the provider registry to state that OpenAI lists both
v1/chat/completions and v1/responses for daybreak-red-latest and
daybreak-blue-latest; if the aliases are locally routed through
openai-responses, document that routing policy rather than claiming Chat
Completions is unsupported.

Sources: Path instructions, MCP tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/providers/registry.ts`:
- Around line 322-323: Update the Daybreak endpoint-support note in the provider
registry to state that OpenAI lists both v1/chat/completions and v1/responses
for daybreak-red-latest and daybreak-blue-latest; if the aliases are locally
routed through openai-responses, document that routing policy rather than
claiming Chat Completions is unsupported.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f567e087-7e1e-437b-ad8c-ce3ac5612371

📥 Commits

Reviewing files that changed from the base of the PR and between 1a31c7b and e266f79.

📒 Files selected for processing (2)
  • src/providers/registry.ts
  • tests/codex-catalog.test.ts

@Wibias
Wibias dismissed Ingwannu’s stale review August 11, 2026 07:30

Addressed on later commits: live Codex discovery (GET /v1/models?client_version=...) now threads providerContextCaps.openai through buildCatalogEntries, with regression coverage for capped discovery rows.

@Wibias Wibias left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving. Cap application is decoupled from hardcoded native overrides, preserved rows without overrides are capped, live discovery matches catalog/routing metadata, and the no-cap 372k default is unchanged.

@Wibias

Wibias commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Thanks @Yuxin-Qiao — this was useful because providerContextCaps.openai was only lowering routed/discovered models while native OpenAI catalog rows (and live Codex discovery) kept the hardcoded 372k windows, so GPT-5.6 Sol/Terra/Luna could disagree across catalog, management rows, and routing. Threading one ceiling through builders, runtime accessors, capability evidence, and discovery keeps those surfaces consistent without changing the uncapped default.

Merging now.

@Wibias
Wibias merged commit cf44362 into lidge-jun:dev Aug 11, 2026
53 of 58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants