Skip to content

Commit 66856da

Browse files
committed
fix(doctor): preserve params prototype semantics
1 parent befcb11 commit 66856da

2 files changed

Lines changed: 57 additions & 4 deletions

File tree

src/commands/doctor-legacy-config.migrations.test.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,59 @@ describe("normalizeCompatibilityConfigValues", () => {
14341434
]);
14351435
});
14361436

1437+
it("keeps native Ollama params prototype-safe while setting num_ctx", () => {
1438+
const providerParams: Record<string, unknown> = { temperature: 0.2 };
1439+
Object.defineProperty(providerParams, "__proto__", {
1440+
enumerable: true,
1441+
value: { think: "high" },
1442+
});
1443+
const modelParams: Record<string, unknown> = { top_p: 0.9 };
1444+
Object.defineProperty(modelParams, "__proto__", {
1445+
enumerable: true,
1446+
value: { keep_alive: "forever" },
1447+
});
1448+
1449+
const res = normalizeCompatibilityConfigValues({
1450+
models: {
1451+
providers: {
1452+
ollama: {
1453+
baseUrl: "http://localhost:11434",
1454+
api: "ollama",
1455+
contextWindow: 65536,
1456+
params: providerParams,
1457+
models: [
1458+
ollamaModel({
1459+
contextWindow: 32768,
1460+
params: modelParams,
1461+
}),
1462+
],
1463+
},
1464+
},
1465+
},
1466+
});
1467+
1468+
const nextProviderParams = res.config.models?.providers?.ollama?.params as Record<
1469+
string,
1470+
unknown
1471+
>;
1472+
const nextModelParams = res.config.models?.providers?.ollama?.models?.[0]?.params as Record<
1473+
string,
1474+
unknown
1475+
>;
1476+
expect(Object.getPrototypeOf(nextProviderParams)).toBe(Object.prototype);
1477+
expect(Object.getPrototypeOf(nextModelParams)).toBe(Object.prototype);
1478+
expect(Object.getOwnPropertyDescriptor(nextProviderParams, "__proto__")?.value).toEqual({
1479+
think: "high",
1480+
});
1481+
expect(Object.getOwnPropertyDescriptor(nextModelParams, "__proto__")?.value).toEqual({
1482+
keep_alive: "forever",
1483+
});
1484+
expect(nextProviderParams.think).toBeUndefined();
1485+
expect(nextModelParams.keep_alive).toBeUndefined();
1486+
expect(nextProviderParams.num_ctx).toBe(65536);
1487+
expect(nextModelParams.num_ctx).toBe(32768);
1488+
});
1489+
14371490
it("keeps existing provider-level native Ollama params.num_ctx ahead of inherited provider budgets", () => {
14381491
const res = normalizeCompatibilityConfigValues({
14391492
models: {

src/commands/doctor/shared/legacy-config-core-normalizers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,7 @@ function applyLegacyOllamaProviderNumCtxParams(params: {
12481248
return {
12491249
provider: {
12501250
...params.provider,
1251-
params: Object.assign({}, rawParams, { num_ctx: numCtx }),
1251+
params: rawParams ? { ...rawParams, num_ctx: numCtx } : { num_ctx: numCtx },
12521252
},
12531253
changed: true,
12541254
};
@@ -1327,9 +1327,9 @@ export function normalizeLegacyOllamaNativeNumCtxParams(
13271327
changes.push(
13281328
`Set models.providers.${sanitizeForLog(providerId)}.models[${index}].params.num_ctx to ${numCtx} for native Ollama compatibility.`,
13291329
);
1330-
const nextModel = Object.assign({}, model);
1331-
nextModel.params = Object.assign({}, rawParams, { num_ctx: numCtx });
1332-
return nextModel;
1330+
return Object.assign({}, model, {
1331+
params: rawParams ? { ...rawParams, num_ctx: numCtx } : { num_ctx: numCtx },
1332+
});
13331333
});
13341334

13351335
if (!modelsChanged && !providerParams.changed) {

0 commit comments

Comments
 (0)