[PR #4758] [Engine] send the stream role with the first response data #5166

Open
opened 2026-11-07 16:33:11 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4758
Author: @Tsury
Created: 10/30/2026
Status: 🔄 Open

Base: main ← Head: fix-first-chunk


📝 Commits (1)

  • ce82e6f [Engine] send the stream role with the first response data

📊 Changes

2 files changed (+169 additions, -1 deletions)

View changed files

📝 serve/server.py (+21 -1)
➕ serve/test_first_chunk.py (+148 -0)

📄 Description

Problem and result

openai_chunks sends the role-only chunk before the prompt is read. A client that times the first data chunk then measures about 0 ms of prefill (#2391, llama-benchy's TTFR and est_ppt). vLLM and llama.cpp send it with the engine's first output.

After this change, the role goes out once, right before the first data chunk. Keep-alive comments are not data and may go first. A progress chunk counts as data.

#2391. Based on #2480 by @KeyanHu-git, which its author closed as a draft on Oct 22 with no review. The test file comes from that PR. If they would rather carry it on, I will close this one.

Approach

A small first() generator yields the role chunk once, and every path that emits data calls it first.

Validation

Passed:

  • New tests against unchanged main (870aedd9): 10 failures. With the change: all pass.
  • python -m unittest serve.test_first_chunk serve.test_server serve.test_structured: 372 tests pass (Linux, Python 3.14).

Not run:

  • python -m unittest discover -s serve and any GPU or model run. This change was split from a maintained v0.2.8 build that runs on an RTX 5090 Laptop; the unit tests above are the evidence for this branch.

Limits

A client that reads the role chunk as a sign of life gets it later. Keep-alive comments still arrive during a long prompt read.

🤖 Generated with Claude Code


🔄 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/4758 **Author:** [@Tsury](https://github.com/Tsury) **Created:** 10/30/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix-first-chunk` --- ### 📝 Commits (1) - [`ce82e6f`](https://github.com/Niko1221/Strata/commit/ce82e6f0c12a66f1852b4c116ba577efdea86bbf) [Engine] send the stream role with the first response data ### 📊 Changes **2 files changed** (+169 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `serve/server.py` (+21 -1) ➕ `serve/test_first_chunk.py` (+148 -0) </details> ### 📄 Description ## Problem and result `openai_chunks` sends the role-only chunk before the prompt is read. A client that times the first data chunk then measures about 0 ms of prefill (#2391, llama-benchy's TTFR and `est_ppt`). vLLM and llama.cpp send it with the engine's first output. After this change, the role goes out once, right before the first data chunk. Keep-alive comments are not data and may go first. A progress chunk counts as data. ## Related discussion #2391. Based on #2480 by @KeyanHu-git, which its author closed as a draft on Oct 22 with no review. The test file comes from that PR. If they would rather carry it on, I will close this one. ## Approach A small `first()` generator yields the role chunk once, and every path that emits data calls it first. ## Validation **Passed:** - New tests against unchanged `main` (870aedd9): 10 failures. With the change: all pass. - `python -m unittest serve.test_first_chunk serve.test_server serve.test_structured`: 372 tests pass (Linux, Python 3.14). **Not run:** - `python -m unittest discover -s serve` and any GPU or model run. This change was split from a maintained v0.2.8 build that runs on an RTX 5090 Laptop; the unit tests above are the evidence for this branch. ## Limits A client that reads the role chunk as a sign of life gets it later. Keep-alive comments still arrive during a long prompt read. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#5166
No description provided.