[PR #4340] [CLOSED] [Engine] serve: keep a long prompt read alive for clients that count events #5015

Closed
opened 2026-11-07 16:32:02 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4340
Author: @suifei
Created: 10/27/2026
Status: ❌ Closed

Base: main ← Head: fix/read-heartbeat


📝 Commits (2)

  • e450b05 [Engine] serve: keep a long prompt read alive for clients that count events
  • 66e0edf test(serve): the read beat on the chat and anthropic streams, not just the structured one

📊 Changes

3 files changed (+100 additions, -2 deletions)

View changed files

📝 serve/server.py (+36 -2)
📝 serve/test_queue_keepalive.py (+37 -0)
📝 serve/test_structured.py (+27 -0)

📄 Description

Problem

While a long prompt is read, the streams sent only SSE comments (: keep-alive). A client whose idle timer counts the
events it parses never sees those, so a long read looks like a dead connection. Measured on a 45K-token read: 434
comments and 7 data events, the largest gap between data events 34.0 s - the whole read
; a 190K-233K prompt is 100-120 s
of the same. One client's 300 s stream-idle timeout took a request down mid-read, and its retry read the prompt again.

What changes (streams only; single stream included)

  • /v1/chat/completions: an empty delta every PREFILL_BEAT_S (5 s) while the prompt is read. Every OpenAI client
    ignores an empty delta; the response content and the final chunk are unchanged.
  • a request with response_format: an empty delta is passed through untouched (_empty_delta) instead of being held in
    the validation buffer, so the beat reaches the client during the read instead of with the answer. The buffered,
    validated answer still goes out exactly as before.
  • /v1/messages: Anthropic's own event: ping every PREFILL_BEAT_S, and the plain comment between two beats.
  • the SSE comment between two beats in openai_chunks is kept.

Cost: one small chunk every 5 s while a prompt is read.

Validation

Revision 66e0edf (branch fix/read-heartbeat). Tests and measurements run on this revision.

Passed:

  • python -m unittest serve.test_structured: 11 tests, 2 skipped (includes the new test_a_read_beat_reaches_the_client_before_the_answer, which checks the beat is out before the next chunk is generated).
  • python -m unittest serve.test_queue_keepalive: 3 tests (the comment between beats is what it checks).
  • On the machine, a 45K-token read: beats at 10.2 / 15.2 / 20.2 / 25.2 / 30.2 s, largest gap 10.2 s (was 34.0 s); /v1/messages on the same read: 5 pings + 18 data events; the structured read: 5 empty deltas spread over the read.

Failed:

  • none observed for the checks above.

Not run:

  • the full serve suite in CI. On the batching branch it ran 1045 tests with one failure in the process-lifeline watcher, which fails on an unmodified checkout of this branch too (environment: this container).

Note

This is independent of the batch/step work: a single-stream deployment hits the same timeout. The batching branch
(feat/dsv41-batch-m1) carries the same change as part of PR #4199; this branch is that change alone.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4340 **Author:** [@suifei](https://github.com/suifei) **Created:** 10/27/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/read-heartbeat` --- ### 📝 Commits (2) - [`e450b05`](https://github.com/Niko1221/Strata/commit/e450b05a132d93712014970edc83b197a3e5f06f) [Engine] serve: keep a long prompt read alive for clients that count events - [`66e0edf`](https://github.com/Niko1221/Strata/commit/66e0edfb57a9e22a0acc7c02c0f1d726317584d7) test(serve): the read beat on the chat and anthropic streams, not just the structured one ### 📊 Changes **3 files changed** (+100 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `serve/server.py` (+36 -2) 📝 `serve/test_queue_keepalive.py` (+37 -0) 📝 `serve/test_structured.py` (+27 -0) </details> ### 📄 Description ## Problem While a long prompt is read, the streams sent only SSE comments (`: keep-alive`). A client whose idle timer counts the events it parses never sees those, so a long read looks like a dead connection. Measured on a 45K-token read: **434 comments and 7 data events, the largest gap between data events 34.0 s - the whole read**; a 190K-233K prompt is 100-120 s of the same. One client's 300 s stream-idle timeout took a request down mid-read, and its retry read the prompt again. ## What changes (streams only; single stream included) * `/v1/chat/completions`: an **empty delta** every `PREFILL_BEAT_S` (5 s) while the prompt is read. Every OpenAI client ignores an empty delta; the response content and the final chunk are unchanged. * a request with `response_format`: an empty delta is passed through untouched (`_empty_delta`) instead of being held in the validation buffer, so the beat reaches the client during the read instead of with the answer. The buffered, validated answer still goes out exactly as before. * `/v1/messages`: Anthropic's own `event: ping` every `PREFILL_BEAT_S`, and the plain comment between two beats. * the SSE comment between two beats in `openai_chunks` is kept. Cost: one small chunk every 5 s while a prompt is read. ## Validation Revision `66e0edf` (branch `fix/read-heartbeat`). Tests and measurements run on this revision. **Passed:** * `python -m unittest serve.test_structured`: 11 tests, 2 skipped (includes the new `test_a_read_beat_reaches_the_client_before_the_answer`, which checks the beat is out before the next chunk is generated). * `python -m unittest serve.test_queue_keepalive`: 3 tests (the comment between beats is what it checks). * On the machine, a 45K-token read: beats at 10.2 / 15.2 / 20.2 / 25.2 / 30.2 s, largest gap **10.2 s** (was 34.0 s); `/v1/messages` on the same read: 5 pings + 18 data events; the structured read: 5 empty deltas spread over the read. **Failed:** * none observed for the checks above. **Not run:** * the full `serve` suite in CI. On the batching branch it ran 1045 tests with one failure in the process-lifeline watcher, which fails on an unmodified checkout of this branch too (environment: this container). ## Note This is independent of the batch/step work: a single-stream deployment hits the same timeout. The batching branch (`feat/dsv41-batch-m1`) carries the same change as part of PR #4199; this branch is that change alone. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:32:02 +07:00
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#5015
No description provided.