[GH-ISSUE #1619] serve: a request waiting for the single request turn sends no bytes, so clients with a stream idle timeout abort it (and the retry re-reads the prompt) #649

Closed
opened 2026-11-04 01:44:47 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @taxah92 on GitHub (Oct 8, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/1619

Summary

With the default single-turn server (parallel / --batch off) a request that is waiting for the request turn receives no bytes at all — not even SSE comments. The 10 s heartbeat exists only for the request that already holds the turn (serve/server.py:1472, 1145), and the FIFO is taken before the first yield of the response (serve/server.py:3466, first yield at 3489). A client with a stream idle timeout therefore aborts a perfectly healthy queued request; ours retries it, and each retry starts a new prompt read, so the queue grows and the loop repeats.

Environment

  • Strata v0.1.41, engine 0.1.41, built from source (sm_70), Ubuntu 26.04, Tesla V100 SXM2 16 GB
  • Qwen3.8-Flash-Next IQ3_S, --max-context 1048576 (YaRN), --kv k8v4 --kv-resident 32768, --spec 3, --prefill auto:16384, conversation cache 24576 MiB / 3 slots, parallel not set (one request at a time)
  • Client: OpenAI-compatible over SSE with a 300 s stream idle timeout

What we see

journalctl -u strata-0141 (three agent contexts sharing one server):

01:05:41 done: 25406 tokens in 529 s (stop)   <- one request generated for 8.8 minutes
01:05:42 done: 0 tokens in 1 s (cancel)       <- two requests that had waited ~5 minutes
01:05:44 done: 0 tokens in 2 s (cancel)
01:06:53 done: 0 tokens in 69 s (cancel)      <- their retries
01:07:03 done: 0 tokens in 10 s (cancel)
01:08:52 done: 585 tokens in 109 s (stop)     <- only now service resumes

The two aborted requests show 1-2 s of engine time: they were ended right after they finally got the turn, so they had spent the whole time queued. The engine log for the retries:

strata serve: prompt 141160 tokens = 12166 reused + 91392 of 128994 read in 68815 ms ... 0 generated

Why it matters

The abort also costs a conversation-cache slot (the restored entry is taken out of the cache and a cancelled turn never parks it — see the companion report), so the retry re-reads everything after the root checkpoint. We counted 28 such events in one day: ~740k tokens ≈ 9-10 minutes of pure re-prefill.

Suggested fix

Send the same heartbeat while a request waits for the FIFO as while it waits for the engine: SSE headers plus a : keepalive comment every ~10 s around the self.fifo acquisition (the heartbeat path already exists — serve/server.py:1145, 1472). SSE comments are the standard liveness signal and would also notice a client that went away while queued. A 300 s idle timeout is not an unusual client setting, and on a 16 GB card the queue can be 8+ minutes long.

Originally created by @taxah92 on GitHub (Oct 8, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/1619 ## Summary With the default single-turn server (`parallel` / `--batch` off) a request that is waiting for the request turn receives **no bytes at all** — not even SSE comments. The 10 s heartbeat exists only for the request that already holds the turn (`serve/server.py:1472`, `1145`), and the FIFO is taken before the first `yield` of the response (`serve/server.py:3466`, first `yield` at `3489`). A client with a stream idle timeout therefore aborts a perfectly healthy queued request; ours retries it, and each retry starts a new prompt read, so the queue grows and the loop repeats. ## Environment - Strata v0.1.41, engine 0.1.41, built from source (sm_70), Ubuntu 26.04, Tesla V100 SXM2 16 GB - Qwen3.8-Flash-Next IQ3_S, `--max-context 1048576` (YaRN), `--kv k8v4 --kv-resident 32768`, `--spec 3`, `--prefill auto:16384`, conversation cache 24576 MiB / 3 slots, `parallel` not set (one request at a time) - Client: OpenAI-compatible over SSE with a 300 s stream idle timeout ## What we see `journalctl -u strata-0141` (three agent contexts sharing one server): ``` 01:05:41 done: 25406 tokens in 529 s (stop) <- one request generated for 8.8 minutes 01:05:42 done: 0 tokens in 1 s (cancel) <- two requests that had waited ~5 minutes 01:05:44 done: 0 tokens in 2 s (cancel) 01:06:53 done: 0 tokens in 69 s (cancel) <- their retries 01:07:03 done: 0 tokens in 10 s (cancel) 01:08:52 done: 585 tokens in 109 s (stop) <- only now service resumes ``` The two aborted requests show 1-2 s of engine time: they were ended right after they finally got the turn, so they had spent the whole time queued. The engine log for the retries: ``` strata serve: prompt 141160 tokens = 12166 reused + 91392 of 128994 read in 68815 ms ... 0 generated ``` ## Why it matters The abort also costs a conversation-cache slot (the restored entry is taken out of the cache and a cancelled turn never parks it — see the companion report), so the retry re-reads everything after the root checkpoint. We counted 28 such events in one day: ~740k tokens ≈ 9-10 minutes of pure re-prefill. ## Suggested fix Send the same heartbeat while a request waits for the FIFO as while it waits for the engine: SSE headers plus a `: keepalive` comment every ~10 s around the `self.fifo` acquisition (the heartbeat path already exists — `serve/server.py:1145`, `1472`). SSE comments are the standard liveness signal and would also notice a client that went away while queued. A 300 s idle timeout is not an unusual client setting, and on a 16 GB card the queue can be 8+ minutes long.
Author
Owner

@Niko1221 commented on GitHub (Oct 10, 2026):

Fixed in v0.1.42. A request that waits for the single turn now sends an SSE keep-alive comment every 10 s (the same comment the running request already sends while the engine reads a prompt), so a client with a stream idle timeout no longer aborts a healthy queued request and re-reads the prompt on retry. A request whose client has gone away while queued now gives its place up instead of taking the turn only to cancel there. Test: serve/test_queue_keepalive.py. Thank you for the precise trace.

<!-- gh-comment-id:6099637360 --> @Niko1221 commented on GitHub (Oct 10, 2026): Fixed in v0.1.42. A request that waits for the single turn now sends an SSE keep-alive comment every 10 s (the same comment the running request already sends while the engine reads a prompt), so a client with a stream idle timeout no longer aborts a healthy queued request and re-reads the prompt on retry. A request whose client has gone away while queued now gives its place up instead of taking the turn only to cancel there. Test: serve/test_queue_keepalive.py. Thank you for the precise trace.
Author
Owner

@rebuilt commented on GitHub (Oct 11, 2026):

Confirmed from a second client, with a correction to the suggested fix.

We hit the same abort+retry loop on OpenCode against a local Strata (gfx1201, IQ3_S 128k). The difference from your report: the requests that aborted were not queued — they held the turn and were mid-prefill, with the server's keep-alive heartbeat flowing the whole time. That heartbeat is written as an SSE comment (: ping).

OpenCode applies its chunkTimeout (default 300 s) to the parsed SSE frame stream and drops comments before that accounting, so comments never reset it. We saw the exact 300 s timeout, then Connection lost while reading the response, then a retry that re-read the prompt:

strata serve: prompt 72822 tokens = 0 reused + 4096 of 72822 read in 17866 ms (229.3 tok/s),
  0 generated in 0 ms (0.0 tok/s), drafts accepted 0 of 0, 0 checkpoints (cancelled)

So the suggested : keepalive comment fixes the no-bytes-at-all case (your queue wait) but not the idle-timeout case: a client that drops comments will still abort. The fix has to be a real frame. We changed serve/server.py to emit an empty chat.completion.chunk (reusing the last real chunk's id/model) and, for Anthropic, event: ping — at the HTTP writer level, so both chunk generators get it.

Details, tests and before/after verification are in #1951. Recommend your fix use real frames too; a real frame also covers the FIFO wait you describe.

<!-- gh-comment-id:6108954021 --> @rebuilt commented on GitHub (Oct 11, 2026): Confirmed from a second client, with a correction to the suggested fix. We hit the same abort+retry loop on OpenCode against a local Strata (`gfx1201`, IQ3_S 128k). The difference from your report: the requests that aborted were **not** queued — they held the turn and were mid-prefill, with the server's keep-alive heartbeat flowing the whole time. That heartbeat is written as an SSE comment (`: ping`). OpenCode applies its `chunkTimeout` (default 300 s) to the **parsed SSE frame** stream and drops comments before that accounting, so comments never reset it. We saw the exact 300 s timeout, then `Connection lost while reading the response`, then a retry that re-read the prompt: ``` strata serve: prompt 72822 tokens = 0 reused + 4096 of 72822 read in 17866 ms (229.3 tok/s), 0 generated in 0 ms (0.0 tok/s), drafts accepted 0 of 0, 0 checkpoints (cancelled) ``` So the suggested `: keepalive` comment fixes the *no-bytes-at-all* case (your queue wait) but not the *idle-timeout* case: a client that drops comments will still abort. The fix has to be a real frame. We changed `serve/server.py` to emit an empty `chat.completion.chunk` (reusing the last real chunk's `id`/`model`) and, for Anthropic, `event: ping` — at the HTTP writer level, so both chunk generators get it. Details, tests and before/after verification are in #1951. Recommend your fix use real frames too; a real frame also covers the FIFO wait you describe.
Author
Owner

@Niko1221 commented on GitHub (Oct 13, 2026):

Thanks for the report. To keep the tracker current we are closing issues older than three days: 0.1.44 is out with a long list of fixes, and many older reports are covered by it or by 0.1.43.1.

If this still happens on 0.1.44, please leave a comment here with your engine log (and the version line it prints), and we will reopen it. A new issue that links this one works too.

<!-- gh-comment-id:6156158392 --> @Niko1221 commented on GitHub (Oct 13, 2026): Thanks for the report. To keep the tracker current we are closing issues older than three days: [0.1.44](https://github.com/Niko1221/Strata/releases/tag/v0.1.44) is out with a long list of fixes, and many older reports are covered by it or by 0.1.43.1. If this still happens on 0.1.44, please leave a comment here with your engine log (and the version line it prints), and we will reopen it. A new issue that links this one works too.
Sign in to join this conversation.
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
Niko1221/Strata#649
No description provided.