Skip to content

feat: Adds configurable backoff to run_and_wait#9

Merged
EspenAlbert merged 7 commits into
mainfrom
task/t08-05-ask-shell-backoff-config
Mar 17, 2026
Merged

feat: Adds configurable backoff to run_and_wait#9
EspenAlbert merged 7 commits into
mainfrom
task/t08-05-ask-shell-backoff-config

Conversation

@EspenAlbert
Copy link
Copy Markdown
Owner

Summary

Add exponential backoff with jitter between retry attempts. Previously retries fired immediately with no delay.

Three new fields on ShellConfig (mirrored as kwargs on run/run_and_wait):

  • retry_initial_wait (default 5s) -- base delay before first retry
  • retry_max_wait (default 60s) -- cap on computed wait
  • retry_jitter (default 5s) -- random [0, jitter) added to each wait

Formula: min(initial * 2^(attempt-2), max_wait) + uniform(0, jitter)

Reviewer notes

  • Backward compatible: defaults produce a 5s initial wait on retry. Existing callers with attempts=1 (the default) are unaffected since backoff only triggers on attempt > 1.
  • Blocking sleep: time.sleep blocks the executor thread. This is acceptable because each run already owns a dedicated thread.
  • The sleep happens before ShellRunRetryAttempt is queued, so callbacks see the event only after the wait completes.

Test plan

  • Existing test_check_all_config_args_in_signatures enforces the new kwargs appear on run/run_and_wait
  • test_backoff_wait_values -- mocks time.sleep, verifies exponential growth [2, 4] with jitter=0
  • test_backoff_respects_max_wait -- verifies cap at max_wait over 5 attempts: [2, 4, 5, 5]
  • pytest-example doc at docs/examples/shell/backoff.md runs a real retry script with wall-clock assertions

@EspenAlbert EspenAlbert merged commit c848f90 into main Mar 17, 2026
16 checks passed
@EspenAlbert EspenAlbert deleted the task/t08-05-ask-shell-backoff-config branch March 17, 2026 20:46
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.84%. Comparing base (96b84c3) to head (c89ae93).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main       #9      +/-   ##
==========================================
+ Coverage   82.75%   82.84%   +0.09%     
==========================================
  Files          20       20              
  Lines        1815     1825      +10     
==========================================
+ Hits         1502     1512      +10     
  Misses        313      313              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants