unslothai/unsloth · info · RuntimeError
Audio generation cancelled
Error message
Audio generation cancelled
What it means
First of three cancellation checkpoints in generate_audio: before acquiring the generation lock, the routine checks cancel_event and raises RuntimeError('Audio generation cancelled'). This gives cancellation a fast exit before prompt-neutralization and codec work, using the same sentinel message as the in-lock and post-generation checks.
Source
Thrown at studio/backend/core/inference/inference.py:2079
"""
if not self.active_model_name:
raise RuntimeError("No active model")
model_info = self.models[self.active_model_name]
audio_type = model_info.get("audio_type")
model = model_info["model"]
tokenizer = model_info.get("tokenizer")
if not audio_type:
raise RuntimeError(f"Model {self.active_model_name} is not an audio model")
top_k = self._normalize_top_k(top_k)
# Every codec below concatenates its prompt instead of templating it, so this
# is the one choke point for all four (#7066).
text = neutralize_tts_prompt_text(text, audio_type)
if cancel_event is not None and cancel_event.is_set():
raise RuntimeError("Audio generation cancelled")
with self._generation_lock:
if cancel_event is not None and cancel_event.is_set():
raise RuntimeError("Audio generation cancelled")
if use_adapter is not None:
self._apply_adapter_state(use_adapter)
stopping_criteria = self._cancel_stopping_criteria(cancel_event)
if audio_type == "snac":
result = self._generate_snac(
model,
tokenizer,
text,
temperature,
top_p,
max_new_tokens,
repetition_penalty,
stopping_criteria = stopping_criteria,
cancel_event = cancel_event,View on GitHub (pinned to 203007d190)
Solutions
- Handle this as normal cancellation (return 'cancelled' status), not an error
- If unexpected, find who shares/sets this cancel_event (watchdog, sibling request)
- Do not auto-retry; re-issue the TTS request if the user still wants the audio
Defensive patterns
Strategy: try-catch
Validate before calling
if cancel_event is not None and cancel_event.is_set():
return {"status": "cancelled"} # skip the call entirely Try / catch
try:
wav, sr = engine.generate_audio(text, cancel_event=ev)
except RuntimeError as e:
if str(e) == "Audio generation cancelled":
return {"status": "cancelled"}
raise Prevention
- Check the cancel event before starting TTS work
- Map the sentinel message to a 'cancelled' status, not an error
- Use a fresh cancel_event per request to avoid cross-talk
When it happens
Trigger: Client sets the cancel event (stop button / request abort) while the audio request is queued or just entering generate_audio, before the generation lock is acquired.
Common situations: User cancels a long TTS job immediately; deduplication logic cancelling superseded requests; client disconnect handlers flipping the event.
Related errors
- No valid audio codes found after START_OF_SPEECH token
- No bicodec_semantic tokens found in generated output
- No DAC code tokens (c1/c2) found in generated output
- Diffusion generation was cancelled.
- Model {self.active_model_name} is not an audio model
AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15).
Data as JSON: /api/errors/d977f4a38928ca58.
Report an issue: GitHub.