Reset hill-climb warmup after idle period to re-seed EMA

When throughput dropped to zero, the monitor reset direction and
decline_streak but not warmup_samples.  On resumption, the first
meaningful throughput sample was compared against a stale pre-idle
EMA value, which could cause the hill-climber to make a scaling
decision based on a meaningless delta (new throughput vs. zero-decayed
EMA from potentially minutes ago).

Reset warmup_samples to 0 in the idle branch so the EMA is re-seeded
from two fresh samples before the hill-climber acts.  This ensures
the first scaling decision after an idle period is based on current
throughput trends rather than stale history.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Antonio S. Musumeci 2026-04-10 13:25:33 -04:00
parent 47a097ee96
commit 1dd979f955

View file

@ -584,11 +584,14 @@ ThreadPool::monitor_routine(void *arg_)
// Only adjust if there's meaningful work happening.
// Reset direction to +1 (bias toward growth) so a stale
// shrink direction from before the idle period doesn't
// penalize the pool when work resumes.
// penalize the pool when work resumes. Also reset warmup
// so the EMA re-seeds from fresh samples rather than
// comparing against a stale pre-idle value.
if(ema_throughput < 0.5 && prev_ema < 0.5)
{
decline_streak = 0;
direction = 1;
warmup_samples = 0;
continue;
}