Compare commits

...

2 Commits

Author SHA1 Message Date
teknium1
0b50fe9579 docs(infographic): flaky fallback-cooldown timing fix 2026-06-27 19:51:09 -07:00
teknium1
5f91da2d1c test(fallback): fix flaky cooldown-window timing assertion
test_non_retryable_exhaustion_arms_cooldown captured `before` ahead of three
_try_activate_fallback() calls, then asserted the armed cooldown was
<= before + 5.0 + 1.0. The cooldown is set relative to the *final* call, and
the activation work (agent init, resolve_provider_client) can take >1s on a
loaded CI worker — so `before`-anchored upper bound overshot by ~0.5s and
failed reliably (slice 8/8, observed twice: 230.21 vs 229.73 bound,
905.80 vs 905.31 bound).

Anchor the upper bound to `after = time.monotonic()` captured once the
cooldown is armed. cooldown is final_call_time + 5.0 and after >= final_call_time,
so cooldown <= after + 5.0 + 1.0 holds regardless of activation latency. Still
proves the short 5s window vs the 60s rate-limit one (well under the +50s
discriminator in the sibling test). Test added in #53909.
2026-06-27 19:49:21 -07:00
2 changed files with 7 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

View File

@@ -67,10 +67,16 @@ class TestExhaustionArmsCooldown:
assert agent._try_activate_fallback() is True # -> entry 1
# Chain now exhausted; a non-rate-limit failure must arm cooldown.
assert agent._try_activate_fallback() is False
after = time.monotonic()
cooldown = getattr(agent, "_rate_limited_until", 0)
assert cooldown > before
# Cooldown is the short exhaustion window, not the 60s rate-limit one.
assert cooldown <= before + _FALLBACK_EXHAUSTED_COOLDOWN_S + 1.0
# Anchor the upper bound to `after` (captured once the cooldown has
# actually been armed) rather than `before`: the activation calls above
# can take >1s on a loaded CI worker, and the cooldown is set relative
# to the time of the *final* call, not `before`. A small slack absorbs
# scheduling jitter without weakening the "short window, not 60s" check.
assert cooldown <= after + _FALLBACK_EXHAUSTED_COOLDOWN_S + 1.0
def test_no_chain_does_not_arm_cooldown(self):
"""An empty chain (no fallback configured) must not arm a cooldown —