Watch
0
0
Fork
You've already forked hyperhive
0

swarm: set the fresh-session threshold per agent

This commit is contained in:
iris 2026-11-16 10:50:13 +01:00
commit 5175d3663e

View file

@ -264,12 +264,16 @@ pub fn stall_sleep_secs() -> u64 {
/// Resolve the auto-reset watermark. Priority order:
/// 1. `HIVE_AUTO_RESET_WATERMARK_TOKENS` env var (explicit override).
/// 2. 50% of the window the API last reported, or `0` before one has been.
/// 2. The swarm's `fresh_session_percent` of the window the API last reported,
/// or 50% when the swarm sets none; `0` before a window has been reported.
///
/// `0` disables auto-reset entirely.
fn auto_reset_watermark_tokens(bus: &Bus) -> u64 {
env_u64("HIVE_AUTO_RESET_WATERMARK_TOKENS")
.unwrap_or_else(|| bus.api_context_window().map_or(0, |window| window / 2))
env_u64("HIVE_AUTO_RESET_WATERMARK_TOKENS").unwrap_or_else(|| {
let percent = u64::from(bus.fresh_session_percent().unwrap_or(50));
bus.api_context_window()
.map_or(0, |window| window * percent / 100)
})
}
/// Resolve the assumed cache TTL: `HIVE_CACHE_TTL_SECS` if set (`0` disables
@ -958,6 +962,11 @@ mod tests {
assert_eq!(auto_reset_watermark_tokens(&bus), 0);
bus.set_api_context_window(1_000_000);
assert_eq!(auto_reset_watermark_tokens(&bus), 500_000);
// The swarm sets the threshold: a percent of the same window.
bus.set_fresh_session_percent(Some(20));
assert_eq!(auto_reset_watermark_tokens(&bus), 200_000);
bus.set_fresh_session_percent(None);
assert_eq!(auto_reset_watermark_tokens(&bus), 500_000);
}
/// A turn that reports no window never triggers the proactive compaction,