Who Reviews Retry Logic Before Merge?
Rate limiting is nearly unavoidable in API clients, and Retry-After handling is where subtle bugs hide. This article explains why treating server responses as a plain number is dangerous, how to correctly handle both relative-second and absolute-timestamp Retry-After values, and what tests and review practices should accompany the fix. You will learn how to avoid zero-wait retry storms and how to make CI failures genuinely reflect semantic errors.
Rate limiting is a near-universal concern in API clients. When a server returns 429, it means the client is sending requests too frequently and should back off before retrying. Many implementations read the suggested wait time from the response header, multiply it by one thousand milliseconds, and hand the result to a timer. The change is only a few lines and looks clean, yet it is often waved through in code review as a minor tweak.
The real danger is not “forgot to wait” but treating two entirely different semantics as the same kind of number.
Two Semantics Behind Retry-After
Servers commonly use two conventions for Retry-After and similar fields:
- A relative duration in seconds, e.g. “wait 30 seconds.”
- An absolute timestamp, e.g. “retry at this specific time.”
If code blindly converts the field to a number, a date string yields an invalid value and a missing field yields zero. If the wait function passes that value to the timer unchanged, both paths effectively skip the wait. The server has just asked the client to slow down, yet the client may burn through its remaining quota all at once—at best worsening the rate limiting, at worst triggering a ban or a cascade of retries.
The value of review before merge lies precisely in surfacing this kind of “runs fine, but semantically wrong” path. A high-quality review comment rarely just says “there’s a problem here”; instead, it offers an immediately verifiable judgment: take one sample with a future timestamp and one with a missing field, run both, and observe when the second request is actually sent. Even if a human ultimately fixes it by hand, the comment has already saved the time of tracing the root cause along the call chain.
Reviews should look at both the business code and the wait wrapper: parsing fails in one place, while the invalid value is handed to the timer in another. Reviewing only one line misses the combined effect.
Fixing More Than the Parser
The fix must go beyond parsing. The correct approach is to recognize both seconds and timestamps:
- Relative value: wait for
max(lower bound, seconds), not exceeding an upper bound. - Absolute time: wait for
max(lower bound, timestamp minus current time). If the difference is negative, treat it as immediate or apply the policy’s lower bound. - Missing or unparseable field: do not treat the interval as zero. Use a capped backoff, e.g. exponential increase with jitter, to avoid synchronized instances hammering the service simultaneously.
Most importantly, the tests must change together with the code. If the existing tests expect “retry immediately,” changing only production code will cause the tests to push the correct behavior back into an erroneous state. Tests should assert that “no next request is sent before the specified moment,” not merely that “the request eventually succeeds.” The latter is easy to green, but it does not answer the question that actually matters here: did we wait the right amount of time?
A Repeatable Review Workflow
This kind of review can be turned into a repeatable process without binding it to any particular code hosting platform or AI coding tool. After making changes locally:
- Commit to a feature branch and verify that the changed files cover only the expected scope.
- Push to the remote, then have the review capability comment on the diff with verifiable findings, submitting revertible fixes and tests where needed.
On versions: keep your command-line tools and version control recent enough to merge mainline commits into your working branch, reducing the chance that review conclusions are based on stale code. For personal projects, start with one of your own change requests: pick an already-completed rate-limit or retry change and see whether review catches consistency across parsing, waiting, and tests.
Pseudocode: Distinguish Semantics Instead of Blindly Converting
If the field is a relative number of seconds: wait max(lower bound, seconds), not exceeding the upper boundIf the field is an absolute timestamp: wait max(lower bound, timestamp minus current time)If the field is missing or unparseable: wait according to the backoff sequence and log the reasonThe timer only receives an already-normalized non-negative interval; never treat invalid values as zero
Tests: Cover At Least Three Input Classes
- A valid number of seconds
- A future timestamp
- An empty or missing field
For the timestamp case, freeze “current time” and assert that the next request falls within the expected time window—not just the final status code. For the empty case, assert that the interval is strictly greater than zero and follows the backoff. If the team has continuous integration, put these cases into the merge gate, so a red build genuinely corresponds to “semantics are wrong” rather than “a flaky timeout.”
Why This Matters
The essence of watching for red builds is not the color of the UI but the contract: the server says “slow down,” so does the client actually slow down? Tests protect the contract—or they protect a broken implementation. Rate limiting, retries, and timeouts are all corners of reliability; when a corner is written incorrectly, production traffic amplifies the error.
Object storage, message queues, logging, monitoring, and alerting in the cloud can only observe the consequences after the fact. Getting the wait semantics right before merge is the cheapest link in the chain. Only when parsing, waiting, testing, and revertible fixes sit on the same review path does a small change deserve the word “merged.”
