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.

feat(create): LoRA picks are kept per task and model (B24)

purple664de371fe80
diff --git a/src/hooks/__tests__/useCreate-character-chain.test.ts b/src/hooks/__tests__/useCreate-character-chain.test.ts
index ff3f4bb8..ffafe7fe 100644
--- a/src/hooks/__tests__/useCreate-character-chain.test.ts
+++ b/src/hooks/__tests__/useCreate-character-chain.test.ts
@@ -119,7 +119,10 @@ function on(intent: CreateIntent, extra: Record<string, unknown> = {}) {
selectedLoras: [{ name: 'film_grain.safetensors', strength: 0.5 }], loraStrengths: {},
} as never)
useCreateStore.getState().setIntent(intent)
+ // B24: the LoRA picks belong to the task and model, so they are picked on
+ // the lane the run is on (a model in `extra` is a lane change).
useCreateStore.setState({ selectedCharacter: MIRA, ...extra } as never)
+ useCreateStore.setState({ selectedLoras: [{ name: 'film_grain.safetensors', strength: 0.5 }] })
useCreateStore.getState().setPrompt('walking through the rain')
}
diff --git a/src/lib/render/lora-lanes.ts b/src/lib/render/lora-lanes.ts
new file mode 100644
index 00000000..7074d09e
--- /dev/null
+++ b/src/lib/render/lora-lanes.ts
@@ -0,0 +1,64 @@
+// B24 (3.0.9, Discord .molot 28.10.2026): the LoRA picks belong to the task and
+// the model they were made for. One list for every tab kept a video LoRA
+// switched on after the change to Image, where it rode along into the run of
+// another model. Each task + model now keeps its own picks: leaving it puts
+// them aside, coming back brings them back, a lane never visited starts empty.
+
+export type LoraPick = { name: string; strength: number }
+
+/** How many lanes are remembered. The oldest one goes first. */
+export const LORA_LANES_MAX = 40
+
+/** The lane a store state is on: its task and the local model that runs it.
+ * Null while that model is not known yet (lists still loading), so a start
+ * of the app never files the saved picks under an empty name. */
+export function loraLaneKey(intent: string, model: string): string | null {
+ return model ? `${intent}|${model}` : null
+}
+
+/** The picks to put aside and the ones to bring back when the lane changes.
+ * Null when nothing changes: same lane, or a side that is not known yet.
+ * `explicit` is true when the change itself chose the picks (a trained
+ * style switched on with its tab), then those stay. */
+export function switchLoraLane(
+ before: { key: string | null; picks: LoraPick[] },
+ after: { key: string | null; picks: LoraPick[] },
+ lanes: Record<string, LoraPick[]>,
+ explicit: boolean,
+): { selectedLoras: LoraPick[]; loraLanes: Record<string, LoraPick[]> } | null {
+ if (!before.key || !after.key || before.key === after.key) return null
+ const { [before.key]: _old, ...rest } = lanes
+ const own = before.picks.filter((p) => !isCharacterLoraName(p.name))
+ const kept = own.length ? { ...rest, [before.key]: own } : rest
+ const keys = Object.keys(kept)
+ const trimmed = keys.length > LORA_LANES_MAX
+ ? Object.fromEntries(keys.slice(keys.length - LORA_LANES_MAX).map((k) => [k, kept[k]]))
+ : kept
+ if (explicit) return { selectedLoras: after.picks, loraLanes: trimmed }
+ // A character's LoRA goes along with the character: its chip stands on
+ // every tab, and picking one may switch the model before or after its
+ // LoRA is ticked.
+ const character = after.picks.filter((p) => isCharacterLoraName(p.name))
+ const back = (lanes[after.key] ?? []).filter((p) => !isCharacterLoraName(p.name))
+ return { selectedLoras: [...back, ...character], loraLanes: trimmed }
+}
+
+/** A trained character's LoRA (`char_<name>_zimage.safetensors`, the trainer's
+ * own naming, api/trainer parseLocalCharacterLora). It belongs to the picked
+ * character, not to a lane. */
+export function isCharacterLoraName(name: string): boolean {
+ return /(?:^|[\\/])char_.+\.safetensors$/i.test(name.trim())
+}
+
+/** A persisted map, checked: anything that is not a list of picks is dropped. */
+export function sanitizeLoraLanes(v: unknown): Record<string, LoraPick[]> {
+ if (!v || typeof v !== 'object' || Array.isArray(v)) return {}
+ const out: Record<string, LoraPick[]> = {}
+ for (const [k, list] of Object.entries(v as Record<string, unknown>)) {
+ if (!Array.isArray(list)) continue
+ const picks = list.filter((p): p is LoraPick =>
+ !!p && typeof p === 'object' && typeof (p as LoraPick).name === 'string' && Number.isFinite((p as LoraPick).strength))
+ if (picks.length) out[k] = picks
+ }
+ return out
+}
diff --git a/src/stores/__tests__/createStore-lora-je-aufgabe-und-modell.test.ts b/src/stores/__tests__/createStore-lora-je-aufgabe-und-modell.test.ts
new file mode 100644
index 00000000..672c6444
--- /dev/null
+++ b/src/stores/__tests__/createStore-lora-je-aufgabe-und-modell.test.ts
@@ -0,0 +1,96 @@
+/**
+ * B24 (3.0.9, Discord .molot 28.10.2026): a video LoRA stayed switched on
+ * after the change to Image and rode into the run of another model. The LoRA
+ * picks now belong to the task and the model: leaving puts them aside, coming
+ * back brings them back, a lane never visited starts empty.
+ *
+ * Run: npx vitest run src/stores/__tests__/createStore-lora-je-aufgabe-und-modell.test.ts
+ */
+import { describe, it, expect, beforeEach } from 'vitest'
+import { useCreateStore } from '../createStore'
+import { sanitizeLoraLanes, switchLoraLane, LORA_LANES_MAX } from '../../lib/render/lora-lanes'
+
+const VIDEO_LORA = 'wan22_lightx2v_4step.safetensors'
+const IMAGE_LORA = 'detail_tweaker_xl.safetensors'
+const CHAR = 'char_mira_zimage.safetensors'
+const names = () => useCreateStore.getState().selectedLoras.map((l) => l.name)
+
+beforeEach(() => {
+ useCreateStore.setState({
+ mode: 'image', imageSubMode: 'text2img', videoSubMode: 't2v', removebg: false, utilityOp: null, cloudOp: null,
+ imageModel: 'sdxl.safetensors', imageModelType: 'sdxl', videoModel: 'wan2.2_t2v_14B.safetensors',
+ selectedLoras: [], loraStrengths: {}, loraLanes: {}, selectedCharacter: null,
+ } as never)
+})
+
+describe('B24: LoRA picks per task and model', () => {
+ it('a video LoRA does not stay on after the change to Image, and comes back on Video', () => {
+ const s = useCreateStore.getState()
+ s.setIntent('video')
+ s.toggleLora(VIDEO_LORA)
+ expect(names()).toEqual([VIDEO_LORA])
+ s.setIntent('image')
+ expect(names()).toEqual([])
+ s.toggleLora(IMAGE_LORA)
+ s.setIntent('video')
+ expect(names()).toEqual([VIDEO_LORA])
+ s.setIntent('image')
+ expect(names()).toEqual([IMAGE_LORA])
+ })
+
+ it('another model in the same task keeps its own picks, the strength comes back too', () => {
+ const s = useCreateStore.getState()
+ s.toggleLora(IMAGE_LORA)
+ s.setLoraStrengthFor(IMAGE_LORA, 0.35)
+ s.setImageModel('flux1-dev.safetensors', 'flux')
+ expect(names()).toEqual([])
+ s.setImageModel('sdxl.safetensors', 'sdxl')
+ expect(useCreateStore.getState().selectedLoras).toEqual([{ name: IMAGE_LORA, strength: 0.35 }])
+ })
+
+ it('Image and Edit are two tasks', () => {
+ const s = useCreateStore.getState()
+ s.toggleLora(IMAGE_LORA)
+ s.setIntent('edit')
+ expect(names()).toEqual([])
+ s.setIntent('image')
+ expect(names()).toEqual([IMAGE_LORA])
+ })
+
+ it('a character LoRA goes along with the character, whatever the order of the clicks', () => {
+ const s = useCreateStore.getState()
+ s.toggleLora(IMAGE_LORA)
+ s.toggleLora(CHAR)
+ s.setImageModel('z_image_turbo.safetensors', 'zimage')
+ expect(names()).toEqual([CHAR])
+ s.setImageModel('sdxl.safetensors', 'sdxl')
+ expect(names()).toEqual([IMAGE_LORA, CHAR])
+ })
+
+ it('a change that sets the picks itself keeps them', () => {
+ useCreateStore.setState({ mode: 'video', selectedLoras: [{ name: 'style_x_zimage.safetensors', strength: 1 }] })
+ expect(names()).toEqual(['style_x_zimage.safetensors'])
+ })
+
+ it('while the model list loads (no model yet) the saved picks are not filed away', () => {
+ useCreateStore.setState({ imageModel: '', selectedLoras: [{ name: IMAGE_LORA, strength: 1 }] })
+ useCreateStore.getState().setImageModel('sdxl.safetensors', 'sdxl')
+ expect(names()).toEqual([IMAGE_LORA])
+ })
+})
+
+describe('lora-lanes', () => {
+ it('keeps at most LORA_LANES_MAX lanes, the oldest goes', () => {
+ let lanes: Record<string, { name: string; strength: number }[]> = {}
+ for (let i = 0; i <= LORA_LANES_MAX + 3; i++) {
+ lanes = switchLoraLane({ key: `image|m${i}`, picks: [{ name: 'a', strength: 1 }] }, { key: `image|m${i + 1}`, picks: [] }, lanes, false)!.loraLanes
+ }
+ expect(Object.keys(lanes)).toHaveLength(LORA_LANES_MAX)
+ expect(lanes['image|m0']).toBeUndefined()
+ })
+
+ it('a damaged saved map is cleaned', () => {
+ expect(sanitizeLoraLanes({ a: [{ name: 'x', strength: 1 }, { name: 2 }], b: 'no', c: [] })).toEqual({ a: [{ name: 'x', strength: 1 }] })
+ expect(sanitizeLoraLanes(null)).toEqual({})
+ })
+})
diff --git a/src/stores/createStore.ts b/src/stores/createStore.ts
index cca4e925..cb2ec6c9 100644
--- a/src/stores/createStore.ts
+++ b/src/stores/createStore.ts
@@ -66,6 +66,7 @@ import { createRunModel } from '../lib/render/create-studio'
import { DEFAULT_UPSCALE_FACTOR, normalizeUpscaleFactor, type UpscaleFactor } from '../lib/local-upscale'
import { characterLoraFile, isLocalCharacter, type CharacterRef } from '../lib/character-ref'
import { triggerWordNote, typedTriggerWord } from '../lib/train-trigger'
+import { loraLaneKey, sanitizeLoraLanes, switchLoraLane, type LoraPick } from '../lib/render/lora-lanes'
// ModelType includes: flux, flux2, zimage, sdxl, sd15, wan, hunyuan, unknown
export type ProgressPhase = 'idle' | 'queued' | 'loading-model' | 'loading-clip' | 'loading-vae' | 'sampling' | 'decoding' | 'complete'
@@ -464,6 +465,10 @@ export interface CreateState {
/** The last strength set for each LoRA file, kept while the LoRA is off, so
* ticking it again brings its own value back instead of the default. */
loraStrengths: Record<string, number>
+ /** B24: the LoRA picks of every task + model the user left, keyed by
+ * lib/render/lora-lanes `loraLaneKey`. `selectedLoras` is the lane on
+ * screen; the subscriber at the end of this file swaps them. */
+ loraLanes: Record<string, LoraPick[]>
selectedVae: string
clipSkip: number
growMaskBy: number // inpaint mask edge feather (VAEEncodeForInpaint grow_mask_by)
@@ -1115,6 +1120,7 @@ export const useCreateStore = create<CreateState>()(
expertOpen: false,
selectedLoras: [] as { name: string; strength: number }[],
loraStrengths: {} as Record<string, number>,
+ loraLanes: {} as Record<string, LoraPick[]>,
selectedVae: 'auto',
clipSkip: 0,
growMaskBy: 6,
@@ -1902,6 +1908,7 @@ export const useCreateStore = create<CreateState>()(
showNegative: state.showNegative,
selectedLoras: state.selectedLoras,
loraStrengths: state.loraStrengths,
+ loraLanes: state.loraLanes,
selectedVae: state.selectedVae,
clipSkip: state.clipSkip,
growMaskBy: state.growMaskBy,
@@ -1975,6 +1982,8 @@ export const useCreateStore = create<CreateState>()(
// Gallery folders came in 3.0.7. An older blob has no list (the
// default stays), a damaged one is cleaned instead of trusted.
if ('galleryFolders' in safe) safe.galleryFolders = sanitizeFolders(safe.galleryFolders)
+ // 3.0.9 B24: an older blob has no lanes, a damaged one is cleaned.
+ if ('loraLanes' in safe) safe.loraLanes = sanitizeLoraLanes(safe.loraLanes)
// 3.0.8 D20: an unknown recipe name would reach the trainer as text.
if ('trainVramPreset' in safe && !isTrainVramPreset(safe.trainVramPreset)) safe.trainVramPreset = TRAIN_VRAM_PRESET_DEFAULT
// 3.0.9 P8: same for the mode, it picks the LoRA's file name.
@@ -2013,3 +2022,22 @@ useCreateStore.subscribe((s, prev) => {
useCreateStore.setState({ cloudOpPicks: { ...s.cloudOpPicks, [slot]: s.cloudOpModel } })
}
})
+
+// B24: the LoRA picks belong to the task and the local model on screen. A
+// change of either puts the picks aside under the lane that was left and
+// brings back the ones of the lane entered (none for a new one), so a video
+// LoRA never stays on after the change to Image. A change that set the picks
+// itself (a trained style switched on with its tab) keeps them, and so does
+// the LoRA of the picked character.
+function loraLaneOf(s: CreateState): string | null {
+ return loraLaneKey(deriveIntent(s), s.mode === 'video' ? s.videoModel : s.imageModel)
+}
+useCreateStore.subscribe((s, prev) => {
+ const swap = switchLoraLane(
+ { key: loraLaneOf(prev), picks: prev.selectedLoras },
+ { key: loraLaneOf(s), picks: s.selectedLoras },
+ s.loraLanes,
+ s.selectedLoras !== prev.selectedLoras,
+ )
+ if (swap) useCreateStore.setState(swap)
+})