{"record":{"id":"c9a7a0d437466f6f","repo":"mudler/LocalAI","slug":"model-not-loaded-call-loadmodel-first","errorCode":null,"errorMessage":"Model not loaded. Call LoadModel first.","messagePattern":"Model not loaded\\. Call LoadModel first\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"backend/python/moonshine/backend.py","lineNumber":88,"sourceCode":"                model_arch = self.options[\"model_arch\"]\n            \n            # Get the model path and architecture\n            model_path, model_arch = get_model_for_language(language, model_arch)\n            print(f\"Loading model: {model_path} with architecture: {model_arch} for language: {language}\", file=sys.stderr)\n            \n            # Initialize the transcriber\n            self.transcriber = Transcriber(model_path=model_path, model_arch=model_arch)\n            print(\"Model loaded successfully\", file=sys.stderr)\n        except Exception as err:\n            return backend_pb2.Result(success=False, message=f\"Unexpected {err=}, {type(err)=}\")\n        return backend_pb2.Result(message=\"Model loaded successfully\", success=True)\n\n    def AudioTranscription(self, request, context):\n        resultSegments = []\n        text = \"\"\n        try:\n            if self.transcriber is None:\n                raise Exception(\"Model not loaded. Call LoadModel first.\")\n            \n            # Load the audio file\n            audio_data, sample_rate = load_wav_file(request.dst)\n            print(f\"Loaded audio file: {request.dst} with sample rate: {sample_rate}\", file=sys.stderr)\n            \n            # Transcribe without streaming\n            transcript = self.transcriber.transcribe_without_streaming(\n                audio_data, sample_rate=sample_rate, flags=0\n            )\n            \n            # Process transcript lines\n            full_text_parts = []\n            for idx, line in enumerate(transcript.lines):\n                line_text = line.text.strip()\n                full_text_parts.append(line_text)\n                \n                # Create segment with timing information\n                start_ms = int(line.start_time * 1000)","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/mudler/LocalAI/blob/44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26/backend/python/moonshine/backend.py#L70-L106","documentation":"Raised inside AudioTranscription of the moonshine backend when a transcription request arrives before any successful LoadModel call has set self.transcriber. It is a plain Exception (not a typed error) raised deliberately to be caught by the surrounding try block and returned as a failed gRPC Result.","triggerScenarios":"Calling the AudioTranscription RPC on a fresh backend instance that never loaded a model, or after a LoadModel that failed (e.g. bad model path/arch) leaving self.transcriber as None.","commonSituations":"Startup ordering issues where the client sends transcription before load completes, failed loads being ignored by orchestration code, or health checks not distinguishing loaded vs unloaded state.","solutions":["Call LoadModel with a valid model_path/model_arch and confirm success=true before transcribing","Check the LoadModel Result message — a prior failure like a missing model file leaves transcriber None","Verify the model directory exists and the moonshine model arch string is correct, then retry the load"],"exampleFix":"# before\nstub.AudioTranscription(req)  # 'Model not loaded. Call LoadModel first.'\n\n# after\nres = stub.LoadModel(load_req)\nassert res.success, res.message\nstub.AudioTranscription(req)","handlingStrategy":"try-catch","validationCode":"# gRPC clients: ensure LoadModel succeeded first\nload_resp = stub.LoadModel(backend_pb2.ModelOptions(model=model_path))\nif not load_resp.success:\n    raise RuntimeError(f'LoadModel failed: {load_resp.message}')\n# only now transcribe","typeGuard":"def backend_ready(servicer) -> bool:\n    return servicer.transcriber is not None","tryCatchPattern":"try:\n    result = stub.AudioTranscription(req)\nexcept grpc.RpcError as err:\n    if 'Model not loaded' in (err.details() or ''):\n        load_and_retry()  # explicit recovery, not silent fallback\n    else:\n        raise","preventionTips":["Gate transcription on LoadModel success in orchestration code","Treat failed loads as fatal, not skippable","Add a readiness/health signal that reflects loaded state"],"tags":["python","grpc","moonshine","lifecycle","audio"],"backgroundTag":null,"analyzedSha":"44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26","analyzedAt":"2026-08-15T10:13:50.291Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}