Repository navigation
fix(flow): close stage after its last producer and drain accepted inputs - #5567
Conversation
|
PASS (source) at d863b1a (Cormac), conditional on CI. Read: the whole diff, and stage.rs at this head (113 lines). The race it fixes: The close and drain ordering, checked:
The fixture drives both last drops from two OS threads behind a |
|
PASS (Cormac) at exact ac93cf9, re-check of the commit since my earlier PASS. ac93cf9 only reclassifies |
…uts (#5567) * fix(flow): publish producer closure before waking stage * test(ci): classify flow as an independent workspace leaf
…M5-calibrated simulator (orphaned since 10-29) (#5729) * continuum-flow: QoS classes, a coalescing serial queue per owner, one event-driven dispatcher per capacity (draft, untested) SERVING-ENGINE §1c. Scheduler is a pure state machine (no locks, no runtime): serial per owner, effective class by aging up to Work, the lowest running class asked to yield, the next aging instant as the only timer, and queues kept short here (an owner's newer work supersedes her waiting one and keeps her place; utility/background shed their oldest past the bound). Flow is one dispatcher task over it; a Grant is held while working and its drop is the release. Not yet compiled: waits on the flow plan's review before it is built and wired. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo * continuum-flow: Stage (CBAR QueueThread), the capacity dispatcher, and a simulator calibrated to the M5; 16 cases green - Stage: a bounded keep-newest input, one worker task woken only by a push, a class. - Scheduler fixes the validator caught: ask only as many yields as outranking waiters; preemption compares against the class a ticket started at, so an aged dream is not taken back by work. - sim: decode 30.5*n^0.865 tok/s across n streams (101 at four), prefill 304/sqrt(n) per job, page-out 0.1 s (M5, 2026-10-28). Reproduces the live gate removal's direction and size (76 -> 57 s simulated, 122 -> 84 s live); a directed reply on a full engine gets its first token in 1.7 s; a dream runs 16 times an hour and slows six residents by 4%. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo * sim: the M5 at a working-context depth (stock llama-bench fit); forecast: 82k -> 79 s/call, 32k -> 43 s, 16k -> 33 s Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo * continuum-flow: a stage's overflow is explicit, Reliable by default (backpressure, never drops) or KeepNewest for signals only Codex on the FLOW plan (6d18b45): committed inputs and tool results must never ride a dropping queue. Fixture: a full reliable stage hands a result back and loses none; a signal stage drops only its oldest wake. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo * fix(flow): close stage after its last producer and drain accepted inputs (#5567) * fix(flow): publish producer closure before waking stage * test(ci): classify flow as an independent workspace leaf * continuum-flow: a stage holds one input in hand and one pending (CBAR's double buffer), not a queue it sizes itself `Stage::DEPTH` was a size each stage picked (ONE-BUDGET's self_sized class). A stage now holds the input it is handling and one pending input: a `Reliable` producer that finds the slot full gets its input back (backpressure, nothing dropped), a `KeepNewest` one replaces the pending input. The two stage tests assert the same contracts at that shape. Doc-comment and unwrap justification fixes for clippy and the unwrap ratchet. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo * continuum-flow: a reliable producer awaits the free slot (send), and a stage whose worker ended hands inputs back (Cormac on #5729) `StageInput::send` waits on the stage's `space` signal (registered before the slot is read, so a take between the read and the wait is never missed) while a `Reliable` slot is taken: backpressure a producer awaits instead of spinning or dropping. `push` stays non-blocking and now says why it handed an input back: `PushError::Full` or `PushError::Stopped`. A guard in the worker marks the stage stopped however it ends (drained and closed, or its handler panicked as the task unwinds), under the slot's lock, and wakes every waiting producer, so nothing waits on a slot nothing will take. Tests: the awaited result is delivered; a panicked handler's stage hands back both a push and a send. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
The stage can sleep forever when its final producers drop concurrently: Arc counts were inspected before their automatic decrement, so no producer necessarily sends the final wake. A wake could also run before the final decrement and be consumed too early.
Track producer count explicitly and publish the final decrement before notifying. Observe queue emptiness and producer closure under the queue lock so a final accepted push cannot arrive between those observations and be abandoned.
Adds a concurrent two-producer fixture covering both an idle worker and draining accepted inputs before stage destruction. Diff-check passed; execution requires CI. This is stacked on #5561 and touches only stage.rs and its tests; scheduler priority/timestamp fixes remain with that owner.