fix(models): keep catalog rows authoritative over colliding standalone prices

This commit is contained in:
Ayaan Zaidi 2026-09-24 15:27:15 +05:30
parent b4746c20b1
commit 2582b9dd1c
No known key found for this signature in database
2 changed files with 15 additions and 3 deletions

View file

@ -97,6 +97,8 @@ beforeEach(() => {
"owner/extra": { input: 6, output: 12, source: "openCode" },
"owner/free": { input: 0, output: 0, source: "openCode" },
"gateway/vendor/own": { input: 3, output: 9, source: "modelsDev" },
// A mirror's standalone rate colliding with an unknown catalog row.
"vendor/catalogued": { input: 7, output: 7, source: "modelsDev" },
},
}),
generated_at: 200,
@ -155,7 +157,10 @@ it.each([
ref: "vendor/listed",
cost: rates(2, 4),
},
{ name: "unknown catalog row is not revived by upstream", ref: "vendor/catalogued" },
{
name: "unknown catalog row is not revived by upstream or a colliding standalone rate",
ref: "vendor/catalogued",
},
{ name: "owner reads its provider-owned rate", ref: "owner/extra", cost: rates(6, 12) },
{ name: "authoritative owner keeps a native free rate", ref: "owner/free", cost: rates(0, 0) },
])("$name", ({ ref, cost }) => {

View file

@ -46,10 +46,17 @@ export function projectRemoteModelCatalog(bundle: RemoteModelCatalogWireBundle):
const providers: Record<string, ModelCatalogProvider> = Object.fromEntries(
Object.entries(bundle.providers).map(([id, provider]) => [id, { ...provider, models: [] }]),
);
// Provider-owned standalone rates keep v1 semantics: zero needs authoritative owner policy.
// A model row owns its key whatever its status: a mirror's standalone rate for an
// unknown or withdrawn row must not price it. Provider-owned standalone rates keep v1
// semantics: zero needs authoritative owner policy.
const rowKeys = new Set(
bundle.models.map(({ provider, id }) => buildModelCatalogRef(provider, id)),
);
const prices: Array<[string, RemoteModelCatalogPrice]> = Object.entries(
bundle.providerPricing ?? {},
).map(([key, { source: _source, ...cost }]) => [key, { cost, explicit: false }]);
)
.filter(([key]) => !rowKeys.has(key))
.map(([key, { source: _source, ...cost }]) => [key, { cost, explicit: false }]);
for (const { provider, pricing, ...model } of bundle.models) {
let cost: ModelCatalogCost | undefined;
if (pricing.status === "known") {