Skip to content

streams: return_progress sends a prompt pass's progress before the first token - #3216

Open
ashhart wants to merge 7 commits into
mainfrom
lead/prefill-progress-events
Open

ashhart wants to merge 7 commits into
mainfrom
lead/prefill-progress-events

Conversation

@ashhart

@ashhart ashhart commented Nov 13, 2026

Copy link
Copy Markdown
Owner

What changed

A streamed chat completion, completion or Responses request that sends return_progress: true now hears how far its prompt pass has come before the reply starts. It builds on the engine's existing prefill reporting:

  • engine_api.Request.return_progress (default false) and a new Event.progress with done, total and cached prompt tokens.
  • The lane host sends a count after each fill-queue call that leaves the pass open, and after each call of a lone driver that fills a prompt in pieces (Flash Next's), for backends that report their filled rows. Each count is higher than the last (a pass requeued for lane memory never counts back), done includes the restored prefix once, and the pass's prefilled event first sends done == total.
  • Chat and completions write each count as a chunk with "choices": [] and the counts under tensorfold.progress, the same shape as the include_usage chunk, so clients that read choices pass over it. Responses writes a tensorfold.progress event, which typed clients skip as an unknown type.
  • The reply's reader keeps only the newest count and reads it under the same lock as the token chunk, so the last count always comes before the first token, and a slow client gets the newest count rather than a backlog.
  • Documented in docs/api.md: the request field table, a Prompt progress section, and the Responses section.

Why streams are unchanged with it off

The engine sends no progress unless the request asks for it and its stream has a progress writer: whole replies, the Messages route and Cortheon turns clear the flag before the request is submitted. Without the field no frame is added and no Responses sequence number moves, and a round costs one boolean test. The SSE goldens and the wire-bytes oracle pass unchanged. No lock is held longer and no GPU sync is added: each count comes from the fill_at atomic the status reader already uses, read after the call returns and sent outside the host lock.

Tests

Host tests, no GPU or weights:

  • lane_host_progress_test.zig: a four-call fill sends 8, 16, 24 and 32 of 32 before the prefilled event, with the same tokens as without the flag; none without the flag, for a prompt filled in one call, or for a backend that does not report fill; counts never go back after a requeue and the end is sent once; a lone driver that fills in pieces counts each call the same way.
  • prompt_progress_test.zig: over HTTP with a scripted engine that moves on only after the client has read each count, chat, completions and Responses each stream the counts once, in order, before the first text, and the reply text matches the same request without the flag; a whole reply, an explicit false and the Messages route ask the engine for none.
  • prompt_progress.zig: the chunk's shape.

Steps run: test-lane-api-host, test-lane-lone-host, test-lane-halt-host, test-lane-interrupted-host, test-prefill-service-host, test-server-cpu, test-golden, test-cuda-host, zig fmt --check and git diff --check; tools/zig/lean_check.py reports no new problems. With the engine's counts, the server's write or the stream gate taken out, the new tests fail.

Still owed: a served check, a 32K prompt on one Metal and one CUDA lane family, showing the counts and the same tokens and token_sha as the same request without the flag.

Fixes #3116

  • Synthena (Ash's Agent)

@ashhart
ashhart force-pushed the lead/prefill-progress-events branch from 01938bd to 07ccc88 Compare November 14, 2026 00:59
@ashhart
ashhart force-pushed the lead/prefill-progress-events branch 2 times, most recently from a7af417 to cef7569 Compare November 18, 2026 02:12
ashhart added a commit that referenced this pull request Nov 18, 2026
Add the Unreleased entry and reclaim one line in lane_host.zig, which the
rebase left at 601 after the new progress call: an empty if-branch's comment
now sits on its brace line, so the file stays at 600. Behaviour is unchanged.
@ashhart
ashhart force-pushed the lead/prefill-progress-events branch from cef7569 to 9bd4d1a Compare November 19, 2026 01:42
ashhart added a commit that referenced this pull request Nov 19, 2026
Add the Unreleased entry and reclaim one line in lane_host.zig, which the
rebase left at 601 after the new progress call: an empty if-branch's comment
now sits on its brace line, so the file stays at 600. Behaviour is unchanged.
ashhart added a commit that referenced this pull request Nov 21, 2026
Add the Unreleased entry and reclaim one line in lane_host.zig, which the
rebase left at 601 after the new progress call: an empty if-branch's comment
now sits on its brace line, so the file stays at 600. Behaviour is unchanged.
@ashhart
ashhart force-pushed the lead/prefill-progress-events branch from 9bd4d1a to 395c0a7 Compare November 21, 2026 10:56
ashhart added a commit that referenced this pull request Nov 21, 2026
Add the Unreleased entry and reclaim one line in lane_host.zig, which the
rebase left at 601 after the new progress call: an empty if-branch's comment
now sits on its brace line, so the file stays at 600. Behaviour is unchanged.
@ashhart
ashhart force-pushed the lead/prefill-progress-events branch from 395c0a7 to ed8479b Compare November 21, 2026 14:15
ashhart added a commit that referenced this pull request Nov 21, 2026
Add the Unreleased entry and reclaim one line in lane_host.zig, which the
rebase left at 601 after the new progress call: an empty if-branch's comment
now sits on its brace line, so the file stays at 600. Behaviour is unchanged.
@ashhart
ashhart force-pushed the lead/prefill-progress-events branch 2 times, most recently from a248ee2 to 4631a56 Compare November 21, 2026 23:19
@ashhart
ashhart force-pushed the lead/prefill-progress-events branch from 4631a56 to 6c2b125 Compare November 23, 2026 19:10
…rst token

A streamed chat completion, completion or Responses request with return_progress: true hears how
far a prompt filled in more than one call has come. The lane host sends Event.progress (done,
total, cached) after each fill-queue call that leaves the pass open and after each call of a lone
driver that fills in pieces, for a backend that reports fill_at, each count higher than the last;
the pass's prefilled event first sends done == total. Chat and completions write a chunk with
"choices": [] and tensorfold.progress, as the include_usage chunk carries usage; Responses writes a
tensorfold.progress event. The mailbox keeps the newest count and the reader takes it with the
token chunk, so the last count always precedes the first token.

Off by default: the engine sends none unless the request asks and its stream has a progress writer
(a whole reply, Messages and Cortheon turns have none), so a stream without the field is unchanged.
Counts come from the fill_at atomic after a call returns, outside the host lock: no lock is held
longer and no GPU sync is added. Host tests cover the fill queue and a lone driver (counts end at
the prompt, tokens unchanged), no counts without the flag, for a one-call fill or without fill
reports, counts that never go back, and each route's frames over HTTP.

Refs #3116.
@ashhart
ashhart force-pushed the lead/prefill-progress-events branch from 6c2b125 to f950798 Compare November 26, 2026 15:32

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prompt-progress events during long prefills

1 participant