mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-10-20 23:45:22 +08:00
Tracing ran inline with the request: every traced call did several database round trips (dedupe probe, actor-name lookup, newest-hash read) and a serialized insert. With tracing on, the WebUI's burst of parallel requests (login alone touches a dozen endpoints) saturated the write path and stalled the whole service. Now the request path only builds a bounded dict and pushes it onto a queue (measured ~0.005ms per trace, zero database work). A single background writer coroutine drains the queue and persists sequentially, which also removes the read-newest-hash race that used to produce false "chain broken" reports; the previous asyncio lock is gone. The actor display-name lookup and the dedupe key hash move into the writer as well. The queue is bounded: when traffic outruns the writer the oldest pending trace is dropped instead of slowing the request down. Verified: migration tests pass, ruff clean, a focused writer test shows enqueue is non-blocking, rows link with zero chain breaks and no internal key leaks into the stored row.