mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #7] [MERGED] serve: fix zero-token replies from engine-queue race between requests #2409
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#2409
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/7
Author: @coolio986
Created: 9/25/2026
Status: ✅ Merged
Merged: 9/26/2026
Merged by: @Niko1221
Base:
main← Head:fix/engine-queue-race📝 Commits (1)
dd03276serve: fix zero-token replies from engine-queue race between requests📊 Changes
1 file changed (+56 additions, -18 deletions)
View changed files
📝
serve/server.py(+56 -18)📄 Description
Summary
Fixes blank/empty responses that appeared when a client (e.g. opencode) has two requests in flight at once — a title-generation request alongside the main tool-calling turn. The second request frequently returned zero tokens: the server logged
done: 0 tokens in 0 s (length, cancel=False)and the client showed an empty reply.Root cause
StrataEnginemultiplexes every request over one residentstrata --servesubprocess and a single shared line queue (self.lines), with no per-request framing. InService.run(), a stop token (<|im_end|>) breaks the token loop with the engine generator still suspended and its internaldoneflagFalse. That generator's cleanup — writeSTOP, then drainself.linesuntilDONE— therefore ran only whenrun()'s frame was torn down later, after thewith self.fifolock had been released. By then the next request held the lock and had issued its ownGEN; the prior request's drain raced it on the shared queue and consumed the new request'sDONE. The new request saw an immediate end-of-stream: 0 tokens,finishleft at its default"length".Fix
Close the engine generator inside the
with self.fifoblock viatry/finally, so a request'sSTOP+drain completes while it still holds the lock and cannot leave stray lines on the shared queue for the next request to misread as its ownDONE.Also included:
max_newto the default (1024) in both/v1/chat/completionsand/v1/messages. Some clients sendmax_tokens: -1("unlimited"); that value passed straight through andGEN -1made the engine yield 0 tokens.GeneratorExitand setfinish="disconnect"instead of leaving it as"length".STRATA_DEBUG(off by default): a per-request_debug_reqline and araw:dump of decoded model output at completion.done:line; emit the progress line every 1 s instead of 15 s.Test plan
python -c "import ast; ast.parse(open('serve/server.py').read())"passes.--engine mock): 2 concurrent streaming + sequential streaming + non-stream OpenAI + Anthropic requests all return content with correct finish reason; no0 tokens (length)regressions.STRATA_DEBUG=1 ./run-iq3_xxs.sh): full opencode agentic loop (title-gen, tool calls, file write/edit, test run, final answer) completes with every turn producing tokens; the previously-blanktools=11main turn now streams normally.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.