Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
prevent stale hydration from overwriting remembered model settings
alkinundcf877423678
diff --git a/studio/frontend/src/features/model-picker/components/model-config-page.tsx b/studio/frontend/src/features/model-picker/components/model-config-page.tsxindex 98cdb5b7cf1..3db093c12f6 100644--- a/studio/frontend/src/features/model-picker/components/model-config-page.tsx+++ b/studio/frontend/src/features/model-picker/components/model-config-page.tsx@@ -118,6 +118,7 @@ import {isServedByMlx,normalizeMaxSeqLength,normalizePerModelConfig,+ perModelConfigStorageChanged,readAdvancedSettingsOpen,resolveInitialConfig,saveAdvancedSettingsOpen,@@ -2096,15 +2097,7 @@ export function ModelConfigPage({// rewrite live input: typing --agent during the window cleared the box instead// of showing the error, and a long paste could be trimmed behind the cursor.const configAtStart = configRef.current;- // What STORAGE holds for this model, which is not always what the panel shows:- // an active model seeds the panel from loadedConfig, the config the resident- // model is running with. The hydrated record is written against this instead,- // or opening the panel replaces settings the user never touched here -- a legacy- // config just migrated in, one saved from another origin -- with the runtime.- const storedAtStart = resolveInitialConfig(- configId,- target.ggufVariant,- ).config;+ const storedAtStart = resolveInitialConfig(configId, target.ggufVariant);const rememberAtStart = rememberRef.current;const localAtStart = configAtStart.llamaExtraArgs;// The denylist, not the catalogue: sanitizing a stored list needs only the flags@@ -2238,6 +2231,13 @@ export function ModelConfigPage({configRef.current === configAtStart &&rememberRef.current === rememberAtStart) {+ const storedConfig = resolveInitialConfig(+ configId,+ target.ggufVariant,+ );+ if (perModelConfigStorageChanged(storedAtStart, storedConfig)) {+ return;+ }setExtraArgsLoadable(hydratedIsLoadable);setConfig(serverConfig);setRemember(true);@@ -2245,10 +2245,6 @@ export function ModelConfigPage({if (hasNonDefaultAdvanced(serverConfig)) {setAutoOpenAdvanced(true);}- // Onto the stored record, not the shown one: see storedAtStart. The row- // outranks both, so the shared settings still land in local storage for- // the load paths that never open this panel.- //// Unconditionally, because savePerModelConfig says "no settings" by// DELETING the entry: a merge that comes out default is a clear that has// to travel, not a write to skip. Clearing a model's only remembered@@ -2256,7 +2252,10 @@ export function ModelConfigPage({// case, and skipping it stranded the old flag here for model-selector's// quick select to reload without ever opening this panel. Writing when// no record exists is already a no-op.- const rememberedConfig = fromApiOverride(resolvedRow, storedAtStart);+ const rememberedConfig = fromApiOverride(+ resolvedRow,+ storedConfig.config,+ );// Same budget as any other write, so the same clean-up: eviction is silent// and still reports success, and a dropped model would keep applying its// server row to API loads while the picker showed defaults, with nothingdiff --git a/studio/frontend/src/features/model-picker/model-config/per-model-config.ts b/studio/frontend/src/features/model-picker/model-config/per-model-config.tsindex 06ee7cda1ea..c289a212d3a 100644--- a/studio/frontend/src/features/model-picker/model-config/per-model-config.ts+++ b/studio/frontend/src/features/model-picker/model-config/per-model-config.ts@@ -1179,10 +1179,26 @@ export function adoptLegacyConfigKey(return writeMap(map);}+export interface ResolvedPerModelConfig {+ config: PerModelConfig;+ remembered: boolean;+}++export function perModelConfigStorageChanged(+ atStart: ResolvedPerModelConfig,+ current: ResolvedPerModelConfig,+): boolean {+ return (+ atStart.remembered !== current.remembered ||+ JSON.stringify(toStoredConfig(atStart.config)) !==+ JSON.stringify(toStoredConfig(current.config))+ );+}+export function resolveInitialConfig(modelId: string,ggufVariant?: string | null,-): { config: PerModelConfig; remembered: boolean } {+): ResolvedPerModelConfig {const saved = loadPerModelConfig(modelId, ggufVariant);if (saved) {return { config: saved, remembered: true };@@ -1202,7 +1218,7 @@ export function resolveInitialConfig(export function resolveResidentInitialConfig(modelId: string,ggufVariant?: string | null,-): { config: PerModelConfig; remembered: boolean } {+): ResolvedPerModelConfig {const direct = resolveInitialConfig(modelId, ggufVariant);if (direct.remembered) {return direct;diff --git a/studio/frontend/tests/llama-extra-args-panel-hydration.test.ts b/studio/frontend/tests/llama-extra-args-panel-hydration.test.tsindex f23512c8f4b..db10a23c6ea 100644--- a/studio/frontend/tests/llama-extra-args-panel-hydration.test.ts+++ b/studio/frontend/tests/llama-extra-args-panel-hydration.test.ts@@ -12,6 +12,24 @@ import path from "node:path";import { test } from "node:test";import { fileURLToPath } from "node:url";+import {+ installLocalStorageFake,+ registerBundlerResolver,+} from "./helpers/kit.ts";++registerBundlerResolver();+installLocalStorageFake();++const {+ DEFAULT_PER_MODEL_CONFIG,+ deletePerModelConfig,+ perModelConfigStorageChanged,+ resolveInitialConfig,+ savePerModelConfig,+} = await import(+ "../src/features/model-picker/model-config/per-model-config.ts"+);+const HERE = path.dirname(fileURLToPath(import.meta.url));const PANEL = readFileSync(path.join(@@ -177,18 +195,6 @@ test("the panel adopts a shared server config without overwriting a live edit",PANEL,/sanitizedLocal = cleaned\.length > 0 \? cleaned : null;/,);- // What it WRITES is merged onto the stored record instead. An active model seeds- // the panel from loadedConfig, so persisting the shown config replaced remembered- // settings this browser never touched (a just-migrated legacy config among them)- // with whatever the resident model is running.- assert.match(- PANEL,- /const storedAtStart = resolveInitialConfig\(\s*\n?\s*configId,\s*\n?\s*target\.ggufVariant,\s*\n?\s*\)\.config;/,- );- assert.match(- PANEL,- /const rememberedConfig = fromApiOverride\(resolvedRow, storedAtStart\);/,- );// Whitespace-tolerant: the call carries an eviction list now, so it spans lines.assert.match(PANEL,@@ -201,6 +207,82 @@ test("the panel adopts a shared server config without overwriting a live edit",assert.match(PANEL, /setSavedRemember\(true\);/);});+test("hydration detects a newer save or forget", () => {+ const modelId = "unsloth/Hydration-Race-GGUF";+ const variant = "Q4_K_M";+ assert.ok(+ savePerModelConfig(modelId, variant, {+ ...DEFAULT_PER_MODEL_CONFIG,+ customContextLength: 2048,+ }),+ );+ const atStart = resolveInitialConfig(modelId, variant);++ assert.ok(+ savePerModelConfig(modelId, variant, {+ ...DEFAULT_PER_MODEL_CONFIG,+ customContextLength: 4096,+ }),+ );+ assert.equal(+ perModelConfigStorageChanged(+ atStart,+ resolveInitialConfig(modelId, variant),+ ),+ true,+ );++ assert.ok(deletePerModelConfig(modelId, variant));+ assert.equal(+ perModelConfigStorageChanged(+ atStart,+ resolveInitialConfig(modelId, variant),+ ),+ true,+ );+ assert.equal(+ perModelConfigStorageChanged(atStart, {+ config: { ...atStart.config },+ remembered: atStart.remembered,+ }),+ false,+ );+});++test("the hydration write-back rejects a stale server response", () => {+ const requestStart = PANEL.indexOf("Promise.all([");+ const storageSnapshot = PANEL.indexOf(+ "const storedAtStart = resolveInitialConfig(configId, target.ggufVariant);",+ );+ const responseStart = PANEL.indexOf(+ ".then(([resolvedOverride, managed]) => {",+ requestStart,+ );+ const adoptionStart = PANEL.indexOf(+ "if (\n resolvedRow &&",+ responseStart,+ );+ const writeBackEnd = PANEL.indexOf(+ "setSavedRemember(hydrationSaved);",+ adoptionStart,+ );+ assert.ok(+ requestStart >= 0 &&+ storageSnapshot >= 0 &&+ storageSnapshot < requestStart &&+ responseStart > requestStart &&+ adoptionStart > responseStart &&+ writeBackEnd > adoptionStart,+ "the storage snapshot must precede the request and guard its write-back",+ );++ const writeBack = PANEL.slice(adoptionStart, writeBackEnd);+ assert.match(+ writeBack,+ /const storedConfig = resolveInitialConfig\(\s*configId,\s*target\.ggufVariant,\s*\);\s*if \(perModelConfigStorageChanged\(storedAtStart, storedConfig\)\) \{\s*return;\s*\}[\s\S]*const rememberedConfig = fromApiOverride\(\s*resolvedRow,\s*storedConfig\.config,\s*\);[\s\S]*savePerModelConfig\(\s*configId,\s*target\.ggufVariant,\s*rememberedConfig,/,+ );+});+test("a build that serves one slot does not raise the floor", () => {// The published default is already effective, but an EXPLICIT Slots value is not:// a build without --kv-unified serves one slot however many are asked for, so