The sliding-window state of a sequence is saved only at positions that are multiples of a block. After prefill, one token is reserved at the end and the position rounds down. During decode, every time the sequence crosses a block boundary its window is copied to a replica region, and the step that crosses may overshoot the boundary by a few tokens; the slot has a few spare positions to absorb that. Implement the bookkeeping.
prefill_store_position(L, block=128)
L - 1 rounded down to a multiple of block. Return it, or None if it is below block (nothing is stored).decode_copies(L0, step_sizes, block=128)
L0 (the prefill length). Each step appends step_sizes[t] tokens. After a step, if the new length has crossed into a later block than the last copy (initially the block of L0), record (length_after_step, boundary, overshoot) where boundary is the highest multiple of block at or below the new length and overshoot = length - boundary. Return the list of copies.final_store(L0, step_sizes, block=128, extra=6, layers=20, bytes_per_token=528)
attach is its boundary and overshoot its overshoot. If no copy happened during decode, attach is prefill_store_position(L0) (or None) and the overshoot is 0.block + extra positions, so a copy fits when overshoot <= extra - 1. Return a dict with "attach", "overshoot", "fits" (bool) and "slot_bytes", the stored-region size: the number of layers times the slot's positions times the bytes per token.length // block exceeds it.None for the attach point is a legitimate result for very short sequences.