Repository navigation
fix(telemetry): record a LiteLlm streamed answer once, not chunks plus aggregate - #7694
Draft
ishan-1010 wants to merge 1 commit into
Draft
ishan-1010 wants to merge 1 commit into
ishan-1010 wants to merge 1 commit into
Conversation
…s aggregate LiteLlm streams chunks without a finish reason and then yields their aggregate with one. record_llm_response kept recording until that finish reason, so gen_ai.output.messages held every chunk and then the whole answer again (a 5-chunk answer was 6 messages, a streamed tool call 4 half-built calls plus the real one). When a complete response with a finish reason follows only partial chunks without one, drop the chunks' output messages and keep the aggregate. Streams whose last chunk carries the finish reason (Gemini) and streams that fail before their aggregate keep their chunks. Fixes google#7630
|
Thanks, Ishan—I’ve attached two supplemental native tests against
The full I’m not claiming a full telemetry-suite pass: the broader run hit a missing SOCKS dependency in the functional tests. The patch only changes tests and was AI-assisted. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to Issue or Description of Change
Problem:
LiteLlm streams chunks without a finish reason and then yields their aggregate with one.
record_llm_responsekeeps recording until a finish reason arrives, sogen_ai.output.messagesheld every chunk and then the whole answer again.Solution:
As suggested in #7630: when a complete response with a finish reason follows only partial chunks without one, drop the chunks' output messages and keep the aggregate. Streams whose last chunk carries the finish reason (Gemini) and streams that fail before their aggregate keep their chunks.
Testing Plan
Unit Tests:
New tests in
tests/unittests/telemetry/test_instrumentation.py:test_aggregate_after_unfinished_chunks_is_recorded_once(fails on main: 3 messages)test_tool_call_aggregate_replaces_its_partial_call_chunks(fails on main: a call witharguments: nullplus the real one)test_stream_cut_off_before_its_aggregate_keeps_its_chunkstest_stream_whose_last_chunk_finishes_keeps_its_chunks(Gemini shape)Manual End-to-End (E2E) Tests:
gen_ai.output.messageson main vs this PR, LiteLlm withStreamingMode.SSE:openai/gpt-oss-20b, text answeropenai/gpt-oss-20b, tool calltool_callwitharguments: nulltool_call({"city": "Oslo"})Same counts in the completion log with
EVENT_ONLY.Checklist
Additional context
The silent cut-off from #7630 (a dropped stream is finalized as
stop) is tracked separately in #7693.