@@ -29,6 +29,7 @@ import type { NormalizedComboConfig } from "../../combos/types";
2929import { providerDestinationResolvedError } from "../../lib/destination-policy" ;
3030import { redactSecretString } from "../../lib/redact" ;
3131import upstreamModelsSnapshot from "../data/upstream-models.json" ;
32+ import { OPENAI_CODEX_PROVIDER_ID } from "../../providers/openai-tiers" ;
3233
3334
3435import { CODEX_CUSTOM_MODEL_CATALOG_KIND , CODEX_PROVIDER_MODEL_CATALOG_KIND , activeCodexModelsCachePath , applyCatalogMetadata , applyMultiAgentMode , applyNativeOpenAiContextOverride , catalogBackupPathFor , catalogHasRoutedEntries , catalogModelSlug , ensureStrictCatalogFields , findNativeTemplate , isDefaultCatalogPath , isRoutedModelCompatibilityExcluded , legacyCatalogBackupPath , normalizeRoutedCatalogEntry , normalizeServiceTiers , readCatalog , readCatalogBackup , readCodexCatalogPath , readNativeBaseline } from "./parsing" ;
@@ -190,9 +191,9 @@ export function effectiveSubagentRoster(
190191 return { candidates, advertised, excluded } ;
191192}
192193
193- export function finishUpstreamNativeEntry ( clone : RawEntry , priority : number ) : RawEntry {
194+ export function finishUpstreamNativeEntry ( clone : RawEntry , priority : number , contextCap ?: number ) : RawEntry {
194195 if ( priority !== 9 ) clone . priority = priority ;
195- applyNativeOpenAiContextOverride ( clone ) ;
196+ applyNativeOpenAiContextOverride ( clone , contextCap ) ;
196197 // GPT-5.6 natives keep their exact upstream ladders (e.g. luna has max but no ultra).
197198 // Older natives (gpt-5.5 / 5.4 / 5.4-mini / 5.3-codex-spark) get mock max + ultra
198199 // (wire-clamped to xhigh). Ultra is always advertised regardless of v2 toggle.
@@ -243,6 +244,7 @@ export function deriveEntry(
243244 priority : number ,
244245 model ?: CatalogModel ,
245246 exactComboSlugs : ReadonlySet < string > = new Set ( ) ,
247+ contextCap ?: number ,
246248) : RawEntry {
247249 const preserveExact = isExactComboCatalogModel ( model , exactComboSlugs ) ;
248250 const isRouted = model !== undefined ;
@@ -251,7 +253,7 @@ export function deriveEntry(
251253 // reasoning ladder — e.g. luna has no ultra — default effort, identity, model_messages)
252254 // instead of cloning an older template.
253255 const upstream = upstreamNativeEntry ( slug ) ;
254- if ( upstream ) return finishUpstreamNativeEntry ( upstream , priority ) ;
256+ if ( upstream ) return finishUpstreamNativeEntry ( upstream , priority , contextCap ) ;
255257 }
256258 if ( template ) {
257259 const e = JSON . parse ( JSON . stringify ( template ) ) as RawEntry ;
@@ -286,7 +288,7 @@ export function deriveEntry(
286288 applyCatalogModelMetadata ( e , model ) ;
287289 if ( model ?. catalogKind ) e . opencodex_catalog_kind = model . catalogKind ;
288290 } else {
289- applyNativeOpenAiContextOverride ( e ) ;
291+ applyNativeOpenAiContextOverride ( e , contextCap ) ;
290292 if ( isGpt56NativeSlug ( slug ) ) ensureGpt56ReasoningLevels ( e ) ;
291293 else ensureUltraReasoningLevel ( e ) ;
292294 // Non-5.6 natives (5.5, 5.4, 5.4-mini, spark) do not support responses-lite;
@@ -323,7 +325,7 @@ export function deriveEntry(
323325 if ( model && isRouted ) applyCatalogMetadata ( entry , model . provider , model . id , model . contextCap ) ;
324326 applyCatalogModelMetadata ( entry , model ) ;
325327 if ( model ?. catalogKind ) entry . opencodex_catalog_kind = model . catalogKind ;
326- if ( ! isRouted ) applyNativeOpenAiContextOverride ( entry ) ;
328+ if ( ! isRouted ) applyNativeOpenAiContextOverride ( entry , contextCap ) ;
327329 return ensureStrictCatalogFields ( normalizeServiceTiers ( entry ) , {
328330 preserveExactInputModalities : preserveExact ,
329331 isRouted,
@@ -342,6 +344,7 @@ export interface ObservedCatalogEntryBuildInput {
342344 readonly suppressedBareNativeSlugs : ReadonlySet < string > ;
343345 readonly disabledNativeAccountSlugs : ReadonlySet < string > ;
344346 readonly multiAgentV2Enabled : boolean ;
347+ readonly openaiContextCap ?: number ;
345348}
346349
347350/** Build entries with the process-observed Codex feature state. */
@@ -356,6 +359,7 @@ export function buildCatalogEntries(
356359 accountSelectors : readonly string [ ] = [ ] ,
357360 suppressedBareNativeSlugs : ReadonlySet < string > = new Set ( ) ,
358361 disabledNativeAccountSlugs : ReadonlySet < string > = new Set ( ) ,
362+ contextCap ?: number ,
359363) : RawEntry [ ] {
360364 return buildCatalogEntriesFromObservedState ( {
361365 template,
@@ -369,6 +373,7 @@ export function buildCatalogEntries(
369373 suppressedBareNativeSlugs,
370374 disabledNativeAccountSlugs,
371375 multiAgentV2Enabled : isMultiAgentV2Enabled ( ) ,
376+ openaiContextCap : contextCap ,
372377 } ) ;
373378}
374379
@@ -385,6 +390,7 @@ export function buildCatalogEntriesFromObservedState({
385390 suppressedBareNativeSlugs,
386391 disabledNativeAccountSlugs,
387392 multiAgentV2Enabled,
393+ openaiContextCap,
388394} : ObservedCatalogEntryBuildInput ) : RawEntry [ ] {
389395 // Codex's models-manager sorts by `priority` ASC and advertises the first 5 picker-visible
390396 // models to spawn_agent (sort_by_key(priority) + MAX_MODEL_OVERRIDES_IN_SPAWN_AGENT=5). Catalog
@@ -419,7 +425,7 @@ export function buildCatalogEntriesFromObservedState({
419425 . filter ( model => model . provider === COMBO_NAMESPACE )
420426 . map ( catalogModelSlug ) ) ;
421427 for ( const slug of gptSlugs ) {
422- const native = deriveEntry ( template , slug , "OpenAI native model (Codex OAuth passthrough)." , 9 ) ;
428+ const native = deriveEntry ( template , slug , "OpenAI native model (Codex OAuth passthrough)." , 9 , undefined , new Set ( ) , openaiContextCap ) ;
423429 if ( rank . has ( slug ) ) native . priority = rank . get ( slug ) ! ;
424430 nativeEntries . push ( native ) ;
425431 const nativeAlias = nativeAliasesBySlug . get ( slug ) ;
@@ -622,6 +628,7 @@ export interface ObservedCatalogMergeInput {
622628 readonly accountBoundEntries : readonly RawEntry [ ] ;
623629 readonly suppressedBareNativeSlugs ?: ReadonlySet < string > ;
624630 readonly policy : ObservedCatalogMergePolicy ;
631+ readonly openaiContextCap ?: number ;
625632}
626633
627634/**
@@ -651,6 +658,7 @@ export function mergeCatalogEntriesFromObservedState({
651658 accountBoundEntries,
652659 suppressedBareNativeSlugs = new Set ( ) ,
653660 policy,
661+ openaiContextCap,
654662} : ObservedCatalogMergeInput ) : RawEntry [ ] {
655663 // Raw catalog rows contain nested arrays/objects that normalization mutates. Detach every row at
656664 // the observed-core boundary so callers can safely retain evidence objects or repeat the merge.
@@ -785,7 +793,7 @@ export function mergeCatalogEntriesFromObservedState({
785793 // genuine catalog entry (real display name) is preserved untouched.
786794 if ( shouldUpgradeToUpstreamEntry ( m ) ) {
787795 const upstream = upstreamNativeEntry ( slug ) ! ;
788- const finished = finishUpstreamNativeEntry ( upstream , 9 ) ;
796+ const finished = finishUpstreamNativeEntry ( upstream , 9 , openaiContextCap ) ;
789797 finished . priority = nativePriority ( slug , upstream . priority ) ;
790798 return finished ;
791799 }
@@ -814,6 +822,9 @@ export function mergeCatalogEntriesFromObservedState({
814822 slug ,
815823 "OpenAI native model (Codex OAuth passthrough)." ,
816824 nativePriority ( slug , upstreamNativeEntry ( slug ) ?. priority ) ,
825+ undefined ,
826+ new Set ( ) ,
827+ openaiContextCap ,
817828 ) ;
818829 entry . priority = nativePriority ( slug , upstreamNativeEntry ( slug ) ?. priority ) ;
819830 native . push ( entry ) ;
@@ -926,7 +937,7 @@ export function mergeCatalogEntriesFromObservedState({
926937 const managedEntries = [ ...finalRoutedEntries , ...alignedAccountBoundEntries ] ;
927938 const mergedEntries = [ ...native , ...managedEntries ] . map ( m => {
928939 const normalized = normalizeServiceTiers ( m ) ;
929- if ( ! isNativeAliasCatalogEntry ( normalized ) ) applyNativeOpenAiContextOverride ( normalized ) ;
940+ if ( ! isNativeAliasCatalogEntry ( normalized ) ) applyNativeOpenAiContextOverride ( normalized , openaiContextCap ) ;
930941 const exactCombo = isExactComboCatalogEntry ( m , exactComboSlugs ) ;
931942 const e = ensureStrictCatalogFields ( normalized , {
932943 preserveExactInputModalities : exactCombo ,
@@ -996,6 +1007,7 @@ export function mergeCatalogEntriesForSync(
9961007 isNativeAliasCatalogEntry ( entry ) && typeof entry . slug === "string" ? [ entry . slug ] : [ ]
9971008 ) ) ,
9981009 ) ,
1010+ openaiContextCap ?: number ,
9991011) : RawEntry [ ] {
10001012 // Retained for source compatibility with the original helper contract. Raw provider ids must
10011013 // not suppress same-named native rows; actual admitted combo entries own that decision now.
@@ -1030,6 +1042,7 @@ export function mergeCatalogEntriesForSync(
10301042 includeNativeOpenAi,
10311043 accountBoundEntries,
10321044 suppressedBareNativeSlugs,
1045+ openaiContextCap,
10331046 policy : {
10341047 ...CANONICAL_NATIVE_CATALOG_CONTENT_POLICY ,
10351048 warningPolicy : "emit" ,
@@ -1247,6 +1260,7 @@ function writeRetainedCatalogSync({
12471260 const hasPhysicalComboProvider = Object . hasOwn ( config . providers , COMBO_NAMESPACE ) ;
12481261 const includeNativeOpenAi = shouldIncludeNativeOpenAi ( config ) ;
12491262 const includeAccountBoundNativeOpenAi = shouldIncludeAccountBoundNativeOpenAi ( config ) ;
1263+ const openaiContextCap = providerContextCap ( config , OPENAI_CODEX_PROVIDER_ID ) ;
12501264 const accountSelectors = includeAccountBoundNativeOpenAi
12511265 ? visibleCodexAccountSelectors ( config )
12521266 : [ ] ;
@@ -1264,6 +1278,7 @@ function writeRetainedCatalogSync({
12641278 suppressedBareNativeSlugs,
12651279 disabledNativeAccountSlugs : new Set ( ) ,
12661280 multiAgentV2Enabled,
1281+ openaiContextCap,
12671282 } ) ;
12681283 // Keep genuine native entries (gpt-*, codex-*) with their real per-model fields and append
12691284 // routed providers as namespaced slugs. Cursor and other adopted providers can expose model ids
@@ -1308,6 +1323,7 @@ function writeRetainedCatalogSync({
13081323 suppressedBareNativeSlugs,
13091324 disabledNativeAccountSlugs : new Set ( [ ...disabledNativeSlugs ( config ) ] . filter ( slug => suppressedBareNativeSlugs . has ( slug ) ) ) ,
13101325 multiAgentV2Enabled,
1326+ openaiContextCap,
13111327 } ) . filter ( entry => trustedAccountBoundNativeCatalogSlug ( entry ) !== undefined )
13121328 : [ ] ;
13131329 catalog . models = mergeCatalogEntriesFromObservedState ( {
@@ -1330,6 +1346,7 @@ function writeRetainedCatalogSync({
13301346 includeNativeOpenAi,
13311347 accountBoundEntries,
13321348 suppressedBareNativeSlugs,
1349+ openaiContextCap,
13331350 policy : {
13341351 ...CANONICAL_NATIVE_CATALOG_CONTENT_POLICY ,
13351352 warningPolicy : "emit" ,
0 commit comments