{"record":{"id":"9d5bebb90bedb769","repo":"unslothai/unsloth","slug":"diffusion-generation-was-cancelled-9d5beb","errorCode":null,"errorMessage":"Diffusion generation was cancelled.","messagePattern":"Diffusion generation was cancelled\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"info","filePath":"studio/backend/core/inference/diffusion_lora.py","lineNumber":333,"sourceCode":"        for spec_id, weight in specs:\n            if weight == 0:\n                continue\n            out.append(\n                resolve_one(\n                    spec_id, weight, family = family, hf_token = hf_token, cancel_event = cancel_event\n                )\n            )\n    except (\n        FileNotFoundError,\n        RepositoryNotFoundError,\n        RevisionNotFoundError,\n        EntryNotFoundError,\n        GatedRepoError,\n    ) as exc:\n        raise ValueError(_scrub_hub_url(str(exc))) from exc\n    except RuntimeError as exc:\n        if str(exc) == \"Cancelled\":\n            raise RuntimeError(DIFFUSION_CANCELLED_MSG) from exc\n        raise\n    return out\n\n\ndef materialize_native_dir(resolved: list[ResolvedLora], dest: Path) -> list[ResolvedLora]:\n    \"\"\"Populate ``dest`` with symlinks (copy fallback) to the resolved LoRA files.\n\n    sd-cli resolves ``<lora:ALIAS:w>`` against filenames in ``--lora-model-dir``, so each adapter\n    needs a uniquely-named file in this dedicated managed directory. Returns the resolved list with\n    aliases updated to the (collision-broken) stems written, so the caller injects matching tags.\n    \"\"\"\n    dest.mkdir(parents = True, exist_ok = True)\n    used: set[str] = set()\n    out: list[ResolvedLora] = []\n    for r in resolved:\n        alias = r.alias\n        n = 1\n        while alias in used:","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/inference/diffusion_lora.py#L315-L351","documentation":"The diffusion pipeline re-raises the sentinel RuntimeError 'Cancelled' as DIFFUSION_CANCELLED_MSG ('Diffusion generation was cancelled.') so that cancellation is distinguishable from a genuine runtime failure. The underlying 'Cancelled' string comes from the generation backend (e.g. sd-cli / diffusers hook) when a cancel_event trips mid-run.","triggerScenarios":"A user hits the cancel/stop control on an image generation while the sampler is running; the backend raises RuntimeError('Cancelled'), and this handler in resolve/translate converts it to the stable sentinel message the API layer matches on.","commonSituations":"Frontend stop button, request timeout triggering cancellation, competing generation requests cancelling each other, or a client disconnect causing cancellation of the in-flight job.","solutions":["Treat this as expected control flow: detect DIFFUSION_CANCELLED_MSG and return a 'cancelled' status instead of a 500","If cancellation was unexpected, check for sibling requests or watchdogs that share the cancel_event","Do not retry automatically on this error; re-issue the generation request when the user wants to continue"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"CANCEL_MSG = \"Diffusion generation was cancelled.\"\ntry:\n    run_diffusion(...)\nexcept RuntimeError as e:\n    if str(e) == CANCEL_MSG:\n        return {\"status\": \"cancelled\"}\n    raise","preventionTips":["Compare the message against the DIFFUSION_CANCELLED_MSG constant, never a substring","Return a distinct 'cancelled' status so clients don't retry blindly","Keep one cancel_event per job to avoid cross-cancellation"],"tags":["cancellation","diffusion","control-flow"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}