Repository navigation
fix(messages): honor OpenAI stop_sequences (#37118) - #48534
Merged
Merged
Conversation
moe-berri
approved these changes
Oct 27, 2026
3 of 5 tasks
Contributor
Merging this PR will not alter performance1 warning
Comparing Footnotes |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
1 task done
11 of 17 tasks
Closed
3 of 5 tasks
4 of 6 tasks
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.
Refs #37118
OpenAI chat models now honor
stop_sequencessent to/v1/messages. Requests with a nonempty stop list use Chat Completions, where the existing adapter forwardsstop. Empty and omitted stop lists keep their current routeDetails
Screenshots / Proof of Fix
Live OpenAI
gpt-4o-mini, using the issue's model and prompt. The base checkout ran on port 4021 and the PR checkout on port 4019, with each checkout explicitly onPYTHONPATH. Both used this config and anOPENAI_API_KEYloaded from protected local storageThe unauthenticated config above was restricted to
127.0.0.1. Save this request asmessages.json{"model":"gpt-mini","max_tokens":80,"stop_sequences":["STOPPROBE"],"messages":[{"role":"user","content":"Write the exact token STOPPROBE as the first word, then write a 40-word poem about cats. Do not skip the token."}]}The response excerpts below retain the full content and stop fields and omit response IDs, model, and usage
Before (53a4cee)
Send the request
Observe HTTP 200 with the stop token and poem
After (4079e66)
Send the same request
Observe HTTP 200 with empty text and no poem
The same live requests with
stream: trueemitted the token and poem before the fix and no text deltas after it, followed bymessage_stop. The/v1/chat/completionscontrol withstop: ["STOPPROBE"]returned empty text andfinish_reason: stopat both commitsCaveats
OpenAI reports
finish_reason: stopfor both a natural end and a matched stop sequence, without identifying the sequence. This patch preserves the existingstop_reason: end_turnandstop_sequence: nullmapping. It fixes the dropped stop request for chat-capable models, while the issue's requestedstop_sequenceresponse reason remains unresolvedThe OSV CI scan fails on dependency findings in existing lockfiles, including filelock, Pillow, and the VS Code extension’s MSAL package. This PR changes no lockfiles or scanner configuration. Other CI jobs are still running