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(models): no counter states a zero it has not counted

purpleedc8ec887579
diff --git a/src/components/models/ModelManager.tsx b/src/components/models/ModelManager.tsx
index 827787c6..b39bf12c 100644
--- a/src/components/models/ModelManager.tsx
+++ b/src/components/models/ModelManager.tsx
@@ -17,6 +17,7 @@ import { checkComfyConnection, refreshComfyModels } from '../../api/comfyui'
import { isMlxImageHost } from '../../api/mlx-image'
import { MlxMediaSettings } from '../settings/MlxMediaSettings'
import { backendCall } from '../../api/backend'
+import { counterView } from '../../lib/inventory-counter'
import type { ModelCategory, AIModel } from '../../types/models'
// One category drives BOTH views (Discover + Installed) — the old split
@@ -31,8 +32,27 @@ const RAIL_ITEMS: { key: Mode; label: string; icon: typeof MessagesSquare }[] =
{ key: 'video', label: 'Video', icon: Clapperboard },
]
+/** The mark a counter wears while it has nothing counted to show. Not a 0:
+ * a 0 next to a card that reads Installed is a wrong answer, and this one
+ * stood for five seconds on the real box (Befund 2, 2026-08-29). */
+function CountingDots({ label }: { label: string }) {
+ return (
+ <span
+ className="text-[0.55rem] font-normal opacity-50 animate-pulse"
+ role="status"
+ aria-label={label}
+ title={label}
+ >
+ &middot;&middot;&middot;
+ </span>
+ )
+}
+
export function ModelManager() {
- const { models, activeModel, setActiveModel, fetchModels, removeModel, categoryFilter, setCategoryFilter } = useModels()
+ const {
+ models, activeModel, setActiveModel, fetchModels, removeModel,
+ categoryFilter, setCategoryFilter, inventoryLoaded, inventoryRefreshing,
+ } = useModels()
const { setView } = useUIStore()
const ollamaEnabled = useProviderStore(s => s.providers.ollama.enabled)
const [pullOpen, setPullOpen] = useState(false)
@@ -109,6 +129,9 @@ export function ModelManager() {
const filteredModels = models.filter((m: AIModel) => m.type === mode)
const modeMeta = RAIL_ITEMS.find(r => r.key === mode)!
+ // One rule for the rail badges and the Installed badge, so the two can
+ // never again disagree about what an uncounted lane looks like.
+ const inventoryState = { loaded: inventoryLoaded, refreshing: inventoryRefreshing }
// d37d7bf5 + neejuh (2.5.5): "models show installed in Discover but the
// Installed tab is empty and I can't select them." Image/video models are
@@ -142,7 +165,7 @@ export function ModelManager() {
<aside className="shrink-0 w-12 lg:w-36 border-r border-gray-200 dark:border-white/[0.06] bg-gray-50/60 dark:bg-white/[0.015] flex flex-col py-3 px-1.5 lg:px-2 gap-1">
{RAIL_ITEMS.map(({ key, label, icon: Icon }) => {
const active = mode === key
- const count = models.filter((m) => m.type === key).length
+ const badge = counterView(models.filter((m) => m.type === key).length, inventoryState)
return (
<button
key={key}
@@ -159,9 +182,13 @@ export function ModelManager() {
<span className={`hidden lg:block text-[0.68rem] font-medium ${active ? 'text-gray-900 dark:text-white' : 'text-gray-500 dark:text-gray-400'}`}>
{label}
</span>
- {count > 0 && (
- <span className="hidden lg:block ml-auto text-[0.55rem] text-gray-400 dark:text-gray-500 tabular-nums">{count}</span>
- )}
+ {badge.kind === 'loading' ? (
+ <span className="hidden lg:block ml-auto">
+ <CountingDots label={`Counting installed ${label.toLowerCase()} models`} />
+ </span>
+ ) : badge.value > 0 ? (
+ <span className="hidden lg:block ml-auto text-[0.55rem] text-gray-400 dark:text-gray-500 tabular-nums">{badge.value}</span>
+ ) : null}
</button>
)
})}
@@ -210,7 +237,14 @@ export function ModelManager() {
}`}
>
<HardDrive size={11} /> Installed
- <span className="text-[0.55rem] font-normal opacity-70 tabular-nums">{filteredModels.length}</span>
+ {(() => {
+ const badge = counterView(filteredModels.length, inventoryState)
+ return badge.kind === 'loading' ? (
+ <CountingDots label="Counting installed models" />
+ ) : (
+ <span className="text-[0.55rem] font-normal opacity-70 tabular-nums">{badge.value}</span>
+ )
+ })()}
</button>
</div>
@@ -265,7 +299,14 @@ export function ModelManager() {
{!showMlxPanel && tab === 'installed' && (
<>
- {imageOrVideo && filteredModels.length === 0 && comfyReachable !== true ? (
+ {counterView(filteredModels.length, inventoryState).kind === 'loading' ? (
+ // The empty state is the same claim the counter makes, in
+ // words: you own none of these. It waits for the count for
+ // the same reason (Befund 2, abnahme counter-check).
+ <div className="text-center py-16 px-6">
+ <p className="text-[0.7rem] text-gray-500">Reading your installed models…</p>
+ </div>
+ ) : imageOrVideo && filteredModels.length === 0 && comfyReachable !== true ? (
// comfyReachable: null = still probing, false = confirmed down.
// Never show the misleading "no models installed" here while the
// probe is pending — on desktop checkComfyConnection has to time
diff --git a/src/hooks/useModels.ts b/src/hooks/useModels.ts
index 984d6c91..25136d57 100644
--- a/src/hooks/useModels.ts
+++ b/src/hooks/useModels.ts
@@ -62,6 +62,7 @@ async function resumeEmbedServer(bundled: BundledModel[]) {
export function useModels() {
const {
models: allModels, activeModel, activePulls, categoryFilter,
+ inventoryLoaded, inventoryRefreshes,
setModels, setActiveModel, startPull, updatePullProgress,
pausePull, completePull, dismissPull, setCategoryFilter,
} = useModelStore()
@@ -103,6 +104,12 @@ export function useModels() {
}, [])
const fetchModels = useCallback(async () => {
+ // Announced before the first await, cleared in the finally below. A
+ // counter reading 0 while this is up has not counted anything yet and
+ // says so instead of stating a number (Befund 2, abnahme counter-check
+ // 2026-08-29: the Models page opened on "Installed 0" beside three
+ // Installed cards, and was right again five seconds later).
+ useModelStore.getState().beginInventoryRefresh()
try {
const allModels: AIModel[] = []
// Built-in engine (2.5.7): when the managed OpenAI-compat backend is the
@@ -238,6 +245,8 @@ export function useModels() {
setModels([...allModels, ...comfyModels])
} catch (err) {
log.warn('[useModels] Model list refresh failed', { err })
+ } finally {
+ useModelStore.getState().endInventoryRefresh()
}
}, [setModels])
@@ -354,6 +363,9 @@ export function useModels() {
return {
models, activeModel, activePulls, isPulling, categoryFilter,
+ // What the counters need to tell "nothing installed" apart from "not
+ // counted yet". See lib/inventory-counter.ts.
+ inventoryLoaded, inventoryRefreshing: inventoryRefreshes > 0,
fetchModels, pullModel, pausePull, dismissPull,
removeModel, setActiveModel: activateModel, setCategoryFilter, getFilteredModels, isPullingModel,
}
diff --git a/src/lib/__tests__/inventory-counter.test.ts b/src/lib/__tests__/inventory-counter.test.ts
new file mode 100644
index 00000000..a8c71a32
--- /dev/null
+++ b/src/lib/__tests__/inventory-counter.test.ts
@@ -0,0 +1,80 @@
+/**
+ * Befund 2 of the abnahme counter-check on the 2.6.7 Windows build
+ * (2026-08-29, ergebnis-abnahme-durchklick.md).
+ *
+ * Opening the Models page showed the Installed tab reading "Installed 0" while
+ * three cards on the same page read Installed, and the rail carried "Chat 2"
+ * with no badge for Image and none for Video. Measured again after a restart:
+ * at 1.2 seconds the two badges were still missing, at 5.2 seconds they were
+ * right. Nothing stayed wrong. But for those seconds the page stated a number
+ * it had not counted, and a stated zero is a claim: you own none of these.
+ *
+ * The rule: a counter shows a number only once there is a number. Until then
+ * it shows that it is counting.
+ *
+ * Run: npx vitest run src/lib/__tests__/inventory-counter.test.ts
+ */
+import { describe, it, expect } from 'vitest'
+import { readFileSync } from 'node:fs'
+import { fileURLToPath } from 'node:url'
+import { dirname, resolve } from 'node:path'
+import { counterView } from '../inventory-counter'
+
+const here = dirname(fileURLToPath(import.meta.url))
+const manager = readFileSync(resolve(here, '../../components/models/ModelManager.tsx'), 'utf8')
+
+describe('a counter never states a number it has not counted', () => {
+ it('THE FIX: nothing loaded yet is a loading mark, not a 0', () => {
+ expect(counterView(0, { loaded: false, refreshing: false })).toEqual({ kind: 'loading' })
+ expect(counterView(0, { loaded: false, refreshing: true })).toEqual({ kind: 'loading' })
+ })
+
+ it('THE FIX: the exact counter-check frame, a lane still being read', () => {
+ // A first pass landed (chat models arrived, hence loaded) while a second
+ // is still running for the ComfyUI lanes. That is the 1.2-second frame.
+ expect(counterView(0, { loaded: true, refreshing: true })).toEqual({ kind: 'loading' })
+ })
+
+ it('a counted zero is shown, because then it is the truth', () => {
+ expect(counterView(0, { loaded: true, refreshing: false })).toEqual({ kind: 'count', value: 0 })
+ })
+
+ it('a number that exists is shown immediately, refresh or not', () => {
+ // The 5.2-second frame, and every frame after it.
+ expect(counterView(3, { loaded: true, refreshing: false })).toEqual({ kind: 'count', value: 3 })
+ expect(counterView(3, { loaded: true, refreshing: true })).toEqual({ kind: 'count', value: 3 })
+ // And a stale-but-real count beats a loading mark even before the first
+ // list of this session landed: a number on screen is never hidden.
+ expect(counterView(8, { loaded: false, refreshing: true })).toEqual({ kind: 'count', value: 8 })
+ })
+
+ it('NEGATIVE CONTROL: a settled empty inventory is not dressed up as loading forever', () => {
+ // ComfyUI is simply not installed. The page has to be allowed to say 0,
+ // or the spinner becomes the new lie.
+ expect(counterView(0, { loaded: true, refreshing: false }).kind).toBe('count')
+ })
+})
+
+describe('the Models page routes both counters through the one rule', () => {
+ it('the rail badge asks counterView', () => {
+ expect(manager).toMatch(/const badge = counterView\(models\.filter\(\(m\) => m\.type === key\)\.length, inventoryState\)/)
+ })
+
+ it('the Installed badge asks counterView', () => {
+ expect(manager).toMatch(/counterView\(filteredModels\.length, inventoryState\)/)
+ })
+
+ it('NEGATIVE CONTROL: neither counter prints a bare list length any more', () => {
+ // This is the shape that put "Installed 0" on the screen.
+ expect(manager).not.toMatch(/tabular-nums">\{filteredModels\.length\}</)
+ expect(manager).not.toMatch(/\{count > 0 && \(/)
+ })
+
+ it('the empty state waits for the count too, because it makes the same claim', () => {
+ expect(manager).toContain('Reading your installed models')
+ })
+
+ it('the loading mark carries a label, so it is not a mute flicker', () => {
+ expect(manager).toMatch(/aria-label=\{label\}/)
+ })
+})
diff --git a/src/lib/inventory-counter.ts b/src/lib/inventory-counter.ts
new file mode 100644
index 00000000..1898dd70
--- /dev/null
+++ b/src/lib/inventory-counter.ts
@@ -0,0 +1,38 @@
+/**
+ * What a model counter is allowed to show while the inventory is still being
+ * read.
+ *
+ * Befund 2 of the abnahme counter-check on the 2.6.7 Windows build
+ * (2026-08-29): opening the Models page showed "Installed 0" next to three
+ * cards that read Installed, and the rail carried no Image and no Video badge
+ * at all. At 1.2 seconds the badges were still missing, at 5.2 seconds they
+ * were right. Nothing was ever wrong for long, but for those seconds the page
+ * stated a number it had not counted, and a stated zero is a claim: you own
+ * none of these.
+ *
+ * A counter may only show a number it has counted. Until then it shows that
+ * it is counting. The rail keeps hiding a settled zero, as it always did.
+ */
+export type CounterView =
+ /** Nothing has been counted yet. Show a loading mark, never a number. */
+ | { kind: 'loading' }
+ /** Counted. `value` may be 0, and then it is the truth. */
+ | { kind: 'count'; value: number }
+
+export interface InventoryState {
+ /** Has a model list ever landed in the store. */
+ loaded: boolean
+ /** Is a refresh running right now. A second pass is what brings the ComfyUI
+ * lanes in: the engine is often not up yet on the first one. */
+ refreshing: boolean
+}
+
+/**
+ * A count is shown as soon as there is something to show. A zero is only ever
+ * shown once no refresh can still turn it into something else.
+ */
+export function counterView(count: number, state: InventoryState): CounterView {
+ if (count > 0) return { kind: 'count', value: count }
+ if (!state.loaded || state.refreshing) return { kind: 'loading' }
+ return { kind: 'count', value: 0 }
+}
diff --git a/src/stores/__tests__/modelStore-inventory-loading.test.ts b/src/stores/__tests__/modelStore-inventory-loading.test.ts
new file mode 100644
index 00000000..2b145cf6
--- /dev/null
+++ b/src/stores/__tests__/modelStore-inventory-loading.test.ts
@@ -0,0 +1,102 @@
+/**
+ * Befund 2 of the abnahme counter-check (2026-08-29), store side.
+ *
+ * The counters on the Models page can only refuse to state an uncounted zero
+ * if the store knows two things: whether a list has ever landed, and whether
+ * a read is running right now. The second one is a number and not a flag on
+ * purpose: fetchModels runs from several mounted components at once, and the
+ * first one to return must not declare the count settled while the slow one,
+ * the one that actually waits on ComfyUI, is still out.
+ *
+ * Run: npx vitest run src/stores/__tests__/modelStore-inventory-loading.test.ts
+ */
+import { describe, it, expect, vi, beforeEach } from 'vitest'
+import { readFileSync } from 'node:fs'
+import { fileURLToPath } from 'node:url'
+import { dirname, resolve } from 'node:path'
+
+vi.mock('@tauri-apps/api/core', () => ({ invoke: vi.fn(async () => undefined) }))
+vi.mock('../../api/backend', () => ({
+ isTauri: vi.fn(() => false),
+ backendCall: vi.fn(async () => undefined),
+}))
+vi.mock('../../api/ollama', () => ({ unloadModel: vi.fn(async () => undefined) }))
+vi.mock('../../api/lmstudio', () => ({ unloadLmStudioModel: vi.fn(async () => undefined) }))
+vi.mock('../../api/engine', () => ({ activateBuiltinModel: vi.fn(async () => undefined) }))
+
+import { useModelStore } from '../modelStore'
+import { counterView } from '../../lib/inventory-counter'
+
+const hook = readFileSync(
+ resolve(dirname(fileURLToPath(import.meta.url)), '../../hooks/useModels.ts'),
+ 'utf8',
+)
+
+const chat = (name: string) => ({
+ name, model: name, size: 0, type: 'text' as const,
+ provider: 'openai' as const, providerName: 'Built-in Engine',
+})
+
+beforeEach(() => {
+ useModelStore.setState({
+ models: [], activeModel: null, inventoryLoaded: false, inventoryRefreshes: 0,
+ })
+})
+
+describe('the store knows whether anything has been counted', () => {
+ it('a fresh store has counted nothing', () => {
+ const s = useModelStore.getState()
+ expect(s.inventoryLoaded).toBe(false)
+ expect(counterView(0, { loaded: s.inventoryLoaded, refreshing: s.inventoryRefreshes > 0 }).kind)
+ .toBe('loading')
+ })
+
+ it('THE FIX: an empty list that really landed is counted, and shows as 0', () => {
+ useModelStore.getState().setModels([])
+ const s = useModelStore.getState()
+ expect(s.inventoryLoaded).toBe(true)
+ expect(counterView(0, { loaded: s.inventoryLoaded, refreshing: s.inventoryRefreshes > 0 }))
+ .toEqual({ kind: 'count', value: 0 })
+ })
+
+ it('two overlapping reads: the count stays uncounted until the LAST one is back', () => {
+ const s = useModelStore.getState()
+ s.beginInventoryRefresh()
+ s.beginInventoryRefresh()
+ // The fast pass returns with the chat models. ComfyUI is still being read.
+ useModelStore.getState().setModels([chat('openai::Hermes-3-Llama-3.2-3B.Q4_K_M')])
+ useModelStore.getState().endInventoryRefresh()
+ const mid = useModelStore.getState()
+ expect(mid.inventoryRefreshes).toBe(1)
+ // This is the 1.2-second frame on the box: Chat 2, no Image badge.
+ expect(counterView(0, { loaded: mid.inventoryLoaded, refreshing: mid.inventoryRefreshes > 0 }).kind)
+ .toBe('loading')
+
+ useModelStore.getState().endInventoryRefresh()
+ const end = useModelStore.getState()
+ expect(end.inventoryRefreshes).toBe(0)
+ expect(counterView(0, { loaded: end.inventoryLoaded, refreshing: end.inventoryRefreshes > 0 }))
+ .toEqual({ kind: 'count', value: 0 })
+ })
+
+ it('NEGATIVE CONTROL: the in-flight count never goes below zero', () => {
+ // An unbalanced end would otherwise leave a permanent negative and every
+ // later refresh would read as "not running".
+ const s = useModelStore.getState()
+ s.endInventoryRefresh()
+ s.endInventoryRefresh()
+ expect(useModelStore.getState().inventoryRefreshes).toBe(0)
+ s.beginInventoryRefresh()
+ expect(useModelStore.getState().inventoryRefreshes).toBe(1)
+ })
+})
+
+describe('the refresh marker is raised and lowered around the whole read', () => {
+ it('fetchModels announces itself before the first await', () => {
+ expect(hook).toMatch(/beginInventoryRefresh\(\)\s*\n\s*try \{/)
+ })
+
+ it('NEGATIVE CONTROL: it is lowered in a finally, so a thrown read cannot pin the mark up', () => {
+ expect(hook).toMatch(/\} finally \{\s*\n\s*useModelStore\.getState\(\)\.endInventoryRefresh\(\)/)
+ })
+})
diff --git a/src/stores/modelStore.ts b/src/stores/modelStore.ts
index 9d29248b..6969ca79 100644
--- a/src/stores/modelStore.ts
+++ b/src/stores/modelStore.ts
@@ -21,6 +21,16 @@ interface ModelState {
activePulls: Record<string, PullState>
isModelLoading: boolean
categoryFilter: ModelCategory
+ /** Has a model list ever landed here. A counter must show a loading mark
+ * until it has, never a 0 (Befund 2 of the abnahme counter-check
+ * 2026-08-29: "Installed 0" next to three Installed cards). */
+ inventoryLoaded: boolean
+ /** How many inventory refreshes are in flight. A number, not a flag,
+ * because fetchModels is called from several mounted components at once
+ * and the first one to finish must not declare the count settled. */
+ inventoryRefreshes: number
+ beginInventoryRefresh: () => void
+ endInventoryRefresh: () => void
setModels: (models: AIModel[]) => void
setActiveModel: (name: string | null) => void
startPull: (name: string, controller: AbortController) => void
@@ -40,6 +50,12 @@ export const useModelStore = create<ModelState>()(
activePulls: {},
isModelLoading: false,
categoryFilter: 'all',
+ inventoryLoaded: false,
+ inventoryRefreshes: 0,
+
+ beginInventoryRefresh: () => set((state) => ({ inventoryRefreshes: state.inventoryRefreshes + 1 })),
+ endInventoryRefresh: () =>
+ set((state) => ({ inventoryRefreshes: Math.max(0, state.inventoryRefreshes - 1) })),
setModels: (models) =>
set((state) => {
@@ -59,6 +75,7 @@ export const useModelStore = create<ModelState>()(
const firstChat = models.find((m) => m.type !== 'image' && m.type !== 'video')
return {
models,
+ inventoryLoaded: true,
activeModel: stillValid
? state.activeModel
: (firstChat ? firstChat.name : null),