mirror of
https://github.com/abhinavxd/libredesk.git
synced 2026-09-11 21:39:00 +00:00
f417aacb92
The AI agent and embedding goroutines only stopped on ctx cancellation. main() never waited for them, so a worker mid-reply could still hit the database after db.Close() ran. Give both AI managers a Close() that stops accepting new work and waits for in-flight workers, matching the existing webhook/sla shutdown pattern. Wire aiAgent.Close() and ai.Close() into main's shutdown right after the HTTP server stops, so in-flight work finishes while its dependencies are still up and before the database closes. Queued-but-unstarted jobs are dropped since ctx is already cancelled - shutdown stays fast instead of grinding through a backlog of slow AI calls.