[PR #1953] [CLOSED] serve: the keep-alive while a prompt is read is a real SSE frame, not a comment #3774

Closed
opened 2026-11-07 15:30:39 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1953
Author: @rebuilt
Created: 10/11/2026
Status: ❌ Closed

Base: main ← Head: fix/sse-keepalive-frames


📝 Commits (1)

  • e17b07c serve: the keep-alive while a prompt is read is a real SSE frame, not a comment

📊 Changes

3 files changed (+81 additions, -11 deletions)

View changed files

📝 docs/DETAILS.md (+5 -3)
📝 serve/server.py (+20 -6)
📝 serve/test_server.py (+56 -2)

📄 Description

What

The streaming keep-alive (the heartbeat while a long prompt is read, or while a tool argument is held back) is written as an SSE comment (: keep-alive). A client that resets its stream idle timeout on parsed SSE frames drops comments before that accounting, so a slow prefill times out and the client retries from scratch every time.

This changes the two writers whose clients time out this way:

  • OpenAI /v1/chat/completions: an empty chat.completion.chunk, reusing the last real chunk's id/created/model (choices: [{index: 0, delta: {}, finish_reason: null}]).
  • Anthropic /v1/messages: a real event: ping / data: {"type":"ping"}.

/v1/responses already sends a real response.in_progress event every 15 s, so it is unchanged.

Why not the comment

Reported from a live OpenCode session against a local Strata (gfx1201, IQ3_S 128k): 72k–100k-token prompts, 1–4 minute prefills. OpenCode applies its chunkTimeout (default 300 s) to the parsed frame stream and ignores comments, so it aborted mid-stream with "Timed out waiting for response data" / "Connection lost while reading the response" and retried, each retry re-reading the prompt. The engine log showed the abandoned turn:

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

After the change, ~5.5 h of the same traffic: 0 client timeouts/retries, 301 requests served, 0 stalls, 0 engine faults.

  • #1619 (a queued request sends no bytes) and #1666 (a held-back tool argument) suggest the same comment. The queue wait and the held-back argument still send real frames now; please use frames, not comments, in those paths too — a comment will not reset a comment-dropping client.
  • Fixes the client-side half of #1951.

Tests

  • New serve/test_server.py::KeepAliveFrames — test_chat_keepalive_is_a_frame, test_anthropic_keepalive_is_a_ping_event.
  • PromptProgress.test_a_client_that_does_not_ask_gets_a_keep_alive_frame now expects the empty chunk instead of the comment.

🔄 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/1953 **Author:** [@rebuilt](https://github.com/rebuilt) **Created:** 10/11/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/sse-keepalive-frames` --- ### 📝 Commits (1) - [`e17b07c`](https://github.com/Niko1221/Strata/commit/e17b07c0bb0e11e1364876d80adf0dc3fb18863f) serve: the keep-alive while a prompt is read is a real SSE frame, not a comment ### 📊 Changes **3 files changed** (+81 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+5 -3) 📝 `serve/server.py` (+20 -6) 📝 `serve/test_server.py` (+56 -2) </details> ### 📄 Description ## What The streaming keep-alive (the heartbeat while a long prompt is read, or while a tool argument is held back) is written as an **SSE comment** (`: keep-alive`). A client that resets its stream idle timeout on parsed SSE **frames** drops comments before that accounting, so a slow prefill times out and the client retries from scratch every time. This changes the two writers whose clients time out this way: - **OpenAI** `/v1/chat/completions`: an empty `chat.completion.chunk`, reusing the last real chunk's `id`/`created`/`model` (`choices: [{index: 0, delta: {}, finish_reason: null}]`). - **Anthropic** `/v1/messages`: a real `event: ping` / `data: {"type":"ping"}`. `/v1/responses` already sends a real `response.in_progress` event every 15 s, so it is unchanged. ## Why not the comment Reported from a live OpenCode session against a local Strata (gfx1201, IQ3_S 128k): 72k–100k-token prompts, 1–4 minute prefills. OpenCode applies its `chunkTimeout` (default 300 s) to the parsed frame stream and ignores comments, so it aborted mid-stream with `"Timed out waiting for response data"` / `"Connection lost while reading the response"` and retried, each retry re-reading the prompt. The engine log showed the abandoned turn: ``` strata serve: prompt 72822 tokens = 0 reused + 4096 of 72822 read in 17866 ms (229.3 tok/s), 0 generated in 0 ms ... (cancelled) ``` After the change, ~5.5 h of the same traffic: **0** client timeouts/retries, 301 requests served, 0 stalls, 0 engine faults. ## Related - #1619 (a queued request sends no bytes) and #1666 (a held-back tool argument) suggest the same comment. The queue wait and the held-back argument still send real frames now; please use frames, not comments, in those paths too — a comment will not reset a comment-dropping client. - Fixes the client-side half of #1951. ## Tests - New `serve/test_server.py::KeepAliveFrames` — `test_chat_keepalive_is_a_frame`, `test_anthropic_keepalive_is_a_ping_event`. - `PromptProgress.test_a_client_that_does_not_ask_gets_a_keep_alive_frame` now expects the empty chunk instead of the comment. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:30:39 +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#3774
No description provided.