Repository navigation
fix(gateway): preserve complete streamed chat completions - #115652
Merged
Merged
Conversation
Preserve cumulative assistant snapshot prefixes and flush same-turn text before terminating OpenAI-compatible Gateway SSE. Fixes #81991 Refs: #82355 Co-authored-by: honor2030 <[email protected]>
steipete
marked this pull request as ready for review
July 29, 2026 06:06
Contributor
Author
|
Merged via squash.
|
vincentkoc
added a commit
that referenced
this pull request
Jul 29, 2026
…ifecycle-hooks * origin/main: fix(mattermost): key private channels as group on outbound routing (#96645) fix(ci): grant Telegram QA runtime scratch access (#115659) fix(telegram): stop retrying blocked recipients (#115640) fix(tts): persist generated speech in media store (#115647) fix(gateway): preserve complete streamed chat completions (#115652) fix(mac): prevent app auth from blocking node-host startup (#115533) fix(heartbeat): keep message-tool final replies private (#115629) fix(gateway): drain root work continuations before direct-stop process exit (#105848) fix(ollama): keep active streams within their idle timeout (#115648) fix(delivery): keep session keys out of inferred message targets (#115657) fix(ci): type code mode matrix catch callback (#115674) refactor(agents): centralize bundled CLI backend auth policy (#115633) refactor: remove 3,527 lines of runtime and test duplication (#115626) [AI] fix(doctor): stop repeated bundledDiscovery migration noise on beta (#115208) # Conflicts: # scripts/code-mode-model-matrix.ts
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Jul 30, 2026
…15652) Preserve cumulative assistant snapshot prefixes and flush same-turn text before terminating OpenAI-compatible Gateway SSE. Fixes openclaw#81991 Refs: openclaw#82355 Co-authored-by: honor2030 <[email protected]>
This was referenced Oct 12, 2026
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.
Closes #81991
Related: #82355
What Problem This Solves
Fixes an issue where users streaming Chat Completions from the Gateway receive incomplete assistant responses: a leading character buffered at an XML-style tag boundary can disappear, and the final assistant text can arrive after the stream has already sent its terminal
[DONE]frame.Why This Change Was Made
Preserve the existing sanitized cumulative assistant snapshot when deriving OpenAI-compatible incremental chunks. Schedule stream completion after the current microtask so the agent's same-turn final text is emitted before the single finish and
[DONE]frames. Preserve tool-call finish precedence, usage ordering, disconnect cleanup, replacement behavior, and intentional reasoning/final-tag suppression.The root cause, proposed repair, and contributor-equivalent regression originate in @honor2030's #82355; the original report is #81991 by @boxiao-qd. The Gateway remains a JSON/SSE transport: literal custom tags and script-like text remain unmodified text, not HTML or executable markup.
User Impact
Streaming OpenAI Chat Completions clients receive the complete assistant response in order, including literal leading
<characters and the final text, before the normal stop and[DONE]frames. Existing structured tool calls, usage frames, authentication, suppressed reasoning, and non-streaming responses remain unchanged.Evidence
[email protected]SDK: cumulative output loses its leading<, and same-turn final content is emitted after the stream closes; both regressions fail before the production change.Stream<ChatCompletionChunk>, includingchoices[].delta.contentand terminalfinish_reason: https://github.com/openai/openai-node/blob/v6.48.0/src/resources/chat/completions/completions.ts. SSE framing is verified against https://html.spec.whatwg.org/multipage/server-sent-events.html.[DONE].pnpm test src/gateway/openai-http.test.ts src/gateway/openresponses-http.test.ts src/gateway/openresponses-parity.test.ts src/gateway/openresponses-phase.test.ts src/agents/embedded-agent-subscribe.subscribe-embedded-agent-session.filters-final-suppresses-output-without-start-tag.test.ts— 110 tests passed.pnpm check:changed— formatting, both core typecheck lanes, lint, and repository safety guards.gpt-5.6-solreview withxhighreasoning.