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(create): same-named training photos get names of their own
purplef9c49e7f62b3
diff --git a/src/components/create/experimental/Stage.tsx b/src/components/create/experimental/Stage.tsxindex 3b1ef264..60857d01 100644--- a/src/components/create/experimental/Stage.tsx+++ b/src/components/create/experimental/Stage.tsx@@ -960,7 +960,9 @@ export function TrainSetBoard() {const addFiles = (files: FileList | File[]) => {// One mint, one release: `mediaRefFrom` is the only place a staged file// gets a blob: URL, and `addTrainImages` gives back every ref it does not- // keep (a name duplicate, anything past the 30 cap). This used to be an+ // keep (a re-drop of a photo already in the set, anything past the cap).+ // Two different photos under one name both stay: the store numbers the+ // second one on. This used to be an// inline copy of those two lines with nothing on the other end.const imgs = Array.from(files).filter((f) => f.type.startsWith('image/'))diff --git a/src/components/create/experimental/__tests__/das-trainingsset-gibt-seine-blobs-zurueck.test.ts b/src/components/create/experimental/__tests__/das-trainingsset-gibt-seine-blobs-zurueck.test.tsindex 53daf520..dcbff24e 100644--- a/src/components/create/experimental/__tests__/das-trainingsset-gibt-seine-blobs-zurueck.test.ts+++ b/src/components/create/experimental/__tests__/das-trainingsset-gibt-seine-blobs-zurueck.test.ts@@ -11,7 +11,7 @@* MediaRef[]. Er wird nicht ersetzt, sondern erweitert, gefiltert und* geleert — und keiner dieser drei Wege gab je etwas zurück:*- * - `addTrainImages` wirft Namensdubletten weg und kappt bei 30,+ * - `addTrainImages` wirft erneut fallen gelassene Dateien weg und kappt bei 30,* - `removeTrainImage` filtert einen heraus,* - `clearTrainImages` leert alles (der Cloud-Trainingslauf ruft das nach* jedem Submit, `useCloudCreate.ts:367`).@@ -43,9 +43,11 @@ beforeEach(() => {useCreateStore.setState({ trainImages: [], audioInput: null, videoInput: null })})-/** Eine Datei, wie der Dateidialog sie liefert. */+/** Eine Datei, wie der Dateidialog sie liefert. Dieselbe Datei von der+ * Platte hat bei jedem Pick dieselbe Änderungszeit; daran (mit Name und+ * Größe) erkennt das Set einen erneuten Drop. */function file(name: string): File {- return new File([new Uint8Array([1, 2, 3])], name, { type: 'image/png' })+ return new File([new Uint8Array([1, 2, 3])], name, { type: 'image/png', lastModified: 1 })}/** Genau das, was `TrainSetBoard.addFiles` (Stage.tsx) mit einem Drop tut. */@@ -65,7 +67,7 @@ describe('das Trainingsset gibt seine Blob-URLs zurück', () => {// Zweimal denselben Ordner fallen lassen ist der Normalfall, nicht der// Sonderfall: der Nutzer sieht nicht, dass die Bilder schon drin sind.// Die Dublette bekommt in `addFiles` eine EIGENE, frische URL und wird- // dann von der Namens-Dedupe weggeworfen — unerreichbar, aber gepinnt.+ // dann von der Dedupe weggeworfen — unerreichbar, aber gepinnt.drop('a.png')const kept = useCreateStore.getState().trainImages[0].urldrop('a.png')diff --git a/src/components/create/experimental/__tests__/same-named-photos-stay-in-the-training-set.test.ts b/src/components/create/experimental/__tests__/same-named-photos-stay-in-the-training-set.test.tsnew file mode 100644index 00000000..970b70c2--- /dev/null+++ b/src/components/create/experimental/__tests__/same-named-photos-stay-in-the-training-set.test.ts@@ -0,0 +1,75 @@+/**+ * Bug hunt C4 (Oktober 2026): Character Studio, Train new.+ *+ * A: IMG_0001..0004.png from one folder, then IMG_0001, IMG_0002, IMG_0005+ * from another folder (other photos). The set said 5/100: the two other+ * photos vanished without a word, because addTrainImages dropped every+ * photo whose NAME the set already held.+ * B: one pick with two different face.png plus a.png, b.png. Both face.png+ * landed (React warned about two children with the key face.png), and one+ * Remove took both out of the state, sharing one caption on the way.+ *+ * Every photo now gets a name of its own (face_2.png, the way the Rust side's+ * free_stem numbers a stem), and Remove takes out exactly that one. A re-drop+ * of the very same file is still skipped.+ *+ * Run: npx vitest run src/components/create/experimental/__tests__/same-named-photos-stay-in-the-training-set.test.ts+ */+import { describe, it, expect, beforeEach } from 'vitest'+import { useCreateStore } from '../../../../stores/createStore'+import { mediaRefFrom } from '../mediaRef'++let minted = 0+beforeEach(() => {+ minted = 0+ globalThis.URL.createObjectURL = () => `blob:test/${++minted}`+ globalThis.URL.revokeObjectURL = () => {}+ useCreateStore.setState({ trainImages: [], trainCaptions: {}, backend: 'local' })+})++/** A photo as the file dialog hands it over: its bytes and its file's time. */+function photo(name: string, content: number, lastModified: number): File {+ return new File([new Uint8Array([content, content, content])], name, { type: 'image/png', lastModified })+}+const pick = (...files: File[]) => useCreateStore.getState().addTrainImages(files.map(mediaRefFrom))+const names = () => useCreateStore.getState().trainImages.map((i) => i.name)++describe('same-named photos in the training set', () => {+ it('A: other photos with names the set already holds join it, numbered on', () => {+ pick(...['IMG_0001', 'IMG_0002', 'IMG_0003', 'IMG_0004'].map((n) => photo(`${n}.png`, 0, 1000)))+ pick(...['IMG_0001', 'IMG_0002', 'IMG_0005'].map((n) => photo(`${n}.png`, 1, 2000)))+ expect(names()).toEqual([+ 'IMG_0001.png', 'IMG_0002.png', 'IMG_0003.png', 'IMG_0004.png',+ 'IMG_0001_2.png', 'IMG_0002_2.png', 'IMG_0005.png',+ ])+ })++ it('B: two face.png in one pick are two photos with two names', () => {+ pick(photo('face.png', 0, 1000), photo('face.png', 1, 1000), photo('a.png', 0, 1000), photo('b.png', 1, 1000))+ expect(names()).toEqual(['face.png', 'face_2.png', 'a.png', 'b.png'])+ expect(new Set(names()).size).toBe(4)+ })++ it('B: one Remove takes out one photo and only its caption', () => {+ pick(photo('face.png', 0, 1000), photo('face.png', 1, 1000), photo('a.png', 0, 1000), photo('b.png', 1, 1000))+ const st = useCreateStore.getState()+ st.setTrainCaption('face.png', 'smiling')+ st.setTrainCaption('face_2.png', 'in profile')+ useCreateStore.getState().removeTrainImage('face.png')+ expect(names()).toEqual(['face_2.png', 'a.png', 'b.png'])+ expect(useCreateStore.getState().trainCaptions).toEqual({ 'face_2.png': 'in profile' })+ })++ it('the very same file dropped again is still skipped', () => {+ const files = ['a.png', 'b.png'].map((n) => photo(n, 0, 1000))+ pick(...files)+ pick(...['a.png', 'b.png'].map((n) => photo(n, 0, 1000)))+ expect(names()).toEqual(['a.png', 'b.png'])+ })++ it('a numbered name does not clash with one the user already has', () => {+ pick(photo('face.png', 0, 1000), photo('face_2.png', 0, 1000))+ pick(photo('FACE.png', 1, 2000))+ expect(names()).toEqual(['face.png', 'face_2.png', 'FACE_3.png'])+ })+})diff --git a/src/components/create/experimental/characterPhotos.ts b/src/components/create/experimental/characterPhotos.tsindex 1a54f48b..813043eb 100644--- a/src/components/create/experimental/characterPhotos.ts+++ b/src/components/create/experimental/characterPhotos.ts@@ -44,9 +44,9 @@ export async function loadPhotosAsReferences(name: string, photos: readonly Blob}/** The photos join the training set in Character Studio. The studio's own- * minimum and maximum stay as they are. The set drops a photo whose name it- * already holds, so a second batch under the same name numbers on after the- * first instead of vanishing. */+ * minimum and maximum stay as they are. A second batch under the same name+ * numbers on after the first, so the frames keep one running count (the set+ * itself would only append _2 to a name it already holds). */export function sendPhotosToStudio(name: string, photos: readonly Blob[]): void {const st = useCreateStore.getState()st.setIntent('character')diff --git a/src/stores/createStore.ts b/src/stores/createStore.tsindex 30f68ed2..223fcc91 100644--- a/src/stores/createStore.ts+++ b/src/stores/createStore.ts@@ -759,6 +759,35 @@ function releaseDroppedMediaRefs(previous: readonly MediaRef[], next: readonly M}}+/**+ * A training photo staged again: the same file as one already in the set, by+ * its original file name, size and modification time (the most a browser+ * knows about a file's identity). Only an earlier batch counts; one pick or+ * one drop never holds the same file twice, so two same-named files in it are+ * two photos.+ */+function isSameTrainFile(had: MediaRef, img: MediaRef): boolean {+ const a = had.blob+ const b = img.blob+ if (a === b) return true+ if (!(a instanceof File) || !(b instanceof File)) return false+ return a.name === b.name && a.size === b.size && a.lastModified === b.lastModified+}++/** `name` if the set does not hold it yet (case-insensitive, like the Mac+ * and Windows file systems the trainer writes to), else `stem_2.ext`,+ * `stem_3.ext` and so on. */+function freeTrainImageName(name: string, taken: ReadonlySet<string>): string {+ if (!taken.has(name.toLowerCase())) return name+ const dot = name.lastIndexOf('.')+ const stem = dot > 0 ? name.slice(0, dot) : name+ const ext = dot > 0 ? name.slice(dot) : ''+ for (let n = 2; ; n++) {+ const next = `${stem}_${n}${ext}`+ if (!taken.has(next.toLowerCase())) return next+ }+}+/** The same rule for a slot that holds at most one ref. */function releaseReplacedMediaRef(previous: MediaRef | null, next: MediaRef | null): void {releaseDroppedMediaRefs(previous ? [previous] : [], next ? [next] : [])@@ -1292,16 +1321,28 @@ export const useCreateStore = create<CreateState>()(setTargetResolution: (targetResolution) => set({ targetResolution }),setMacUpscaleScale: (macUpscaleScale) => set({ macUpscaleScale }),setCharacterTab: (characterTab) => set((s) => withOwnStudioOptions(s, { characterTab })),- // Cap at the backend's photo limit (lib/train-image-cap) and de-dupe by filename so- // a re-drop of the same files doesn't double the set. Both of those- // THROW REFS AWAY — the caller minted a blob: URL for every file it- // handed over, including the ones landing in the dedupe and the ones- // the cap cuts off, and neither is reachable from the store afterwards.- // So "before" is everything in play, not just what was already staged.+ // Cap at the backend's photo limit (lib/train-image-cap) and skip a+ // re-drop of a file already in the set, so the same folder twice does+ // not double it. Every photo keeps a name of its own: a DIFFERENT photo+ // under a name the set already holds (IMG_0001.png from a second+ // folder, two face.png in one drop) is numbered on, face_2.png, the way+ // the Rust side's free_stem numbers a stem. The name is the photo's id+ // for Remove, its caption and the grid key. Skipping and capping both+ // THROW REFS AWAY: the caller minted a blob: URL for every file it+ // handed over, and none of the dropped ones is reachable from the store+ // afterwards. So "before" is everything in play, not just what was+ // already staged.addTrainImages: (imgs) => {const before = get().trainImages- const have = new Set(before.map((i) => i.name))- const trainImages = [...before, ...imgs.filter((i) => !have.has(i.name))].slice(0, maxTrainImages(get().backend))+ const taken = new Set(before.map((i) => i.name.toLowerCase()))+ const added: MediaRef[] = []+ for (const img of imgs) {+ if (before.some((had) => isSameTrainFile(had, img))) continue+ const name = freeTrainImageName(img.name, taken)+ taken.add(name.toLowerCase())+ added.push(name === img.name ? img : { ...img, name })+ }+ const trainImages = [...before, ...added].slice(0, maxTrainImages(get().backend))releaseDroppedMediaRefs([...before, ...imgs], trainImages)set({ trainImages })},