Calling Hindsight From FastAPI Without Breaking the Event Loop
One of the more annoying bugs we hit while building IncidentIQ passed every isolated test and then failed intermittently once the real server was running. The code path was identical. The Hindsight bank was the same. The only thing that changed was which thread made the SDK call.
IncidentIQ is an incident investigation assistant. An engineer submits a production incident, a Groq model proposes root-cause hypotheses, and an engineer later verifies what actually happened. Only that verified outcome is retained in Hindsight , so the next related incident can recall it. This article is about the backend that makes that loop work, and about the event-loop problem that nearly derailed it. Everything here uses synthetic incidents, and the system is a prototype running locally, not something we have exposed to real production traffic.
The shape of the backend
The backend is FastAPI with SQLAlchemy on PostgreSQL, and Alembic handles migrations.…