fix(sse): guard model-less registry entries in getUnsupportedParams (mimocode) (#4015)

Real bugfix: guard model-less registry entries (mimocode) in getUnsupportedParams so handleChatCore no longer throws 'entry.models is not iterable' / reports 'All models failed' for unrelated requests. Includes a regression test. Fast QG green.
This commit is contained in:
Diego Rodrigues de Sa e Souza
2026-06-16 16:36:42 -03:00
committed by GitHub
parent 33493586b4
commit 599c10b048
2 changed files with 26 additions and 2 deletions

View File

@@ -189,7 +189,8 @@ function ensureUnsupportedParamsPopulated(): void {
if (_unsupportedParamsPopulated) return;
_unsupportedParamsPopulated = true;
for (const entry of Object.values(REGISTRY)) {
for (const model of entry.models) {
// Some entries (e.g. the `mimocode` proxy) legitimately have no model catalogue.
for (const model of entry.models ?? []) {
if (model.unsupportedParams && !_unsupportedParamsMap.has(model.id)) {
_unsupportedParamsMap.set(model.id, model.unsupportedParams);
}
@@ -207,7 +208,7 @@ export function getUnsupportedParams(provider: string, modelId: string): readonl
ensureUnsupportedParamsPopulated();
// 1. Check current provider's registry (exact match)
const entry = getRegistryEntry(provider);
const modelEntry = entry?.models.find((m) => m.id === modelId);
const modelEntry = entry?.models?.find((m) => m.id === modelId);
if (modelEntry?.unsupportedParams) return modelEntry.unsupportedParams;
// 2. O(1) lookup in precomputed map (handles cross-provider routing)

View File

@@ -0,0 +1,23 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { getUnsupportedParams } from "../../open-sse/config/providerRegistry.ts";
// Regression guard for `TypeError: entry.models is not iterable`.
//
// A registry entry can legitimately have no static model catalogue — e.g. the
// `mimocode` proxy provider, whose `models` is `undefined`. The byModelId map
// builder already tolerates this (`if (entry.models && entry.models.length > 0)`),
// but `getUnsupportedParams` had two unguarded accesses:
// - `ensureUnsupportedParamsPopulated()` iterated `entry.models` for EVERY entry,
// - the per-provider lookup did `entry?.models.find(...)`.
// Either one threw on the first call once a model-less entry existed, which made
// `handleChatCore` report "All models failed" for unrelated requests.
test("getUnsupportedParams does not throw when a registry entry has no models (mimocode regression)", () => {
// This call triggers ensureUnsupportedParamsPopulated() which walks ALL entries.
assert.doesNotThrow(() => getUnsupportedParams("openai", "gpt-4o"));
});
test("getUnsupportedParams returns [] for a model-less proxy provider", () => {
assert.deepEqual(getUnsupportedParams("mimocode", "anything"), []);
});