Repository navigation
Return TIMED_OUT when a 429 or 503 body is cut off at the wait deadline - #106
Open
Aaron-hub-dev-maker wants to merge 5 commits into
Open
Aaron-hub-dev-maker wants to merge 5 commits into
Aaron-hub-dev-maker wants to merge 5 commits into
Conversation
waitForReview returns TIMED_OUT when a 429 or 503 arrives with a complete
body and its Retry-After cannot start before the deadline. When the same
refusal's body is still streaming as the deadline passes, the transport
reported it as HTTP 429/503 "the response is not valid UTF-8 JSON", and
waitForReview rethrew it, so a slow overloaded gateway turned a timed-out
wait into an error with a misleading diagnosis.
At the wait deadline a 429 or 503 body read now times out as a successful
body does. Other refusals, such as 403, keep their status. Plain reads
outside a wait are unchanged. This matches the Python SDK's check_stream
rule ("Retryable statuses time out as an expired read does").
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In the "elapsed" case the stalled body was cut off by the request's abort signal, so decoded() returned through signal.aborted and the performance.now() >= deadline branch was never exercised: removing it left every case passing. The elapsed case now moves the observed clock past the wait deadline and then ends the connection while the request's abort signal is still 20 seconds away, so it fails without the clock check, and the native-abort case fails without the signal check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The flag is true for every successful response, timed out or not; it decides whether an expired body read is reported as a timeout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The rule does not make a cut-off refusal behave exactly like a complete one: a complete 429/503 is still thrown when its Retry-After exceeds 60 s or the retries are spent. Say what it does instead, rename the test accordingly, and use one RETRYABLE_STATUSES list for both the retry loop and the deadline rule so they cannot drift apart. The native-abort case gets a 500 ms budget so the response headers arrive before its abort fires on a slow runner. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The test proved that a 429 or 503 body cut off at the wait deadline times the wait out, but not that the rule stops there: making every cut-off retryable refusal in a wait time out, even long before the deadline, still passed the whole suite. Add an "interrupted" case whose body ends while the deadline is far away. Every status must keep its invalid-response error, so a change that bypasses both deadline checks now fails it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
waitForReviewthrowsProoflineError(503, "urn:proofline:sdk:invalid-response")instead of returningTIMED_OUTwhen a 429 or 503 body is still streaming at the wait deadline. This PR ports the wait half of the Python SDK's rule for that case.Problem
An overloaded gateway may send
503(or429) headers, then stall before finishing the body. If the wait deadline passes whilewaitForReviewis reading that body, the transport throwsand
waitForReviewrethrows it, because its status is not 0. The wait fails instead of reportingTIMED_OUT. A CI job that gates on the outcome therefore sees an error rather than a timeout it can handle.The Python SDK already times this case out, both ways the deadline can strike. An expired read of a 429 or 503 body raises its timeout error, and prooflinedev/sdk-python#12 extended that to a chunk checked after the deadline: "Retryable statuses time out as an expired read does; other problems keep their status." The TypeScript transport does neither during a wait. Given the same stalled 503, Python returns
TIMED_OUTand TypeScript throws (output below).Change
In
decoded()(src/transport.ts), a429or503body read cut off by the wait deadline now raises theurn:proofline:sdk:timeouterror that a successful body already raises there.waitForReviewalready maps that error toTIMED_OUT. A newRETRYABLE_STATUSESconstant is shared with the retry loop, so the two lists cannot drift apart.When it applies: only to a read that starts while the wait deadline is within the request timeout (
waitTimeout). With the defaults, that is a read starting in the last 30 s of a wait, or any read iftimeoutMs≤requestTimeoutMs. A read that starts earlier hitsrequestTimeoutMsfirst and keeps its current error, as a successful body does.What does not change:
403, keep their status, asthe wait timeout includes an in-flight request and returns the retained review URLrequires.invalid-responsewith the refusal's status, whichrefusal retries preserve response bounds and the caller deadlineandinvalid UTF-8 never hides successful-body or incomplete-body failurespin. Python times these out too. I kept the tested TypeScript behaviour rather than change it here.waitForReviewis the only caller that passes a wait deadline to the transport, so mutations, exports and MCP calls are unaffected.Only
src/transport.ts(+9/−2) andtests/http.test.mjs(+63) change.Verification
Unit test.
a retryable refusal times the wait out only when cut off at the wait deadlinecovers 429, 503 and 403. Each status runs three ways:elapsed: the observed clock passes the deadline, then the connection ends while the abort signal is still 20 s away.native-abort: the observed clock is frozen and only the abort signal fires.interrupted: the connection ends while the deadline is still 20 s away. Every status must keep itsinvalid-responseerror.To check that each case tests its own branch, I disabled each check in turn (
false && …, so the build still type-checks), then bypassed both deadline checks for 429/503:main(no fix)The test passed 15 of 15 repeated runs on the final commit.
Project checks. CI ran the
Checksworkflow on the final commit in my fork, on ubuntu-24.04. Generate with no diff, lint, typecheck, claims check, build, every test, and pack all passed: https://github.com/Aaron-Stephen/sdk-typescript/actions/runs/46588004772. On Windows 11 with Node 22.16, everything passes excepta new public operation generates a callable typed client method. That test fails there withspawnSync pnpm ENOENT, onmaintoo (see #53).Through a fault proxy in front of the real API. A small loopback proxy forwards to
https://proofline.sh. The real service won't stall on demand, so when armed, the proxy answers the next review read itself with 503 or 429,Retry-After: 1and half a problem body, then stalls. The plain waits read a real completed review in my organization (60 s timeout). The stall runs use a 3 s timeout and never reach the server. Review URLs are trimmed from the output.Reproduce with the fault proxy (fault-proxy.mjs, wait.mjs)
fault-proxy.mjswait.mjsProofline review
I installed Proofline on my organization and reviewed this change there: Aaron-Stephen#1.
elapsedcase never reached the clock check. I confirmed it before changing anything: with that check removed, all six subtests still passed. I rewrote the case as recommended, and the table above shows each case now fails without its own check.Overlap
#83, #84, #92 and #100 add lines in the same
catchblock ofdecoded()without changing this condition, so a rebase would be mechanical. #88 handles a different deadline case: a successful body that finishes after the deadline.I worked with Claude Code (Claude Opus 5.5) on this change. The commits carry its co-author trailer, and the session prompts are in the hidden section below, as
AGENTS.mdasks.🤖 Generated with Claude Code