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(chat): the Cloud switch is a money gate the send path enforces itself
purple35792ee884cf
diff --git a/src/components/layout/AppShell.tsx b/src/components/layout/AppShell.tsxindex 03b3e89b..803a215e 100644--- a/src/components/layout/AppShell.tsx+++ b/src/components/layout/AppShell.tsx@@ -118,7 +118,12 @@ export function AppShell() {const fallback = allModels.find((m) =>chatCapable(m) && (appMode === 'cloud' ? m.provider === 'lu-cloud' : m.provider !== 'lu-cloud'),)- if (fallback) setActiveModel(fallback.name)+ // No in-mode model to fall back to? Then the selection must CLEAR, not+ // silently stay on the old mode's model: a lu-cloud model left active in+ // Local mode kept billing credits after the switch said Local (Discord+ // bug-reports 2026-08-09, helpslowlydying). The send path refuses the+ // mismatch too, this just keeps the header honest.+ if (activeModel !== null || fallback) setActiveModel(fallback ? fallback.name : null)}, [appMode, allModels])// Local-hardware views (Models/Benchmark) don't exist in cloud mode — thediff --git a/src/hooks/useChat.ts b/src/hooks/useChat.tsindex 6f3a5442..9a43e387 100644--- a/src/hooks/useChat.ts+++ b/src/hooks/useChat.ts@@ -22,6 +22,7 @@ import { useAgentModeStore } from "../stores/agentModeStore"import { useGenerationStore } from "../stores/generationStore"import { resolveChatToolRoute, CHAT_TOOLS, type ChatToolRouteMsg } from "../lib/chat-tool-intent"import { getProviderForModel, getProviderIdFromModel } from "../api/providers"+import { modelOutOfMode } from "../lib/modeGate"import { syncOllamaHealthFromError } from "../lib/sync-ollama-health"import { isThinkingCompatible, isPlainTextPlanner } from "../lib/model-compatibility"import { stripNonCanonicalTags, finalStripThinkingTags } from "../lib/thinking-stripper"@@ -253,6 +254,18 @@ export function useChat() {const store = useChatStore.getState()const persona = useSettingsStore.getState().getActivePersona()+ // The Cloud switch is a MONEY gate, so the send path enforces it itself+ // instead of trusting the AppShell reselect effect: when that effect found+ // no in-mode fallback (Ollama down, engine off), the old mode's model+ // silently stayed active and every chat kept billing cloud credits with+ // the switch on Local (Discord bug-reports 2026-08-09, helpslowlydying).+ // A model from the wrong mode never reaches a provider: clear it and let+ // the picker's empty state ask for a real selection.+ if (modelOutOfMode(activeModel, settings.appMode)) {+ useModelStore.getState().setActiveModel(null)+ return+ }+// Agent mode delegation: if active for this conversation, use agent chat.//// 2.5.9: slash commands work here too. They were Code-only, which meant thediff --git a/src/lib/__tests__/modeGate.test.ts b/src/lib/__tests__/modeGate.test.tsnew file mode 100644index 00000000..0c5d939e--- /dev/null+++ b/src/lib/__tests__/modeGate.test.ts@@ -0,0 +1,63 @@+/**+ * E4 (Discord bug-reports 2026-08-09, helpslowlydying): flipping the Cloud+ * switch to Local with no local model installed left the lu-cloud model+ * silently active, and every chat kept billing cloud credits. The send path+ * now refuses any model from the wrong mode via modelOutOfMode, and the+ * AppShell reselect clears the selection when the new mode has no fallback.+ *+ * Run: npx vitest run src/lib/__tests__/modeGate.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 { modelOutOfMode } from '../modeGate'++const here = dirname(fileURLToPath(import.meta.url))+const read = (rel: string) => readFileSync(resolve(here, rel), 'utf8')++describe('modelOutOfMode: the money gate predicate', () => {+ it('blocks a lu-cloud model while the switch says Local (the reported bug)', () => {+ expect(modelOutOfMode('lu-cloud::moonshotai/Kimi-K3', 'local')).toBe(true)+ })++ it('NEGATIVE CONTROL: the same cloud model is fine in Cloud mode', () => {+ expect(modelOutOfMode('lu-cloud::moonshotai/Kimi-K3', 'cloud')).toBe(false)+ })++ it('blocks local models in Cloud mode (symmetric guard)', () => {+ expect(modelOutOfMode('qwen3:4b', 'cloud')).toBe(true) // Ollama, unprefixed+ expect(modelOutOfMode('openai::gemma-3-4b', 'cloud')).toBe(true) // built-in / LM Studio+ })++ it('NEGATIVE CONTROL: local models pass in Local mode', () => {+ expect(modelOutOfMode('qwen3:4b', 'local')).toBe(false)+ expect(modelOutOfMode('openai::gemma-3-4b', 'local')).toBe(false)+ })++ it('an empty selection is never out of mode (nothing to block)', () => {+ expect(modelOutOfMode(null, 'local')).toBe(false)+ expect(modelOutOfMode(undefined, 'cloud')).toBe(false)+ expect(modelOutOfMode('', 'local')).toBe(false)+ })+})++describe('wiring: the gate sits at the choke points', () => {+ it('sendMessage clears the selection and returns BEFORE any routing', () => {+ const src = read('../../hooks/useChat.ts')+ const guard = src.indexOf('modelOutOfMode(activeModel, settings.appMode)')+ const agentDelegation = src.indexOf('Agent mode delegation')+ expect(guard).toBeGreaterThan(-1)+ expect(agentDelegation).toBeGreaterThan(-1)+ // The guard must run before the agent/group/chat-tools routing, or a+ // wrong-mode model still reaches a provider through those paths.+ expect(guard).toBeLessThan(agentDelegation)+ expect(src.slice(guard, guard + 300)).toContain('setActiveModel(null)')+ })++ it('the AppShell reselect clears the selection when the new mode has no model', () => {+ const src = read('../../components/layout/AppShell.tsx')+ expect(src).toContain('setActiveModel(fallback ? fallback.name : null)')+ })+})diff --git a/src/lib/modeGate.ts b/src/lib/modeGate.tsnew file mode 100644index 00000000..5070745c--- /dev/null+++ b/src/lib/modeGate.ts@@ -0,0 +1,20 @@+import { getProviderIdFromModel } from '../api/providers'++/**+ * The Cloud switch is a MONEY gate: a model from the wrong mode must never+ * reach a provider. Discord bug-reports 2026-08-09 (helpslowlydying): with no+ * local model installed, flipping the switch to Local left the lu-cloud model+ * silently active and every chat kept billing credits. The AppShell reselect+ * keeps the header honest; this predicate is what the send path enforces.+ *+ * True = the selected model belongs to the OTHER mode and must not be used.+ * A null selection is never out of mode (there is nothing to block).+ */+export function modelOutOfMode(+ modelName: string | null | undefined,+ appMode: string | undefined,+): boolean {+ if (!modelName) return false+ const cloudSelected = getProviderIdFromModel(modelName) === 'lu-cloud'+ return cloudSelected !== (appMode === 'cloud')+}diff --git a/src/stores/modelStore.ts b/src/stores/modelStore.tsindex 63f952ed..9d29248b 100644--- a/src/stores/modelStore.ts+++ b/src/stores/modelStore.ts@@ -22,7 +22,7 @@ interface ModelState {isModelLoading: booleancategoryFilter: ModelCategorysetModels: (models: AIModel[]) => void- setActiveModel: (name: string) => void+ setActiveModel: (name: string | null) => voidstartPull: (name: string, controller: AbortController) => voidupdatePullProgress: (name: string, progress: PullProgress) => voidpausePull: (name: string) => void@@ -104,14 +104,16 @@ export const useModelStore = create<ModelState>()(backendCall('stop_bundled_engine').catch((e) =>log.warn('[modelStore] failed to stop built-in engine on switch-away', { err: e }),)- } else {+ } else if (name) {// built-in → DIFFERENT built-in: llama-server serves exactly ONE// gguf and ignores the request's model field, and the send-path// self-heal only revives a DEAD server — so without a swap right// here, a pick on the Models page would keep every chat silently// answering from the OLD model. The composer picker awaits this// same call itself before setting the store; Rust's argv- // idempotence turns that double-swap into a no-op.+ // idempotence turns that double-swap into a no-op. (A cleared+ // selection, name = null, has nothing to swap to; nextIsBuiltin+ // is false then anyway, this branch just spells it out for tsc.)activateBuiltinModel(name).catch((e) =>log.warn('[modelStore] failed to swap built-in engine to the picked model', { model: name, err: e }),)