mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #5495] [Engine] serve: a picture's encode whose client left no longer holds every request #5468
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#5468
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/5495
Author: @Keoian
Created: 11/7/2026
Status: 🔄 Open
Base:
main← Head:serve-vision-cancel-encode📝 Commits (1)
566a962[Engine] serve: a picture's encode whose client left no longer holds every request📊 Changes
3 files changed (+463 additions, -36 deletions)
View changed files
📝
docs/DETAILS.md(+5 -0)📝
serve/server.py(+212 -36)➕
serve/test_vision_cancel.py(+246 -0)📄 Description
Problem and result
If the client leaves while a picture is being read (the web page's Stop, a closed connection), the server stops answering for the rest of that picture's encode. Nothing crashes and nothing is logged.
With this PR, a picture's encode whose client left goes on only while that is useful:
/unload?wait). The reader is killed within 0.1 s of seeing that, started again at once (0.9-1.2 s on the CPU below), and the turn is handed on. The half-written output file is deleted.Measured on 2x Xeon E5-2696 v3 and 2x Tesla P100 16 GB (layer split, power-capped at 150 W). Model: Qwen3.8-Flash-Next (a Q4_K_XL / IQ4_NL pack). The picture reader ran on the CPU (
"vision": {"gpu": false, "threads": 16, "max_tokens": 3600}, Q8_0 mmproj). Each case used fresh pictures (a random 6-character code in a white box on a noisy background, so nothing was cached), sent over HTTP and cancelled the way a browser does: the socket was shut down. Times run from sending a request to the end of its answer."stream": false/v1/messagesThe cost: if another request ended a cancelled picture's encode, a later question about that picture reads it again from the start. In the first row, the follow-up sent after the text took 94.1 s instead of 15.0 s (when it was cached), and it read the code right.
Log lines name each outcome:
Related discussion
#1999 (closed). It added the cancel event to
prepare()and named this case as the remaining limit. This is a focused fix with no new setting and no changed default, so there was no separate scope discussion.Approach
Service.fifobecomes aTurn: athreading.Lockthat also counts the requests blocked on it. Everything that used the lock (acquirewith or without a timeout,acquire(blocking=False),release,with) works the same. A refused non-blocking try does not count as waiting.unload_waitingcounts as waiting.Vision.wanting). A waiting request with the same picture keeps the cancelled encode going.Vision._readlinetakes an optionalstop. It checks it every 0.1 s and, when it is true, kills the encoder the same way #1317's timeout does, then raisesClientGone.stopis passed only when the request has a cancel event, so the other callers are unchanged._vision_upstarts it, and a failure there is a 503 as at load. An elastic encoder starts with its next picture, as before.docs/DETAILS.md(Images): one paragraph on what a Stop does while a picture is read.Compatibility: the change only matters once a client has left during an encode. Requests whose client stays take the same turns in the same order. The extra work is a 0.1 s poll while an encode runs and one more SHA-256 of each picture's bytes as sent (one for the encode, one more for a request that has to wait for the turn).
Validation
Passed:
python -m serve.test_vision_cancel, on this branch (146df3c4plus this commit), Ubuntu, Python 3.14: 7 tests OK. They use a fake reader: a request that stays is never stopped; a cancelled encode is stopped as soon as another request waits and the reader is started again before the turn is handed on, with no half-written file left; it is kept while nobody waits; it is kept for a waiting request with the same picture; a reader that did not start again starts with the next picture;unload_waitingcounts as waiting;Turncounts its waiters.python -m pytest serve, same machine. With this commit: 1467 passed, 49 skipped, 1 failed (below). On146df3c4alone: 1460 passed, 49 skipped, the same 1 failed. The 7 more are this PR's tests. The full run was made before a test-only fix:test_unload_with_wait_counts_as_waitingpassed, but its thread ended in an AttributeError on the mock engine (one pytest warning more than on146df3c4). Since the fix, that file passes 3 of 3 with no warning."stream": falsecase (the two numbers in those rows). The server code was this commit'sserve/server.pychanges on my P100 working branch (upstream9f7d977dplus P100 engine commits, including #5436). The commit applies cleanly to146df3c4, and no upstream commit between the two touches the changed functions.Failed:
serve/test_keepawake.py::test_service_holds_for_the_whole_request_including_early_closefailed in every fullpython -m pytest serverun here, with and without this commit (one run on146df3c4alone, two with this commit). Run alone, the file fails about once in 20 runs, the same with and without (1 of 20 each). It was failing before this change.Not run:
restart()and_vision_upas #1317's timeout, but I did not run them on a card.Popen.kill()there was not exercised.Limits
http(s)URL (fetched after the wait), does not keep a cancelled encode going.🤖 Generated with Claude Code
https://claude.ai/code/session_01N976PznRue6hXdFtmrbJNj
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.