unslothai/unsloth · info · AudioGenerationCancelledError

Audio generation cancelled

Error message

Audio generation cancelled

What it means

AudioGenerationCancelledError raised at admission time: the caller's cancel_event became set while the request waited for the dispatcher (compare requests) to go idle under _gen_lock. The request never reached the worker; this is a clean, cooperative cancellation before work started.

Source

Thrown at studio/backend/core/inference/orchestrator.py:2126

        Blocking — sends command and waits for the full audio response.
        """
        if not self._ensure_subprocess_alive():
            raise RuntimeError("Inference subprocess is not running")
        if not self.active_model_name:
            raise RuntimeError("No active model")
        expected_model = self.active_model_name

        # Serialize under _gen_lock and reserve dispatcher admission before waiting for
        # compare work to drain. A bare idle wait is racy: a compare request can register
        # between the wait and this command, leaving TTS queued without safe ownership of
        # the worker's single shared cancel event.
        with self._gen_lock:
            with self._dispatcher_lifecycle_lock:
                self._exclusive_tts_pending = True
            try:
                dispatcher_idle = self._wait_dispatcher_idle(cancel_event = cancel_event)
                if cancel_event is not None and cancel_event.is_set():
                    raise AudioGenerationCancelledError("Audio generation cancelled")
                if not dispatcher_idle:
                    raise RuntimeError(
                        "Cannot start audio generation while compare requests are active"
                    )

                # Recheck after the dispatcher wait: unload can set its flag without
                # _gen_lock, and a switch may have completed while this call was queued.
                if self._unload_pending or self.active_model_name != expected_model:
                    raise AudioGenerationCancelledError("model is being unloaded")

                # Bound public API integers before either enqueuing work or
                # calculating the floating-point watchdog deadline.
                max_new_tokens = min(
                    AUDIO_GENERATION_MAX_TOKENS,
                    max(1, int(max_new_tokens)),
                )
                generation_timeout = _audio_generation_timeout(max_new_tokens)
                request_id = str(uuid.uuid4())

View on GitHub (pinned to 203007d190)

Solutions

  1. Treat as normal cancellation — do not show it as an error to the user.
  2. If cancellation was unexpected, check what set cancel_event (client disconnect, unload flow).
  3. Retry the request if audio is still wanted and the model remains loaded.

Example fix

// before
wav, sr = orchestrator.generate_audio(text)
// after
try:
    wav, sr = orchestrator.generate_audio(text)
except AudioGenerationCancelledError:
    return  # user cancelled — not an error
Defensive patterns

Strategy: try-catch

Try / catch

try:
    wav, sr = orchestrator.generate_audio(text, cancel_event=ev)
except AudioGenerationCancelledError:
    return None  # admission-time cancel: nothing ran, nothing to clean up

Prevention

When it happens

Trigger: Caller sets cancel_event (user pressed stop, request aborted, unload triggered) while compare/generation traffic keeps the dispatcher busy and generate_audio is still parked in _wait_dispatcher_idle.

Common situations: User cancels TTS playback while comparisons are running; HTTP client disconnects and the server cancels the pending audio task; UI unload racing an in-flight TTS request.

Related errors


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