Skip to content

Keep streamed responses alive when clients pause reading - #207

Merged
lukealonso merged 3 commits into
mainfrom
astra/stream-consumer-backpressure
Nov 5, 2026
Merged

lukealonso merged 3 commits into
mainfrom
astra/stream-consumer-backpressure

Conversation

@voipmonitor

Copy link
Copy Markdown
Collaborator

A connected streaming client can pause reading without losing its request. The worker buffers the remaining output and terminal event without waiting for the socket. Disconnecting still cancels unfinished generation.

Fixes #199.

  • Implemented: size the existing bounded channel from the request's complete output budget, including token observations, prompt scores, reasoning continuation, and terminal events. Tokio allocates queue blocks as events arrive; the full budget is not allocated on admission.
  • Keep the native admission permit until the response is released. Completed generation releases its model slot and live KV normally, while unread responses continue to count toward the host admission limit.
  • Count queued presentation events as published even when the socket is blocked. A slow reader gains no scheduler priority.
  • Route prompt scores, stop-prefix flushes, and terminal completions through the same emission path. A closed receiver is cancellation; exhausting the calculated budget indicates a producer invariant violation.

This uses one queue and its existing wakeups. It adds no worker-side backlog flushing, relay task, stall timeout, or scheduling policy.

Compatibility: no HTTP, graph, package, or sampling changes. ServerConfig.event_capacity becomes a minimum capacity. Native callers must release completed Generation handles to release admission permits. Paused long responses can retain more CPU memory; retained output is bounded by request budgets and admission capacity.

Qualified: 269 server tests passed; 2 existing tests ignored. Native worker tests use synthetic completion records and the production admission, scheduling, and output paths. No GPU throughput claim.

Condition Result
512 generated tokens, observations, with/without logprobs; reader waits until completion Exact ordered output and terminal event; another request completes while the first remains unread
Reasoning cut followed by readmission, reader paused throughout All 161 output tokens retained, including the forced closing token
HTTP response body remains unpolled for all 100 tokens plus observations Complete text and token IDs; preserves either finish_reason/[DONE] or a subsequent genuine error
Receiver dropped; producer budget deliberately undersized Cancellation without a false execution error; invariant failure remains bounded and preserves the first error

The unread native-response and HTTP-response regressions fail against base b4196955 and pass with this patch. These tests hold the consumer stopped directly, avoiding dependence on TCP buffer sizes or sleep durations.

.venv/bin/python tests/frontend/prepare_templates.py --recipe qwen38 --output /tmp/flare-test-templates
FLARE_TEST_TEMPLATE_DIR=/tmp/flare-test-templates cargo test --locked --release \
  --manifest-path helios/Cargo.toml --features server,runtime-package --lib server::

voipmonitor and others added 2 commits November 4, 2026 21:18
Size the bounded event channel from the validated response budget, including observation, prompt scores, reasoning continuation and terminal events. Queue blocks allocate on demand. Retain native admission capacity through the response lifetime while completed requests release model slots and live KV. Keep disconnected consumers as cancellations and reserve overflow errors for a violated producer budget.

Qualified: 269 server tests passed, 2 ignored. Deterministic unread native and HTTP response tests fail on b419695 and pass with this change. GPU computation and package formats are unchanged; no GPU throughput claim.

Design-Signed-Off-By: Codex (GPT-6); design-review=a38f
The Helios README still said slow consumers face the bounded per-request event queue. Describe the response budget and admission lifetime instead. Port the paused-body regression from #200: chat completions, completions, messages and responses each queue 3,000 tokens while the body is unread, keep the native admission permit until delivery, then deliver all text and the terminal event.

Qualified: 270 server tests passed, 2 ignored; full Helios library suite 1,270 passed, 25 ignored, run without CAP_DAC_OVERRIDE and CAP_DAC_READ_SEARCH for the filesystem-permission test. The new test fails when the channel is restored to the fixed event capacity or the response's admission permit is removed. Tests and documentation only; events are synthetic, no GPU inference.

Signed-off-by: Martin Vit <martin@voipmonitor.org>
Design-Signed-Off-By: Claude Opus 5.5; design-review=a38f
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Check native response ownership with a reusable-cell TLA+ model and Rust
conformance over admission, event delivery, producer retirement, reader
drops, failures, and grouped generations. Extend the lifecycle checker
with worker continuation, HTTP terminal-frame, and mutation checks.

Validation: TLC checked 39,799 reachable response states and 141,057
observed Rust transitions. The lifecycle checker and response mutations
passed. Release server tests passed: 272 passed, two GPU tests ignored.
The model covers two admission permits, three response cells, and two
nonterminal events per response. HTTP encoder state and non-streaming
serialized bodies are outside the model. No GPU execution was performed.

Design-Signed-Off-By: Codex (GPT-6); design-review=a38f
@lukealonso
lukealonso merged commit 0009b89 into main Nov 5, 2026
4 of 5 checks passed
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.

Streaming: a client that stops reading for 2–5 s loses the request ("generation consumer exceeded the bounded output queue")

2 participants