You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The chat question refund runs its Firestore transaction on the event loop #15966
release_chat_quota_question (backend/database/llm_usage.py:375) is synchronous and, per its own docstring, marks the event doc released "in the same transaction as the decrement", so it is a Firestore transaction, not a single write.
Both callers are inside generate_stream (backend/routers/chat.py:728 and :744), the async generator handed to StreamingResponse, so its body runs on the event loop rather than in FastAPI's threadpool. Line 744 is in the except Exception: arm, so the transaction also runs while a failure is propagating.
The timing is what makes this worth fixing. A release only happens when a turn fails terminally, so these calls do not arrive one at a time; they arrive in a burst when a provider is degraded and many turns fail at once. That is the moment the loop can least afford a stall, and every other request and WebSocket on the pod waits behind them.
The same generator already has both halves of the correct shape: it offloads with await run_blocking(db_executor, notification_db.sync_user_time_zone_from_client, ...) at line 623, and it awaits a yielded helper at yield await emit_done_frame(response).
Proposing this as a paid bounty ($50) per the contribution docs, @kodjima33.
Fixed in #16028 (merged as 3c5fd43) — the chat quota release now runs via run_blocking(db_executor, ...) instead of inline on the event loop. Closing as resolved.
Activity
fix(backend): offload chat quota release off the event loop (#15966) (#…
kodjima33 commentedon Sep 23, 2026
Fixed in #16028 (merged as 3c5fd43) — the chat quota release now runs via
run_blocking(db_executor, ...)instead of inline on the event loop. Closing as resolved.