Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(desktop): keep user-pinned model limits across provider enrichment

yexisua606de3c0206
diff --git a/apps/desktop/electron/main/runtime/provider-catalog.ts b/apps/desktop/electron/main/runtime/provider-catalog.ts
index 5dcdba2e8..a8b2e05bd 100644
--- a/apps/desktop/electron/main/runtime/provider-catalog.ts
+++ b/apps/desktop/electron/main/runtime/provider-catalog.ts
@@ -12,9 +12,11 @@ import {
import {
capabilitiesFromModelConfig,
type ModelConfig,
+ modelConfigWithBinding,
visionFromModelConfig,
type ThinkingCapabilities,
} from "@pi-desktop/agent-runtime";
+import { resolveBindingLimits } from "@pi-desktop/shared";
import type { HostProcess } from "../host-process";
import {
catalogModelConfigFor,
@@ -115,10 +117,19 @@ export function createProviderCatalogRuntime({
providerId: provider.id, vendorKey: provider.vendorKey, baseUrl: provider.baseUrl, modelId,
});
const models = provider.models?.map((binding) => {
- const effective = catalogModelConfigFor(modelsDevCatalog, {
+ const catalogConfig = catalogModelConfigFor(modelsDevCatalog, {
providerId: provider.id, vendorKey: provider.vendorKey, baseUrl: provider.baseUrl, modelId: binding.id,
});
- return { ...binding, contextWindow: effective.contextWindow, maxTokens: effective.maxTokens, maxTokensSource: binding.maxTokensSource ?? "user" as const };
+ // A user-pinned window/cap is never replaced by the published number
+ // (spec §9.1, issue #1176); an inherited one keeps following the catalog.
+ const limits = resolveBindingLimits(catalogConfig, binding);
+ const effective = modelConfigWithBinding(limits.catalogConfig, limits.binding);
+ return {
+ ...binding,
+ contextWindow: effective.contextWindow,
+ maxTokens: effective.maxTokens,
+ maxTokensSource: binding.maxTokensSource ?? "user" as const,
+ };
});
return {
...provider,
diff --git a/apps/desktop/test/provider-catalog-runtime.test.mjs b/apps/desktop/test/provider-catalog-runtime.test.mjs
index 5e9426c3a..1838f9a3a 100644
--- a/apps/desktop/test/provider-catalog-runtime.test.mjs
+++ b/apps/desktop/test/provider-catalog-runtime.test.mjs
@@ -199,3 +199,27 @@ test("a saved missing or disabled account never inherits another account's capab
}
assert.equal(runtime.enrichSession({}, [provider], defaults).supportsVision, true);
});
+
+test("a user-pinned context window is never replaced by the catalog number (#1176)", async () => {
+ const { runtime } = await fixtureRuntime();
+ // A relay model whose catalog hit publishes 16k while the user pinned 1M.
+ const provider = {
+ id: "relay",
+ name: "Relay",
+ vendorKey: "example",
+ baseUrl: "https://models.example/v1",
+ models: [
+ { id: "catalog-model", contextWindow: 1_000_000, maxTokens: 8_192, thinkingLevels: [] },
+ { id: "hand-typed-model", contextWindow: 1_000_000, maxTokens: 8_192, thinkingLevels: [] },
+ ],
+ };
+ const enriched = runtime.enrichProvider(provider).models;
+ assert.equal(enriched[0].contextWindow, 1_000_000, "a user pin on a catalog hit stays");
+ assert.equal(enriched[1].contextWindow, 1_000_000, "a user pin on an unmatched id stays");
+ // An inherited row keeps following the catalog.
+ const inherited = runtime.enrichProvider({
+ ...provider,
+ models: [{ id: "catalog-model", contextWindow: 8_000, maxTokens: 8_192, thinkingLevels: [], contextWindowSource: "catalog" }],
+ }).models;
+ assert.equal(inherited[0].contextWindow, 128_000, "a catalog-sourced window follows the published value");
+});