fix(retry): cap jittered delay to max_delay#2676
fix(retry): cap jittered delay to max_delay#2676Dhakshin2007 wants to merge 3 commits intoopenai:mainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0161128362
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…andomness at saturation
|
Thanks for the P2 feedback, @chatgpt-codex-connector! You are correct — applying jitter to the uncapped exponential ( The second commit addresses this by clamping the base first, then applying jitter to the clamped value, and finally capping the result: # Clamp base first so jitter stays effective even at saturation
base = min(initial_delay * (multiplier ** max(attempt - 1, 0)), max_delay)
if not use_jitter:
return base
return min(max(base * (0.875 + random.random() * 0.25), 0.0), max_delay)With this approach at saturation ( |
|
Note To use Codex here, create a Codex account and connect to github. |
seratch
left a comment
There was a problem hiding this comment.
I think the Retry-After overflow handling is not necessary in practice. That header value is supplied by the model provider, and an extremely large numeric value there is a very unlikely scenario. Also, the current overflow change does not materially improve the common path enough to justify carrying the extra logic.
The jitter cap fix, on the other hand, is useful on its own. It preserves randomness while ensuring the computed retry delay never exceeds max_delay, which is a concrete improvement to the backoff behavior.
Could you please update this PR to keep only the jitter improvement and drop the Retry-After overflow handling changes?
Refactor exception handling to onPer review by seratch: remove the Retry-After OverflowError handling as it is unnecessary in practice (the header value is supplied by the model provider and an extremely large numeric value is very unlikely). Keep only the jitter cap fix.ly catch ValueError.
|
@seratch Thank you for the review! I've addressed your feedback:
Updated the PR title and description accordingly. |
Summary
This PR fixes a bug introduced in the
feat: add opt-in model retry policiescommit (3a52673) insidesrc/agents/run_internal/model_retry.py.Per reviewer feedback from @seratch, the
Retry-AfterOverflowErrorhandling has been dropped as it is unnecessary in practice. This PR now focuses solely on the jitter cap fix.Bug: Jitter can produce delay >
max_delay(silent backoff violation)Location:
_default_retry_delay(), lines 287–290Root cause:
The original code caps the exponential delay with
min(..., max_delay)before applying jitter:Because jitter multiplies the already-capped value by up to 1.125, the final result can exceed
max_delayby ~12.5%.Fix:
Apply
min(..., max_delay)after jitter so the final delay is always bounded bymax_delay.