Skip to content

feat(http): max_backoff caps and spreads 429 retries; Retry-After as HTTP date - #146

Open
oly-agents[bot] wants to merge 3 commits into
mainfrom
feat/http-max-backoff
Open

oly-agents[bot] wants to merge 3 commits into
mainfrom
feat/http-max-backoff

Conversation

@oly-agents

@oly-agents oly-agents Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Requested by: snehal.ahire@pattern.com

Oly issue: https://oly.pattern.com/issue/01a23591-7ca8-7125-8890-60fedde1bcdd

Description

Adds max_backoff to the http task and reads Retry-After as either seconds or an HTTP date. keepa-central's async Keepa pipelines need it to retry rate-gate 429s (ClickUp DATA-12007, https://app.clickup.com/t/1dfq9k65mjz).

Why it's needed. The old 429 backoff was 2^attempt seconds with no cap, or exactly Retry-After when sent. Rate-gate's Retry-After is one token's refill time (1–4 s), so many workers behind one bucket all retry together and give up after about 30 s. And 2^attempt grows past an hour at the retry counts needed to wait out a busy bucket.

What changes:

  • max_backoff is new and optional. When set, a 429 waits a uniform random time from Retry-After up to the longer of Retry-After and 2^attempt seconds, capped at max_backoff. The randomness keeps workers throttled by one bucket from retrying in lockstep. With max_retries: 30 and max_backoff: 60s, a throttled call keeps retrying for about 15 minutes.
  • Without max_backoff, behavior is unchanged: a 429 waits exactly Retry-After, or 2^attempt seconds. The one difference is that 2^attempt now saturates instead of overflowing past attempt 30.
  • Retry-After now also accepts an HTTP date (RFC 9110 10.2.3). Before, a date was silently ignored and the task retried with no wait.
  • A huge delay-seconds Retry-After saturates instead of overflowing time.Duration. An overflow used to wrap negative, so the retry ran with no wait; with max_backoff's jitter it would panic.
  • Non-429 retries keep using retry_delay.

Proxy and TLS: no change needed. scheme: http with insecure_tls: true already works without ca_certificate; errCertPath only applies to scheme: https. I checked this end to end: the real asins pipeline, loaded by caterpillar, ran against a local fake rate-gate. Calls carried the scope headers, got 429 with Retry-After, retried and finished.

Related PRs

The keepa-central pipelines only set max_backoff when their rate-gate flag is on. This PR must be released, and the caterpillar image Heimdall runs updated, before that flag is turned on. An older caterpillar ignores the field (no strict YAML decode) and falls back to the uncapped backoff.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation and I have updated the documentation accordingly. (internal/pkg/pipeline/task/http/README.md)
  • I have added tests to cover my changes. (retry_test.go: seconds and date Retry-After, past date, missing or bad header, overflow of the attempt count and of Retry-After, cap, jitter bounds and spread, non-429.) go test ./... passes. go vet reports only existing copy-lock findings in compress, archive and file; nothing in http.

Blockers

  • How caterpillar gets released and picked up by the Heimdall ECS task family (caterpillar-task-small) is outside this repo. Someone has to cut the release and update the image before keepa-central's KEEPA_FLAG_ASYNC_FAIR_SHARE goes on.

🤖 Generated with Claude Code

…HTTP date

A 429 with max_backoff set waits the longer of Retry-After and 2^attempt
seconds, capped at max_backoff. Without max_backoff the wait is unchanged,
except that 2^attempt no longer overflows at high attempt counts.
Retry-After is read as delay-seconds or an HTTP-date (RFC 9110 10.2.3).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Snehal Ahire <snehal.ahire@pattern.com>
@oly-agents
oly-agents Bot requested a review from a team as a code owner December 2, 2026 08:55
@argus-pattern

argus-pattern Bot commented Dec 2, 2026

Copy link
Copy Markdown

👀 Reviewing 83ad6ae.

@argus-pattern argus-pattern Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argus reviewed max_backoff, Retry-After parsing (seconds and HTTP date), the saturating exponential, how it plugs into call() (attempt starts at 1, nil response → retry_delay), and the new tests. go test ./internal/pkg/pipeline/task/http/ passes. rate-gate sends Retry-After as integer seconds, so the switch to strconv.Atoi does not break the main consumer. With max_backoff unset, behavior is unchanged apart from the documented HTTP-date and overflow fixes.

PR body links to "create PR" pages, not the related PRs
Severity: Low

Under Related PRs, the body links to .../pull/new/feat/async-fair-share and .../pull/new/feat/keepa-async-per-consumer. Those are compare pages for opening a PR. The PRs already exist, so the cross-links the task asks for point to the wrong place.

Fix: Replace them with https://github.com/patterninc/keepa-central-server/pull/172 and https://github.com/patterninc/rate-gate/pull/147.

…ntial

With max_backoff set, a 429 now waits a uniform random time from
Retry-After up to min(max(Retry-After, 2^attempt), max_backoff), so
throttled workers stop retrying in lockstep.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Snehal Ahire <snehal.ahire@pattern.com>
@oly-agents

oly-agents Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Updated the PR description: the Related PRs links now point to keepa-central-server#172 and rate-gate#147 instead of the "create PR" compare pages. The description also covers the jittered 429 wait.

@argus-pattern argus-pattern Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argus follow-up on 83ad6ae..aa1742e: the new commit adds jitter to the 429 backoff and switches the tests to bounds checks. go test ./internal/pkg/pipeline/task/http/ passes.

Earlier comments

  • ✅ addressed: 429 backoff has no jitter, so throttled workers still retry in lockstep. When max_backoff is set, the wait is now floor + jitter(ceiling-floor+1), with floor = min(Retry-After, ceiling). Because ceiling ≥ floor, the argument to rand.N is always ≥ 1 for normal values. The pinned-draw test and the spread test cover both bounds.
  • ✅ addressed: PR body links to "create PR" pages, not the related PRs. The body now links keepa-central-server#172 and rate-gate#147.

New this round

  • 1 inline comment: a very large Retry-After overflows time.Duration, and the jitter path then panics in rand.N (I reproduced it).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Snehal Ahire <snehal.ahire@pattern.com>

@argus-pattern argus-pattern Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argus follow-up on aa1742e..6985681: the new commit clamps delay-seconds Retry-After in parseRetryAfter and adds two TestBackoff cases. go test -race and go vet pass for ./internal/pkg/pipeline/task/http/.

Earlier comments

  • ✅ addressed: Huge Retry-After overflows and makes the jitter panic. Delay-seconds now saturates at math.MaxInt64/time.Second seconds, so floor and ceiling stay non-negative and the argument to rand.N is always ≥ 1. The HTTP-date path was already safe, because time.Time.Sub saturates. The new cases cover the saturated wait with and without max_backoff. The untyped constant fits int on the amd64 and arm64 release targets.
  • ✅ addressed (earlier round): 429 backoff has no jitter, so throttled workers still retry in lockstep.
  • ✅ addressed (earlier round): PR body links to "create PR" pages, not the related PRs.

New this round
No new findings.

@oly-agents

oly-agents Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Oly has paused automatic upkeep on this PR.

No human has commented, reviewed, or pushed here in 2 workdays (Monday to Friday, UTC). Until someone does, Oly will not run merge-conflict checks or fixes, automatic Argus reviews, or PR-feedback runs on this PR.

To resume, comment, leave a review, push a commit, or comment /argus review. Comments from Oly, including this one, do not count.

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