Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(neuron): a model switch sends the new model only its own sliders

purple0a6ecd1771bc
diff --git a/src/components/neuron/NeuronView.tsx b/src/components/neuron/NeuronView.tsx
index ad72d258..d6b8b386 100644
--- a/src/components/neuron/NeuronView.tsx
+++ b/src/components/neuron/NeuronView.tsx
@@ -72,7 +72,9 @@ export function NeuronView() {
const [models, setModels] = useState<BundledModel[]>([])
const [modelsLoaded, setModelsLoaded] = useState(false)
const [modelPath, setModelPath] = useState<string>('')
- const [info, setInfo] = useState<NeuronInfo | null>(null)
+ // The info is kept with the model it was read for: after a switch the old
+ // model's sliders must not reach the new one while its info is on the way.
+ const [loadedInfo, setLoadedInfo] = useState<{ path: string; info: NeuronInfo } | null>(null)
const [presets, setPresets] = useState<NeuronPreset[]>([])
const [job, setJob] = useState<NeuronJob | null>(null)
const [error, setError] = useState<string | null>(null)
@@ -81,6 +83,9 @@ export function NeuronView() {
const backend = chatBackend(activeModel, appMode)
const model = models.find((m) => m.path === modelPath)
+ const info = loadedInfo?.path === modelPath ? loadedInfo.info : null
+ const pathRef = useRef(modelPath)
+ pathRef.current = modelPath
// Models and presets once; the loaded model (or the chat's) preselected.
useEffect(() => {
@@ -100,10 +105,13 @@ export function NeuronView() {
const refreshInfo = useCallback(async (path: string) => {
if (!path) return
try {
- setInfo(await neuronInfo(path))
+ const read = await neuronInfo(path)
+ if (path !== pathRef.current) return
+ setLoadedInfo({ path, info: read })
setError(null)
} catch (e) {
- setInfo(null)
+ if (path !== pathRef.current) return
+ setLoadedInfo(null)
setError(String(e))
}
}, [])
diff --git a/src/components/neuron/__tests__/neuron-view-steers-the-engine.test.tsx b/src/components/neuron/__tests__/neuron-view-steers-the-engine.test.tsx
index 8bffede2..3f2b284a 100644
--- a/src/components/neuron/__tests__/neuron-view-steers-the-engine.test.tsx
+++ b/src/components/neuron/__tests__/neuron-view-steers-the-engine.test.tsx
@@ -23,7 +23,12 @@ vi.mock('../../../api/neuron', () => ({
{ id: 'creative', left: 'Sober', right: 'Creative' },
{ id: 'cheerful', left: 'Serious', right: 'Cheerful' },
],
- neuronInfo: async () => ({
+ neuronInfo: async (path: string) => path === LLAMA.path ? {
+ // The second model's info comes later than the first's, as on disk.
+ ...(await new Promise((r) => setTimeout(r, 200)), {}),
+ facts: { arch: 'llama', nLayer: 28, nEmbd: 3072, template: 'llama3', name: 'Llama 3.2 3B' },
+ modelKey: 'llama-1', generator: true, band: [4, 22], vectors: [...vectors], sae: null, activeMix: null,
+ } : ({
facts: { arch: 'qwen2', nLayer: 24, nEmbd: 896, template: 'chatMl', name: 'Qwen2.5 0.5B Instruct' },
modelKey: 'qwen-1',
generator: true,
@@ -45,6 +50,7 @@ vi.mock('../../../api/engine', () => ({
}))
vi.mock('../../../api/backend', () => ({ openExternal: vi.fn(), backendCall: vi.fn() }))
const QWEN = { name: 'qwen2.5-0.5b-instruct-q8_0', path: '/models/qwen.gguf', size: 1, loaded: true }
+const LLAMA = { name: 'llama-3.2-3b-q4_k_m', path: '/models/llama.gguf', size: 1, loaded: false }
const NOMIC = { name: 'nomic-embed-text-v1.5.Q4_K_M', path: '/models/nomic.gguf', size: 1, loaded: false }
const disk = vi.hoisted(() => ({ models: [] as Array<Record<string, unknown>> }))
const slot = vi.hoisted(() => ({ managed: true }))
@@ -91,6 +97,21 @@ describe('Neuron tweaker view', () => {
await waitFor(() => expect(apply.mock.calls.at(-1)?.[1]).toEqual([]), { timeout: 3000 })
})
+ // T1 (3.0.9): after a switch the old model's sliders went to the new
+ // model (twice, each a restart) until its info was in.
+ it('sends the new model only its own sliders after a switch', async () => {
+ disk.models = [QWEN, LLAMA]
+ vectors.push({ id: 'creative', kind: 'preset', name: 'Sober ↔ Creative', left: 'Sober', right: 'Creative', unit: 0.8, builtAt: 1, more: [], less: [] })
+ useNeuronStore.setState({ profiles: { 'qwen-1': { creative: 0.5 } }, scopeByModel: {} })
+ render(createElement(NeuronView))
+ await waitFor(() => expect(apply.mock.calls.at(-1)?.[1]).toEqual([{ id: 'creative', strength: 0.5 }]))
+ fireEvent.change(screen.getByTestId('neuron-model'), { target: { value: LLAMA.path } })
+ await waitFor(() => expect(apply.mock.calls.some((c) => c[0] === LLAMA.path)).toBe(true))
+ await new Promise((r) => setTimeout(r, 300))
+ const toLlama = apply.mock.calls.filter((c) => c[0] === LLAMA.path)
+ expect(toLlama.map((c) => c[1])).toEqual([[]])
+ })
+
// T1 (3.0.9): the embedding model of Document Chat was the only choice,
// and the vector tool aborted on it.
it('offers chat models only, under a labelled picker', async () => {