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(update): free our own engine before the installer, on every lane
Davidca071a86fb84
diff --git a/src/stores/__tests__/update-frees-the-sidecar.test.ts b/src/stores/__tests__/update-frees-the-sidecar.test.tsnew file mode 100644index 00000000..b1d1a5f5--- /dev/null+++ b/src/stores/__tests__/update-frees-the-sidecar.test.ts@@ -0,0 +1,105 @@+/**+ * The update path has to free our own engine before the installer runs.+ *+ * C4 came from aldrich_ironhart on 2026-08-10: the update stopped at "Error+ * opening file for writing: llama-server.exe" with Abort, Retry, Ignore.+ * Windows locks a running image against writes and that file lives in the+ * install directory. The fix went into the NSIS hook, and on 2026-08-15 the+ * installed build was measured to really take the NSIS lane: the exe carries+ * `__TAURI_BUNDLE_TYPE_VAR_NSS`, so the updater asks for `windows-x86_64-nsis`+ * first, which our latest.json carries.+ *+ * That covers the .exe. It does not cover the .msi, which our own release notes+ * offer for system-wide installs: a machine that installed it reports the MSI+ * bundle type, gets the MSI update, and WiX has no hook of ours. The `exit_app`+ * in this store is no substitute either, because it runs AFTER install() has+ * handed over to the installer.+ *+ * So the app stops its own sidecars first, on every lane. This test pins the+ * ORDER, which is the whole point: stopping them after the installer starts+ * would be the same bug with extra steps.+ *+ * Run: npx vitest run src/stores/__tests__/update-frees-the-sidecar.test.ts+ */+import { describe, it, expect, vi, beforeEach } from 'vitest'++const calls: string[] = []++vi.mock('../../api/backend', () => ({+ isTauri: () => true,+ openExternal: vi.fn(),+ backendCall: vi.fn(async (cmd: string) => {+ calls.push(`backend:${cmd}`)+ return null+ }),+}))++vi.mock('../../api/engine', () => ({+ stopBundledEngine: vi.fn(async () => {+ calls.push('stop:engine')+ }),+ stopBundledEmbed: vi.fn(async () => {+ calls.push('stop:embed')+ }),+}))++vi.mock('../../../package.json', () => ({ version: '2.6.5' }))++const install = vi.fn(async () => {+ calls.push('install')+})++vi.mock('@tauri-apps/plugin-updater', () => ({+ check: vi.fn(async () => ({ version: '2.6.6', body: 'notes', install, download: vi.fn() })),+}))++import { useUpdateStore } from '../updateStore'++async function armPendingUpdate() {+ // The Update handle only exists after a successful check.+ await useUpdateStore.getState().checkForUpdate(true)+}++describe('installing an update frees our own engine first', () => {+ beforeEach(() => {+ calls.length = 0+ install.mockClear()+ useUpdateStore.setState({+ downloadStatus: 'downloaded',+ autoDownload: false,+ lastChecked: null,+ latestVersion: null,+ updateAvailable: false,+ errorMessage: null,+ })+ })++ it('stops both sidecars before handing over to the installer', async () => {+ await armPendingUpdate()+ calls.length = 0++ await useUpdateStore.getState().installAndRestart()++ expect(calls).toContain('stop:engine')+ expect(calls).toContain('stop:embed')+ expect(calls.indexOf('stop:engine')).toBeLessThan(calls.indexOf('install'))+ expect(calls.indexOf('stop:embed')).toBeLessThan(calls.indexOf('install'))+ // And the exit still comes last, after the installer has been handed the job.+ expect(calls.indexOf('install')).toBeLessThan(calls.indexOf('backend:exit_app'))+ })++ it('installs anyway when a sidecar refuses to stop', async () => {+ // A stop that throws must not become the reason the update never happens:+ // the installer has its own recovery, this is the belt on top of it.+ const engine = await import('../../api/engine')+ vi.mocked(engine.stopBundledEngine).mockRejectedValueOnce(new Error('busy'))++ await armPendingUpdate()+ calls.length = 0++ await useUpdateStore.getState().installAndRestart()++ expect(install).toHaveBeenCalledTimes(1)+ expect(useUpdateStore.getState().downloadStatus).not.toBe('error')+ })+})diff --git a/src/stores/updateStore.ts b/src/stores/updateStore.tsindex 86aeb094..42df1c65 100644--- a/src/stores/updateStore.ts+++ b/src/stores/updateStore.ts@@ -2,6 +2,7 @@ import { create } from 'zustand'import { persist } from 'zustand/middleware'import { version as currentVersion } from '../../package.json'import { isTauri, backendCall, openExternal } from '../api/backend'+import { stopBundledEngine, stopBundledEmbed } from '../api/engine'import type { Update } from '@tauri-apps/plugin-updater'// ── Types ─────────────────────────────────────────────────────@@ -220,8 +221,21 @@ export const useUpdateStore = create<UpdateState>()(set({ downloadStatus: 'installing' })try {+ // Free our own sidecars BEFORE the installer runs. Windows locks a+ // running image against writes, and llama-server.exe lives in the+ // install directory, which is why aldrich_ironhart's update stopped at+ // "Error opening file for writing" (C4). The NSIS hook handles that+ // case, but it is the only installer that has one: a machine that+ // installed the .msi takes the WiX path, where nothing frees the+ // sidecar. And the exit below is no help either, it runs AFTER+ // install() has already handed over.+ // Both stops are lazy-restart no-ops when nothing is running, and the+ // next thing to happen here is an installer, so there is nothing to+ // lose by being early. Best effort: a failure here must not stop the+ // update, the installer still has its own recovery.+ await Promise.allSettled([stopBundledEngine(), stopBundledEmbed()])await _pendingUpdate.install()- // Exit so NSIS installer can overwrite the binary+ // Exit so the installer can overwrite the binaryawait backendCall('exit_app')} catch (e) {set({