{"record":{"id":"24967d1e75417b8b","repo":"unslothai/unsloth","slug":"transcription-cancelled-24967d","errorCode":null,"errorMessage":"Transcription cancelled.","messagePattern":"Transcription cancelled\\.","errorType":"http","errorClass":"SttTranscriptionCancelledError","httpStatus":499,"severity":"info","filePath":"studio/backend/core/inference/stt_sidecar.py","lineNumber":1117,"sourceCode":"            unit = \"minute\" if max_minutes == 1 else \"minutes\"\n            raise SttAudioTooLongError(f\"Audio must be {max_minutes} {unit} or shorter.\")\n        raw_buffer.write(array)\n\n    try:\n        with av.open(io.BytesIO(audio), mode = \"r\", metadata_errors = \"ignore\") as container:\n            if not container.streams.audio:\n                raise SttAudioDecodeError(\"Could not decode the audio.\")\n            frames = iter(container.decode(audio = 0))\n            while True:\n                try:\n                    frame = next(frames)\n                except StopIteration:\n                    break\n                except InvalidDataError:\n                    # Skip a corrupt frame rather than fail the whole transcription.\n                    continue\n                if cancel_event is not None and cancel_event.is_set():\n                    raise SttTranscriptionCancelledError(\"Transcription cancelled.\")\n                frame.pts = None\n                fifo.write(frame)\n                if fifo.samples >= 500000:\n                    for resampled in resampler.resample(fifo.read()):\n                        write_frame(resampled)\n            if fifo.samples > 0:\n                for resampled in resampler.resample(fifo.read()):\n                    write_frame(resampled)\n            for resampled in resampler.resample(None):\n                write_frame(resampled)\n    except (SttAudioDecodeError, SttAudioTooLongError, SttTranscriptionCancelledError):\n        raise\n    except (FFmpegError, ValueError, RuntimeError) as exc:\n        raise SttAudioDecodeError(\"Could not decode the audio.\") from exc\n    finally:\n        del fifo, resampler\n\n    if sample_count == 0:","sourceCodeStart":1099,"sourceCodeEnd":1135,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/inference/stt_sidecar.py#L1099-L1135","documentation":"Raised in the decode loop when the caller-supplied cancel_event is set between frames. Cancellation is polled inside the frame loop precisely so an abandoned upload stops decoding immediately instead of running to EOF or the sample cap.","triggerScenarios":"Passing cancel_event to transcribe()/the decode helper and setting it (user hit Stop, another request preempted this one) while PyAV is still yielding frames.","commonSituations":"A Stop button on a dictation UI; request deduplication where an older duplicate request is cancelled; navigating away from the recording view mid-decode.","solutions":["Treat as a normal control-flow outcome: catch SttTranscriptionCancelledError and discard partial results; nothing is broken.","Ensure the cancel event is only set when you truly want abandonment, and do not reuse a set event across requests.","If cancellation was unexpected, audit who shares the event object — a stale set event cancels every later call."],"exampleFix":"# before\ntext = stt.transcribe(audio, cancel_event=evt)  # raises if evt set\n# after\ntry:\n    text = stt.transcribe(audio, cancel_event=evt)\nexcept SttTranscriptionCancelledError:\n    return None  # user abandoned the request","handlingStrategy":"try-catch","validationCode":"if cancel_event is not None and cancel_event.is_set():\n    return None  # skip the call entirely","typeGuard":null,"tryCatchPattern":"try:\n    text = stt.transcribe(audio, cancel_event=evt)\nexcept SttTranscriptionCancelledError:\n    return {\"status\": \"cancelled\", \"text\": None}","preventionTips":["One fresh threading.Event per request","Clear (or drop) events once a request finishes; never reuse them","Model cancellation as a first-class outcome in your request handler"],"tags":["stt","cancellation","decode","control-flow"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}