unslothai/unsloth · info · RuntimeError

Diffusion generation was cancelled.

Error message

Diffusion generation was cancelled.

What it means

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.

Source

Thrown at studio/backend/core/inference/diffusion_lora.py:333

        for spec_id, weight in specs:
            if weight == 0:
                continue
            out.append(
                resolve_one(
                    spec_id, weight, family = family, hf_token = hf_token, cancel_event = cancel_event
                )
            )
    except (
        FileNotFoundError,
        RepositoryNotFoundError,
        RevisionNotFoundError,
        EntryNotFoundError,
        GatedRepoError,
    ) as exc:
        raise ValueError(_scrub_hub_url(str(exc))) from exc
    except RuntimeError as exc:
        if str(exc) == "Cancelled":
            raise RuntimeError(DIFFUSION_CANCELLED_MSG) from exc
        raise
    return out


def materialize_native_dir(resolved: list[ResolvedLora], dest: Path) -> list[ResolvedLora]:
    """Populate ``dest`` with symlinks (copy fallback) to the resolved LoRA files.

    sd-cli resolves ``<lora:ALIAS:w>`` against filenames in ``--lora-model-dir``, so each adapter
    needs a uniquely-named file in this dedicated managed directory. Returns the resolved list with
    aliases updated to the (collision-broken) stems written, so the caller injects matching tags.
    """
    dest.mkdir(parents = True, exist_ok = True)
    used: set[str] = set()
    out: list[ResolvedLora] = []
    for r in resolved:
        alias = r.alias
        n = 1
        while alias in used:

View on GitHub (pinned to 203007d190)

Solutions

  1. Treat this as expected control flow: detect DIFFUSION_CANCELLED_MSG and return a 'cancelled' status instead of a 500
  2. If cancellation was unexpected, check for sibling requests or watchdogs that share the cancel_event
  3. Do not retry automatically on this error; re-issue the generation request when the user wants to continue
Defensive patterns

Strategy: try-catch

Try / catch

CANCEL_MSG = "Diffusion generation was cancelled."
try:
    run_diffusion(...)
except RuntimeError as e:
    if str(e) == CANCEL_MSG:
        return {"status": "cancelled"}
    raise

Prevention

When it happens

Trigger: 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.

Common situations: Frontend stop button, request timeout triggering cancellation, competing generation requests cancelling each other, or a client disconnect causing cancellation of the in-flight job.

Related errors


AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15). Data as JSON: /api/errors/9d5bebb90bedb769. Report an issue: GitHub.