Repository navigation
Keep waiting for a review through rate limits and unavailability - #2
apoorvarohilla wants to merge 7 commits into
Conversation
wait_for_review raised the 429 or 503 that ended one read's retries, even with most of its timeout left: five brief 503s, or one Retry-After over 60 seconds, failed a 300-second wait. A Retry-After of 20 against a 10-second wait already returned TIMED_OUT, so the outcome depended on the header's length rather than on the wait's deadline. The wait now treats such a problem like an unfinished review. It polls again no sooner than the Retry-After, or its own backoff, and returns TIMED_OUT when its deadline passes. Other problems still end the wait. A single call keeps its four-attempt and 60-second bounds. ProoflineError carries the parsed retry_after for a 429 or 503 so the wait can honor it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| seconds its valid Retry-After asked for, and None otherwise. | ||
| """ | ||
|
|
||
| retry_after: float | None = None |
There was a problem hiding this comment.
Warning · Review waits poll before Retry-After on encoded responses
Both transports reject encoded 429 and 503 responses before attaching Retry-After, but this change makes both waits retry those errors by status alone.
With enough time remaining, a first encoded response asking for 90 seconds can trigger another poll after five seconds.
Preserve Retry-After on encoding errors without reading the rejected body.
Also at:
proofline/client.pylines 969 to 976
There was a problem hiding this comment.
Still present in this version: Proofline found the issue again. Proofline's finding in this version: Retry documentation leaves malformed 429 and 503 bodies ambiguous. View review
Review feedback on the previous commit: - Both transports raise an encoded or unreadable 429 or 503 before the retry policy reads it, and the wait retried those by status alone. Mark the problems that pass through the retry policy as retryable and continue the wait only for those, so an encoded or unreadable response still raises as it did before. - A wait with a very large timeout passed the whole Retry-After to time.sleep, which overflows near 1e10 seconds. Hold the next read until the Retry-After passes and sleep toward it in steps of at most a minute. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| """An invalid or longer Retry-After returns the problem without an early retry.""" | ||
| if value is None: | ||
| return float(2**attempt) | ||
| delay = retry_after(value) |
There was a problem hiding this comment.
Warning · Review waits poll early when a valid Retry-After overflows
A valid decimal Retry-After that overflows float becomes None, so both waits fall back to their normal polling interval.
After a readable 429 or 503, either wait can poll again after five seconds instead of returning TIMED_OUT without another request.
Distinguish overflowing delays from missing or invalid headers and suppress polling until the wait deadline for overflowing delays.
Also at:
proofline/_transport.pylines 539 to 550proofline/client.pylines 980 to 986
There was a problem hiding this comment.
Still present in this version: Proofline found the issue again. Proofline's finding in this version: Oversized Retry-After values expose undocumented infinity. View review
There was a problem hiding this comment.
Still present in this version: Proofline found the issue again. Proofline's finding in this version: A 429 or 503 can time out after its last chunk without retry metadata. View review
| sleep(min(held, 60, _transport.remaining() or 0)) | ||
| continue | ||
| try: | ||
| last = self.get_review(organization_id, review_id) |
There was a problem hiding this comment.
Warning · An expiring retry hold can start a review read after the deadline
Both wait loops check the deadline before sampling the clock for the retry hold. If that sample is past both cutoffs, they call get_review with no time left.
The wait enters the review-read path instead of exiting immediately.
Use the same monotonic timestamp to check the deadline and the retry hold before polling.
Details
The built-in transports reject the expired read before network I/O. The specific retry-hold trigger was absent before this change because service errors ended the wait rather than setting a hold.
Also at:
proofline/client.pylines 969 to 986
| ## Errors and refusals | ||
|
|
||
| A refused request raises `ProoflineError` with the server problem's `status`, `type`, `title` and `detail`. When a review request creates nothing, the error also carries `refusal`, whose `reason` names the setting to change, such as `NO_LINKED_ENVIRONMENT` or `ENVIRONMENT_NOT_READY`, and `repository_name`. `RunNowRefusal` names the type of `refusal`. A refusal that does not match the public contract keeps its status, `title` and `detail` with the type `urn:proofline:sdk:invalid-response` and no `refusal`. Any other status, such as the 402 a review request answers when credits cannot pay, is a plain problem with no `refusal`. The token is redacted from every text field, and `repr` and `str` show only the status. | ||
| A refused request raises `ProoflineError` with the server problem's `status`, `type`, `title` and `detail`. When a review request creates nothing, the error also carries `refusal`, whose `reason` names the setting to change, such as `NO_LINKED_ENVIRONMENT` or `ENVIRONMENT_NOT_READY`, and `repository_name`. `RunNowRefusal` names the type of `refusal`. A refusal that does not match the public contract keeps its status, `title` and `detail` with the type `urn:proofline:sdk:invalid-response` and no `refusal`. Any other status, such as the 402 a review request answers when credits cannot pay, is a plain problem with no `refusal`. A 429 or 503 problem the service sent is `retryable`, and its `retry_after` holds the seconds its valid `Retry-After` asked for, or `None`; an encoded or unreadable response is not retryable. `wait_for_review` does not end on a retryable problem: it polls again no sooner than that `Retry-After` and returns `TIMED_OUT` if its timeout passes first. The token is redacted from every text field, and `repr` and `str` show only the status. |
There was a problem hiding this comment.
Warning · Retry docs blur invalid problem JSON and unreadable HTTP bodies
The README says unreadable responses are not retryable without distinguishing a failed body read from invalid problem JSON. A fully read 429 or 503 can be retryable even without a valid problem document.
Callers may expect wait_for_review to raise when it instead keeps waiting.
Clarify that retryability requires reading the HTTP body successfully, not decoding a problem document.
Also at:
proofline/_transport.pylines 87 to 89
There was a problem hiding this comment.
Still present in this version: Proofline found the issue again. Proofline's finding in this version: Deeply nested 429 or 503 bodies abort review waits. View review
Review feedback on the previous commit: - A Retry-After with more digits than a float holds parsed to inf and was discarded, so the wait polled at its own interval. Keep it as inf: the wait holds until its deadline. retry_delay still refuses it for a single call, as before. - The docs called unreadable responses not retryable, while a fully received 429 or 503 without a problem document is retryable. Say which: only one refused before its body is read, such as an encoded one. - The Retry-After test now offers completion only after the asked-for 90 seconds and checks when each request arrived. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| ## Errors and refusals | ||
|
|
||
| A refused request raises `ProoflineError` with the server problem's `status`, `type`, `title` and `detail`. When a review request creates nothing, the error also carries `refusal`, whose `reason` names the setting to change, such as `NO_LINKED_ENVIRONMENT` or `ENVIRONMENT_NOT_READY`, and `repository_name`. `RunNowRefusal` names the type of `refusal`. A refusal that does not match the public contract keeps its status, `title` and `detail` with the type `urn:proofline:sdk:invalid-response` and no `refusal`. Any other status, such as the 402 a review request answers when credits cannot pay, is a plain problem with no `refusal`. The token is redacted from every text field, and `repr` and `str` show only the status. | ||
| A refused request raises `ProoflineError` with the server problem's `status`, `type`, `title` and `detail`. When a review request creates nothing, the error also carries `refusal`, whose `reason` names the setting to change, such as `NO_LINKED_ENVIRONMENT` or `ENVIRONMENT_NOT_READY`, and `repository_name`. `RunNowRefusal` names the type of `refusal`. A refusal that does not match the public contract keeps its status, `title` and `detail` with the type `urn:proofline:sdk:invalid-response` and no `refusal`. Any other status, such as the 402 a review request answers when credits cannot pay, is a plain problem with no `refusal`. A 429 or 503 whose body the client received in full is `retryable`, even without a problem document, and its `retry_after` holds the seconds its valid `Retry-After` asked for, or `None`. A 429 or 503 the client refuses before reading its body, such as an encoded one, is not retryable. `wait_for_review` does not end on a retryable problem: it polls again no sooner than that `Retry-After` and returns `TIMED_OUT` if its timeout passes first. The token is redacted from every text field, and `repr` and `str` show only the status. |
There was a problem hiding this comment.
Warning · Fully received 429 or 503 can end review polling early
This change promises retries for fully received 429 and 503 responses, but deeply nested JSON can raise RecursionError before retry metadata is set.
Both clients can exit wait_for_review with a nonretryable invalid-response error while time remains.
Treat JSON decoding recursion failures as missing problem documents so the transport preserves the status and retry metadata.
Details
The parser already let this exception escape before this change; the documented retry guarantee is new.
There was a problem hiding this comment.
Still present in this version: Proofline found the issue again. Proofline's finding in this version: A fully received 429 or 503 can still end the review wait. View review
Review feedback on the previous commit: - A 429 or 503 body nested too deeply for the JSON decoder or redaction raised RecursionError out of problem parsing, before the transport could mark it retryable. Treat it like any body that is not a problem document. - Document that retry_after is inf for more seconds than a float holds. - The test of a rate limit without a problem document now checks the exact sleeps, so it proves the wait held before the final read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| while (_transport.remaining() or 0) > 0: | ||
| held = not_before - monotonic() | ||
| if held > 0: | ||
| # Sleep in bounded steps until the service's Retry-After passes. |
There was a problem hiding this comment.
Warning · Long Retry-After crashes review polling under Trio
The new retry hold calls asyncio.sleep after a fully read 429 or 503 with a Retry-After above 60 seconds. Trio has no running asyncio loop for that sleep.
The wait raises RuntimeError instead of polling again or returning TIMED_OUT.
Use anyio.sleep for the async retry hold.
Details
Before this change, the wait re-raised the HTTP error before reaching its asyncio-only polling sleep. This change reaches that sleeper even when the first read fails, provided time remains in the wait budget.
| with Server(respond) as server: | ||
| async with session(mode, server.url) as client: | ||
| result = await call(client, "wait_for_review", ORG, REVIEW, timeout=100) | ||
| assert result.status == "TIMED_OUT" |
There was a problem hiding this comment.
Warning · Last-review test passes even if a 503 ends the wait early
The test checks only TIMED_OUT and the retained RUNNING review, both returned if the retryable 503 branch exits immediately after a successful poll.
A regression that skips the retry hold would pass in both client modes.
Assert that the fake clock reaches the deadline and verify the expected requests and sleep intervals.
Review feedback: the test checked only the outcome, which an early exit after the first unavailable read would also return. It now checks that the wait held for the Retry-After and read again before its deadline. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
prooflinedev#75 already catches RecursionError where problem() decodes the body, so this change no longer does. The HTML 503 test keeps its exact sleeps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| ## Errors and refusals | ||
|
|
||
| A refused request raises `ProoflineError` with the server problem's `status`, `type`, `title` and `detail`. When a review request creates nothing, the error also carries `refusal`, whose `reason` names the setting to change, such as `NO_LINKED_ENVIRONMENT` or `ENVIRONMENT_NOT_READY`, and `repository_name`. `RunNowRefusal` names the type of `refusal`. A refusal that does not match the public contract keeps its status, `title` and `detail` with the type `urn:proofline:sdk:invalid-response` and no `refusal`. Any other status, such as the 402 a review request answers when credits cannot pay, is a plain problem with no `refusal`. The token is redacted from every text field, and `repr` and `str` show only the status. | ||
| A refused request raises `ProoflineError` with the server problem's `status`, `type`, `title` and `detail`. When a review request creates nothing, the error also carries `refusal`, whose `reason` names the setting to change, such as `NO_LINKED_ENVIRONMENT` or `ENVIRONMENT_NOT_READY`, and `repository_name`. `RunNowRefusal` names the type of `refusal`. A refusal that does not match the public contract keeps its status, `title` and `detail` with the type `urn:proofline:sdk:invalid-response` and no `refusal`. Any other status, such as the 402 a review request answers when credits cannot pay, is a plain problem with no `refusal`. A 429 or 503 whose body the client received in full is `retryable`, even without a problem document, and its `retry_after` holds the seconds its valid `Retry-After` asked for (`inf` for more seconds than a float holds), or `None`. A 429 or 503 the client refuses before reading its body, such as an encoded one, is not retryable. `wait_for_review` does not end on a retryable problem: it polls again no sooner than that `Retry-After` and returns `TIMED_OUT` if its timeout passes first. The token is redacted from every text field, and `repr` and `str` show only the status. |
There was a problem hiding this comment.
Warning · Receiving the full body does not guarantee retry metadata
The README and ProoflineError docstring promise retryability after full body receipt, but both transports can time out after yielding the last chunk, before attaching metadata.
Callers can receive a timeout instead of a retryable 429 or 503 with retry metadata.
Document that metadata is available only when the transport surfaces a 429 or 503 as a retryable ProoflineError.
Also at:
proofline/_transport.pylines 87 to 91 · Fully received 429 and 503 bodies do not guarantee retry metadata · Retryability docs omit the final body-read deadline check
There was a problem hiding this comment.
Still present in this version: Proofline found the issue again. Proofline's finding in this version: A fully read 429 or 503 can still end review polling. View review
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| ## Errors and refusals | ||
|
|
||
| A refused request raises `ProoflineError` with the server problem's `status`, `type`, `title` and `detail`. When a review request creates nothing, the error also carries `refusal`, whose `reason` names the setting to change, such as `NO_LINKED_ENVIRONMENT` or `ENVIRONMENT_NOT_READY`, and `repository_name`. `RunNowRefusal` names the type of `refusal`. A refusal that does not match the public contract keeps its status, `title` and `detail` with the type `urn:proofline:sdk:invalid-response` and no `refusal`. Any other status, such as the 402 a review request answers when credits cannot pay, is a plain problem with no `refusal`. The token is redacted from every text field, and `repr` and `str` show only the status. | ||
| A refused request raises `ProoflineError` with the server problem's `status`, `type`, `title` and `detail`. When a review request creates nothing, the error also carries `refusal`, whose `reason` names the setting to change, such as `NO_LINKED_ENVIRONMENT` or `ENVIRONMENT_NOT_READY`, and `repository_name`. `RunNowRefusal` names the type of `refusal`. A refusal that does not match the public contract keeps its status, `title` and `detail` with the type `urn:proofline:sdk:invalid-response` and no `refusal`. Any other status, such as the 402 a review request answers when credits cannot pay, is a plain problem with no `refusal`. A 429 or 503 that the client finishes reading within its deadline is `retryable`, even without a problem document, and its `retry_after` holds the seconds its valid `Retry-After` asked for (`inf` for more seconds than a float holds), or `None`. A 429 or 503 the client refuses before reading its body, such as an encoded one, is not retryable, and a deadline that passes first raises the timeout instead. `wait_for_review` does not end on a retryable problem: it polls again no sooner than that `Retry-After` and returns `TIMED_OUT` if its timeout passes first. The token is redacted from every text field, and `repr` and `str` show only the status. |
There was a problem hiding this comment.
Warning · MCP body-read deadlines surface as generic transport errors
The new README promises a timeout when a 429 or 503 body read misses its deadline, but MCP helpers wrap that read timeout as a generic transport error.
MCP callers receive urn:proofline:sdk:transport and cannot distinguish the deadline from other transport failures.
Map MCP timeouts separately or explicitly limit the README guarantee to REST calls.
Also at:
proofline/_mcp.pylines 129 to 134
| with pytest.raises(ProoflineError) as raised: | ||
| await call(client, "rerun_review", ORG, REVIEW) | ||
| assert raised.value.retryable | ||
| assert raised.value.retry_after == 75 |
There was a problem hiding this comment.
Warning · Metadata test misses Retry-After loss after GET retries
The metadata test uses Retry-After: 75, above the 60-second cap, so the GET raises before exhausting its retries.
Dropping retry_after only on the final GET attempt leaves the metadata test green.
Use Retry-After: 0 in the retry-count test and assert retry_after == 0 on the error after four attempts.
Details
The existing retry-count test already catches an incorrectly retried POST with an in-cap header. Its GET case checks the status and attempt count, but not the retry metadata.
| the repository_name it refers to. A 429 or 503 read in full within the | ||
| deadline is retryable, even without a problem document, and retry_after | ||
| holds the seconds its valid Retry-After asked for (inf for more seconds | ||
| than a float holds), or None. A 429 or 503 refused before its body is |
There was a problem hiding this comment.
Warning · Fully read 429 and 503 responses can lack retry metadata
The docstring promises retryability after a full read within the deadline, but deeply nested problem bodies can raise RecursionError before either transport attaches metadata.
Callers receive a generic invalid-response error without retry metadata.
Limit the documented guarantee to errors that reach the retry policy after problem parsing.
| the repository_name it refers to. A 429 or 503 read in full within the | ||
| deadline is retryable, even without a problem document, and retry_after | ||
| holds the seconds its valid Retry-After asked for (inf for more seconds | ||
| than a float holds), or None. A 429 or 503 refused before its body is |
There was a problem hiding this comment.
Warning · Deeply nested error bodies suppress retry metadata
After reading a 429 or 503 within the deadline, both transports parse and redact the body before setting retry metadata, so RecursionError skips the new assignments.
Callers receive an invalid-response error instead of the HTTP status and retry metadata.
Catch RecursionError during decoding and redaction and use the status-preserving about:blank fallback.
Details
The parser could already raise before this change, but the base did not promise or expose retry metadata.
Problem
wait_for_reviewraised the 429 or 503 that ended one read's retries, even when most of its timeout was left. A CI job waiting on a review failed on a brief rate limit or service restart instead of waiting.Loopback reproduction (real sockets and real time,
ProoflineClient; the tests below cover both clients):Retry-After: 0), then the review isCOMPLETEDCOMPLETEDafter 6 requests, 5.0 sRetry-After: 90TIMED_OUTafter 1 request, 3.0 sThe outcome also depended on the length of the header rather than on the wait's deadline.
test_retry_after_is_bounded_by_wait_deadlinepins that a 503 withRetry-After: 20against a 10-second wait returnsTIMED_OUT, and prooflinedev#12 describesTIMED_OUTas the only consistent outcome for a retryable problem in a wait. ButRetry-After: 61against a 300-second wait raised 503 immediately, because the transport refuses a single call's retry above 60 seconds and the wait re-raised that refusal.Approach
A single call keeps its bounds: at most four attempts, never retried earlier than its
Retry-After, and aRetry-Afterover 60 seconds is returned to the caller. Those are the right limits for one request. The wait is the part that has a longer budget, so the change is in the wait:wait_for_reviewtreats it like an unfinished review. It holds the next read until the larger of its own poll interval and the problem'sRetry-Afterhas passed, sleeping toward it in steps of at most a minute and never past the deadline, and reads again. When the deadline passes it returnsTIMED_OUTwith the last review it read, as it already does for a review that is still running.retryableand records their parsedRetry-After(retry_after,inffor more seconds than a float holds,Nonewhen absent or invalid) on theProoflineErrorit raises.retry_delayis split intoretry_after(parse) and the existing 60-second retry bound, with unchanged results. Callers of non-retried requests such asrequest_reviewcan read the same value.The README and the
wait_for_reviewdocstring describe the new behavior.Verification
New tests in
tests/test_http.py, all on both clients with the suite's fakeClock:test_wait_keeps_polling_after_one_request_exhausts_its_retries(429, 503): five 503s then a completed review returnsCOMPLETED; the requests and sleeps are exactly four transport attempts, one five-second wait poll, and the final read.test_wait_honors_a_retry_after_longer_than_one_request_retries: withRetry-After: 90the second request arrives exactly 90 seconds after the first (completion is only offered then), slept as 60 + 30.test_wait_holds_a_retry_after_too_long_for_a_float_until_its_deadline: a 400-digitRetry-Afterholds the wait to its deadline (TIMED_OUT, one request) instead of polling early.test_wait_retries_a_rate_limit_without_a_problem_document: four HTML 503 pages, then a completed review, returnsCOMPLETED; the sleeps are exactly the transport's 1, 2, 4 and the wait's 5.test_wait_sleeps_a_very_long_retry_after_in_bounded_steps:Retry-After: 100000in a wait withtimeout=1e12sleeps exactly 100000 seconds in steps of at most 60, then completes.test_wait_times_out_when_retry_after_outlasts_its_deadline:Retry-After: 90in a 60-second wait sleeps to the deadline and returnsTIMED_OUT.test_wait_keeps_the_last_review_read_before_the_service_was_unavailable: aRUNNINGread followed by 503s returnsTIMED_OUTthat still carries theRUNNINGreview, after exactly three reads and sleeps of 5, 60 + 30 (theRetry-After) and 5 (to the deadline).test_wait_still_raises_problems_that_are_not_retryable(400, 401, 403, 404, 500, 502): one request, no sleep, the same status raised.test_wait_raises_an_encoded_rate_limit_it_cannot_read(429, 503): a gzip-encoded problem still raisesinvalid-responseafter one request, and is notretryable.test_a_rate_limit_problem_carries_its_retry_after(429, 503):retryableandretry_afteron a retriedGETand a non-retriedPOST; a 403 has neither.Against
main, 28 of these 40 cases fail: the 20 cases of the seven waiting tests each raise 429 or 503, and the 8 cases of the last two tests fail only becausemainhas noretryableorretry_after(an encoded problem raises there too). The 12 non-retryable cases pass on both. The existing single-call tests (test_retry_count_is_bounded_for_rate_limit_and_provider_unavailable,test_long_retry_after_is_not_retried_early, the malformedRetry-Aftercases) pass unchanged.scripts/check.pydoes not run on Windows (prooflinedev#87), so I ran its steps directly. On Windows,test_streaming_and_resolution_keep_deadline_outcomes_explicit[sync]fails intermittently onmainas well (2 of 12 runs before this change); that is the clock-resolution issue prooflinedev#85 addresses.Review feedback
I ran Proofline on the first commit in my fork. It reported four warnings, which came down to two issues, and I confirmed both:
retryable;test_wait_raises_an_encoded_rate_limit_it_cannot_readdid not raise on the first commit and does now.Retry-Afterwent totime.sleep, which raisesOverflowErrornear 1e10 seconds. The wait now sleeps toward theRetry-Afterin steps of at most a minute.A second run on that commit raised five more warnings:
Retry-Afterwith more digits than a float holds parsed toinfand was discarded, so the wait polled early. Confirmed: it is now kept asinfand the wait holds until its deadline. A single call still refuses it, as before.get_reviewwith no time left. I disagree that this needs a change:limit_timeoutrefuses the request before anything is sent when no budget remains, and the wait returnsTIMED_OUT, the same as the loop onmain.A third run raised three more, all confirmed:
RecursionErrorout of problem parsing before it can be marked retryable (reported three times). Confirmed, but it applies to every error status onmain, and Don't report caller errors as invalid API responses prooflinedev/sdk-python#75 already catchesRecursionErrorthere, so I left it to that PR; with both merged, such a 429 or 503 is retryable.retry_aftercan beinf. They do now.A fourth run raised three more. I fixed one and disagree with two:
TIMED_OUTtest checked only the outcome, which an early exit would also return. Confirmed: it now checks every read and sleep.asyncio.sleep, which does not run under Trio. The wait's existing poll sleep and the transport's retry sleep onmainalready useasyncio.sleep, so a Trio wait already fails there for aRUNNINGreview; the hold follows that. Moving the client toanyio.sleepwould be a separate change.retryablebut the deadline check can raise first. When the wait's deadline passes during a retry, the transport raises its timeout error rather than the 429 or 503, so there is no rate-limit problem to mark;wait_for_reviewreturnsTIMED_OUT, as the same README sentence says.Related
prooflinedev#75 handles problem bodies nested too deeply to decode (see above).
prooflinedev#85 changes the condition just above this one (which timeout ends a wait as
TIMED_OUT); it still re-raises 429 and 503, so the two changes are independent and compose.