{"record":{"id":"7c2b2145c00254d0","repo":"unslothai/unsloth","slug":"dictation-model-loading-was-cancelled","errorCode":null,"errorMessage":"Dictation model loading was cancelled.","messagePattern":"Dictation model loading was cancelled\\.","errorType":"http","errorClass":"SttLoadCancelledError","httpStatus":409,"severity":"info","filePath":"studio/backend/core/inference/stt_mtmd_sidecar.py","lineNumber":846,"sourceCode":"                # optimisation, never worth killing a running transcription\n                # for, so an in-flight request keeps the server it has and the\n                # next idle load picks the GPU back up.\n                if self._gpu_disabled == training or self._active_requests:\n                    self._schedule_idle_unload_locked()\n                    return\n            # Announced before the slow probe and reap: is_loading() is read lock-free,\n            # so a training start would otherwise see False and wait out the startup in\n            # unload() instead of cancelling this load.\n            cancel_event = (\n                request_cancel_event if request_cancel_event is not None else threading.Event()\n            )\n            self._load_cancel_event = cancel_event\n            self._load_owner_cancel_event = request_cancel_event\n            self._loading = True\n            released = False\n            try:\n                if cancel_event.is_set():\n                    raise SttLoadCancelledError(\"Dictation model loading was cancelled.\")\n                # Before the release: a 409 for a model that is not downloaded\n                # must not cost the user the server they were already using.\n                model_path, mmproj_path = self._ensure_model_downloaded(model_id)\n                # Only when there is a live server to protect: a request against\n                # a server that already died must not block recovery.\n                if self._active_requests and self._process_alive():\n                    raise SttModelBusyError(\n                        \"A transcription is still running on the current dictation model. \"\n                        \"Try again in a moment.\"\n                    )\n                self._release_locked()\n                released = True\n            finally:\n                # Nothing started, so take the announcement back; past here the startup owns it.\n                if not released:\n                    self._loading = False\n                    self._load_cancel_event = None\n                    self._load_owner_cancel_event = None","sourceCodeStart":828,"sourceCodeEnd":864,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/inference/stt_mtmd_sidecar.py#L828-L864","documentation":"SttLoadCancelledError raised inside _load_locked after _loading=True is announced: if the (possibly internally created) cancel_event is set, the startup aborts before checking model download or releasing the current server. The finally block resets _loading/_load_cancel_event so the sidecar state stays consistent.","triggerScenarios":"A cancel or training-preemption signal sets _load_cancel_event between the load entering _load_locked's critical section and the startup body — e.g. unload() for a training run cancels an in-flight startup.","commonSituations":"Training run starting exactly as a dictation model loads; user cancelling while the lock queue delayed the load; back-to-back model switches where the older request is cancelled.","solutions":["Catch SttLoadCancelledError and treat it as preemption, not failure (the route maps it to 409).","Retry the load once the preemption source (training run) is done, if the user still wants dictation.","Avoid issuing loads while a training run is known to be starting."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"```python\ntry:\n    sidecar.load(model_id)\nexcept SttLoadCancelledError:\n    return {\"status\": \"cancelled\", \"retry\": True}, 409\n```","preventionTips":["Map SttLoadCancelledError to HTTP 409 so clients distinguish preemption from runtime failure (501).","Do not start loads you expect to cancel; cancel before calling load.","After preemption by training, re-load only when the user actually dictates again."],"tags":["stt","cancellation","load","training-preemption"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}