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): the gallery reports the seed the image was actually made with
purplea71f5dc2314e
diff --git a/src/api/comfyui.ts b/src/api/comfyui.tsindex 556212d9..955a2482 100644--- a/src/api/comfyui.ts+++ b/src/api/comfyui.ts@@ -1,6 +1,7 @@import { comfyuiUrl, localFetch, fetchLocalhostBytes, isTauri, backendCall } from "./backend"import { log } from "../lib/logger"import { LU_CLIENT_PREFIX } from "./comfyui-ws"+import { resolveRunSeed } from '../lib/run-seed'// ─── Control-plane fetch timeouts ───//@@ -1435,7 +1436,7 @@ function validateVideoParams(params: VideoParams) {}function getSeed(seed: number): number {- return seed === -1 ? Math.floor(Math.random() * 2147483647) : Math.floor(seed)+ return resolveRunSeed(seed)}// ─── Snap video dimensions to valid values ───diff --git a/src/api/dynamic-workflow.ts b/src/api/dynamic-workflow.tsindex 681eedeb..d3140245 100644--- a/src/api/dynamic-workflow.ts+++ b/src/api/dynamic-workflow.ts@@ -1,6 +1,7 @@import { classifyModel, findMatchingVAE, findMatchingCLIP, findFluxCLIPPair } from './comfyui'import type { ModelType, GenerateParams, VideoParams } from './comfyui'import { log } from '../lib/logger'+import { resolveRunSeed } from '../lib/run-seed'import {getAllNodeInfo,categorizeNodes,@@ -416,7 +417,7 @@ export async function buildDynamicWorkflow()}- const seed = params.seed === -1 ? Math.floor(Math.random() * 2147483647) : params.seed+ const seed = resolveRunSeed(params.seed)// ─── Wrapper Strategies (custom node pipelines — completely different node chains) ───@@ -1602,7 +1603,7 @@ export function buildMotionWorkflow(params: LocalOpParams, seed: number, allNode* catalogue once and dispatches to the lane's builder. */export async function buildLocalOpWorkflow(params: LocalOpParams): Promise<Record<string, any>> {const allNodes = await getAllNodeInfo()- const seed = params.seed === -1 ? Math.floor(Math.random() * 2147483647) : params.seed+ const seed = resolveRunSeed(params.seed)switch (params.op) {case 'music': return buildMusicWorkflow(params, seed, allNodes)case 'lipsync': return buildS2VWorkflow(params, seed, allNodes)diff --git a/src/api/workflows.ts b/src/api/workflows.tsindex cb35e9ef..282f1a5d 100644--- a/src/api/workflows.ts+++ b/src/api/workflows.ts@@ -4,6 +4,7 @@ import type { GenerateParams, VideoParams } from './comfyui'import { findMatchingVAE, findMatchingCLIP } from './comfyui'import { fetchExternal, fetchExternalBytes } from './backend'import { log } from '../lib/logger'+import { resolveRunSeed } from '../lib/run-seed'import type {WorkflowTemplate,WorkflowSearchResult,@@ -335,7 +336,7 @@ export async function injectParameters(inject(paramMap.model, params.model)inject(paramMap.positivePrompt, params.prompt)inject(paramMap.negativePrompt, params.negativePrompt || '')- inject(paramMap.seed, params.seed === -1 ? Math.floor(Math.random() * 2147483647) : params.seed)+ inject(paramMap.seed, resolveRunSeed(params.seed))inject(paramMap.steps, params.steps)inject(paramMap.cfgScale, params.cfgScale)let widthMapping = paramMap.widthdiff --git a/src/hooks/useCloudCreate.ts b/src/hooks/useCloudCreate.tsindex 6050db10..47a668d1 100644--- a/src/hooks/useCloudCreate.ts+++ b/src/hooks/useCloudCreate.ts@@ -30,6 +30,7 @@ import {cloudMediaLive,} from '../stores/cloudCatalogStore'import { checkPromptSafety, SAFETY_BLOCK_MESSAGE } from '../lib/render/safety'+import { resolveRunSeed } from '../lib/run-seed'// Character-Studio generation endpoint per trained-LoRA family (fast default;// mirrors uselu's LORA_GEN_FAMILY — ltx-2 video characters have no image-gen@@ -196,6 +197,11 @@ export function useCloudCreate(opts: { onQuotaChange?: () => void } = {}) {const ac = new AbortController()activeAbort = ac+ // Same rule as the local path (#110): throw the dice here, send that exact+ // number, record that exact number. Leaving the seed out let the provider+ // roll one we never learn, and the gallery wrote 0 for it.+ const runSeed = resolveRunSeed(s.seed)+try {// Utility endpoints (removebg/upscale/eraser) and the 2.5.8 specialized// ops take no generation knobs — send only what the op consumes so the@@ -211,7 +217,7 @@ export function useCloudCreate(opts: { onQuotaChange?: () => void } = {}) {height: s.height,steps: s.steps,cfg: s.cfgScale,- seed: s.seed === -1 ? undefined : s.seed,+ seed: runSeed,}if (kind === 'video' && !bare) {params.frames = s.frames@@ -351,7 +357,7 @@ export function useCloudCreate(opts: { onQuotaChange?: () => void } = {}) {negativePrompt: s.negativePrompt,model,modelType: 'unknown',- seed: s.seed === -1 ? 0 : s.seed,+ seed: runSeed,steps: s.steps,cfgScale: s.cfgScale,sampler: s.sampler,diff --git a/src/hooks/useCreate.ts b/src/hooks/useCreate.tsindex acd556eb..c8c97364 100644--- a/src/hooks/useCreate.ts+++ b/src/hooks/useCreate.ts@@ -41,6 +41,7 @@ import { getAllNodeInfo, clearNodeCache } from '../api/comfyui-nodes'import { installCustomNodes } from '../api/discover'import { backendCall } from '../api/backend'import { checkPromptSafety, SAFETY_BLOCK_MESSAGE } from '../lib/render/safety'+import { resolveRunSeed } from '../lib/run-seed'import {clearTrainingSet, stageTrainingImage, startCharacterTraining,characterTrainingStatus, cancelCharacterTraining,@@ -444,6 +445,12 @@ export function useCreate() {setIsGenerating, setProgress, setCurrentPromptId, setError, addToGallery, addToPromptHistory,} = state+ // The dice are thrown here, once, and the number travels with the run.+ // Every builder used to roll its own -1 internally and keep the result to+ // itself, so the gallery wrote 0 and no image could ever be reproduced+ // (#110). A concrete seed also stops those builders from re-rolling.+ const runSeed = resolveRunSeed(seed)+const isI2I = mode === 'image' && state.imageSubMode === 'img2img'// Which redesign intent produced this run (gallery tag).const intent = state.intent()@@ -502,7 +509,7 @@ export function useCreate() {state.setProgressPhase('sampling')setProgress(40, 'Generating with MLX...')const { dataUrl, width: outW, height: outH, localPath } = await generateMlxImageDataUrl({- prompt, steps, seed, width, height,+ prompt, steps, seed: runSeed, width, height,model: mlxModelIdFor(effImageModel),negativePrompt: negativePrompt || undefined,})@@ -515,7 +522,7 @@ export function useCreate() {// localPath is what survives the restart: partialize strips dataUrl,// and there is no ComfyUI /view to fall back to on a Mac.dataUrl, localPath, prompt, negativePrompt, model: imageModel, modelType: 'unknown',- seed: seed === -1 ? 0 : seed, steps, cfgScale, sampler, scheduler,+ seed: runSeed, steps, cfgScale, sampler, scheduler,width: outW || width, height: outH || height, batchSize: 1,createdAt: Date.now(), builderUsed: 'dynamic', intent,})@@ -567,7 +574,7 @@ export function useCreate() {prompt,seconds: Math.max(0.5, frames / Math.max(1, fps)),fps,- seed: seed === -1 ? undefined : seed,+ seed: runSeed,})} catch (e) {useCreateStore.getState().setError(`Failed to start: ${e instanceof Error ? e.message : String(e)}`)@@ -621,7 +628,7 @@ export function useCreate() {// download-to-disk path that wants to reference it directly.localPath: result.output,prompt, negativePrompt, model: videoModel, modelType: 'wan',- seed: seed === -1 ? 0 : seed, steps, cfgScale, sampler, scheduler,+ seed: runSeed, steps, cfgScale, sampler, scheduler,width, height, batchSize: 1,createdAt: Date.now(), builderUsed: 'dynamic', intent,})@@ -781,7 +788,7 @@ export function useCreate() {let outputWidth = widthlet outputHeight = heightconst baseParams = {- prompt, negativePrompt, model: activeModel, sampler, scheduler, steps, cfgScale, width, height, seed, batchSize,+ prompt, negativePrompt, model: activeModel, sampler, scheduler, steps, cfgScale, width, height, seed: runSeed, batchSize,...(isRemoveBg && effInputImage ? { removebg: true, inputImage: effInputImage } : {}),...(isI2I && !isRemoveBg && effInputImage ? { inputImage: effInputImage, denoise } : {}),...(!isRemoveBg && maskFilename ? { maskImage: maskFilename, growMaskBy } : {}),@@ -837,7 +844,7 @@ export function useCreate() {model: activeModel,prompt,negativePrompt,- seed, steps, cfgScale, sampler, scheduler,+ seed: runSeed, steps, cfgScale, sampler, scheduler,// The shared width/height/frames sliders follow the picked model via// setLocalOpModel; fall back to the architecture defaults when a// stale persisted value would be off-grid for the lane.@@ -1116,7 +1123,7 @@ export function useCreate() {filename: file.filename, subfolder: file.subfolder ?? '', comfyType: file.type ?? 'output',prompt, negativePrompt, model: activeModel,modelType: mode === 'image' ? imageModelType : (videoModelsList.find(m => m.name === activeModel)?.type ?? 'wan'),- seed: seed === -1 ? 0 : seed,+ seed: runSeed,steps, cfgScale, sampler, scheduler, width: outputWidth, height: outputHeight, batchSize,createdAt: Date.now(), builderUsed, intent,})@@ -1214,7 +1221,7 @@ export function useCreate() {filename: file.filename, subfolder: file.subfolder ?? '', comfyType: file.type ?? 'output',prompt, negativePrompt, model: activeModel,modelType: mode === 'image' ? imageModelType : (videoModelsList.find(m => m.name === activeModel)?.type ?? 'wan'),- seed: seed === -1 ? 0 : seed,+ seed: runSeed,steps, cfgScale, sampler, scheduler, width: outputWidth, height: outputHeight, batchSize,createdAt: Date.now(), builderUsed,})@@ -1321,7 +1328,7 @@ export function useCreate() {filename: file.filename, subfolder: file.subfolder ?? '', comfyType: file.type ?? 'output',prompt, negativePrompt, model: activeModel,modelType: mode === 'image' ? imageModelType : (videoModelsList.find(m => m.name === activeModel)?.type ?? 'wan'),- seed: seed === -1 ? 0 : seed,+ seed: runSeed,steps, cfgScale, sampler, scheduler, width: outputWidth, height: outputHeight, batchSize,createdAt: Date.now(), builderUsed, intent,})diff --git a/src/lib/__tests__/run-seed.test.ts b/src/lib/__tests__/run-seed.test.tsnew file mode 100644index 00000000..f2457781--- /dev/null+++ b/src/lib/__tests__/run-seed.test.ts@@ -0,0 +1,49 @@+// Regression guard for #110: the gallery reported seed 0 for every random+// run, so two different images both claimed to come from the same seed and+// neither could be reproduced. The dice are thrown once per run now, and the+// number that comes out of here is the number the sampler gets AND the number+// the gallery stores.+import { describe, it, expect, vi, afterEach } from 'vitest'+import { resolveRunSeed } from '../run-seed'++afterEach(() => { vi.restoreAllMocks() })++describe('resolveRunSeed', () => {+ it('turns the -1 placeholder into a concrete seed, never 0', () => {+ vi.spyOn(Math, 'random').mockReturnValue(0.5)+ expect(resolveRunSeed(-1)).toBe(1073741823)+ })++ it('passes a user-chosen seed through untouched, so the builders cannot re-roll it', () => {+ expect(resolveRunSeed(42)).toBe(42)+ expect(resolveRunSeed(2147483646)).toBe(2147483646)+ expect(resolveRunSeed(0)).toBe(0)+ })++ it('floors a fractional seed instead of handing ComfyUI a float', () => {+ expect(resolveRunSeed(12.9)).toBe(12)+ })++ it('stays inside the 32 bit signed range the KSampler accepts', () => {+ for (const r of [0, 0.25, 0.999999]) {+ vi.spyOn(Math, 'random').mockReturnValue(r)+ const s = resolveRunSeed(-1)+ expect(Number.isInteger(s)).toBe(true)+ expect(s).toBeGreaterThanOrEqual(0)+ expect(s).toBeLessThanOrEqual(2147483647)+ vi.restoreAllMocks()+ }+ })++ it('rolls a different number on consecutive random runs', () => {+ const seeds = new Set(Array.from({ length: 50 }, () => resolveRunSeed(-1)))+ expect(seeds.size).toBeGreaterThan(45)+ expect(seeds.has(0)).toBe(false)+ })++ it('treats any negative or broken value as a roll, not as a literal seed', () => {+ vi.spyOn(Math, 'random').mockReturnValue(0.5)+ expect(resolveRunSeed(-7)).toBe(1073741823)+ expect(resolveRunSeed(Number.NaN)).toBe(1073741823)+ })+})diff --git a/src/lib/run-seed.ts b/src/lib/run-seed.tsnew file mode 100644index 00000000..83ec10be--- /dev/null+++ b/src/lib/run-seed.ts@@ -0,0 +1,18 @@+// One place where a run's seed becomes a real number.+//+// Before 2.6.5 four call sites rolled their own dice for `-1` (comfyui's+// getSeed, two branches of the dynamic builder, the custom-workflow injector)+// and none of them told anybody the result. The gallery therefore recorded+// `0` for every random run, so an image the user liked could never be+// reproduced (#110). The rule now: the caller that starts the run resolves the+// seed once and passes the number down. The builders keep calling this too, as+// a safety net for any other caller, but a resolved seed passes straight+// through untouched.++/** ComfyUI's KSampler takes a 32 bit signed seed. */+const SEED_MAX = 2147483647++export function resolveRunSeed(seed: number): number {+ if (!Number.isFinite(seed) || seed < 0) return Math.floor(Math.random() * SEED_MAX)+ return Math.floor(seed)+}