Skip to content

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

Draft
Yuxin-Qiao wants to merge 2 commits into
lidge-jun:devfrom
Yuxin-Qiao:fix/native-context-cap-openai
Draft

fix(catalog): apply providerContextCaps.openai to native OpenAI rows#1435
Yuxin-Qiao wants to merge 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, not just routed/provider-discovered models. The live Codex discovery endpoint (/v1/models?client_version=...) now receives the same cap, keeping endpoint responses consistent with synchronized catalog and routing metadata. Previously the fixed native overrides kept GPT-5.6 Sol/Terra/Luna at 372k even when the OpenAI provider cap was set to 272k (providerContextCaps.openai is ignored for native GPT-5.6 catalog rows #1430).
  • Threaded the cap through the catalog sync builders (finishUpstreamNativeEntry, deriveEntry, buildCatalogEntries, mergeCatalogEntriesForSync), the runtime native metadata accessors (nativeOpenAiContextWindow, nativeModelRows), and routing capability evidence (candidateCapabilityEvidence), so the on-disk catalog, management model rows, and proxy routing agree.
  • Review remediation: hardcoded NATIVE_OPENAI_CONTEXT_OVERRIDES entries are now decoupled from cap application. applyNativeOpenAiContextOverride applies an override first if one exists, then caps the resulting context_window / max_context_window regardless of origin, so preserved native rows without an override (e.g. gpt-5.4-mini) cannot bypass the cap; auto-compaction is recomputed from the capped window.
  • The 372k native value remains the default when no cap is configured; the cap only lowers known windows, matching the documented behavior of providerContextCaps.
  • Removed the unused OPENAI_CODEX_GPT56_CONTEXT_WINDOW / OPENAI_GPT56_CONTEXT_WINDOWS registry constants flagged in the issue suspected-cause section; they were dead code.

Closes #1430

Verification

  • bun run typecheck passes.
  • Focused suites pass: tests/codex-catalog.test.ts, tests/native-model-toggle.test.ts, tests/route-explainability.test.ts, tests/claude-models-discovery.test.ts, plus grok/claude context-window suites (230 tests, 0 fail), including the live discovery regression for 272000 / 272000 / 244800.
  • New regression tests: capped catalog rows for gpt-5.6-sol/terra/luna (272000/272000/244800), merge re-apply on preserved/upgraded rows, preserved gpt-5.4-mini row without a hardcoded override capped at 200000/200000/180000, nativeModelRows and candidateCapabilityEvidence ceiling behavior, and no-cap default unchanged at 372k.
  • bun run privacy:scan passes; git diff --check clean.
  • Rebased onto the current dev head 0c170525c; the exact head 1a31c7b0 is green on the repository gates (enforce-target, label, hygiene, resolve-pr). Cross-platform CI and React Doctor require maintainer approval to run on this fork PR.
  • Full suite: the failing set was compared against a clean dev baseline on the same files and is identical except one crash-guard breadcrumb test that passes on rerun (load flake during the full run). Pre-existing dev failures (management-provider-validation, crash-guard timeout, retained-root serialization seam) reproduce on the clean baseline and are unrelated.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed (the existing providerContextCaps documentation already 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.

Summary by CodeRabbit

  • New Features

    • Added support for applying configured OpenAI context limits to native model context windows.
    • Context limits now apply consistently during model discovery, synchronization, routing, and capability reporting.
    • Native model context windows and auto-compaction limits are capped without increasing existing limits.
  • Bug Fixes

    • Corrected GPT-5.6 context metadata to use the shared API context window.
    • Preserved configured limits for existing and restored native model entries.

@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 (0/4 boxes ticked).

What to do

  • Tick all four boxes in the PR description once you're done (currently 0/4).

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.

0/4 boxes ticked.

This PR stays in draft 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/providers/registry.ts, 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. GPT-5.6 no longer uses a separate 372,000-token registry mapping.
Catalog construction and synchronization
src/codex/catalog/sync.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 cover catalog construction, sync preservation and backfill, native model rows, direct context resolution, capped routing evidence, and the uncapped default.

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

Possibly related issues

Possibly related PRs

Suggested reviewers: ingwannu, lidge-jun

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: applying providerContextCaps.openai to native OpenAI catalog rows.
✨ 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.

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

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