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(engine): der Steckplatzwechsel toetet nur die Chat-Engine, und holt sie zurueck

purpled0e7e4096927
diff --git a/src/lib/__tests__/displaced-engine-frees-its-memory.test.ts b/src/lib/__tests__/displaced-engine-frees-its-memory.test.ts
index 075c47d5..624d6e9e 100644
--- a/src/lib/__tests__/displaced-engine-frees-its-memory.test.ts
+++ b/src/lib/__tests__/displaced-engine-frees-its-memory.test.ts
@@ -15,8 +15,24 @@
* Round 7 answered the same question for the window's X (the model stayed in
* VRAM after the window went to the tray) by routing the hide through
* `offload_local_models`, the call the switch into Cloud mode makes, after a
- * grace period. This is that answer applied one door further along, with the
- * same call and the same grace period.
+ * grace period. This applied that answer one door further along, with the same
+ * call and the same grace period.
+ *
+ * UND DIE GEGENPROBE G2 (04.09.2026) hat gezeigt, dass "dieselbe Freigabe" an
+ * dieser Tuer zu viel freigibt. `offload_local_models` raeumt Whisper, den
+ * Einbettungsserver auf Port 8128 und die geladenen Ollama-Modelle mit weg.
+ * Gemessen: LM Studio als Provider hinzufuegen, zwanzig Sekunden warten, und
+ * beide `lu-llama-server`-Prozesse sind weg, auch der auf 8128, der mit dem
+ * Chat-Steckplatz nichts zu tun hat. Document Chat arbeitet danach stumm nicht
+ * mehr, und der Server kam in 60 Sekunden nicht von allein wieder.
+ *
+ * Der Steckplatzwechsel heisst nicht "die App hat nichts mehr zu tun", sondern
+ * "die Chat-Engine hat nichts mehr zu tun". Also `stop_bundled_engine`.
+ *
+ * Dazu die Rueckrichtung, ebenfalls aus G2: nach Enable und Remove lief auf
+ * 8127 nichts mehr und startete auch nach dreimaligem Ansichtswechsel nicht
+ * nach. 'cancel' sagte nur eine noch nicht ausgefuehrte Freigabe ab. War sie
+ * schon gelaufen, geschah gar nichts.
*
* Run: npx vitest run src/lib/__tests__/displaced-engine-frees-its-memory.test.ts
*/
@@ -63,22 +79,27 @@ describe('THE FIX: the engine that loses the slot lets go of its model', () => {
onLocalSlotChanged(BUILTIN, JAN)
expect(backendCall).not.toHaveBeenCalled() // grace period first
vi.advanceTimersByTime(BUILTIN_SLOT_OFFLOAD_GRACE_MS)
- expect(backendCall).toHaveBeenCalledWith('offload_local_models', { includeComfyui: false })
+ expect(backendCall).toHaveBeenCalledWith('stop_bundled_engine')
})
- it('it is the call the cloud switch makes, not a second mechanism', () => {
- const shell = read('src/components/layout/AppShell.tsx')
- expect(shell).toMatch(/backendCall\('offload_local_models'\)/)
+ it('und NUR die Chat-Engine, nicht die Rundum-Freigabe (Gegenprobe G2)', () => {
+ onLocalSlotChanged(BUILTIN, JAN)
+ vi.advanceTimersByTime(BUILTIN_SLOT_OFFLOAD_GRACE_MS)
+ expect(backendCall).toHaveBeenCalledTimes(1)
+ expect(backendCall.mock.calls[0][0]).toBe('stop_bundled_engine')
+ // Der Einbettungsserver, Whisper und die geladenen Ollama-Modelle haben
+ // mit dem Chat-Steckplatz nichts zu tun und bleiben, wo sie sind.
+ // Im ausfuehrbaren Teil steht der Name nicht mehr, nur in der Notiz, die
+ // erklaert, warum er weg ist.
const evict = read('src/lib/builtin-slot-eviction.ts')
- expect(evict).toMatch(/backendCall\('offload_local_models', \{ includeComfyui: false \}\)/)
- // and it does NOT reach for a private unload path of its own
- expect(evict).not.toMatch(/stop_bundled_engine/)
+ const code = evict.split('\n').filter((z) => !/^\s*(\*|\/\/|\/\*)/.test(z)).join('\n')
+ expect(code).not.toMatch(/offload_local_models/)
})
- it('the ComfyUI checkpoint is left alone, a chat slot is none of its business', () => {
- onLocalSlotChanged(BUILTIN, JAN)
- vi.advanceTimersByTime(BUILTIN_SLOT_OFFLOAD_GRACE_MS)
- expect(backendCall.mock.calls[0][1]).toEqual({ includeComfyui: false })
+ it('der Cloud-Wechsel behaelt seine Rundum-Freigabe, das ist eine andere Frage', () => {
+ // Dort hat die App wirklich nichts mehr lokal zu tun.
+ const shell = read('src/components/layout/AppShell.tsx')
+ expect(shell).toMatch(/backendCall\('offload_local_models'\)/)
})
it('a user who swaps straight back pays nothing, the same grace round 7 built', () => {
@@ -103,7 +124,28 @@ describe('THE FIX: the engine that loses the slot lets go of its model', () => {
it('Disable on the engine itself frees it too, it is the same loss of the slot', () => {
onLocalSlotChanged(BUILTIN, { enabled: false, managed: true })
vi.advanceTimersByTime(BUILTIN_SLOT_OFFLOAD_GRACE_MS)
- expect(backendCall).toHaveBeenCalledWith('offload_local_models', { includeComfyui: false })
+ expect(backendCall).toHaveBeenCalledWith('stop_bundled_engine')
+ })
+
+ it('und kommt zurueck, wenn der Steckplatz zurueckkommt (Gegenprobe G2)', async () => {
+ onLocalSlotChanged(BUILTIN, JAN)
+ vi.advanceTimersByTime(BUILTIN_SLOT_OFFLOAD_GRACE_MS)
+ await vi.advanceTimersByTimeAsync(0)
+ expect(backendCall).toHaveBeenCalledWith('stop_bundled_engine')
+ // Enable auf der Standby-Karte, spaeter Remove: der Steckplatz ist wieder
+ // unserer, und die Engine wird geholt statt liegen gelassen.
+ const evict = read('src/lib/builtin-slot-eviction.ts')
+ expect(evict).toContain('void bringEngineBack()')
+ expect(evict).toContain('ensureBuiltinEngineAlive(gewaehlt)')
+ })
+
+ it('der Rueckweg wird nur nach einer WIRKLICH gelaufenen Freigabe gegangen', () => {
+ // Sonst wuerde jedes Enable auf einer Karte, die den Steckplatz nie
+ // verloren hat, eine Engine anstossen, die laengst laeuft.
+ const evict = read('src/lib/builtin-slot-eviction.ts')
+ const zweig = evict.slice(evict.indexOf("if (decision === 'cancel')"))
+ expect(zweig.slice(0, 300)).toContain('if (entladen)')
+ expect(zweig.slice(0, 300)).toContain('entladen = false')
})
it('the wiring: every write to the shared slot asks the question, once', () => {
@@ -160,7 +202,6 @@ describe('NEGATIVE CONTROL: nobody else loses their model over this', () => {
// The lazy reload this leans on is the one a Create render already leans
// on, and it predates this change.
const ensure = read('src/api/builtin-ensure.ts')
- expect(ensure).toMatch(/offload_local_models/)
expect(ensure).toMatch(/export async function ensureBuiltinEngineAlive/)
})
diff --git a/src/lib/builtin-slot-eviction.ts b/src/lib/builtin-slot-eviction.ts
index 629801a0..9bd3f4b8 100644
--- a/src/lib/builtin-slot-eviction.ts
+++ b/src/lib/builtin-slot-eviction.ts
@@ -13,20 +13,31 @@
*
* The same shape as round 7's close-to-tray finding, one door further along:
* the app agrees the engine has nothing left to do, and the model sits in
- * memory anyway until the process is restarted. Round 7 answered it by routing
- * the hide through `offload_local_models`, the call the switch into Cloud mode
- * already made, after a short grace period so a mis-click costs nothing. This
- * is the same answer for the same question, so it is the same call and the same
- * grace period, not a second mechanism.
+ * memory anyway until the process is restarted. A short grace period so a
+ * mis-click costs nothing, then the engine lets its model go.
*
* The trigger is narrow on purpose. Only a slot the app's OWN engine was
* holding can leave a `lu-llama-server` behind, so only that transition fires:
* LM Studio replacing Jan frees nothing of ours and must not evict anybody's
* Ollama residents for nothing.
*
- * Nothing is lost by unloading. Everything comes back lazily on first use, the
- * way `builtin-ensure.ts` already revives the engine after a Create render did
- * exactly this call.
+ * WAS FREIGEGEBEN WIRD, ist seit der Gegenprobe G2 (04.09.2026) genau eine
+ * Sache: die Chat-Engine. Vorher lief das ueber `offload_local_models`, die
+ * Rundum-Freigabe, die auch der Wechsel in den Cloud-Modus benutzt, und die
+ * raeumt Whisper, den Einbettungsserver auf 8128 und die geladenen
+ * Ollama-Modelle gleich mit weg. Der Tester hat gemessen, was das heisst:
+ * LM Studio als Provider hinzufuegen, und zwanzig Sekunden spaeter ist der
+ * Einbettungsserver tot, der mit dem Chat-Steckplatz nichts zu tun hat, und
+ * Document Chat arbeitet stumm nicht mehr. Der Steckplatzwechsel ist nicht
+ * "die App hat nichts mehr zu tun", sondern "die Chat-Engine hat nichts mehr
+ * zu tun", und `stop_bundled_engine` ist genau das.
+ *
+ * UND ZURUECK. Nimmt unsere Engine den Steckplatz wieder, kommt die Chat-
+ * Engine wieder. Vorher hiess 'cancel' nur "eine noch nicht ausgefuehrte
+ * Freigabe faellt aus"; war die Frist schon abgelaufen, geschah nichts, und
+ * derselbe Tester stand nach Enable und Remove ohne Engine da, auch nach
+ * dreimaligem Ansichtswechsel. Der Weg zurueck ist derselbe, den der
+ * Absendeweg geht.
*/
import { backendCall, isTauri } from '../api/backend'
@@ -85,15 +96,19 @@ function cancelPending(): void {
}
}
+/**
+ * Ist die Freigabe wirklich gelaufen, oder stand sie nur an.
+ *
+ * Der Unterschied entscheidet, was beim Zurueckgeben des Steckplatzes zu tun
+ * ist: eine abgesagte Freigabe hinterlaesst eine laufende Engine, eine
+ * ausgefuehrte hinterlaesst nichts.
+ */
+let entladen = false
+
/**
* Wire the decision to the call. Safe to invoke on every write to the `openai`
* slot: it does nothing unless the app's own engine actually lost the slot, and
* nothing at all outside the desktop build.
- *
- * `includeComfyui: false` for the same reason a local render passes it: the
- * image checkpoint has no part in a chat backend change, and freeing it here
- * would buy a slow reload on the next generate for nothing. That is the flag
- * the Create hand-off has always used.
*/
export function onLocalSlotChanged(
before: BuiltinSlotView | null | undefined,
@@ -103,6 +118,10 @@ export function onLocalSlotChanged(
if (decision === 'none') return
if (decision === 'cancel') {
cancelPending()
+ if (entladen) {
+ entladen = false
+ void bringEngineBack()
+ }
return
}
if (!isTauri()) return
@@ -111,13 +130,42 @@ export function onLocalSlotChanged(
pending = setTimeout(() => {
if (mine !== generation) return
pending = null
- backendCall('offload_local_models', { includeComfyui: false })
- .then(() => log.info('[builtin-slot] engine lost the local slot, released its model'))
+ backendCall('stop_bundled_engine')
+ .then(() => {
+ entladen = true
+ log.info('[builtin-slot] engine lost the local slot, released its model')
+ })
.catch((e) => log.warn('[builtin-slot] could not release the displaced engine', { err: e }))
}, BUILTIN_SLOT_OFFLOAD_GRACE_MS)
}
+/**
+ * Die Chat-Engine zurueckholen, nachdem der Steckplatz wieder unserer ist.
+ *
+ * Der Aufruf kommt spaet und dynamisch, weil `builtin-ensure` ueber den
+ * providerStore auf dieses Modul zurueckzeigt. Ein fest verdrahteter Import
+ * waere ein Ladekreis. `ensureBuiltinEngineAlive` ist genau der Weg, den auch
+ * das Absenden einer Nachricht geht: Zustand fragen, Datei suchen, mit der
+ * Feineinstellung des Nutzers starten.
+ */
+async function bringEngineBack(): Promise<void> {
+ if (!isTauri()) return
+ try {
+ const { useModelStore } = await import('../stores/modelStore')
+ const gewaehlt = useModelStore.getState().activeModel
+ if (!gewaehlt) return
+ const { ensureBuiltinEngineAlive } = await import('../api/builtin-ensure')
+ await ensureBuiltinEngineAlive(gewaehlt)
+ log.info('[builtin-slot] engine has the local slot again, brought it back')
+ } catch (e) {
+ // Kein Grund, den Steckplatzwechsel scheitern zu lassen. Der Absendeweg
+ // versucht dasselbe noch einmal, sobald jemand etwas schreibt.
+ log.warn('[builtin-slot] could not bring the engine back', { err: e })
+ }
+}
+
/** Test-only: forget a pending unload so tests stay isolated. */
export function __resetBuiltinSlotOffloadForTests(): void {
cancelPending()
+ entladen = false
}