Skip to content

feat(retry): rate-limit aware retries and RateLimit header parsing - #905

Open
Naoray wants to merge 3 commits into
mainfrom
agent-v3-rate-limit
Open

feat(retry): rate-limit aware retries and RateLimit header parsing#905
Naoray wants to merge 3 commits into
mainfrom
agent-v3-rate-limit

Conversation

@Naoray

@Naoray Naoray commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

This backport adds response header accessors and parsed rate-limit metadata, exposes Retry-After delays through TooManyRequestsException without changing its inherited positional constructor behavior, and introduces an opt-in exponential retry strategy with jitter and a configurable delay budget. The default linear strategy continues to retry temporary network failures as before.

RetryStrategyContract and LinearRetryStrategy remain byte-for-byte identical to v3.13.1, so existing implementations and subclasses continue to load unchanged. Strategies that need exception-aware decisions, including HTTP 429 handling, can opt into ConditionalRetryStrategyContract, which extends the existing contract without adding requirements to legacy implementations.

The backport retains PHP 7.4 compatibility by using explicit properties and constructors instead of constructor property promotion, avoiding newer syntax, and parsing rate-limit dates with the platform DateTimeImmutable API.

@Naoray
Naoray requested a review from sandervanhooft August 12, 2026 12:34
Comment thread src/Http/Data/RateLimit.php Outdated
return null;
}

$segments = array_map('trim', explode(';', $header));

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Blocking: this is the pre-hardening parser rather than the behavior already merged on the v4 line. Response::header() uses PSR-7 getHeaderLine(), so multiple field values arrive comma-joined. This parser treats the complete value as one policy and returns null for valid inputs such as "get-v2-refunds";r=3, "get-v2-payments";r=7 paired with "post-v2-payments";q=5, "get-v2-payments";q=20.

There is a second omitted hardening in src/Http/ExponentialRetryStrategy.php:69: the exponential value is cast to int before it is capped, so delayBeforeAttemptMs(PHP_INT_MAX) returns 0 instead of maxDelayMs.

Please port PHP 7.4-compatible versions of the merged v4 list splitting/policy matching and finite/capped exponential calculation, together with their regression tests.

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