mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #454] [CLOSED] serve: honor stop and stop_sequences #2648
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#2648
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/454
Author: @zuraiz-anjum
Created: 10/2/2026
Status: ❌ Closed
Base:
main← Head:serve-stop-sequences📝 Commits (1)
5fac0d7serve: honor stop and stop_sequences, cut the answer before the stop string and stop the engine there📊 Changes
3 files changed (+231 additions, -8 deletions)
View changed files
📝
docs/DETAILS.md(+3 -1)📝
serve/server.py(+101 -7)📝
serve/test_server.py(+127 -0)📄 Description
The server ignored OpenAI
stopand Anthropicstop_sequenceswithout an error, so a client got the text past its stop string and stop_reason "end_turn". With the mock engine scripted to say "alpha END beta gamma":Before:
OpenAI stop=['END'] -> 'alpha END beta gamma' stop
Anthropic stop_sequences=['END'] -> 'alpha END beta gamma' end_turn None
After:
OpenAI stop=['END'] -> 'alpha ' stop
Anthropic stop_sequences=['END'] -> 'alpha ' stop_sequence END
Service.run now cuts the answer text at the first stop string and leaves it out. Only the end of the text that could still be the start of a stop string is held back, so a stop split across tokens or streamed chunks is caught, and anything that turns out not to be a stop goes out as normal. On a match run() breaks out of the generation loop the same way a stop token does, so gen.close() sends STOP and the engine does not keep decoding. No engine change was needed. OpenAI takes a string or a list of up to 4 and Anthropic a list; a bad value is a 400. Anthropic sets stop_reason "stop_sequence" and stop_sequence to the matched string, streamed and not. Only answer text is matched, not thinking or tool call arguments. docs/DETAILS.md lists stop strings with the other honored fields.
New tests in serve/test_server.py (StopStrings) cover both APIs, streamed and not, several stops, a stop split across tokens, a near miss prefix, no stop, an empty list, bad values, and that the engine stopped early.
python -m unittest serve.test_server serve.test_mcp serve.test_lifecycle serve.test_monitor serve.test_detok serve.test_structured serve.test_winjob plus all tools.test_setup_* modules: 270 tests OK (7 skipped).
One edge I left alone: if a reply hits a stop string and also has a finished tool call, OpenAI still reports finish_reason "tool_calls". Easy to change if you'd rather stop win.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.