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.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(models): K6 - Picker-Absturz beim Gruppieren faengt sich selbst ab
purple4bb2eeb555f2
diff --git a/src/components/models/ModelSelector.tsx b/src/components/models/ModelSelector.tsxindex 263e2b92..71c28c83 100644--- a/src/components/models/ModelSelector.tsx+++ b/src/components/models/ModelSelector.tsx@@ -35,6 +35,7 @@ import {} from '../../api/lu-engine-switch'import { tryAcquireLuEngineSwap, releaseLuEngineSwap, luEngineSwapInFlight, useLuEngineSwapRunning } from '../../api/lu-engine-swap-lock'import { HINWEIS_TEXT } from '../../lib/hinweis'+import { log } from '../../lib/logger'import { ModelPickerSkeleton } from '../layout/ViewSkeletons'import type { AIModel } from '../../types/models'import { MOTION_S } from '../ui/motion'@@ -389,6 +390,68 @@ function groupByFamily(models: AIModel[]): { family: string; models: AIModel[] }.map(([family, models]) => ({ family, models }))}+/**+ * K6 (3.0.1): GitHub #132, AppImage/Ubuntu 24.04 — "it adds models and then+ * breaks the selection field... it's fixed by restarting". Not reproduced in+ * this pass (no Linux box available, see proof doc), but a restart-only fix+ * for a component with no error boundary of its own is the exact signature+ * of an uncaught render throw: ChatView wraps the WHOLE chat area in one+ * ErrorBoundary (AppShell.tsx), so a single bad row breaking here during+ * grouping would take the entire chat view down with it, not just this+ * picker, and only a full remount (restart) clears a tripped React+ * error-boundary. Grouping freshly downloaded, not-yet-fully-normalized model+ * data is exactly the computation most likely to meet a field a fresh entry+ * does not carry yet.+ *+ * Extracted as its own pure function for the same reason as the LM Studio+ * helpers below: no test harness exists for the whole ModelSelector+ * component, and this is exactly the kind of decision that needs a+ * regression test more than it needs to stay physically inline.+ *+ * On success: real grouping, unchanged behaviour. On a throw: falls back to+ * one flat, ungrouped list (still fully usable — every model is still there+ * and still clickable) instead of letting the exception reach React and take+ * the whole chat view with it, and logs which models were in play so the+ * NEXT report carries a stack trace pointing at the real field instead of+ * nothing at all.+ */+export function computeModelGroups(+ textModels: AIModel[],+ luEngineHoldsChat: boolean,+ standbyName: string | null,+ holderName: string | null,+): { groups: { family: string; models: AIModel[] }[]; showHeadings: boolean; groupingFailed: boolean } {+ try {+ const wechsel = splitBackendSwitchRows(textModels, luEngineHoldsChat, standbyName, holderName)+ const groups: { family: string; models: AIModel[] }[] = [+ ...(wechsel.switching.length > 0 && wechsel.label+ ? [{ family: wechsel.label, models: wechsel.switching }]+ : []),+ // Das fremde Backend, das den Platz haelt, unter seinem eigenen Namen+ // statt verstreut ueber die Familien.+ ...(wechsel.holding.length > 0 && wechsel.holderLabel+ ? [{ family: wechsel.holderLabel, models: wechsel.holding }]+ : []),+ ...groupByFamily(wechsel.rest),+ ]+ // The one rule, asked rather than copied (second review): one group+ // normally draws no heading, except the switch group, where the heading+ // is the warning that picking from it moves the backend.+ const showHeadings = needsBackendSwitchHeading(groups.map((g) => g.family), wechsel.label)+ return { groups, showHeadings, groupingFailed: false }+ } catch (e) {+ log.error('[ModelSelector] grouping the model list threw, falling back to a flat ungrouped list', {+ err: e, modelCount: textModels.length,+ modelNames: textModels.slice(0, 20).map((m) => m.name),+ })+ return {+ groups: textModels.length > 0 ? [{ family: '', models: textModels }] : [],+ showHeadings: false,+ groupingFailed: true,+ }+ }+}+// ── LM Studio selection helpers (§18) ─────────────────────────//// Extracted as pure module-level functions so the select-time auto-load@@ -1131,22 +1194,12 @@ export function ModelSelector({ openUpward = false, surface = 'chat', answeredBy// wartenden Backends unter unserer eigenen Engine. Gibt es nichts zu// wechseln, gruppiert der Waehler nach Familie wie eh und je, denn dann gibt// es keine Folge zu melden und Abstammung ist, wonach Menschen waehlen.- const wechsel = splitBackendSwitchRows(textModels, luEngineHoldsChat, standbyName, holderName)- const groups: { family: string; models: AIModel[] }[] = [- ...(wechsel.switching.length > 0 && wechsel.label- ? [{ family: wechsel.label, models: wechsel.switching }]- : []),- // Das fremde Backend, das den Platz haelt, unter seinem eigenen Namen- // statt verstreut ueber die Familien.- ...(wechsel.holding.length > 0 && wechsel.holderLabel- ? [{ family: wechsel.holderLabel, models: wechsel.holding }]- : []),- ...groupByFamily(wechsel.rest),- ]- // The one rule, asked rather than copied (second review): one group normally- // draws no heading, except the switch group, where the heading is the- // warning that picking from it moves the backend.- const showHeadings = needsBackendSwitchHeading(groups.map((g) => g.family), wechsel.label)+ //+ // K6 (3.0.1): siehe computeModelGroups oben fuer die volle Begruendung, warum+ // dieser Schritt jetzt gegen einen Absturz gepanzert ist statt roh JSX zu+ // fuettern.+ const { groups, showHeadings, groupingFailed } =+ computeModelGroups(textModels, luEngineHoldsChat, standbyName, holderName)const hasOllamaModels = textModels.some(m => ('provider' in m && m.provider === 'ollama') || !('provider' in m))textModelsEmptyRef.current = textModels.length === 0@@ -1245,6 +1298,23 @@ export function ModelSelector({ openUpward = false, surface = 'chat', answeredBy</div>)}+ {/* K6: grouping threw and was caught above instead of crashing the+ whole chat view. Says so, in the dropdown itself, with a way+ to try again — the fallback list below still works, this is+ just honesty about why it looks flat. */}+ {groupingFailed && (+ <div className="px-2.5 py-1.5 border-b border-black/5 dark:border-white/[0.06] text-[0.55rem] text-amber-600 dark:text-amber-400 flex items-center justify-between gap-2">+ <span>Couldn't group the model list, showing it flat.</span>+ <button+ onClick={() => void fetchModels()}+ data-testid="model-grouping-retry"+ className="underline shrink-0"+ >+ Retry+ </button>+ </div>+ )}+{/* Say WHY the list is shorter here than in Chat, otherwise amissing favourite reads as a bug. */}{hiddenForCode > 0 && (diff --git a/src/components/models/__tests__/compute-model-groups-k6.test.ts b/src/components/models/__tests__/compute-model-groups-k6.test.tsnew file mode 100644index 00000000..7f931a99--- /dev/null+++ b/src/components/models/__tests__/compute-model-groups-k6.test.ts@@ -0,0 +1,92 @@+/**+ * K6 (3.0.1): GitHub locally-uncensored #132, AppImage/Ubuntu 24.04 —+ * "closing... it looks like it adds models and then breaks the selection+ * field... it's fixed by restarting". A restart-only fix for a component with+ * no error boundary of its own is the signature of an uncaught render throw:+ * ChatView wraps the WHOLE chat area in one ErrorBoundary, so one bad row+ * from a freshly finished download would take the entire chat view down,+ * and only a full remount clears a tripped error boundary.+ *+ * computeModelGroups is the extracted, testable core: grouping wrapped in a+ * try/catch that falls back to a flat list instead of throwing, with a log+ * line naming the models in play.+ *+ * Run: npx vitest run src/components/models/__tests__/compute-model-groups-k6.test.ts+ */+import { describe, it, expect, vi, beforeEach } from 'vitest'+import type { AIModel } from '../../../types/models'++vi.mock('../../../lib/logger', () => ({+ log: { error: vi.fn(), warn: vi.fn(), info: vi.fn(), debug: vi.fn() },+}))++// A deterministic stand-in for "something in the real grouping pipeline+// threw" — the point of this test is the try/catch in computeModelGroups+// itself, not any particular crash in splitBackendSwitchRows (which is+// defensively written elsewhere in this codebase; the mock proves the SAFETY+// NET works regardless of whether today's helper code happens to have a+// hole tomorrow — a freshly downloaded, not-yet-fully-normalized model entry+// is exactly the kind of value that could reach it).+let throwOnSplit = false+vi.mock('../../../lib/lu-engine-rows', async (importOriginal) => {+ const actual = await importOriginal<typeof import('../../../lib/lu-engine-rows')>()+ return {+ ...actual,+ splitBackendSwitchRows: (...args: Parameters<typeof actual.splitBackendSwitchRows>) => {+ if (throwOnSplit) throw new TypeError("Cannot read properties of undefined (reading 'toLowerCase')")+ return actual.splitBackendSwitchRows(...args)+ },+ }+})++const { computeModelGroups } = await import('../ModelSelector')++function textModel(name: string): AIModel {+ return {+ name, model: name, size: 0, digest: '', modified_at: '',+ details: { parent_model: '', format: '', family: '', families: [], parameter_size: '', quantization_level: '' },+ type: 'text', provider: 'ollama', providerName: 'Ollama',+ } as AIModel+}++describe('K6 — computeModelGroups never crashes the picker', () => {+ beforeEach(() => { vi.clearAllMocks(); throwOnSplit = false })++ it('groups normally when nothing throws', () => {+ const models = [textModel('qwen2.5-0.5b-instruct'), textModel('llama3.1:8b')]+ const { groups, groupingFailed } = computeModelGroups(models, false, null, null)+ expect(groupingFailed).toBe(false)+ expect(groups.flatMap((g) => g.models)).toHaveLength(2)+ })++ it('a throw during grouping falls back to one flat list instead of propagating', () => {+ throwOnSplit = true+ const models = [textModel('qwen2.5-0.5b-instruct'), textModel('llama3.1:8b')]+ expect(() => computeModelGroups(models, false, null, null)).not.toThrow()+ const { groups, groupingFailed, showHeadings } = computeModelGroups(models, false, null, null)+ expect(groupingFailed).toBe(true)+ expect(showHeadings).toBe(false)+ // Nothing is lost — the fallback is flat, not empty. This is the+ // difference between "the picker looks a little plain" and "the picker+ // (and with it the whole chat view, see ChatView's ErrorBoundary) is+ // gone until the user restarts the app".+ expect(groups).toHaveLength(1)+ expect(groups.flatMap((g) => g.models)).toHaveLength(2)+ })++ it('logs which models were in play, so the next report carries a real trace', async () => {+ throwOnSplit = true+ const { log } = await import('../../../lib/logger')+ computeModelGroups([textModel('broken-model')], false, null, null)+ expect(log.error).toHaveBeenCalledWith(+ expect.stringContaining('grouping the model list threw'),+ expect.objectContaining({ modelNames: ['broken-model'] }),+ )+ })++ it('an empty model list is not an error, just an empty result', () => {+ const { groups, groupingFailed } = computeModelGroups([], false, null, null)+ expect(groupingFailed).toBe(false)+ expect(groups).toEqual([])+ })+})