Skip to content

fix(controller): keep a streaming request in flight until the relay ends - #644

Merged
shipiyouniao merged 4 commits into
ovg-project:mainfrom
Epimeleia7:fix/sleep-kills-running-request
Nov 24, 2026
Merged

shipiyouniao merged 4 commits into
ovg-project:mainfrom
Epimeleia7:fix/sleep-kills-running-request

Conversation

@Epimeleia7

@Epimeleia7 Epimeleia7 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

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

截屏2026-11-23 上午10 08 38

Setup

  • NVIDIA RTX 4080, Qwen2.5-0.5B, vLLM 0.30.0
  • Flags used: --enable-sleep-mode
  • VLLM_SERVER_DEV_MODE=1 exposed the /sleep route
main This PR
output tokens received 299 / 1500 1243 / 1500
finish_reason abort stop
engine sleep calls during the request 1 0
/traffic/stats after the request successful=1 failed=0 avg=0.012s successful=1 failed=0 avg=26.3s

On main branch, the engine logs a sleep call while the request is still running:

INFO: 127.0.0.1:48632 - "POST /sleep?level=1&mode=abort HTTP/1.1" 200 OK

@shipiyouniao shipiyouniao left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread controller/sleep_manager.py Resolved
Comment thread controller/sleep_manager.py Resolved
Comment thread controller/frontend.py Resolved
- 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.
@Epimeleia7

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I have addressed all three in 98ab4ab. PTAL😊 @shipiyouniao

@shipiyouniao shipiyouniao left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I retested the three cases from the previous review on 98ab4ab. All three passed. Two SSE parsing cases remain before merge.

Comment thread controller/frontend.py Resolved
Comment thread controller/frontend.py Resolved
- 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.
@Epimeleia7

Copy link
Copy Markdown
Contributor Author

I retested the three cases from the previous review on 98ab4ab. All three passed. Two SSE parsing cases remain before merge.

Fixed both in 1b58ddb. Events are now consumed at blank lines for LF, CRLF and CR endings, including a CRLF split
across reads. The data field is decoded as JSON, so whitespace after the colon cannot change the result. Multiple data lines in one event are joined before decoding as well. PTAL, Thanks! @shipiyouniao

@shipiyouniao shipiyouniao left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread controller/frontend.py Resolved
- 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.
@Epimeleia7

Copy link
Copy Markdown
Contributor Author

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.

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 shipiyouniao left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@shipiyouniao
shipiyouniao merged commit 65905a9 into ovg-project:main Nov 24, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto-sleep can put a model to sleep mid-generation and abort the streaming request

2 participants