{"record":{"id":"479877b82b6be474","repo":"lfnovo/open-notebook","slug":"failed-to-load-default-models-configuration","errorCode":null,"errorMessage":"Failed to load default models configuration","messagePattern":"Failed to load default models configuration","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"open_notebook/ai/models.py","lineNumber":291,"sourceCode":"            return AIFactory.create_speech_to_text(\n                model_name=model.name,\n                provider=provider,\n                config=config,\n            )\n        elif model.type == \"text_to_speech\":\n            return AIFactory.create_text_to_speech(\n                model_name=model.name,\n                provider=provider,\n                config=config,\n            )\n        else:\n            raise ConfigurationError(f\"Invalid model type: {model.type}\")\n\n    async def get_defaults(self) -> DefaultModels:\n        \"\"\"Get the default models configuration from database\"\"\"\n        defaults = await DefaultModels.get_instance()\n        if not defaults:\n            raise RuntimeError(\"Failed to load default models configuration\")\n        return defaults\n\n    async def get_speech_to_text(self, **kwargs) -> Optional[SpeechToTextModel]:\n        \"\"\"Get the default speech-to-text model\"\"\"\n        defaults = await self.get_defaults()\n        model_id = defaults.default_speech_to_text_model\n        if not model_id:\n            return None\n        model = await self.get_model(model_id, **kwargs)\n        assert model is None or isinstance(model, SpeechToTextModel), (\n            f\"Expected SpeechToTextModel but got {type(model)}\"\n        )\n        return model\n\n    async def get_text_to_speech(self, **kwargs) -> Optional[TextToSpeechModel]:\n        \"\"\"Get the default text-to-speech model\"\"\"\n        defaults = await self.get_defaults()\n        model_id = defaults.default_text_to_speech_model","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/lfnovo/open-notebook/blob/a7de90d38aaf18ee85fd661854d35c11e44613e2/open_notebook/ai/models.py#L273-L309","documentation":"Raised by ModelManager.get_defaults() when DefaultModels.get_instance() returns None — i.e. the singleton default-models row cannot be loaded from SurrealDB. Every model lookup (embedding, STT, TTS, default LLM, content processing) funnels through get_defaults(), so this error blocks nearly all AI features. It usually means the database is unreachable, migrations have not created the DefaultModels record, or the record was deleted.","triggerScenarios":"Calling any of get_speech_to_text, get_text_to_speech, get_embedding_model, get_default_model, or content_process before the DefaultModels row exists; running against a fresh/empty SurrealDB; pointing OPEN_NOTEBOOK_DB at the wrong namespace/database; API started before SurrealDB (schema migrations that seed defaults never ran).","commonSituations":"Fresh install where startup migrations didn't run (API started before database), wrong SurrealDB connection env vars, a migrated schema missing the seeded DefaultModels singleton, or accidentally deleting the settings record via the UI/API.","solutions":["Verify SurrealDB is running (make database) and restart the API so startup migrations/seed run","Check OPEN_NOTEBOOK_DB* env vars point to the intended namespace/database","Query SurrealDB directly (SELECT * FROM default_models) to confirm the singleton exists; if missing, restart API to re-seed or recreate via the Settings API","As a last resort, clear and re-run migrations on a dev database"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"from open_notebook.database.repository import repo_query\nrows = await repo_query(\"SELECT * FROM default_models LIMIT 1\")\nif not rows:\n    # trigger setup / seeding before any AI call\n    ...","typeGuard":null,"tryCatchPattern":"try:\n    model = await model_manager.get_default_model('language')\nexcept RuntimeError as e:\n    if 'default models configuration' in str(e):\n        raise HTTPException(503, 'Models not configured — run setup')\n    raise","preventionTips":["Start SurrealDB before the API so seeding migrations run","Health-check DefaultModels existence at app startup and fail fast with a clear message","Don't delete the default_models row via raw DB access; use the settings UI"],"tags":["database","surrealdb","configuration","models","startup"],"backgroundTag":"missing-database-record","analyzedSha":"a7de90d38aaf18ee85fd661854d35c11e44613e2","analyzedAt":"2026-08-27T02:39:58.166Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}