Fix 'default' model selection breaking readiness indicator

When a user selected the 'Default' option in Settings, the dropdown
sent an empty string "" to the backend. The route saved it as a DB row,
which caused get_setting() to return "" instead of falling back to
Config defaults. The chat status endpoint then tried to match "" against
installed model names — always failing — resulting in model: "not_found"
and a permanently failing readiness indicator.

services/settings.py:
- Add delete_setting() helper: removes a setting row so get_setting()
  correctly falls back to its hardcoded default argument

routes/settings.py:
- Import delete_setting
- When default_model or intent_model are saved as empty string, delete
  the DB row instead of storing "" — cleanly restores Config fallback

routes/chat.py:
- chat_status_route: add explicit `or Config.OLLAMA_MODEL` guard for
  any existing "" rows written before this fix (migration safety net)
- send_message and summarize routes: same guard on model resolution
  so empty settings never cause silent generation failures

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-28 16:06:02 -05:00
parent 926e4bb570
commit fb3a6d2445
3 changed files with 30 additions and 5 deletions
+10 -1
View File
@@ -1,6 +1,6 @@
import logging
from sqlalchemy import select
from sqlalchemy import delete as sa_delete, select
from fabledassistant.models import async_session
from fabledassistant.models.setting import Setting
@@ -46,6 +46,15 @@ async def set_settings_batch(user_id: int, settings: dict[str, str]) -> None:
logger.info("Batch-updated %d settings for user %d", len(settings), user_id)
async def delete_setting(user_id: int, key: str) -> None:
"""Remove a setting row so get_setting() returns its hardcoded default instead."""
async with async_session() as session:
await session.execute(
sa_delete(Setting).where(Setting.user_id == user_id, Setting.key == key)
)
await session.commit()
async def get_all_settings(user_id: int) -> dict[str, str]:
async with async_session() as session:
result = await session.execute(