Skip to content

Commit a60d517

Browse files
ntdatt812lidge-jun
andauthored
fix(catalog): match selectedModels the way the canonical resolver matches it (#2481)
* fix(catalog): match selectedModels the way the canonical resolver matches it `filterCatalogVisibleModels` built the per-provider allowlist as a plain `Set(selectedModels)` and tested it with `allow.has(m.id)` — the native model id, exactly. The canonical resolution of the same list keys it through the slug equivalence: sync.ts:819-821 new Set([...models].map(m => slugEquivalenceKey(routedSlug(provider, m)))) sync.ts:1039 selected === undefined || selected.has(slugEquivalenceKey(slug)) so the two disagree for any provider whose native ids contain a slash: stored "moonshotai/kimi-k3-free" sync accepts=true catalog filter accepts=true stored "moonshotai-kimi-k3-free" sync accepts=true catalog filter accepts=false The second is the Codex-facing slug `routedSlug()` produces and the picker displays, and `ocx models remove` already accepts it (tests/cli-models.test.ts:332, "models remove accepts raw and encoded slash selectors"). An allowlist written from what the user sees therefore blanked the provider's catalog silently, while `routeModel` decoded the same string back and served the model happily. Affects providers with slash-bearing native ids: openrouter, zenmux, nvidia, together, fireworks. The `disabledModels` loop three lines above is already tolerant of both forms via `slugEquals`, and slug-codec.ts:20-21 states the rule this restores: "Config comparisons are tolerant … so legacy raw values keep working regardless of which form was stored." * test(catalog): pin the lossy collision and record the rejected alternative The key comparison is right for the reported bug, but it is lossy in a way worth writing down: "a/b" and "a-b" collapse to one equivalence key, so a provider publishing both spellings has them selected together. That behavior now has tests asserting what the code actually does, rather than being left for someone to discover from a support thread. It also has a rejected alternative recorded next to it. Resolving each selection against the provider's current rows looks stricter and is not: the roster is an incomplete dictionary, so when live discovery omits "a-b" but returns "a/b", an exact "a-b" selection resolves onto "a/b" and reproduces the same over-grant. It would additionally make fresh filtering disagree with the equivalence relation sync.ts applies when merging the persisted catalog — two catalog stages with different rules is the bug class this change removes. The real fix is one selection resolver shared by filtering, persisted sync, CLI removal, and routing, evaluated against a complete known-id set, with a single ambiguity policy. That is an architecture change and does not belong in a bugfix-only release; tracked as #2491. Tests: 242 pass across selected-models, codex-catalog, slug-codec, and cli-models. tsc --noEmit clean. --------- Co-authored-by: bitkyc08-arch <[email protected]>
1 parent 3e3a028 commit a60d517

2 files changed

Lines changed: 94 additions & 3 deletions

File tree

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import type { FastPolicyAuthority } from "../../providers/fastwire";
4141
import { effectiveGoogleMode, getProviderRegistryEntry, providerMatchesRegistryTransport } from "../../providers/registry";
4242
import { parseAntigravityAvailableModels, registerAntigravityDiscoveredWireModels } from "../../providers/antigravity-models";
4343
import { applyProviderContextCap, providerContextCap, resolveUnknownRoutedContextWindow } from "../../providers/context-cap";
44-
import { routedSlug, slugEquals, slugsEquivalent } from "../../providers/slug-codec";
44+
import { routedSlug, slugEquals, slugEquivalenceKey, slugsEquivalent } from "../../providers/slug-codec";
4545
import { CODEX_GPT5_IDENTITY_LINE } from "../../adapters/identity";
4646
import { filterCursorConfiguredModelsByLiveDiscovery } from "../../adapters/cursor/discovery";
4747
import { fetchCursorUsableModels } from "../../adapters/cursor/live-models";
@@ -1560,7 +1560,24 @@ export function filterCatalogVisibleModels(
15601560
const allowByProvider = new Map<string, Set<string>>();
15611561
for (const [name, prov] of Object.entries(config.providers)) {
15621562
const sel = prov.selectedModels;
1563-
if (Array.isArray(sel) && sel.length > 0) allowByProvider.set(name, new Set(sel));
1563+
// Keyed the way `sync.ts` keys the same list, so a slash-bearing native id and
1564+
// the encoded slug the Codex picker displays are one entry rather than two. A
1565+
// bare `Set(sel)` matched only the native form, so an allowlist written from the
1566+
// displayed slug — which `ocx models remove` also accepts — hid every model it
1567+
// was meant to keep.
1568+
//
1569+
// The key is deliberately lossy: `p/a/b` and `p/a-b` collapse to one entry, so a
1570+
// provider publishing both spellings has them selected together. That is a real
1571+
// limitation, pinned by the tests below and tracked as a follow-up; it is NOT
1572+
// fixed here. Resolving selections against the current roster instead was tried
1573+
// and rejected — the roster is an incomplete dictionary (live discovery can omit
1574+
// a published id), so it produces the same over-grant while additionally
1575+
// disagreeing with the `slugEquivalenceKey` contract `sync.ts` uses at merge time.
1576+
// Two catalog stages with different equivalence relations is the exact bug class
1577+
// this change exists to remove.
1578+
if (Array.isArray(sel) && sel.length > 0) {
1579+
allowByProvider.set(name, new Set(sel.map(model => slugEquivalenceKey(routedSlug(name, model)))));
1580+
}
15641581
}
15651582
return models.filter(m => {
15661583
const nativeAlias = m.provider === COMBO_NAMESPACE && m.nativeAlias === true;
@@ -1572,7 +1589,7 @@ export function filterCatalogVisibleModels(
15721589
if (slugEquals(stored, m.provider, m.id)) return false;
15731590
}
15741591
const allow = allowByProvider.get(m.provider);
1575-
return !allow || allow.has(m.id);
1592+
return !allow || allow.has(slugEquivalenceKey(routedSlug(m.provider, m.id)));
15761593
});
15771594
}
15781595

‎tests/selected-models.test.ts‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,77 @@ describe("filterCatalogVisibleModels — per-provider allowlist", () => {
4747
expect(out.map(x => x.id).sort()).toEqual(["model-1999", "model-7"]);
4848
});
4949
});
50+
51+
describe("filterCatalogVisibleModels — slash-bearing ids", () => {
52+
// The Codex picker displays a slash-bearing native id in its ENCODED form, and
53+
// `ocx models remove` accepts that form too, so an allowlist is routinely written
54+
// with slugs the provider never published. A bare `Set(selectedModels)` matched
55+
// only the native spelling and hid every model it was meant to keep.
56+
const native = "moonshotai/kimi-k3-free";
57+
const encoded = "moonshotai-kimi-k3-free";
58+
const rows = [m("zenmux", native), m("zenmux", "openai/gpt-5.5")];
59+
60+
test("an allowlist written with the encoded slug keeps the model", () => {
61+
const visible = filterCatalogVisibleModels(rows, cfg({
62+
zenmux: { selectedModels: [encoded] },
63+
}));
64+
expect(visible.map(v => v.id)).toEqual([native]);
65+
});
66+
67+
test("the native form keeps working", () => {
68+
const visible = filterCatalogVisibleModels(rows, cfg({
69+
zenmux: { selectedModels: [native] },
70+
}));
71+
expect(visible.map(v => v.id)).toEqual([native]);
72+
});
73+
74+
test("a mixed allowlist keeps both, without duplicating either", () => {
75+
const visible = filterCatalogVisibleModels(rows, cfg({
76+
zenmux: { selectedModels: [encoded, "openai/gpt-5.5"] },
77+
}));
78+
expect(visible.map(v => v.id).sort()).toEqual([native, "openai/gpt-5.5"].sort());
79+
});
80+
81+
test("a model outside the allowlist is still hidden", () => {
82+
const visible = filterCatalogVisibleModels(rows, cfg({
83+
zenmux: { selectedModels: [encoded] },
84+
}));
85+
expect(visible.map(v => v.id)).not.toContain("openai/gpt-5.5");
86+
});
87+
88+
// The encoding is lossy: `a/b` and `a-b` share one encoded form, so a provider that
89+
// publishes both spellings has them selected TOGETHER. These tests pin that as known
90+
// behavior rather than leaving it undiscovered.
91+
//
92+
// It is not fixed here, and the obvious alternative does not work. Resolving each
93+
// selection against the provider's current rows was tried: the roster is an
94+
// incomplete dictionary — live discovery can omit a published id — so an exact
95+
// `a-b` selection still resolves onto `a/b` whenever `a-b` is missing from that
96+
// snapshot, producing the same over-grant. It would additionally disagree with the
97+
// `slugEquivalenceKey` relation `sync.ts` applies when merging the persisted
98+
// catalog, and two catalog stages using different equivalence rules is the bug
99+
// class this change removes. A real fix needs ONE selection resolver shared by
100+
// filtering, persisted sync, and routing, against a complete known-id set.
101+
describe("a provider publishing both spellings (known lossy case)", () => {
102+
const both = [m("p", "a/b"), m("p", "a-b")];
103+
104+
test("selecting either spelling selects both", () => {
105+
const viaSlash = filterCatalogVisibleModels(both, cfg({ p: { selectedModels: ["a/b"] } }));
106+
expect(viaSlash.map(v => v.id).sort()).toEqual(["a-b", "a/b"]);
107+
const viaDash = filterCatalogVisibleModels(both, cfg({ p: { selectedModels: ["a-b"] } }));
108+
expect(viaDash.map(v => v.id).sort()).toEqual(["a-b", "a/b"]);
109+
});
110+
111+
test("an unrelated model is still hidden, so the allowlist has not collapsed", () => {
112+
const rows = [...both, m("p", "unrelated")];
113+
const visible = filterCatalogVisibleModels(rows, cfg({ p: { selectedModels: ["a-b"] } }));
114+
expect(visible.map(v => v.id)).not.toContain("unrelated");
115+
});
116+
});
117+
118+
test("a nested-slash id is kept by its fully encoded slug", () => {
119+
const nested = [m("p", "x/y/z"), m("p", "other")];
120+
const visible = filterCatalogVisibleModels(nested, cfg({ p: { selectedModels: ["x-y-z"] } }));
121+
expect(visible.map(v => v.id)).toEqual(["x/y/z"]);
122+
});
123+
});

0 commit comments

Comments
 (0)