fn front_of(
messages: &[Message],
sizes: &[usize],
measured_from: usize,
budget: Budget,
) -> usizeExpand description
Where the window’s front moves to in messages: the first frame of the
oldest turn it keeps.
The window ends at the end of a turn, so its front is a turn’s first
frame. line is where a count-based cut would land - len less the cap -
and the front is the first turn open at or above it, which keeps the window
whole turns and can come in slightly under the cap. The byte ceiling lands
the same way: its own line is the first frame whose tail weighs no more
than the ceiling, and the cut is made at whichever line reaches later, so
what a drop leaves is inside both ceilings or a turn short of the later one.
(A copy grows toward a ceiling’s slack again between drops, and the append
at its edge rides one frame past before the next push checks - the shape the
count alone has always had.)
A turn crossing the line rides into the slack. The newest turn holds
the newest frames, so a window cannot drop it: when it alone is longer than
the cap, the window keeps it whole up to the cap’s slack rather than cutting
inside it - and only when that single turn alone would push the window past
the slack is the cut made inside it, the one case with no whole turn to land
on. crate::conversation_turns answers where the turns open, and the walk
stops at the first one at or above the line.
The window is never left empty. A single frame heavier than the whole byte budget keeps the window at that one frame rather than at none: the newest frame cannot be dropped - a page would open on nothing - and the appends that follow shed it as soon as the tail fits again.
sizes is what each frame of history[measured_from..] weighs; nothing
older than that was measured, and nothing older than it can be kept (the
ceilings that would reach further back are inside the measure’s own stop).