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(engine): the Built-in Engine row stops calling a stopped engine failed
purple0c54137a158d
diff --git a/src/api/__tests__/builtin-slot-probe.test.ts b/src/api/__tests__/builtin-slot-probe.test.tsnew file mode 100644index 00000000..dccd4753--- /dev/null+++ b/src/api/__tests__/builtin-slot-probe.test.ts@@ -0,0 +1,111 @@+/**+ * The second half of the #118 leftover: the reader, and the two places in+ * Settings, AI Backends that have to go through it.+ *+ * Counter-check on the real 2.6.7 Windows build (2026-08-29): the Built-in+ * Engine row read "Failed" right after app start, and the Test click that+ * disproved it first printed `GET http://127.0.0.1:8127/v1/models+ * net::ERR_CONNECTION_REFUSED` in the console. Both halves come from the same+ * habit of asking a port instead of asking the app that owns the process.+ *+ * The React half is asserted at the source level, the way+ * model-visible-wait.test.ts does it: mounting the whole settings tree around a+ * mocked engine would test the mock.+ *+ * Run: npx vitest run src/api/__tests__/builtin-slot-probe.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'++const backendCall = vi.fn<(cmd: string, args?: unknown) => Promise<unknown>>()+const localFetch = vi.fn()+vi.mock('../backend', () => ({+ backendCall: (...a: unknown[]) => backendCall(...(a as [string, unknown])),+ localFetch: (...a: unknown[]) => localFetch(...a),+ fetchExternal: vi.fn(),+}))++let managed = true+vi.mock('../../stores/providerStore', () => ({+ useProviderStore: { getState: () => ({ providers: { openai: { enabled: true, managed } } }) },+}))+vi.mock('../../stores/settingsStore', () => ({+ useSettingsStore: { getState: () => ({ settings: { builtinEngine: {} } }) },+}))++const { readBuiltinSlotStatus } = await import('../builtin-ensure')++beforeEach(() => {+ vi.clearAllMocks()+ managed = true+})++describe('readBuiltinSlotStatus — ask the app, not the port', () => {+ it('THE FIX: an engine that never started reads stopped, with no request sent', async () => {+ backendCall.mockResolvedValue({ running: false, healthy: false })+ expect(await readBuiltinSlotStatus()).toBe('stopped')+ expect(localFetch).not.toHaveBeenCalled()+ })++ it('a healthy engine reads connected, still with no request sent', async () => {+ backendCall.mockResolvedValue({ running: true, healthy: true })+ expect(await readBuiltinSlotStatus()).toBe('connected')+ expect(localFetch).not.toHaveBeenCalled()+ })++ it('up but not answering yet hands the question back to a real probe', async () => {+ backendCall.mockResolvedValue({ running: true, healthy: false })+ expect(await readBuiltinSlotStatus()).toBeNull()+ })++ it('a slot that is NOT the app-managed engine is none of our business', async () => {+ managed = false+ expect(await readBuiltinSlotStatus()).toBeNull()+ expect(backendCall).not.toHaveBeenCalled()+ })++ it('a backend that cannot answer decides nothing (browser and dev)', async () => {+ backendCall.mockRejectedValue(new Error('command not found'))+ expect(await readBuiltinSlotStatus()).toBeNull()+ })++ it('never answers failed, whatever the engine says', async () => {+ for (const answer of [{ running: false, healthy: false }, { running: true, healthy: false }, {}]) {+ backendCall.mockResolvedValue(answer)+ expect(await readBuiltinSlotStatus()).not.toBe('failed')+ }+ })+})++const here = dirname(fileURLToPath(import.meta.url))+const providerConfig = readFileSync(resolve(here, '../../components/settings/ProviderConfig.tsx'), 'utf8')++describe('the AI Backends row goes through that reader', () => {+ it('the mount check calls probeSlot, not checkConnection directly', () => {+ // The old loop was `const ok = await client.checkConnection()` inside the+ // mount effect, which is what stamped "Failed" on an engine nobody had+ // started yet.+ expect(providerConfig).toMatch(/const status = await probeSlot\(id\)/)+ expect(providerConfig).toMatch(/const probeSlot = async[\s\S]{0,400}readBuiltinSlotStatus\(\)/)+ })++ it('the Test click skips the doomed request when the engine is stopped', () => {+ expect(providerConfig).toMatch(+ /const stopped = providerId === 'openai' && \(await readBuiltinSlotStatus\(\)\) === 'stopped'/,+ )+ expect(providerConfig).toMatch(/if \(!stopped\) \{[\s\S]{0,200}checkConnection\(\)/)+ })++ it('there is a "Not running" state and it is not painted as a failure', () => {+ expect(providerConfig).toContain('Not running')+ expect(providerConfig).toMatch(/status === 'stopped' \? 'bg-amber-500'/)+ })++ it('the user-facing strings on this row are English', () => {+ for (const s of ['Not running', 'Connected', 'Failed']) {+ expect(providerConfig).toContain(s)+ }+ })+})diff --git a/src/api/builtin-ensure.ts b/src/api/builtin-ensure.tsindex 92b3d6f4..6d23195e 100644--- a/src/api/builtin-ensure.ts+++ b/src/api/builtin-ensure.ts@@ -17,6 +17,7 @@import { backendCall } from './backend'import { useProviderStore } from '../stores/providerStore'import { useSettingsStore } from '../stores/settingsStore'+import { builtinSlotStatus, type SlotStatus } from '../lib/builtin-slot-status'import { AGENT_CONTEXT_CAP } from '../lib/context-window'interface EngineStatusLite {@@ -204,6 +205,22 @@ export async function ensureBuiltinAgentCtx(modelName: string): Promise<void> {}}+// ── What the AI Backends row may say before anyone probed ────────────────────++/** Ask the app about its own engine, without a socket.+ *+ * Returns null when this slot is not the managed built-in engine, when the+ * backend command is unavailable (browser/dev), or when the answer does not+ * settle the question. The caller then probes as it always did. */+export async function readBuiltinSlotStatus(): Promise<SlotStatus | null> {+ if (!isManagedBuiltinSlot()) return null+ try {+ return builtinSlotStatus(await backendCall<EngineStatusLite>('bundled_engine_status'))+ } catch {+ return null+ }+}+// ── "Why is the built-in engine not answering?" ──────────────────────────────export interface BuiltinEngineDiagnosis {diff --git a/src/components/settings/ProviderConfig.tsx b/src/components/settings/ProviderConfig.tsxindex d5fb1b1e..6c037941 100644--- a/src/components/settings/ProviderConfig.tsx+++ b/src/components/settings/ProviderConfig.tsx@@ -6,7 +6,8 @@ import { getProvider } from '../../api/providers'import { PROVIDER_PRESETS } from '../../api/providers/types'import { Modal } from '../ui/Modal'import { backendCall } from '../../api/backend'-import { diagnoseBuiltinEngine } from '../../api/builtin-ensure'+import { diagnoseBuiltinEngine, readBuiltinSlotStatus } from '../../api/builtin-ensure'+import type { SlotStatus } from '../../lib/builtin-slot-status'import type { ProviderId, ProviderConfig } from '../../api/providers/types'const isTauri = typeof window !== 'undefined' && !!(window as any).__TAURI_INTERNALS__@@ -87,7 +88,7 @@ export function ProviderSettings() {const { providers, setProviderConfig, setProviderApiKey, getProviderApiKey } = useProviderStore()const [dropdownOpen, setDropdownOpen] = useState(false)const [testing, setTesting] = useState<ProviderId | null>(null)- const [statuses, setStatuses] = useState<Record<string, 'idle' | 'connected' | 'failed'>>({})+ const [statuses, setStatuses] = useState<Record<string, SlotStatus>>({})// Per-slot English explanation for a failed Test (GH #118).const [testDetail, setTestDetail] = useState<Record<string, string>>({})const [showKey, setShowKey] = useState<Record<string, boolean>>({})@@ -109,6 +110,28 @@ export function ProviderSettings() {} catch { /* command unavailable on older builds — leave null */ }}+ // One status for one slot, and never a verdict nobody earned.+ //+ // GH #118 leftover, counter-check 2026-08-29: right after app start, with no+ // chat model loaded, this row read "Failed" for the app's OWN engine, and+ // the click that disproved it printed ERR_CONNECTION_REFUSED on 127.0.0.1:8127+ // in the console first. The app starts that process itself, so it can simply+ // ask whether it runs. An engine that was never started is "Not running",+ // which is a true sentence and also a different one from "Failed".+ const probeSlot = async (id: ProviderId): Promise<SlotStatus> => {+ if (id === 'openai') {+ const known = await readBuiltinSlotStatus()+ // 'connected' or 'stopped' answers it without touching a socket. Only an+ // engine that is up but not yet answering falls through to a real probe.+ if (known) return known+ }+ try {+ return (await getProvider(id).checkConnection()) ? 'connected' : 'failed'+ } catch {+ return 'failed'+ }+ }+// Auto-check connection status for all enabled providers on mount.// Also probe lmstudio_server_status so the inline "Start Server"// affordance is correct from first render, not just after a Test click.@@ -116,13 +139,8 @@ export function ProviderSettings() {const checkAll = async () => {const ids = (Object.keys(providers) as ProviderId[]).filter(id => providers[id].enabled)for (const id of ids) {- try {- const client = getProvider(id)- const ok = await client.checkConnection()- setStatuses(prev => ({ ...prev, [id]: ok ? 'connected' : 'failed' }))- } catch {- setStatuses(prev => ({ ...prev, [id]: 'failed' }))- }+ const status = await probeSlot(id)+ setStatuses(prev => ({ ...prev, [id]: status }))}await refreshLmStudioInfo()}@@ -170,11 +188,17 @@ export function ProviderSettings() {setStatuses(prev => ({ ...prev, [providerId]: 'idle' }))setTestDetail(prev => ({ ...prev, [providerId]: '' }))let ok = false- try {- const client = getProvider(providerId)- ok = await client.checkConnection()- } catch {- ok = false+ // A stopped engine is a thing to start, not a thing to probe. Skipping the+ // doomed request is what keeps ERR_CONNECTION_REFUSED out of the console+ // on the way to a green dot (GH #118).+ const stopped = providerId === 'openai' && (await readBuiltinSlotStatus()) === 'stopped'+ if (!stopped) {+ try {+ const client = getProvider(providerId)+ ok = await client.checkConnection()+ } catch {+ ok = false+ }}// GH #118: a red dot was the whole answer the built-in engine gave, while// the console carried ERR_CONNECTION_REFUSED on 127.0.0.1:8127. The app@@ -264,6 +288,7 @@ export function ProviderSettings() {<span className={`w-1.5 h-1.5 rounded-full shrink-0 ${status === 'connected' ? 'bg-green-500' :status === 'failed' ? 'bg-red-500' :+ status === 'stopped' ? 'bg-amber-500' :'bg-gray-500'}`} /><span className="text-[0.65rem] text-gray-300 font-medium truncate">{view.label}</span>@@ -272,6 +297,7 @@ export function ProviderSettings() {{!config.isLocal && <span className="text-[0.5rem] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400 shrink-0">CLOUD</span>}{status === 'connected' && <Wifi size={8} className="text-green-400 shrink-0" />}{status === 'failed' && <WifiOff size={8} className="text-red-400 shrink-0" />}+ {status === 'stopped' && <WifiOff size={8} className="text-amber-400 shrink-0" />}</div><ChevronDown size={10} className={`text-gray-500 transition-transform shrink-0 ${isExpanded ? 'rotate-180' : ''}`} /></button>@@ -368,6 +394,14 @@ export function ProviderSettings() {<WifiOff size={10} /> Failed</span>)}+ {status === 'stopped' && (+ <span+ className="flex items-center gap-1 text-[0.6rem] text-amber-400"+ title="The engine is installed but not started yet. It starts when you pick a chat model, or when you press Test."+ >+ <WifiOff size={10} /> Not running+ </span>+ )}</div>{/* Why it failed, when the app can tell (GH #118). */}diff --git a/src/lib/__tests__/builtin-slot-status.test.ts b/src/lib/__tests__/builtin-slot-status.test.tsnew file mode 100644index 00000000..1a9fa2d0--- /dev/null+++ b/src/lib/__tests__/builtin-slot-status.test.ts@@ -0,0 +1,53 @@+/**+ * GH #118 leftover, from the counter-check on the real 2.6.7 Windows build+ * (2026-08-29): Settings, AI Backends showed the Built-in Engine as "Failed"+ * straight after app start with no chat model loaded. The Test click then put+ * `GET http://127.0.0.1:8127/v1/models net::ERR_CONNECTION_REFUSED` in the+ * console and flipped the very same row to "Connected". The engine was fine.+ *+ * These pin the rule the row follows now: a verdict of failure only ever comes+ * from a probe that actually ran, and an engine the app has not started yet is+ * reported as not running.+ *+ * Run: npx vitest run src/lib/__tests__/builtin-slot-status.test.ts+ */+import { describe, it, expect } from 'vitest'+import { builtinSlotStatus } from '../builtin-slot-status'++describe('builtinSlotStatus — what the row may claim without a socket', () => {+ it('THE FIX: an engine that was never started reads "not running", not "failed"', () => {+ expect(builtinSlotStatus({ running: false, healthy: false })).toBe('stopped')+ })++ it('a healthy engine is connected, with no request to a port at all', () => {+ expect(builtinSlotStatus({ running: true, healthy: true })).toBe('connected')+ })++ it('up but not answering yet is the one case worth a real probe', () => {+ // The child is alive and the port may still be binding. Guessing either+ // way here is how the wrong verdict got made in the first place.+ expect(builtinSlotStatus({ running: true, healthy: false })).toBeNull()+ })++ it('no answer from the backend decides nothing', () => {+ expect(builtinSlotStatus(null)).toBeNull()+ expect(builtinSlotStatus(undefined)).toBeNull()+ })++ it('never returns "failed" on its own, whatever it is handed', () => {+ const cases = [+ { running: false, healthy: false },+ { running: true, healthy: false },+ { running: true, healthy: true },+ { running: false, healthy: true },+ {},+ null,+ undefined,+ ]+ for (const c of cases) expect(builtinSlotStatus(c)).not.toBe('failed')+ })++ it('an empty answer is treated as not running, not as broken', () => {+ expect(builtinSlotStatus({})).toBe('stopped')+ })+})diff --git a/src/lib/builtin-slot-status.ts b/src/lib/builtin-slot-status.tsnew file mode 100644index 00000000..11b526b3--- /dev/null+++ b/src/lib/builtin-slot-status.ts@@ -0,0 +1,44 @@+/**+ * What the AI Backends list may say about the app's own built-in engine+ * BEFORE anyone has probed it.+ *+ * GH #118 leftover, found by the counter-check on the real 2.6.7 build+ * (2026-08-29): Settings, AI Backends showed the Built-in Engine as "Failed"+ * straight after app start, with no model loaded. A click on Test then put+ * `GET http://127.0.0.1:8127/v1/models net::ERR_CONNECTION_REFUSED` in the+ * console and flipped the same row to "Connected". The engine was healthy the+ * whole time. The display was wrong twice: it called an engine that had never+ * been started a failure, and it produced a red console line to find that out.+ *+ * A server the app has not started yet is not a failed server. The app owns+ * that process and can ask the Rust side whether it runs, which costs no+ * socket and cannot be refused by a port nobody is listening on. Only when+ * that answer is ambiguous is a real probe worth making.+ */++export type SlotStatus = 'idle' | 'connected' | 'failed' | 'stopped'++/** The engine status the Rust `bundled_engine_status` command returns. */+export interface EngineHealth {+ running?: boolean+ healthy?: boolean+}++/**+ * The status the built-in slot may claim from the engine answer alone.+ *+ * - healthy -> 'connected', it is answering right now+ * - not running -> 'stopped', nothing to fail yet+ * - running, unhealthy -> null, the process is up and the port may still be+ * binding, so this one IS worth a real probe+ * - no answer at all -> null, we know nothing, fall back to the probe+ *+ * Never returns 'failed': a verdict of failure has to come from a probe that+ * actually ran.+ */+export function builtinSlotStatus(engine: EngineHealth | null | undefined): SlotStatus | null {+ if (!engine) return null+ if (engine.healthy) return 'connected'+ if (engine.running) return null+ return 'stopped'+}