Skip to content

lane host: a slow reader's stream sits out rounds at 1,024 unread tokens; one stalled 60 s is cancelled - #3234

Merged
ashhart merged 4 commits into
mainfrom
lead/slow-reader-pause
Nov 21, 2026
Merged

ashhart merged 4 commits into
mainfrom
lead/slow-reader-pause

Conversation

@ashhart

@ashhart ashhart commented Nov 13, 2026

Copy link
Copy Markdown
Owner

A streamed reply's tokens went to its mailbox with no bound, so a client that read slowly, or stopped reading without closing, left its lane decoding text nobody was taking.

What changed

  • The server's mailbox counts a streamed reply's tokens that have landed and are not yet written to the client, and gives the engine that count (Request.unread). Whole (non-streamed) replies pass none and are never watched.
  • Before each turn the shared lane host holds a stream whose count reaches 1,024: it sits out rounds until the count falls to 512, then continues from where it stopped. A stream with a step queued ahead lands that step in its next round first, so a held stream never keeps a draw in flight.
  • A held stream whose client reads nothing for 60 seconds goes on the cancel list a disconnect uses: the reply ends cancelled and its lane goes to the next request. Any read restarts the 60 seconds.
  • A lone driver hands back a stream whose reader is behind and does not take such a stream back.
  • With every stream held and no cancel waiting, the engine thread waits up to 2 ms for an arrival instead of running empty rounds.
  • docs/api.md names the limit, the resume point and the timeout.

Why delivered text and other streams are unchanged

  • A hold removes whole rounds between two rounds and changes none. Draws are keyed by position, so a held stream's later tokens are the ones it would have drawn; its cache, drafts and sampler position stay as its last round left them.
  • The host lifts only holds it placed: a stream its backend paused for its own reasons stays paused.
  • Other streams' rounds are planned as before, without the held stream. A reader that keeps up has at most one round's tokens unread, far below 1,024. With no slow reader the per-turn cost is one pass over the admitted requests with an atomic load each: no lock, no clock read, no allocation.

Tests (lane host with the fake backend): a normal reader never pauses, even at a limit of 8; a slow reader's backlog stays within a round of the limit and its text equals a fast reader's, in one-token steps and in drafted windows; a stalled reader holds only its own stream while another finishes with its solo tokens; a held stream leaves no draw in a four-slot ring while a peer decodes; a reader stalled past the timeout is cancelled, the next request gets the lane, and the engine thread does not spin; a lone driver hands back a slow reader's stream and its reply is unchanged; the hold rules themselves. Server: a streamed reply's engine sees the count fall as tokens are written; a whole reply's engine sees none. With the change switched off, every new test except the normal-reader guard fails.

Still owed: a served check on a device: decode speed at 1-8 streams against main with normal readers, plus a slow and a stalled reader beside normal ones, with token hashes equal.

Fixes #3198

  • Synthena (Ash's Agent)

ashhart added a commit that referenced this pull request Nov 18, 2026
…ne limit

Keep main's wait_reason and fell_back fields in lane_job.Job and place the PR's backlog field after them. Join lane_host.zig's two trailing test blocks into one (all imports kept) so the merged file is 600 lines. Add the CHANGELOG entry under Unreleased.
@ashhart
ashhart force-pushed the lead/slow-reader-pause branch from ef640d7 to a3128cc Compare November 18, 2026 01:54
ashhart added a commit that referenced this pull request Nov 19, 2026
…ne limit

Keep main's wait_reason and fell_back fields in lane_job.Job and place the PR's backlog field after them. Join lane_host.zig's two trailing test blocks into one (all imports kept) so the merged file is 600 lines. Add the CHANGELOG entry under Unreleased.
@ashhart
ashhart force-pushed the lead/slow-reader-pause branch from a3128cc to 4c19615 Compare November 19, 2026 01:48
…ens; one stalled 60 s is cancelled

A streamed reply's tokens went to its mailbox with no bound, so a client
that read slowly, or stopped reading without closing, left its lane
decoding text nobody was taking.

- The mailbox counts a streamed reply's tokens that have landed and are
  not yet written to the client, and hands the count to the engine as
  Request.unread. A whole reply passes none and is never watched.
- Before each turn the shared lane host holds a stream whose count
  reaches 1,024 (Stream.paused) until it falls to 512. A stream with a
  step queued ahead lands it in its next round first, so a held stream
  keeps no draw in flight (GLM's ring would refuse a peer's next one).
- A held stream whose client reads nothing for 60 s goes on the cancel
  list a disconnect uses; any read restarts the 60 s.
- The host lifts only holds it placed: a stream its backend paused
  (Flash Next's sized sessions) stays paused.
- A lone driver hands back a stream whose reader is behind, and reclaim
  leaves such a stream in the lane core.
- With every stream held and no cancel waiting, the engine thread waits
  up to 2 ms for an arrival, outside its activity scope, instead of
  turning empty rounds.

The scan runs on the engine thread with no lock or clock read while no
stream is held. Host tests with the fake backend cover a normal reader,
a slow reader in stepped and drafted rounds, a stalled reader beside a
fast one, a four-slot ring, the stall cancel, the lone driver and the
hold rules; a server test checks the count a streamed reply's engine
sees. docs/api.md names the limit, the resume point and the timeout.

Fixes #3198
…ne limit

Keep main's wait_reason and fell_back fields in lane_job.Job and place the PR's backlog field after them. Join lane_host.zig's two trailing test blocks into one (all imports kept) so the merged file is 600 lines. Add the CHANGELOG entry under Unreleased.
@ashhart
ashhart force-pushed the lead/slow-reader-pause branch from 4c19615 to 4f43020 Compare November 21, 2026 04:52
@ashhart
ashhart merged commit a3d6d8c into main Nov 21, 2026
10 of 11 checks passed
ashhart added a commit that referenced this pull request Nov 21, 2026
…ne limit

Keep main's wait_reason and fell_back fields in lane_job.Job and place the PR's backlog field after them. Join lane_host.zig's two trailing test blocks into one (all imports kept) so the merged file is 600 lines. Add the CHANGELOG entry under Unreleased.
@ashhart
ashhart deleted the lead/slow-reader-pause branch November 21, 2026 04:52
ashhart added a commit to bikepresentball/TensorFold that referenced this pull request Nov 21, 2026
ashhart added a commit that referenced this pull request Nov 21, 2026
ashhart added a commit to AIflow-Labs/TensorFold that referenced this pull request Nov 21, 2026
ashhart added a commit that referenced this pull request Nov 21, 2026
ashhart added a commit to AIflow-Labs/TensorFold that referenced this pull request Nov 21, 2026
ashhart added a commit that referenced this pull request Nov 21, 2026
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.

Slow readers: bound a stream's undelivered events and pause its lane

1 participant