{"record":{"id":"77bf1695b59d2a5d","repo":"unslothai/unsloth","slug":"training-images-cannot-be-changed-while-diffusion-77bf16","errorCode":null,"errorMessage":"Training images cannot be changed while diffusion training is active. Stop the run before uploading, importing, editing captions, or deleting images.","messagePattern":"Training images cannot be changed while diffusion training is active\\. Stop the run before uploading, importing, editing captions, or deleting images\\.","errorType":"http","errorClass":"HTTPException","httpStatus":409,"severity":"warning","filePath":"studio/backend/routes/training.py","lineNumber":2505,"sourceCode":"    except TrainingActiveError as exc:\n        raise _DiffusionStartInFlight(\n            \"A diffusion (Images) LoRA training job is already running. \"\n            \"Stop it before starting an LLM training run.\"\n        ) from exc\n    try:\n        yield\n    finally:\n        cm.__exit__(None, None, None)\n\n\ndef _require_diffusion_dataset_mutable() -> None:\n    \"\"\"Reject a dataset mutation while a diffusion run is active.\n\n    The trainer re-opens dataset images during the loop, so mutating underneath it makes the run\n    nondeterministic or raises a FileNotFoundError mid-step. Fails open (a service-import failure\n    never blocks a mutation on an unknowable state), matching the start interlock.\"\"\"\n    if _diffusion_training_active():\n        raise HTTPException(\n            status_code = 409,\n            detail = (\n                \"Training images cannot be changed while diffusion training is active. \"\n                \"Stop the run before uploading, importing, editing captions, or deleting images.\"\n            ),\n        )\n\n\ndef diffusion_dataset_interlock():\n    \"\"\"Dependency holding the dataset interlock for a whole mutating request.\n\n    The check above only covers the instant it runs: every one of these endpoints then hands its\n    filesystem work to a thread, and a ``/diffusion/start`` reserving in that gap would move\n    captions or images underneath the preflight or the running trainer. As a yield dependency the\n    registration spans the endpoint, so ``reserve()`` sees it and refuses instead. Fails open on an\n    import error, like the check it replaces.\"\"\"\n    try:\n        from core.training.diffusion_training_service import (","sourceCodeStart":2487,"sourceCodeEnd":2523,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/routes/training.py#L2487-L2523","documentation":"HTTP 409 from _require_diffusion_dataset_mutable(): the diffusion trainer re-opens dataset images during its loop, so any dataset mutation (upload, import, caption edit, delete) while a diffusion run is active would make the run nondeterministic or crash it with FileNotFoundError mid-step. The guard deliberately fails open — if the training service cannot be imported/state is unknowable, mutations are allowed — matching the start interlock.","triggerScenarios":"Calling any image dataset mutation endpoint (upload, import, caption edit, delete) while a diffusion (Images) training run is active, once the request enters the diffusion_dataset_interlock dependency.","commonSituations":"Users preparing the next dataset while a long SDXL/Flux LoRA run is going; automation scripts that upload images on a schedule regardless of training state.","solutions":["Stop the diffusion training run and wait for it to finish (poll /training/status).","Retry the mutation once the run is idle.","Queue dataset edits client-side and flush them when no run is active."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const active = await get('/training/diffusion/status').catch(() => null)\nif (active?.is_running) throw new Error('Stop the diffusion run before mutating training images')\nawait mutateDataset(...)","typeGuard":null,"tryCatchPattern":"try { await uploadDatasetImage(file) } catch (e) { if (e.status === 409 && /cannot be changed while diffusion training/.test(e.detail)) { queueForLater(file); return } throw e }","preventionTips":["Disable dataset edit controls in the UI while a diffusion run is active.","Queue mutations client-side and flush the queue when training is idle.","Prepare datasets fully before starting a long diffusion run."],"tags":["diffusion","dataset","interlock","mutation","http-409"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}