Repository navigation
fix(dispatcher): add jitter to the deferral backoff - #773
Conversation
Runs blocked by the concurrency limit at the same moment were deferred by the same 60 * 2**n delay, so they all retried together and hit the limit together again. Scale each delay by a random factor in [0.5, 1.5], as the sandbox-provisioning retry already does, so they spread out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Your comment is too long (maximum is 65536 characters), so the coverage report was not added. See the job log for how to reduce it. |
ak684
left a comment
There was a problem hiding this comment.
Approving. Small, safe change, and it merges cleanly with #772. The dispatcher tests pass with both together (109 passed in a local run).
One note on expectations: this would not have prevented the midnight burst. That was lined up by the quota reset, not by retry timers. It does help runs blocked together by the concurrency limit, such as a shared cron minute.
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Approving. The change is in scope for this repository (dispatcher deferral / run-state scheduling) and is a small, localized fix with adequate context in the description.
What I verified on head 58ce8c1:
- The delay is now
min(base * 2**n * random.uniform(0.5, 1.5), remaining)on the deferral branch only; the terminal skip branch and the race-guardedrequeue_deferred_runwrite are untouched, so run-state transitions stay idempotent and runs neardefer_max_age_secondsstill cannot be rescheduled past their deadline. I executed the real_defer_or_skip_blocked_runwith factors 0.5/1.0/1.5 across attempt counts and age-cap boundary cases (including age 21590s of 21600s) and the persisted delays match the formula exactly. - The
±50%jitter matches the pre-existing provisioning-retry jitter in_acquire_execution_context, andrandomwas already imported in this module. deferred_untilis honored by the dispatch poll (deferred_until IS NULL OR <= now()), so jittered delays are applied as written.- Tests are sound:
test_backoff_delay_is_jitteredpins the factor at both endpoints and fails againstmain(uniform never called), and pinningtest_backoff_delay_grows_per_attemptat factor 1.0 removes the real flakiness jitter would introduce into a strictly-increasing assertion.test_backoff_bounded_by_remaining_agepassing unchanged is consistent with the cap applying after jitter. - All GitHub Actions checks are green on this exact head, including
unit-tests. Local note: the Docker/PostgreSQL test fixture cannot run in this sandbox, so instead of the container-backed suite I exercised the deferral path directly against the changed code (above) and ranruff format/ruff check/pyrighton the three changed files — all clean; the non-container tests intests/test_daily_sandbox_limit.pypass locally.
No material correctness, security, or compatibility findings. The relationship to #772 is compatible: that PR remains open, and with or without it, runs still blocked by the organization concurrency limit now retry with spread-out delays rather than in lockstep.
✅ APPROVED
|
🚀 Released in 1.34.0. |
Summary
AUTOMATION_DEFER_BACKOFF_BASE_SECONDS * 2**n) multiplied by a random factor between 0.5 and 1.5. It is still capped by the time left beforeAUTOMATION_DEFER_MAX_AGE_SECONDS.random.uniform(0.5, 1.5)as the sandbox-provisioning retry in_acquire_execution_context.Why
Follow-up to #772. That PR stops deferring runs blocked by the daily sandbox limit, which removes the nightly burst described in #771. Runs blocked by the organization concurrency limit are still deferred.
Without jitter, runs blocked at the same moment wait exactly the same time, so they all retry together and hit the limit together again. This is common, for example when several automations share a cron minute. Last night, from 23:40 to 23:59 UTC, prod deferred about 100 runs a minute, with retry counts spread over 1–9. Jitter spreads these retries out so they don't arrive together.
Tests
test_backoff_delay_is_jittered, run with factors 0.5 and 1.5. It checks that the delay is the backoff times the random factor, and thatrandom.uniform(0.5, 1.5)is called. Both cases fail against theorigin/maindispatcher (uniformcalled 0 times).test_backoff_delay_grows_per_attemptnow fixes the factor at 1.0. With jitter, delays are no longer strictly increasing (for example 14s then 11s), so the test would be flaky otherwise.test_backoff_bounded_by_remaining_agepasses unchanged: the cap applies after jitter.tests/test_dispatcher.pyandtests/test_daily_sandbox_limit.py: 109 passed.pre-commitpasses.🤖 Generated with Claude Code