Skip to content

Commit 794d8eb

Browse files
fix(catalog): synthesize incomplete combo members with context fallback (#1305)
A combo member whose provider row is incomplete — missing a context window, or absent from the fetched catalog — was dropped from the generated Codex catalog rather than synthesized. `resolveComboCatalogMember` fills the gap from configuration, falling back to the provider's declared max input and then to 128k, so a combo stays selectable when one member's upstream row is thin. Republished from #1163 by 关俊江, whose branch was 366 commits behind dev. Two conflicts, both mechanical and both on a single line: `dev` renamed `augmentRoutedModelsWithJawcodeMetadata` to `augmentRoutedModelsWithMetadata` and added `CODEX_ACCOUNT_BOUND_CATALOG_KIND` plus a `catalog/parsing` import block, while this branch added `resolveComboCatalogMember` to the same export and import lines. Resolved by keeping every symbol from both sides; no behavior was re-decided. Co-authored-by: 关俊江 <[email protected]>
1 parent 14e9485 commit 794d8eb

6 files changed

Lines changed: 375 additions & 19 deletions

File tree

‎docs-site/src/content/docs/reference/configuration/routing.md‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,16 @@ Per-request route-decision traces are recorded when a policy profile executes.
184184
A combo remains directly routable even when it cannot be listed. `ocx sync`, `/v1/models`, and the
185185
Codex picker list it only when every target exposes capabilities that can be intersected:
186186

187-
- a positive `contextWindow`, from live metadata, registry hints, or provider
188-
`modelContextWindows` / `contextWindow`; and
187+
- a positive `contextWindow`, from live metadata, registry hints, provider
188+
`modelContextWindows` / `contextWindow`, a known positive `maxInputTokens` on the member row,
189+
or — when the provider is known and enabled but every source still omits a window — a
190+
conservative 128,000-token fallback (clamped by `providerContextCaps` when set); and
189191
- a non-empty `inputModalities` intersection, treating an omitted member value as `["text"]`.
190192

191-
A bare relay id with no context metadata or targets with disjoint modalities removes the combo from
192-
the catalog. Sync emits a summary warning and the dashboard marks it **Needs attention**. Add context
193-
metadata, align modalities, or target models with discoverable compatible capabilities.
193+
A target on a disabled provider (even with a complete discovery row), on an unknown provider with
194+
no discovery row, or targets with disjoint modalities, removes the combo from the catalog. Sync
195+
emits a summary warning and the dashboard marks it **Needs attention**. Add context metadata,
196+
align modalities, or target models with discoverable compatible capabilities.
194197

195198
## Request history and routing analytics
196199

‎docs-site/src/content/docs/zh-cn/reference/configuration/routing.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,12 @@ selector 校验、冲突规则和隐私说明见[提供方配置](/reference/con
8282

8383
即使某个 combo 不能被列出,它仍然可以直接路由。只有当所有目标都暴露出可以交集的能力时,`ocx sync`、`/v1/models` 和 Codex 选择器才会列出它:
8484

85-
- 一个正的 `contextWindow`,来源可以是实时元数据、注册表提示,或提供方的
86-
`modelContextWindows` / `contextWindow`;以及
85+
- 一个正的 `contextWindow`,来源可以是实时元数据、注册表提示、提供方的
86+
`modelContextWindows` / `contextWindow`、成员行上已知的正 `maxInputTokens`,或者——当提供方已知且启用但所有来源仍未给出窗口时——
87+
保守的 128,000 token 回退(若配置了 `providerContextCaps` 则会按上限夹紧);以及
8788
- 非空的 `inputModalities` 交集,其中省略的成员值按 `["text"]` 处理。
8889

89-
如果是一个没有上下文元数据的裸 relay id,或者目标之间的模态互不相交,combo 就会从
90+
目标位于已禁用提供方(即使有完整 discovery 行)、未知且无 discovery 行的提供方,或目标之间的模态互不相交时,combo 会从
9091
目录中移除。同步时会输出一条汇总警告,仪表板会将其标记为 **Needs attention**。
9192
补充上下文元数据、对齐模态,或者把目标模型切换为可发现且兼容的能力。
9293

‎src/codex/catalog.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export type { CatalogModel, MultiAgentMode } from "./catalog/parsing";
55
export { NATIVE_OPENAI_MODELS, nativeOpenAiContextWindow, disabledNativeSlugs, visibleNativeSlugs, desktopVisibleNativeSlugs, nativeModelRows, applyNativeVisibility, upstreamNativeEntry, nativeOpenAiSlugs, listCatalogNativeSlugs, nativeReasoningEfforts, nativeDefaultReasoningEffort, shouldIncludeAccountBoundNativeOpenAi, shouldIncludeNativeOpenAi } from "./catalog/metadata";
66
export { isSpawnableCodexCandidate, codexExecInvocation, loadBundledCodexCatalog, materializeBundledCodexCatalog, loadCatalogTemplate } from "./catalog/bundled";
77
export { nativeEffortClamp, shouldApplyNativeEffortClamp, catalogModelEfforts, codexSupportedReasoningEfforts, clampedDefaultEffort, clampEntryToCodexSupportedEfforts, clampCatalogModelsToCodexSupport } from "./catalog/effort";
8-
export { applyProviderConfigHints, isDatedVariantId, filterCatalogVisibleModels, gatherRoutedModels, clearGatherRoutedModelsInflight, augmentRoutedModelsWithRegistryOpenAiApiRows, augmentRoutedModelsWithMetadata } from "./catalog/provider-fetch";
8+
export { applyProviderConfigHints, isDatedVariantId, filterCatalogVisibleModels, gatherRoutedModels, clearGatherRoutedModelsInflight, augmentRoutedModelsWithRegistryOpenAiApiRows, augmentRoutedModelsWithMetadata, resolveComboCatalogMember } from "./catalog/provider-fetch";
99
export { deriveComboCatalogModel, exactComboCatalogSlugs, getLastComboCatalogOmissions, resetOpenAiApiCatalogWarningStateForTests, uniqueCatalogModelsForPublicList, uniqueCatalogModelsForRawPublicList, buildComboCatalogOmission, comboCatalogOmissionReason, summarizeComboCatalogOmissions } from "./catalog/aggregation";
1010
export type { ComboCatalogOmission, ComboCatalogOmissionReason } from "./catalog/aggregation";
1111
export { MAX_SPAWN_AGENT_MODEL_OVERRIDES, CANONICAL_NATIVE_CATALOG_CONTENT_POLICY, effectiveSubagentRoster, buildCatalogEntries, mergeCatalogEntriesFromObservedState, resetCatalogRuntimeStateForTests, orderForSubagents, mergeCatalogEntriesForSync, syncCatalogModels, restoreCodexCatalog, invalidateCodexModelsCache } from "./catalog/sync";

‎src/codex/catalog/aggregation.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,14 @@ export function deriveComboCatalogModel(
131131
const inputModalities = intersectStrings(
132132
members.map(member => member.inputModalities ?? ["text"]),
133133
);
134-
const reasoningEfforts = intersectStrings(
135-
members.map(member => member.reasoningEfforts ?? []),
136-
);
134+
// Unknown ladders (`undefined`) are wildcards for catalog derivation — same
135+
// boundary as the GUI picker. An explicit empty ladder still constrains.
136+
const advertisedLadders = members
137+
.map(member => member.reasoningEfforts)
138+
.filter((ladder): ladder is string[] => ladder !== undefined);
139+
const reasoningEfforts = advertisedLadders.length === 0
140+
? []
141+
: intersectStrings(advertisedLadders);
137142
const contextWindow = Math.min(...members.map(member => member.contextWindow!));
138143
const maxInputTokens = Math.min(
139144
...members.map(member => member.maxInputTokens ?? member.contextWindow!),

‎src/codex/catalog/provider-fetch.ts‎

Lines changed: 107 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,104 @@ export function applyConfigHintsToCachedModels(name: string, prov: OcxProviderCo
620620
return models.map(model => applyProviderConfigHints(name, prov, model, contextCap));
621621
}
622622

623+
624+
/**
625+
* Last-resort context window for combo member synthesis when discovery and
626+
* provider config both omit one. Matches the catalog entry default in
627+
* `normalizeRoutedCatalogEntry` so incomplete live rows still catalog.
628+
*/
629+
const COMBO_MEMBER_CONTEXT_FALLBACK = 128_000;
630+
631+
/**
632+
* Resolve a combo target to a catalog member for derivation.
633+
* Prefer discovery metadata; when the target is missing from the gather map or
634+
* lacks a positive contextWindow, synthesize from the (registry-enriched)
635+
* provider config so combos remain catalogued when targets are configured but
636+
* discovery metadata is incomplete. Disabled providers stay unresolved.
637+
* When hints still omit contextWindow, prefer known maxInputTokens, else
638+
* COMBO_MEMBER_CONTEXT_FALLBACK so a live row without ctx does not drop the
639+
* whole combo from the public catalog.
640+
*/
641+
export function resolveComboCatalogMember(
642+
target: { provider: string; model: string },
643+
memberByKey: ReadonlyMap<string, CatalogModel>,
644+
providers: ReadonlyMap<string, OcxProviderConfig>,
645+
contextCap?: number,
646+
): CatalogModel | undefined {
647+
const existing = memberByKey.get(targetKey(target));
648+
const prov = providers.get(target.provider);
649+
// Disabled providers never contribute members — even a complete discovery row
650+
// is unusable for catalog derivation while the provider is off.
651+
if (prov?.disabled === true) return undefined;
652+
653+
// Complete live/configured rows still honor providerContextCaps so a high
654+
// discovery window cannot outrun an operator-configured cap.
655+
if (
656+
existing
657+
&& typeof existing.contextWindow === "number"
658+
&& existing.contextWindow > 0
659+
) {
660+
const capped = applyProviderContextCap(existing.contextWindow, contextCap);
661+
if (capped === undefined || capped === existing.contextWindow) return existing;
662+
const maxInput = typeof existing.maxInputTokens === "number" && existing.maxInputTokens > 0
663+
? Math.min(existing.maxInputTokens, capped)
664+
: capped;
665+
return {
666+
...existing,
667+
contextWindow: capped,
668+
maxInputTokens: maxInput,
669+
contextCap,
670+
contextCapped: true as const,
671+
};
672+
}
673+
674+
const base: CatalogModel = existing ?? {
675+
id: target.model,
676+
provider: target.provider,
677+
};
678+
const hinted = prov
679+
? applyProviderConfigHints(target.provider, prov, base, contextCap)
680+
: base;
681+
const hintedContext = typeof hinted.contextWindow === "number" && hinted.contextWindow > 0
682+
? hinted.contextWindow
683+
: undefined;
684+
// Prefer a known positive maxInputTokens over inventing 128k when discovery
685+
// advertised an input limit but no context window (common thin /models rows).
686+
const knownMaxInput = typeof hinted.maxInputTokens === "number" && hinted.maxInputTokens > 0
687+
? hinted.maxInputTokens
688+
: (typeof base.maxInputTokens === "number" && base.maxInputTokens > 0
689+
? base.maxInputTokens
690+
: undefined);
691+
const uncappedContext = hintedContext
692+
?? knownMaxInput
693+
?? (existing || prov ? COMBO_MEMBER_CONTEXT_FALLBACK : undefined);
694+
if (uncappedContext === undefined) return undefined;
695+
const usedFallback = hintedContext === undefined;
696+
const cappedContext = applyProviderContextCap(uncappedContext, contextCap);
697+
const contextWindow = cappedContext ?? uncappedContext;
698+
const fallbackCapped = usedFallback
699+
&& contextCap !== undefined
700+
&& cappedContext !== undefined
701+
&& cappedContext !== uncappedContext;
702+
703+
const inputModalities = hinted.inputModalities ?? base.inputModalities ?? ["text"];
704+
const reasoningEfforts = hinted.reasoningEfforts
705+
?? (prov ? configuredReasoningEfforts(prov, target.model) : undefined)
706+
?? base.reasoningEfforts;
707+
const maxInputTokens = knownMaxInput !== undefined
708+
? Math.min(knownMaxInput, contextWindow)
709+
: contextWindow;
710+
711+
return {
712+
...hinted,
713+
inputModalities,
714+
...(reasoningEfforts !== undefined ? { reasoningEfforts } : {}),
715+
contextWindow,
716+
maxInputTokens,
717+
...(fallbackCapped ? { contextCap, contextCapped: true as const } : {}),
718+
};
719+
}
720+
623721
export function isDatedVariantId(liveId: string, configuredId: string): boolean {
624722
if (!liveId.startsWith(`${configuredId}-`)) return false;
625723
return /^\d{8}$/.test(liveId.slice(configuredId.length + 1));
@@ -1319,21 +1417,26 @@ async function gatherRoutedModelsUncached(
13191417
if (!memberByKey.has(key)) memberByKey.set(key, synthetic);
13201418
}
13211419
}
1420+
// Enriched (registry-hydrated) provider clones — shared by combo member synthesis and
1421+
// custom-model vision-sidecar inheritance so both see the same merged registry view.
1422+
const enrichedByName = new Map(activeProviders.map(provider => [provider.name, provider.provider]));
13221423
for (const id of listComboIds(config)) {
13231424
const combo = getCombo(config, id);
13241425
if (!combo) continue;
13251426
const members = combo.targets
1326-
.map(target => memberByKey.get(targetKey(target)))
1427+
.map(target => resolveComboCatalogMember(
1428+
target,
1429+
memberByKey,
1430+
enrichedByName,
1431+
providerContextCap(config, target.provider),
1432+
))
13271433
.filter((member): member is CatalogModel => member !== undefined);
13281434
const derived = deriveComboCatalogModel(id, combo, members);
13291435
if (derived) all.push(derived);
13301436
else warnUncataloguedComboOnce(id, combo, members, localOmissions);
13311437
}
13321438
replaceLastComboCatalogOmissions(localOmissions);
13331439
all.sort((a, b) => (a.provider === b.provider ? a.id.localeCompare(b.id) : a.provider.localeCompare(b.provider)));
1334-
// Enriched (registry-hydrated) provider clones, keyed by name — the same view used above so
1335-
// custom rows get the same noVisionModels / inputModalities treatment as discovered rows.
1336-
const enrichedByName = new Map(activeProviders.map(provider => [provider.name, provider.provider]));
13371440
// Provider-derived rows keyed by their Codex-facing slug: a custom override replaces the row
13381441
// with the same slug below, so that row's provider capability metadata is the inheritance source.
13391442
const replacedByRoutedSlug = new Map(all.map(model => [routedSlug(model.provider, model.id), model]));

0 commit comments

Comments
 (0)