messageCapTriggerReached function
Whether the live messageCount is at/above the pre-emptive trigger for
a learned cap: count ≥ cap − margin (AC4). A null/unknown cap never
triggers (AC8); a margin of zero means "at the cap itself". A cap at or
below the margin stands down: cap − margin is not a meaningful
threshold inside the fixed request overhead, and an always-true trigger
would wedge the session into a compact-every-turn state (PR #1695
review) — the reactive heal still coalesces with its own
max(1, cap − margin) clamp per refusal.
Implementation
bool messageCapTriggerReached(
int messageCount,
int? learnedCap, {
int margin = kMessageCapDefaultMargin,
}) =>
learnedCap != null &&
learnedCap > margin &&
messageCount >= learnedCap - margin;