Command Palette

Search for a command to run...

Hectal
Phase 6: Cost, Latency and Limits
LLM Engineering · Exercise 3 of 6 PreviousNext
Intermediate

Full jitter with Retry-After

Write retry_delay_ms(attempt, base_ms, cap_ms, rand, retry_after_s=None). attempt counts from 1 (the number of the attempt that just failed) and rand is a number from 0 up to but not including 1.

The ceiling is min(cap_ms, base_ms * 2 ** (attempt - 1)). The jittered wait is int(rand * (ceiling + 1)). If retry_after_s is not None, never return less than retry_after_s * 1000.

What Check tests

  1. With rand 0.0 the wait is 0
  2. Attempt 1 with rand 0.5 waits 250 ms
  3. The ceiling doubles: attempt 3 with rand 0.5 waits 1000 ms
  4. The ceiling is capped: attempt 10 with rand 0.5 waits 4000 ms
  5. Retry-After wins when it is larger
  6. A smaller Retry-After does not shorten the jittered wait

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.