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 <noreply@anthropic.com>
This commit is contained in:
2026-02-10 19:16:54 -05:00
parent 8a0b4d77f8
commit f4c7deba66
+14 -8
View File
@@ -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():