Skip to content

Time out retryable problems whose body outlives the deadline - #12

Merged
mohsen1 merged 1 commit into
mainfrom
claude/public-contract-sync-k3vcta
Oct 25, 2026
Merged

mohsen1 merged 1 commit into
mainfrom
claude/public-contract-sync-k3vcta

Conversation

@mohsen1

@mohsen1 mohsen1 commented Oct 25, 2026

Copy link
Copy Markdown
Member

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:

  • When the expiry is caught while waiting for a chunk (anyio.fail_after or the socket deadline), it raises httpx.ReadTimeout. The except httpx.HTTPError branch re-raises it for 429/503, and _network() turns it into timeout_error() (status 0). wait_for_review then returns TIMED_OUT.
  • When a chunk has already arrived but check_stream finds the deadline passed, the code went to _transport.py:216 and raised unreadable_problem(503). That is a ProoflineError, not an httpx.HTTPError, so it skipped the 429/503 branch, and wait_for_review re-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: the Retry-After sleep is capped at the remaining budget, and the next attempt's limit_timeout raises a timeout. So TIMED_OUT is 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 raises unreadable_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-After limits, 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_policy covers 429, 503 and 403 against the real loopback server in both sync and async modes. It wraps the real check_stream so that a frozen Clock moves 10 s forward while a received chunk is being checked, which reproduces the race on every run without real-time sleeps. It asserts:

  • 429 and 503 return TIMED_OUT with the review URL, after one request and no retry sleep.
  • 403 still raises ProoflineError with status 403.

Verification

  • Reproduced on 821c68d with 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.
  • The natural race did not trigger in 30 runs of the original test under CPU load on a 4-core container, so the deterministic test is the reproduction.
  • After the fix: pytest tests/ gave 81 passed.
  • python3 scripts/check.py --artifacts <fresh dir> exited 0 (Python 3.13). It ran:
    • generate.py --check: no drift
    • contracts.py: passed
    • ruff check and ruff format --check: clean
    • mypy: no issues in 211 files
    • pytest: 81 passed
    • build: one wheel and one sdist
    • the sync/async HTTP smoke test against both the installed wheel and the installed sdist: passed
  • No schema, generated model, generator, version, README or workflow changes. Held PR Add named-file review and stop operations #3 is untouched.

Head: 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

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
@mohsen1

mohsen1 commented Oct 25, 2026

Copy link
Copy Markdown
Member Author

Coordinator review accepts actual head c7c4b60bf9ef67965bb50ff5674661517a635043. I fetched the commit and read the complete two-file patch, the original transport paths, Clock and the adjacent deadline/authority tests. The condition makes the received-chunk expiry for429/503 agree with the existing ReadTimeout path. Other HTTP statuses keep their error; the size check still runs first. The six regression cases exercise the real sync/async HTTP paths with deterministic clock advancement, including preserved403 and no extra request or retry sleep.

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.

@mohsen1
mohsen1 marked this pull request as ready for review October 25, 2026 00:37
@mohsen1
mohsen1 merged commit e20077b into main Oct 25, 2026
4 checks passed

mohsen1 commented Oct 25, 2026

Copy link
Copy Markdown
Member Author

Main receipt (proofline issue 3331)

  • Merge commit: e20077b992208f6aca9a75d87edf88d792ff47a1, merging the coordinator-reviewed head c7c4b60bf9ef67965bb50ff5674661517a635043.
  • Verified locally:
    • git merge-base --is-ancestor c7c4b60 e20077b holds.
    • git diff c7c4b60 e20077b is empty, so the merge tree is identical to the reviewed head.
    • openapi.public.json at e20077b is still blob 17205ad172142b574f598a4540d16e93d8041782, SHA-256 65785abda787dac8c2426cfca27ba050dbe3c22fbce7cfa20a2b0fe7cd3c6cf9.
  • Main CI on e20077b:
  • Failing-before evidence (kept): on 821c68d, before the fix, the new deterministic test failed 4 of 4 cases ([429|503]-[sync|async]). Each failure had the CI traceback: check_stream → _transport.py:216 → ProoflineError (HTTP 503). The 403 case passed. After the fix: 81 passed, and the full scripts/check.py passed.

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. e20077b is the Python SDK commit for the pin follow-up.


Generated by Claude Code

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.

2 participants