Empty intermediate SSE fix#4321
Open
mzegla wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR targets a streaming edge case where the final “finish-only” flush can lead to an extra/empty intermediate SSE iteration by propagating an isLast flag from OVMSTextStreamer through servable callbacks into DeltaChannel.
Changes:
- Extend
OVMSTextStreamer::Callbackto include anisLastboolean derived fromfinish_reason != NONE. - Extend
DeltaChannel::push()to acceptisLastand (currently) mark the channel complete whenisLast=true. - Update GenAI + legacy LM/VLM servables to forward
isLastthrough their streamer callbacks.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/llm/visual_language_model/legacy/servable.cpp |
Updates legacy VLM callbacks to forward isLast into the delta channel / unary accumulator. |
src/llm/servable.hpp |
Updates DeltaChannel::push() signature and completion behavior when pushing the last delta. |
src/llm/servable.cpp |
Updates base GenAI streaming callback signature to accept/forward isLast. |
src/llm/ovms_text_streamer.hpp |
Updates OVMSTextStreamer::Callback typedef and documents isLast. |
src/llm/ovms_text_streamer.cpp |
Computes isLast from finish_reason and forwards it to the callback, including finish-only flush handling. |
src/llm/language_model/legacy/servable.cpp |
Updates legacy LM streaming callback signature and forwards isLast into the delta channel. |
Comments suppressed due to low confidence (1)
src/llm/visual_language_model/legacy/servable.cpp:162
- The streamer callback can receive finish-only deltas (no "delta" object). In that case,
rapidjson::Documentmay be empty/non-object, and callingHasMember()directly can trigger RapidJSON assertions/UB. Guard ondelta.IsObject()beforeHasMember()so the unary VLM path safely ignores finish-only documents.
auto unaryCallback = [& ctx = *legacyExecutionContext](rapidjson::Document delta, bool /*isLast*/) -> ov::genai::StreamingStatus {
if (delta.HasMember("delta") && delta["delta"].IsObject() &&
delta["delta"].HasMember("content") && delta["delta"]["content"].IsString()) {
ctx.accumulatedUnaryText += delta["delta"]["content"].GetString();
}
Comment on lines
+203
to
208
| if (isLast) { | ||
| // Parser produced no delta for the final flush (e.g. generation ended on a | ||
| // special token the parser absorbed). Still fire the callback with an empty | ||
| // Document so the caller can emit the finish_reason chunk. | ||
| return m_callback(rapidjson::Document{}, true); | ||
| } |
Comment on lines
+84
to
92
| // When isLast is true, also marks the channel complete atomically so consumers | ||
| // always see the final document and the completion flag in the same observation. | ||
| void push(rapidjson::Document delta, bool isLast = false) { | ||
| { | ||
| std::lock_guard<std::mutex> lock(m_mutex); | ||
| m_deltas.push_back(std::move(delta)); | ||
| if (isLast) | ||
| m_complete = true; | ||
| } |
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.
No description provided.