fix(llm, cli, config): Jitter retry backoff so sessions don't collide - #1080
Merged
Conversation
Retry waits now carry a random extra of up to a quarter of the delay, so several JP sessions sharing one API key stop resuming in the same instant after being rate limited together. Cerebras enforces its limits per organization and answers a 429 with `retry-after: 60`, so every session that hit the limit slept exactly 60000ms, woke together, and walked into the limit again — burning the whole retry budget without any of them getting through. The `base_backoff_ms` documentation has described this jitter since the setting was introduced, down to a stated 0-500ms range, but nothing ever implemented it. That text reaches users through the generated `config.toml` and the exported JSON schema, so it was a promise the program did not keep. It now describes what the code does. Jitter is added after the backoff ceiling rather than folded inside it. Folding it in means it disappears exactly when it matters, since every caller pinned at the ceiling gets the same number. It is also only ever added, never subtracted: a `retry_after` is the minimum the provider asked for, and waiting less walks straight back into the limit. One consequence worth knowing about is that an individual wait can now exceed `max_backoff_secs` by up to a quarter. Both retry layers pick their delay through the new `jp_llm::retry_delay`, which replaces the identical `retry_after`-or-exponential match they each carried. `exponential_backoff` stays pure and keeps its exact tests. Signed-off-by: Jean Mertz <git@jeanmertz.com>
Signed-off-by: Jean Mertz <git@jeanmertz.com>
Signed-off-by: Jean Mertz <git@jeanmertz.com>
Signed-off-by: Jean Mertz <git@jeanmertz.com>
Signed-off-by: Jean Mertz <git@jeanmertz.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Retry waits now carry a random extra of up to a quarter of the delay, so several JP sessions sharing one API key stop resuming in the same instant after being rate limited together. Cerebras enforces its limits per organization and answers a 429 with
retry-after: 60, so every session that hit the limit slept exactly 60000ms, woke together, and walked into the limit again — burning the whole retry budget without any of them getting through.The
base_backoff_msdocumentation has described this jitter since the setting was introduced, down to a stated 0-500ms range, but nothing ever implemented it. That text reaches users through the generatedconfig.tomland the exported JSON schema, so it was a promise the program did not keep. It now describes what the code does.Jitter is added after the backoff ceiling rather than folded inside it. Folding it in means it disappears exactly when it matters, since every caller pinned at the ceiling gets the same number. It is also only ever added, never subtracted: a
retry_afteris the minimum the provider asked for, and waiting less walks straight back into the limit. One consequence worth knowing about is that an individual wait can now exceedmax_backoff_secsby up to a quarter.Both retry layers pick their delay through the new
jp_llm::retry_delay, which replaces the identicalretry_after-or-exponential match they each carried.exponential_backoffstays pure and keeps its exact tests.