fix(api): initialize LearningPropagationService in the app lifespan

The learning singleton was created on demand but initialize(optimal_service)
was never called, so record_learning() always raised "not initialized" and
every task completion logged "Failed to extract learnings". The lifespan now
wires it to OptimalService once RAG is up (skipped when RAG is disabled).
This commit is contained in:
Renn F
2026-06-04 06:02:52 +02:00
parent d47adfe027
commit 172d639ba6
+12
View File
@@ -47,6 +47,7 @@ from roboco.config import settings
from roboco.db.base import close_db, init_db
from roboco.logging import get_logger, setup_logging
from roboco.services.extraction import ExtractionPipeline, ExtractionService
from roboco.services.learning import get_learning_service
from roboco.services.optimal import close_optimal_service, get_optimal_service
from roboco.services.transcription import TranscriptionService
@@ -108,6 +109,17 @@ async def lifespan(app: FastAPI) -> AsyncGenerator[None]:
)
app.state.optimal = None
# Wire the learning-propagation singleton to OptimalService. Without this,
# record_learning() raises "not initialized" and every task completion logs
# "Failed to extract learnings". Skipped when RAG is disabled (no optimal).
if app.state.optimal is not None:
try:
learning_service = await get_learning_service()
await learning_service.initialize(app.state.optimal)
logger.info("LearningPropagationService initialized")
except Exception as e:
logger.warning("LearningPropagationService init failed", error=str(e))
logger.info("All services initialized, API ready")
yield