Skip to content

fix: uncapped and eager backoff calculation #52

Merged
quettabit merged 1 commit into
mainfrom
qb/fix-retry
May 16, 2026
Merged

fix: uncapped and eager backoff calculation #52
quettabit merged 1 commit into
mainfrom
qb/fix-retry

Conversation

@quettabit
Copy link
Copy Markdown
Member

No description provided.

@quettabit
Copy link
Copy Markdown
Member Author

@greptileai review pls

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 16, 2026

Greptile Summary

This PR refactors the retry backoff mechanism from eagerly pre-computing a list of all backoff values upfront to computing each backoff value lazily on demand. It also adds proper OverflowError handling via math.ldexp to ensure the delay is correctly capped for astronomically large attempt counts.

  • compute_backoffs(attempts) -> list[float] is replaced by compute_backoff(attempt) -> float, and the Retrier constructor is renamed from max_attempts to max_retries (with callers updated to pass retry._max_retries() instead of retry.max_attempts).
  • Session retry loops in _append_session.py and _read_session.py are updated in parallel to use the same lazy single-value API, removing the pre-allocation of the backoff list at session start.

Confidence Score: 5/5

The change is safe to merge — it is a clean, semantically equivalent refactor that makes backoff computation lazy and adds overflow protection for extreme attempt counts.

The old compute_backoffs list is replaced by compute_backoff one call at a time, producing identical delay values for all realistic attempt counts. The math.ldexp / OverflowError path correctly falls back to max_base_delay, matching what min(inf, max_base_delay) did implicitly before. The max_retries rename aligns with _max_retries() which has always returned max_attempts - 1, so the retry budget is unchanged.

No files require special attention.

Important Files Changed

Filename Overview
src/s2_sdk/_retrier.py Core change: replaces eager list-returning compute_backoffs with lazy compute_backoff using math.ldexp and OverflowError guard; Retrier constructor renamed max_attempts to max_retries; logic is semantically equivalent to the old implementation.
src/s2_sdk/_ops.py All four Retrier constructor call-sites updated to pass max_retries=retry._max_retries() instead of max_attempts=retry.max_attempts; semantically equivalent since _max_retries() returns max(max_attempts-1, 0).
src/s2_sdk/_s2s/_append_session.py Switched from pre-computed backoffs list to per-failure compute_backoff call; retry counter reset on successful ack is unchanged; logging updated correctly.
src/s2_sdk/_s2s/_read_session.py Mirrors the append_session change: pre-computed backoff list removed in favour of per-exception compute_backoff call; no behavioural regression.
tests/test_retrier.py New test file covering compute_backoff ranges for attempts 0-5 and the sys.maxsize overflow guard; all expected ranges align with the math.ldexp implementation.
tests/test_retry.py Deleted; tests for compute_backoffs (now gone), has_no_side_effects, is_safe_to_retry_unary, and is_safe_to_retry_session were removed intentionally per author.

Reviews (3): Last reviewed commit: "initial commit" | Re-trigger Greptile

Comment thread tests/test_retrier.py
@quettabit quettabit changed the title [WIP] fix: uncapped and eager backoff calculation May 16, 2026
@quettabit
Copy link
Copy Markdown
Member Author

@greptileai address your comment. pls review again and update your score.

@quettabit quettabit marked this pull request as ready for review May 16, 2026 04:24
@quettabit quettabit requested a review from a team as a code owner May 16, 2026 04:24
@quettabit quettabit merged commit 89ba250 into main May 16, 2026
9 of 10 checks passed
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.

1 participant