Repository navigation
Time out retryable problems whose body outlives the deadline - #12
Conversation
When the request or wait deadline passed after a 429 or 503 body chunk arrived, check_stream raised unreadable_problem(status) instead of the timeout that an expired read of the same body already produced. A wait_for_review racing its deadline against a 503 therefore raised HTTP 503 rather than returning TIMED_OUT, which failed test_retry_after_is_bounded_by_wait_deadline[async] intermittently in CI. Treat a deadline seen in check_stream for 429 and 503 the same way as an expired read. Other problems, including 403, keep their status. The new test advances a fake clock while a received chunk is checked, so it reproduces the race on every run in both sync and async modes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G8YzhJ7iLeZF8kY4HTma3u
|
Coordinator review accepts actual head Checks40147085252 succeeded on this exact head. I inspected its log: operation contracts, formatting/lint, mypy211files,81tests, package builds and both installed-package sync/async smoke checks pass. No schema, version or runtime scope beyond the observed deadline handling changed. The coordinator review hold is satisfied. The author may mark ready and merge under repository checks, then follow actual main Checks and CodeQL and report the merge SHA. No package publication or release is authorized. |
|
Main receipt (proofline issue 3331)
Nothing on main is failing that this change caused, so no repair is needed. No packages, tags or releases were published, and no other PRs were changed. Generated by Claude Code |
Summary
Fixes the intermittent
tests/test_http.py::test_retry_after_is_bounded_by_wait_deadline[async]failure in proofline main run 40142500877 (41067a1d, saas-web: 74 passed, 1 failed). Owned under proofline issue 3331 (comment 6391410830). This is separate from the contract sync in #11.Root cause (a runtime bug, not a wrong test assumption). A 429 or 503 response can hit the request or wait deadline while its body is being read, and the transport handled that in two different ways depending on where it noticed:
anyio.fail_afteror the socket deadline), it raiseshttpx.ReadTimeout. Theexcept httpx.HTTPErrorbranch re-raises it for 429/503, and_network()turns it intotimeout_error()(status 0).wait_for_reviewthen returnsTIMED_OUT.check_streamfinds the deadline passed, the code went to_transport.py:216and raisedunreadable_problem(503). That is aProoflineError, not anhttpx.HTTPError, so it skipped the 429/503 branch, andwait_for_reviewre-raised it as HTTP 503.The test's expectation is correct. When the body is read in time, the same 503 also ends as
TIMED_OUT: theRetry-Aftersleep is capped at the remaining budget, and the next attempt'slimit_timeoutraises a timeout. SoTIMED_OUTis the only consistent outcome. The CI failure came from a slow runner landing in the window between receiving a chunk and checking it.Fix (one condition). In
check_stream, an expired deadline is treated as a timeout for 429 and 503, as it already was for 2xx. That matches the expired-read path above. Every other status still raisesunreadable_problem(status), so 403/authorization and other non-retryable problems keep their status. Nothing is caught or swallowed, and no timeouts were increased. Retry counts,Retry-Afterlimits, the 8 MiB stream limit, the timeout budget and token redaction are unchanged.Regression test.
test_deadline_expiring_with_a_received_problem_chunk_keeps_retry_policycovers 429, 503 and 403 against the real loopback server in both sync and async modes. It wraps the realcheck_streamso that a frozenClockmoves 10 s forward while a received chunk is being checked, which reproduces the race on every run without real-time sleeps. It asserts:TIMED_OUTwith the review URL, after one request and no retry sleep.ProoflineErrorwith status 403.Verification
821c68dwith the new test before the fix: 4 failed ([429|503]-[sync|async]), each with the CI traceback (check_stream→_transport.py:216→ProoflineError: ... (HTTP 503)). 403 passed.pytest tests/gave 81 passed.python3 scripts/check.py --artifacts <fresh dir>exited 0 (Python 3.13). It ran:generate.py --check: no driftcontracts.py: passedruff checkandruff format --check: cleanmypy: no issues in 211 filespytest: 81 passedbuild: one wheel and one sdistHead:
c7c4b60bf9ef67965bb50ff5674661517a635043. CI results will be added once they finish.Do not merge until the coordinator has reviewed the current head. Any pin follow-up happens only after the reviewed merge.
Generated by Claude Code