[GH-ISSUE #483] Queued requests are byte-silent: streaming clients with an idle timeout kill turns waiting for the engine (like #403, one layer up) #194

Closed
opened 2026-10-29 21:22:24 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @catonooka on GitHub (Oct 25, 2026).
Original GitHub issue: https://github.com/mw00/project-maya/issues/483

The behavior

A request waiting in the FIFO for its first engine turn sends zero bytes to a streaming client — no SSE events, no keep-alive comments. On v1.1.27 (also present on v1.1.20 where we first measured it), Service.run wraps the initial wait in with self._turn(hold, cancel):, and _turn only yields None (a keep-alive) on the fair-slice re-queue path (serve/server.py); the initial fifo.wait_turn loop is silent. Once the turn starts, prompt-progress pings flow fine.

With one conversation at a time, any second concurrent request queues for the whole duration of the running turn. A client with a stream-idle timeout then kills the turn while the model is working fine. Same failure class as #403, one layer up.

Measured (v1.1.20-line tree, DeepSeek-V4.1-Flash-1017 EXL3, 2x RTX 3090, one queued stream behind a ~2000-token generation):

  • 103 s of total wire silence for the queued request (socket-level probe, timestamps every read)
  • pi-ai-class clients default streamIdleTimeoutMs to 300000 (5 min) — a long generation or a queue behind several requests crosses it easily

The fix we run locally (small, tested)

Inline the initial wait the same way the fair-slice re-queue does, yielding ("ping", None) every 50 ms; the SSE layer already writes those as : keep-alive comment lines:

place = self.fifo.enqueue(units=1)
while not cancel.is_set():
    if self.fifo.wait_turn(place, timeout=0.05):
        break
    yield "ping", None

After: 2104 keep-alives over a 105 s queue wait, max silent gap 2.2 s (OpenAI dialect); 1263 keep-alives / 1.9 s max gap on the Anthropic dialect. Answers unchanged; solo / non-stream / thinking paths unregressed.

One trap we hit while making it (worth knowing if you fix it directly): a yield inside that wait lands outside the try: in run, so a client disconnecting while queued throws GeneratorExit at the ping yield and leaks the FIFO place and the status["queued"] counter — wrap the wait inside the try and give both back in the finally (our local test_server.GoneClients (test_a_queued_request_leaves_when_its_client_goes) catches exactly this; it went red the moment we moved the yield out).

Full writeup + patch: catonooka/maya-s24-turbo, dsv41-3090/deepseek-campaign-1024/FIX-queue-heartbeats.md and patches/queue-heartbeats.patch (format-patch against v1.1.20-line; the surrounding code has moved a little by v1.1.27 — run now tracks a queued flag in the finally, which covers the counter half of the same leak already).

Happy to turn this into a PR against current main if useful.

Originally created by @catonooka on GitHub (Oct 25, 2026). Original GitHub issue: https://github.com/mw00/project-maya/issues/483 ## The behavior A request waiting in the FIFO for its first engine turn sends **zero bytes** to a streaming client — no SSE events, no keep-alive comments. On `v1.1.27` (also present on v1.1.20 where we first measured it), `Service.run` wraps the initial wait in `with self._turn(hold, cancel):`, and `_turn` only yields `None` (a keep-alive) on the **fair-slice re-queue** path (`serve/server.py`); the initial `fifo.wait_turn` loop is silent. Once the turn starts, prompt-progress pings flow fine. With one conversation at a time, any second concurrent request queues for the whole duration of the running turn. A client with a stream-idle timeout then kills the turn while the model is working fine. Same failure class as #403, one layer up. ## Measured (v1.1.20-line tree, DeepSeek-V4.1-Flash-1017 EXL3, 2x RTX 3090, one queued stream behind a ~2000-token generation): - **103 s of total wire silence** for the queued request (socket-level probe, timestamps every read) - pi-ai-class clients default `streamIdleTimeoutMs` to 300000 (5 min) — a long generation or a queue behind several requests crosses it easily ## The fix we run locally (small, tested) Inline the initial wait the same way the fair-slice re-queue does, yielding `("ping", None)` every 50 ms; the SSE layer already writes those as `: keep-alive` comment lines: ```python place = self.fifo.enqueue(units=1) while not cancel.is_set(): if self.fifo.wait_turn(place, timeout=0.05): break yield "ping", None ``` After: **2104 keep-alives over a 105 s queue wait, max silent gap 2.2 s** (OpenAI dialect); 1263 keep-alives / 1.9 s max gap on the Anthropic dialect. Answers unchanged; solo / non-stream / thinking paths unregressed. One trap we hit while making it (worth knowing if you fix it directly): a `yield` inside that wait lands **outside** the `try:` in `run`, so a client disconnecting while queued throws `GeneratorExit` at the ping yield and leaks the FIFO place and the `status["queued"]` counter — wrap the wait inside the try and give both back in the `finally` (our local `test_server.GoneClients` (`test_a_queued_request_leaves_when_its_client_goes`) catches exactly this; it went red the moment we moved the yield out). Full writeup + patch: [catonooka/maya-s24-turbo](https://github.com/catonooka/maya-s24-turbo), `dsv41-3090/deepseek-campaign-1024/FIX-queue-heartbeats.md` and `patches/queue-heartbeats.patch` (format-patch against v1.1.20-line; the surrounding code has moved a little by v1.1.27 — `run` now tracks a `queued` flag in the finally, which covers the counter half of the same leak already). Happy to turn this into a PR against current main if useful.
Author
Owner

@mw00 commented on GitHub (Oct 27, 2026):

Thank you for the measurements and for pointing out the GeneratorExit trap. From v1.1.30 a streamed request waiting in the queue for its first turn sends an SSE keep-alive comment (: keep-alive) every 2 seconds (MAYA_QUEUE_PING_S changes it), on the OpenAI, Anthropic and Responses streams. Every SSE client ignores these comments, so they only keep idle timeouts from firing. The wait sits inside the request's cleanup, so a client that disconnects while queued still gives its place back; a test covers both.

<!-- gh-comment-id:6436263988 --> @mw00 commented on GitHub (Oct 27, 2026): Thank you for the measurements and for pointing out the GeneratorExit trap. From v1.1.30 a streamed request waiting in the queue for its first turn sends an SSE keep-alive comment (`: keep-alive`) every 2 seconds (`MAYA_QUEUE_PING_S` changes it), on the OpenAI, Anthropic and Responses streams. Every SSE client ignores these comments, so they only keep idle timeouts from firing. The wait sits inside the request's cleanup, so a client that disconnects while queued still gives its place back; a test covers both.
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mw00/project-maya#194
No description provided.