Repository navigation
Conversation
|
Thanks @singhharsh1708 — verified this end to end against the head. backend/routers/chat.py:
backend/tests/unit/test_chat_stream_persist_offload.py: ran the suite locally against the head source — 5/5 pass. The AST guard pins the async emitter, the awaited run_blocking on db_executor, and rejects both a direct process_message call and a bare One non-blocking observation: db_executor (max_workers=24) is shared with the other offloads in this router, so under Firestore degradation these persists will queue there instead of stalling the event loop — the right trade for the pod, just worth remembering when reading db-executor queue metrics. Leaving merge sign-off to the maintainers; note the linked issue #15270 requests a bounty payout, which is a maintainer call. 🤖 Automated review on behalf of the maintainers. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
kodjima33
left a comment
There was a problem hiding this comment.
Offloads the blocking Firestore persistence call (process_message) in emit_done_frame off the event loop via run_blocking on the existing db_executor pool, matching the pattern already used elsewhere in this generator (Fixes #15270). Scoped diff, AST-guard test + existing chat/stream/nps suite passes, CI green. Confidence 5/5.
Fixes #15270
emit_done_frameranprocess_message, and with it up to three sequential Firestore writes, directly on the event loop for every completed chat answer. It is nowasync defand offloads that one call:and its two yields became
yield await emit_done_frame(response).That is the whole change. Only
process_messagemoves to the executor; the message construction, base64 encoding,journey_attempt.finishandrecord_fallbackcalls are in-memory and stay where they are. Thetry/except Exceptionaround the persistence still catches the same failures, becauserun_blockingre-raises in the awaiting frame, so the fail-open contract in the docstring is unchanged: a failed write still emits an in-memorydone:frame and still recordspersist_outcome = 'exhausted'.db_executoris the pool this generator already uses at line 607 forsync_user_time_zone_from_client, andyield await ...is the shape it already uses at line 710 foremit_stream_error_fallback.Tests:
backend/tests/unit/test_chat_stream_persist_offload.py, an AST guard. It asserts the generator is still async, that the emitter is async, thatprocess_messageis not called directly inside it, that it goes through an awaitedrun_blockingondb_executor, and that noyield emit_done_frame(...)remains withoutawait, which would yield a coroutine object instead of a frame and silently break the stream.Verification:
That selection includes
test_chat_stream_error_fallback.py, which exercises the done-frame and fallback paths directly, so the behaviour of this function is covered by existing tests rather than only by the new static guard.With
routers/chat.pyreverted to its state on main and the guard kept, 4 of the 5 fail; the one that still passes is thatgenerate_streamis async, which is true on main too.chat.pydoes not change line count, so no line-count exception is needed.Note on overlap: #15207, #15210 and #14970 also touch
routers/chat.py, for the picked file name on chat uploads. That is a different function and a different defect; I do not expect a textual conflict, and I will rebase if one lands first.Product invariants affected
none
Failure class (fixes)
Failure-Class: none