From f4c7deba66a077dedcc4a66d467180cfb02605ce Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Tue, 10 Feb 2026 19:16:54 -0500 Subject: [PATCH] Run model pull as background task to avoid startup timeout ensure_model() can take minutes to pull a multi-GB model, which exceeds Hypercorn's startup timeout. Now fires as an asyncio background task so the app starts immediately. Co-Authored-By: Claude Opus 4.6 --- src/fabledassistant/app.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/fabledassistant/app.py b/src/fabledassistant/app.py index 9ca9d8b..75e0a55 100644 --- a/src/fabledassistant/app.py +++ b/src/fabledassistant/app.py @@ -24,16 +24,22 @@ def create_app() -> Quart: @app.before_serving async def startup(): + import asyncio + from fabledassistant.services.llm import ensure_model - try: - await ensure_model(Config.OLLAMA_MODEL) - except Exception: - logger.warning( - "Failed to ensure model '%s' on startup — chat may not work until model is available", - Config.OLLAMA_MODEL, - exc_info=True, - ) + async def _pull_model(): + try: + await ensure_model(Config.OLLAMA_MODEL) + except Exception: + logger.warning( + "Failed to ensure model '%s' — chat may not work until model is available", + Config.OLLAMA_MODEL, + exc_info=True, + ) + + # Fire-and-forget so model pull doesn't block startup + asyncio.create_task(_pull_model()) @app.route("/") async def serve_index():