Repository navigation
feat(doc): resend a reader's 429 with Retry-After, like its 503 - #2261
Conversation
A rate limit answered with `Retry-After` refuses before any work (RFC 6585 §4), so resending it after the wait can't bill a read twice. Without it, a folder-sized `doc ingest` against a reader with a per-account rate limit fails every document past the limit. Same caps as the 503 rule: four attempts, five minutes of waiting, each wait reported. A 429 without `Retry-After` is still not resent. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016CjYmSfiNVsRZmcpMicDfq
jdorety
left a comment
There was a problem hiding this comment.
Three findings, inline. The first should be fixed before merge. I reproduced #1 and #2 with temporary stub tests (not committed). The existing reader::client tests pass. No test covers a Retry-After above 60 s or the MAX_WAIT branch.
- A 429 with
Retry-After> 60 s is resent before the time the server names. - The
MAX_WAIT(5 min) check can never trigger, so the reworded error never appears. - The "refuse before any work" reason for 429 cites RFC 6585, which doesn't say that; whether a resend can bill twice depends on the reader server.
🤖 Generated with Claude Code
| } | ||
| let message = error_message(&text); | ||
| let retry_after = (status == 503) | ||
| let retry_after = (status == 503 || status == 429) |
There was a problem hiding this comment.
Resends a 429 before the time it names. With 429 now in the resend set, the clamp at line 253 (secs.clamp(1, MAX_RETRY_AFTER)) cuts any Retry-After above 60 s to 60 s. I checked this with a stub that answers 429 + Retry-After: 120 and then 200: the client resent after 60 s. That breaks the doc's "after the wait it names". A quota limiter asking for minutes gets up to 3 requests that are sure to fail, and the run sleeps 180 s before failing anyway. (503 had the same clamp before this PR; it matters more for 429.)
Suggested fix: if the server's unclamped wait is more than MAX_RETRY_AFTER or more than the remaining budget, fail right away and give the requested wait in the error. Add a test that a 429 with Retry-After: 120 gets no resend.
There was a problem hiding this comment.
You're right. With 429 in the resend set, the clamp meant a quota limiter asking for two minutes got hit again at one minute, and three times in all, and those resends were sure to fail. Fixed in 17a2dfd, mostly the way you suggested, with one difference.
The wait is now the server's, uncut (secs.max(1), and MAX_RETRY_AFTER is gone). If that wait would take the call past MAX_WAIT, it fails at once with the wait it was asked for in the error, e.g. …; the reader asks to wait 301s, and a call waits at most 300s in all (0s so far), so it is not resent. The difference: I dropped the separate 60 s per-wait cap rather than failing anything over it. With the per-wait cap kept, MAX_WAIT stays unreachable (your point on line 259), and a 503 from a model that's still starting can reasonably ask for more than a minute. Honouring the server's wait up to the five minutes the doc already promises seemed the simplest rule that's true. So a 429 with Retry-After: 120 is resent once, but only after 120 s (a_long_retry_after_is_waited_in_full), and one asking for 301 s is not resent at all (a_wait_past_the_cap_is_not_resent, for both 429 and 503). The tests swap out the sleep, so they don't actually wait. If you'd rather keep a short per-wait cap and lower MAX_WAIT to match, happy to go that way instead.
| status, | ||
| message: format!( | ||
| "no capacity after {}s of waiting: {message}", | ||
| "still refused after {}s of waiting: {message}", |
There was a problem hiding this comment.
This branch can't be reached. Only attempts 1–3 can wait, and each wait is at most 60 s, so waited + wait peaks at 180 s and never exceeds MAX_WAIT (300 s). I checked: four 503 + Retry-After: 120 responses fail after 180 s with the plain error, and this message never appears. The documented "five minutes of waiting" cap has no effect. This predates the PR, but the PR edits this line. Either make the cap reachable (the fix above does that) or remove MAX_WAIT and the doc sentence, and test whichever branch you keep.
There was a problem hiding this comment.
Good catch, and thank you for flagging it even though it predates the PR. 17a2dfd makes it reachable: with the clamp gone (see the thread on line 246), waits add up against MAX_WAIT as written. waiting_stops_at_the_total_cap covers it: three 503 + Retry-After: 120 answers, two waits spent, and the third fails at once with (240s so far) rather than waiting past five minutes. The four-attempt cap is a separate branch now, and its error says so (still refused after 4 attempts and 3s of waiting: …). resends_stop_at_the_attempt_cap checks that message.
| //! **Resends.** A read is resent only when the answer is a 503 or a 429 that | ||
| //! carries `Retry-After`: the endpoint saying it had no capacity (a model | ||
| //! still starting, a full queue) or that the caller is over a rate limit, | ||
| //! and when to come back. Both refuse before any work (RFC 9110 §15.6.4, |
There was a problem hiding this comment.
RFC 6585 doesn't say this. §4 defines 429 as "too many requests in a given amount of time" and says it MAY carry Retry-After. It says nothing about whether the server did any work on the request. So the rule against billing a read twice rests on the reader endpoint's behavior. A request covers several windows; if the endpoint passes on an upstream provider's 429 partway through, a resend bills the windows it already read again. I couldn't check the server from this repo. Could someone confirm it only returns 429 before reading anything? If so, cite that here instead of the RFC. If not, I'd keep 429 out of the resend set.
There was a problem hiding this comment.
You're right, and that was a bad citation on my part. Neither RFC 6585 §4 nor RFC 9110 says anything about whether the server did work before answering 429 or 503. They define both by cause. 17a2dfd drops both citations and rests the rule on the reader's behavior, in the module doc and in docs/cli/doc.md.
On your question about the server: I checked, and fluree.ai's reader bills only a call it answers. The fuel is priced from the token counts of the 200, so a 429 is never billed. That covers its own rate limit, which answers before the request goes anywhere, and also the case you raised, a 429 or 503 it passes on from the model behind it. A request's windows are read in one upstream call, so a refusal can't leave some windows billed and others not. That's what the doc now says, along with the condition for any other reader: it should send Retry-After with a 429 or 503 only when the same holds. So I've kept 429 in the resend set. If you think the generic [doc.reader] case needs more than the doc saying so (say, resending a 429 only for an account reader), I'm open to that.
… ground the 429 rule A Retry-After above 60 s was clamped to 60 s, so a 429 asking for minutes was resent before the time it named, up to three times. The wait is now the endpoint's, uncut. Waiting is capped only by MAX_WAIT across a call's resends, and a wait that would pass it fails at once, naming the wait the reader asked for. That makes MAX_WAIT reachable: with the 60 s clamp, three waits peaked at 180 s and the cap never fired. The attempt cap's error now says it stopped after four attempts. The module doc and docs/cli/doc.md cited RFC 6585 and RFC 9110 for "a 429 or 503 refuses before any work", which neither says. The rule rests on the reader instead: fluree.ai's reader bills only a call it answers, so a 429 or 503 is never billed, and a reader of another kind should send Retry-After with them only when the same holds. Tests: a 429 or 503 asking 301 s is not resent and says so; a 429 asking 120 s is waited in full; two 120 s waits are spent and the third fails at the total cap; the attempt cap's message. Waits are injected in tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thank you, @jdorety. All three were right, and they're fixed in 17a2dfd (with |
bplatz
left a comment
There was a problem hiding this comment.
Approving. The full Retry-After wait, the reachable MAX_WAIT and the corrected rationale all look right, and the injected sleep keeps the tests fast. Please look at the inline comment before merging. It's fine as a follow-up.
| waited.as_secs() | ||
| ))); | ||
| } | ||
| if waited + wait > MAX_WAIT { |
There was a problem hiding this comment.
When an account is over a quota whose Retry-After passes the cap, this fails the document at once, which is right for this call. But doc ingest then marks it ✗ and continues, so the next document sends another request that is sure to get a 429, and so does every one after it. A large folder becomes N refused requests and N ✗ lines. Suggest ending the run (or at least its reader calls) on a 429 past the cap, and saying how long the reader asked to wait.
There was a problem hiding this comment.
Agreed, and fixed in 76a56bc, by the same rule I applied in #2260: a failure of this document fails it, and a failure every remaining document is sure to repeat ends the run with one message.
The client now tells that case apart. A wait that passes MAX_WAIT on its own comes back as a new DocError::Unavailable { status, wait, .. } instead of Endpoint, and the CLI's read_document maps it to ReadFailure::Run. doc ingest then marks that one document ✗, stops, still indexes and totals what it committed, and ends with one error that carries the wait, e.g. … 429 quota_exceeded: Monthly quota reached; the reader asks to wait 3600s, and a call waits at most 300s in all (0s so far), so it is not resent, plus hint: the reader refuses every call for about 60 min; try again after that. doc_ingest_stops_when_the_reader_asks_to_wait_past_the_cap covers it: three documents, one request sent, one ✗.
Two choices in there you may want to check:
- A 503 whose
Retry-Afterpasses the cap on its own ends the run too, not only a 429. The reader is saying no call gets served before then, whichever document it's for. - A wait that passes the cap only because of waits this call already spent (
(240s so far)) stays an ordinary refusal of this document. The next call's waits start afresh, so it isn't sure to repeat.waiting_stops_at_the_total_capnow asserts it staysEndpoint.
A 429 (or 503) whose Retry-After passes MAX_WAIT on its own failed that
document, which is right for the call. But `doc ingest` then marked it ✗
and went on, so each later document sent a request sure to be refused the
same way: N refused requests and N ✗ lines for one quota.
The client now tells that case apart as DocError::Unavailable, carrying the
wait asked for. A wait that passes the cap only with the waits already
spent stays an ordinary refusal of this call: the next call's waits start
afresh. The CLI keeps one rule for every failure in the ingest loop: a
failure of this document marks it ✗ and the next is read; one every
remaining document is sure to meet too ends the run with one error, after
what was done is indexed and totalled. read_document says which with
ReadFailure::{Document, Run}, and the error says how long the reader asked
to wait.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018gr44NC1vnaK3VWs79jCxm
|
Thanks @bplatz! I folded the inline note in here rather than as a follow-up (76a56bc, answered in the thread): a reader that asks to wait past the cap now ends |
…d-429 # Conflicts: # docs/cli/doc.md # fluree-db-cli/src/commands/doc.rs # fluree-db-cli/src/commands/doc_reader.rs # fluree-db-cli/tests/integration.rs # fluree-db-doc/src/reader/client.rs
|
Merged |
The HTTP reader resent only a 503 with
Retry-After. This adds a 429 withRetry-After, under the same caps: four attempts, five minutes of waiting in all, each wait shown as it starts.Why it's safe: the status code alone doesn't promise it: RFC 6585 and RFC 9110 define 429 and 503 by cause, not by whether work was done. The rule rests on the reader: fluree.ai's reader bills only a call it answers, so neither its own rate limit's 429 nor a 429 or 503 it passes on from a model is billed (Arnaud's point on #2207). A reader of another kind should send
Retry-Afterwith them only when the same holds; the module doc anddocs/cli/doc.mdsay so.Waits (after review): a resend waits the full
Retry-After, never less (the old 60 s clamp is gone), andMAX_WAIT(five minutes across a call's resends) is the cap on waiting: a wait that would pass it fails at once, naming the wait asked for. With the clamp, three waits peaked at 180 s and the cap could never trigger.Why it matters: with a per-account rate limit, a folder-sized
doc ingestwould otherwise fail every document past the limit.What doesn't change: a 429 without
Retry-Afteris still not resent (a WAF block, say), and neither is a 503 without it, a 502, or a 504.fluree-db-doc/src/reader/client.rs: the rule, its module doc, and the give-up message, which no longer says "no capacity" for a rate limit.a_429_with_retry_after_is_resent; the not-resent test now covers a 429 without the header and a 502 with it;a_wait_past_the_cap_is_not_resent,a_long_retry_after_is_waited_in_full,waiting_stops_at_the_total_cap, and the attempt cap's message (waits are injected in tests).docs/cli/doc.md"Resends", the book'sreadpage, and thefluree.docdocstring.cargo test -p fluree-db-docgreen, clippy clean,cargo fmt --all --checkclean.🤖 Generated with Claude Code
https://claude.ai/code/session_016CjYmSfiNVsRZmcpMicDfq