Skip to content

fix: honor a Retry-After that fits inside a review wait's deadline - #130

Open
abdelrahman-ah1 wants to merge 3 commits into
prooflinedev:mainfrom
abdelrahman-ah1:retry-after-wait
Open

abdelrahman-ah1 wants to merge 3 commits into
prooflinedev:mainfrom
abdelrahman-ah1:retry-after-wait

Conversation

@abdelrahman-ah1

Copy link
Copy Markdown

What this changes

A review wait now honors a Retry-After that fits inside its own deadline, instead of ending with the server's refusal.

Transport.request applied MAX_RETRY_SECONDS (60) to every Retry-After header, including the reads waitForReview makes with a deadline. A server that answered a review read with 503 and Retry-After: 90 inside a ten-minute wait got no retry at all: retryDelay returned undefined, the read threw, and waitForReview rejected with ProoflineError 503 after a single read.

The docs say a wait stops early only when the retry delay would reach or pass the deadline (https://proofline.sh/docs/sdks). The deadline check directly below the delay already covers that case and returns TIMED_OUT, so the one-minute cap now applies only to reads without a caller deadline.

Reproduction

repro-retry-after.mjs starts a server that answers the first review read with 503 + Retry-After: 90 and the second with a completed review, then calls waitForReview with timeoutMs: 10 * 60_000. It compresses the retry sleep and records what the client asked to sleep for.

  • before this change: threw ProoflineError 503: Proofline request failed with status 503 after 1 reads, slept []
  • after: outcome COMPLETED after 2 reads, slept 90000

Tests

tests/http.test.mjs: "a review wait honors a Retry-After longer than one read does" covers a 90-second hint inside a ten-minute wait (slept out, wait completes), the same hint inside a one-minute wait (returns TIMED_OUT instead of throwing), and a plain getReview (still refuses a hint it cannot spend).

  • node --test tests/*.test.mjs -> 110 pass, 0 fail, three consecutive runs
  • pnpm typecheck, pnpm lint, node generate.mjs --check, node check-claims.mjs -> clean

Python SDK

retry_delay in sdk-python/proofline/_transport.py caps the header at 60 seconds the same way, so wait_for_review rejects with the 503 in the same situation. This PR does not touch it.

The published SDK docs say a review wait stops early only when a 429 or 503 retry delay would reach or pass the remaining budget. The transport applied the one-minute cap that single reads use instead, so a Retry-After of 61 to 90 seconds inside a ten-minute wait ended the wait with the server's 503 refusal after one read.

The cap now applies only to reads without a caller deadline. A wait passes its own deadline, so a Retry-After that fits inside it is waited out, and one that reaches the deadline still returns TIMED_OUT.
The new test pins the behavior from the previous commit: a 90-second Retry-After inside a ten-minute wait is slept out and the wait completes, the same hint inside a one-minute wait returns TIMED_OUT instead of throwing, and a single read still refuses a hint it cannot spend.
scripts/repro-retry-after.mjs starts a server that answers the first review read with 503 and Retry-After: 90, then a completed review. Run it after pnpm build: against the build before this branch it throws the 503 after one read, and against this branch it completes after two.

This branch has not been deployed

No deployments
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