Repository navigation
fix(controller): keep a streaming request in flight until the relay ends - #644
Conversation
shipiyouniao
left a comment
There was a problem hiding this comment.
I confirmed that an open stream stays off the sleep candidate list. I also reproduced two timing cases in the controller and one stats error with a local HTTP backend.
- Requests wait for an in-progress sleep transition before waking and forwarding. - Auto-sleep rechecks the configured idle interval, not just the busy flag. - Abort detection now reads complete SSE events so split reads are not missed.
|
Thanks for the review. I have addressed all three in 98ab4ab. PTAL😊 @shipiyouniao |
shipiyouniao
left a comment
There was a problem hiding this comment.
I retested the three cases from the previous review on 98ab4ab. All three passed. Two SSE parsing cases remain before merge.
- Consume events at blank lines with LF, CRLF or CR endings, including a split CRLF. - Decode the data field as JSON so whitespace cannot change the abort result.
Fixed both in 1b58ddb. Events are now consumed at blank lines for LF, CRLF and CR endings, including a CRLF split |
shipiyouniao
left a comment
There was a problem hiding this comment.
I verified that complete CRLF events are consumed and JSON whitespace no longer changes abort accounting. All 19 streaming tests passed. One performance regression remains in the event scanner.
- Continue the scan where it stopped so a split event is not rescanned from zero. - Keep the trailing line ending state so a CRLF split across reads still parses.
Fixed in dfacf14. The scan now resumes from the last scanned position instead of restarting at zero, and it keeps the trailing line ending state so a split CRLF is still recognized. Locally, a 64 KiB event fed in 1024-byte chunks went from 395 ms to about 2.6 ms. 😊 @shipiyouniao |
shipiyouniao
left a comment
There was a problem hiding this comment.
Rechecked the long, fragmented SSE event on dfacf14. The relay now resumes scanning at the previous offset, and split CRLF and abort events are still handled correctly. LGTM.
Closes #643
Summary
The controller marks a model eligible for sleep when it appears idle. vLLM sleep with mode abort terminates any ongoing work. #643
There were two root causes where an in progress generation was mistakenly considered idle.
ModelActivityStats only updated the activity timestamp after a request finished, and it used the request start time for that timestamp.
For streaming requests, route_request marked the request finished immediately after upstream headers returned, which happens when session.post resolves.
traffic_monitor tracks in flight requests. is_idle returns false while a request is being served.
Activity timestamp updates to the time the request completes and never moves backward.
router and frontend keep a streamed response marked in flight until the relay sending data to client finishes via StreamedResponse.aclose.
A cancelled relay or a stream ending with finish_reason abort counts as a failed request.
sleep_manager skips busy models from sleep candidates. It treats unknown states as not safe to sleep.
It checks model state one more time right before triggering sleep.
Manual sleep can still run, and a warning is shown to note it will abort active requests.
/models/idle and /models/active now use the configured threshold by default instead of a fixed 300s value.
Bad threshold or window parameters return 400 error instead of 500.
Test
pytest tests/test_traffic_activity.py tests/test_frontend_streaming.py
tests/test_sleep_manager.py tests/test_controller_errors.py
→ 73 passed
Setup
finish_reasonabortstop/traffic/statsafter the requestsuccessful=1 failed=0 avg=0.012ssuccessful=1 failed=0 avg=26.3sOn main branch, the engine logs a sleep call while the request is still running: