Skip to content

Commit bb96869

Browse files
committed
fix(catalog): synthesize incomplete combo members with context fallback
Recover multi-target combos when discovery omits context windows by synthesizing members from provider config (or a 128k fallback clamped by providerContextCaps). Prefer known maxInputTokens over inventing 128k, skip disabled providers, and treat unknown effort ladders as wildcards in catalog derivation while empty ladders stay restrictive.
1 parent e9d957b commit bb96869

6 files changed

Lines changed: 381 additions & 30 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
@@ -182,13 +182,16 @@ Per-request route-decision traces are recorded when a policy profile executes.
182182
A combo remains directly routable even when it cannot be listed. `ocx sync`, `/v1/models`, and the
183183
Codex picker list it only when every target exposes capabilities that can be intersected:
184184

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

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

193196
## Request history and routing analytics
194197

‎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`,或者——当提供方已知但所有来源都未给出窗口时——
87+
保守的 128,000 token 回退(若配置了 `providerContextCaps` 则会按上限夹紧);以及
8788
- 非空的 `inputModalities` 交集,其中省略的成员值按 `["text"]` 处理。
8889

89-
如果是一个没有上下文元数据的裸 relay id,或者目标之间的模态互不相交,combo 就会从
90+
目标位于未知/已禁用且无 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, augmentRoutedModelsWithJawcodeMetadata } from "./catalog/provider-fetch";
8+
export { applyProviderConfigHints, isDatedVariantId, filterCatalogVisibleModels, gatherRoutedModels, clearGatherRoutedModelsInflight, augmentRoutedModelsWithRegistryOpenAiApiRows, augmentRoutedModelsWithJawcodeMetadata, 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, effectiveSubagentRoster, buildCatalogEntries, 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: 116 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,113 @@ export function applyConfigHintsToCachedModels(name: string, prov: OcxProviderCo
607607
return models.map(model => applyProviderConfigHints(name, prov, model, contextCap));
608608
}
609609

610+
/**
611+
* Last-resort context window for combo member synthesis when discovery and
612+
* provider config both omit one. Matches the catalog entry default in
613+
* `normalizeRoutedCatalogEntry` so incomplete live rows still catalog.
614+
*/
615+
const COMBO_MEMBER_CONTEXT_FALLBACK = 128_000;
616+
617+
/**
618+
* Resolve a combo target to a catalog member for derivation.
619+
* Prefer discovery metadata; when the target is missing from the gather map or
620+
* lacks a positive contextWindow, synthesize from the (registry-enriched)
621+
* provider config so combos remain catalogued when targets are configured but
622+
* discovery metadata is incomplete. Disabled/missing providers stay unresolved.
623+
* When hints still omit contextWindow, apply COMBO_MEMBER_CONTEXT_FALLBACK so a
624+
* live row without ctx (common for LiteLLM / custom xai ids) does not drop the
625+
* whole combo from the public catalog.
626+
*/
627+
export function resolveComboCatalogMember(
628+
target: { provider: string; model: string },
629+
memberByKey: ReadonlyMap<string, CatalogModel>,
630+
providers: ReadonlyMap<string, OcxProviderConfig>,
631+
contextCap?: number,
632+
): CatalogModel | undefined {
633+
const existing = memberByKey.get(targetKey(target));
634+
const prov = providers.get(target.provider);
635+
// Disabled providers never contribute members — even a complete discovery row
636+
// is unusable for catalog derivation while the provider is off.
637+
if (prov?.disabled === true) return undefined;
638+
639+
// Complete live/configured rows still honor providerContextCaps so a high
640+
// discovery window cannot outrun an operator-configured cap.
641+
if (
642+
existing
643+
&& typeof existing.contextWindow === "number"
644+
&& existing.contextWindow > 0
645+
) {
646+
const capped = applyProviderContextCap(existing.contextWindow, contextCap);
647+
if (capped === undefined || capped === existing.contextWindow) return existing;
648+
const maxInput = typeof existing.maxInputTokens === "number" && existing.maxInputTokens > 0
649+
? Math.min(existing.maxInputTokens, capped)
650+
: capped;
651+
return {
652+
...existing,
653+
contextWindow: capped,
654+
maxInputTokens: maxInput,
655+
contextCap,
656+
contextCapped: true as const,
657+
};
658+
}
659+
660+
const base: CatalogModel = existing ?? {
661+
id: target.model,
662+
provider: target.provider,
663+
};
664+
// Reuse the same hint path configured/static catalog rows use when a provider
665+
// config exists; otherwise keep the base (possibly incomplete) discovery row.
666+
const hinted = prov
667+
? applyProviderConfigHints(target.provider, prov, base, contextCap)
668+
: base;
669+
const hintedContext = typeof hinted.contextWindow === "number" && hinted.contextWindow > 0
670+
? hinted.contextWindow
671+
: undefined;
672+
// Prefer a known positive maxInputTokens over inventing 128k when discovery
673+
// advertised an input limit but no context window (common thin /models rows).
674+
const knownMaxInput = typeof hinted.maxInputTokens === "number" && hinted.maxInputTokens > 0
675+
? hinted.maxInputTokens
676+
: (typeof base.maxInputTokens === "number" && base.maxInputTokens > 0
677+
? base.maxInputTokens
678+
: undefined);
679+
// Prefer config/discovery; fall back so incomplete live rows still catalog.
680+
// Pure ghosts (no discovery row) on a known provider still synthesize: live
681+
// discovery is often incomplete for LiteLLM/custom relays, and dropping the
682+
// whole combo solely for a missing /v1/models row is worse than a stub window.
683+
const uncappedContext = hintedContext
684+
?? knownMaxInput
685+
?? (existing || prov ? COMBO_MEMBER_CONTEXT_FALLBACK : undefined);
686+
if (uncappedContext === undefined) return undefined;
687+
// Fallback bypasses applyProviderConfigHints' cap path — clamp here so a
688+
// providerContextCaps value below 128k still wins (same semantics as hints).
689+
const usedFallback = hintedContext === undefined;
690+
const cappedContext = applyProviderContextCap(uncappedContext, contextCap);
691+
const contextWindow = cappedContext ?? uncappedContext;
692+
const fallbackCapped = usedFallback
693+
&& contextCap !== undefined
694+
&& cappedContext !== undefined
695+
&& cappedContext !== uncappedContext;
696+
697+
const inputModalities = hinted.inputModalities ?? base.inputModalities ?? ["text"];
698+
// applyProviderConfigHints already folds configuredReasoningEfforts; keep an
699+
// explicit fallback for stubs that only had base fields.
700+
const reasoningEfforts = hinted.reasoningEfforts
701+
?? (prov ? configuredReasoningEfforts(prov, target.model) : undefined)
702+
?? base.reasoningEfforts;
703+
const maxInputTokens = knownMaxInput !== undefined
704+
? Math.min(knownMaxInput, contextWindow)
705+
: contextWindow;
706+
707+
return {
708+
...hinted,
709+
inputModalities,
710+
...(reasoningEfforts !== undefined ? { reasoningEfforts } : {}),
711+
contextWindow,
712+
maxInputTokens,
713+
...(fallbackCapped ? { contextCap, contextCapped: true as const } : {}),
714+
};
715+
}
716+
610717
export function isDatedVariantId(liveId: string, configuredId: string): boolean {
611718
if (!liveId.startsWith(`${configuredId}-`)) return false;
612719
return /^\d{8}$/.test(liveId.slice(configuredId.length + 1));
@@ -736,17 +843,6 @@ function modelInputModalities(
736843
value === "text" || value === "image" || value === "audio"
737844
));
738845
if (explicit && explicit.length > 0) return explicit;
739-
const architecture = plainRecord(item.architecture);
740-
const architectureModality = typeof architecture?.modality === "string"
741-
? normalizedMetadataString(architecture.modality, 64)
742-
: undefined;
743-
if (architectureModality?.includes("->")) {
744-
const [rawInput = ""] = architectureModality.split("->");
745-
const inferred = rawInput
746-
.split("+")
747-
.filter(value => value === "text" || value === "image" || value === "audio");
748-
if (inferred.length > 0) return [...new Set(inferred)];
749-
}
750846
if (capabilityRecord?.vision === false) return ["text"];
751847
if (capabilityRecord?.vision === true || capabilities?.some(value => value === "vision" || value === "image-input")) {
752848
return ["text", "image"];
@@ -1273,21 +1369,26 @@ async function gatherRoutedModelsUncached(
12731369
if (!memberByKey.has(key)) memberByKey.set(key, synthetic);
12741370
}
12751371
}
1372+
// Enriched (registry-hydrated) provider clones — shared by combo member synthesis and
1373+
// custom-model vision-sidecar inheritance so both see the same merged registry view.
1374+
const enrichedByName = new Map(activeProviders.map(provider => [provider.name, provider.provider]));
12761375
for (const id of listComboIds(config)) {
12771376
const combo = getCombo(config, id);
12781377
if (!combo) continue;
12791378
const members = combo.targets
1280-
.map(target => memberByKey.get(targetKey(target)))
1379+
.map(target => resolveComboCatalogMember(
1380+
target,
1381+
memberByKey,
1382+
enrichedByName,
1383+
providerContextCap(config, target.provider),
1384+
))
12811385
.filter((member): member is CatalogModel => member !== undefined);
12821386
const derived = deriveComboCatalogModel(id, combo, members);
12831387
if (derived) all.push(derived);
12841388
else warnUncataloguedComboOnce(id, combo, members, localOmissions);
12851389
}
12861390
replaceLastComboCatalogOmissions(localOmissions);
12871391
all.sort((a, b) => (a.provider === b.provider ? a.id.localeCompare(b.id) : a.provider.localeCompare(b.provider)));
1288-
// Enriched (registry-hydrated) provider clones, keyed by name — the same view used above so
1289-
// custom rows get the same noVisionModels / inputModalities treatment as discovered rows.
1290-
const enrichedByName = new Map(activeProviders.map(provider => [provider.name, provider.provider]));
12911392
// Provider-derived rows keyed by their Codex-facing slug: a custom override replaces the row
12921393
// with the same slug below, so that row's provider capability metadata is the inheritance source.
12931394
const replacedByRoutedSlug = new Map(all.map(model => [routedSlug(model.provider, model.id), model]));

0 commit comments

Comments
 (0)