You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 1484b0a
Browse filesBrowse the repository at this point in the historyBrowse files
Two reality reconciliations found while drafting the plan:
1. The spec referenced httpware.ConnectError (doesn't exist).
Replace with NetworkError(TransportError) — a new subclass for
transient network failures only, so Retry doesn't noisily retry
InvalidURL / CookieConflict. Terminal mapping refines to route
transient httpx2 errors through NetworkError; bare TransportError
stays for non-transient cases.
2. The AsyncClient terminal already raises StatusError subclasses on
4xx/5xx, so Retry sees an exception (not a Response with non-2xx
status). Clarify the failure-type gate accordingly and explain
that on exhaustion the original StatusError subclass is re-raised
unwrapped.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: planning/specs/2026-06-05-retry-and-retry-budget-design.md
+24-5Lines changed: 24 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,11 +16,25 @@ Items deliberately deferred so this slice ships clean:
16
16
17
17
-**No per-call retry override.** No `extensions["httpware_retry"]` key in v1. Callers with heterogeneous retry needs construct a second `AsyncClient` with different middleware. Purely additive to add later.
18
18
-**No `Backoff` protocol.** Backoff is hardcoded to exponential with full jitter (AWS-recommended). Add a protocol later if a real use case emerges (YAGNI).
19
-
-**No `retry_on_exception=` configuration.** The retryable-exception set is hardcoded to `(httpware.ConnectError, httpware.TimeoutError, asyncio.TimeoutError)`. Users wanting `ChunkedEncodingError`-style additions wait for v0.5.
19
+
-**No `retry_on_exception=` configuration.** The retryable-exception set is hardcoded to `(httpware.NetworkError, httpware.TimeoutError, asyncio.TimeoutError)`. Users wanting `ChunkedEncodingError`-style additions wait for v0.5.
20
20
-**No `Bulkhead`.** Slice C, separate spec.
21
21
-**No standalone per-attempt-timeout middleware.** Folded into `Retry.attempt_timeout=` (3-1 dissolved during brainstorming — `asyncio.timeout()` and httpx2's built-in per-op timeouts cover the standalone use case).
22
22
-**No status-code re-classification.**`RetryBudgetExhaustedError` and `httpware.TimeoutError` map cleanly to existing exception types — no new `_internal/` plumbing.
23
23
24
+
## Prerequisite refinement: `NetworkError`
25
+
26
+
The current `AsyncClient._terminal` maps every non-timeout `httpx2.HTTPError` (including non-transient `InvalidURL` and `CookieConflict`) to `httpware.TransportError`. Retrying on `TransportError` would noisily retry typos and bad cookies. This slice adds:
And refines the terminal mapping so that `httpx2`'s transient-network exception family (`httpx2.NetworkError` per httpx convention, or whichever symbols httpx2 exposes for the same hierarchy) raises `httpware.NetworkError` rather than the broader `TransportError`. `InvalidURL` and `CookieConflict` continue to raise `TransportError` directly so they are NOT retried. Existing tests catching `TransportError` keep working (`NetworkError` is a subclass).
35
+
36
+
This is the single load-bearing assumption Retry depends on — without it, Retry can't distinguish transient from permanent transport-layer failures.
37
+
24
38
## Architecture & module layout
25
39
26
40
```text
@@ -131,8 +145,8 @@ For each completed attempt (exception OR response), `Retry` evaluates:
131
145
132
146
1.**Idempotency gate.** If `request.method.upper() not in retry_methods`, return the result as-is. POST/PATCH never retry by default.
133
147
2.**Failure-type gate.** Retry IF:
134
-
- the attempt raised `httpware.ConnectError`, `httpware.TimeoutError`, or `asyncio.TimeoutError`; OR
135
-
- the attempt returned a response with `status_codein retry_status_codes`.
148
+
- the attempt raised `httpware.NetworkError`, `httpware.TimeoutError`, or `asyncio.TimeoutError`; OR
149
+
- the attempt raised an `httpware.StatusError` subclass whose `.response.status_code` is in `retry_status_codes` (since the `AsyncClient` terminal raises `StatusError` on 4xx/5xx, retryable status codes surface as exceptions, not response objects — see "Implementation note" below).
136
150
3.**Attempt-count gate.** If `attempt_index + 1 >= max_attempts`, stop.
137
151
4.**Budget gate.** Call `budget.try_withdraw()`. If `False`, raise `RetryBudgetExhaustedError` (see "Errors raised" below).
138
152
5.**Sleep, then retry.** Compute delay via backoff (Retry-After overrides if applicable), `await self._sleep(delay)`, increment attempt index.
@@ -180,7 +194,11 @@ Rationale: putting `Retry` at the outermost position means each attempt re-runs
180
194
-**`max_attempts` exhausted**: the *last* error (exception or `StatusError`) is **re-raised unwrapped**. `exc.__notes__` is appended with `"httpware: gave up after N attempts"` (PEP 678) so the gave-up-after context is preserved without changing the exception type. This keeps consumer `except SomeStatusError:` blocks working unchanged.
181
195
-**`attempt_timeout` firing**: caught as `asyncio.TimeoutError` inside the retry loop, re-raised as `httpware.TimeoutError` (whether retried or surfaced as the final error). This matches the existing httpx2-error-mapping pattern in the `AsyncClient` terminal.
182
196
183
-
`RetryBudgetExhaustedError` lives in `src/httpware/errors.py` alongside the existing exception tree, exported from `httpware/__init__.py`.
197
+
`RetryBudgetExhaustedError` and `NetworkError` both live in `src/httpware/errors.py` alongside the existing exception tree, exported from `httpware/__init__.py`.
198
+
199
+
### Implementation note: `StatusError` surfaces as exception, not response
200
+
201
+
The `AsyncClient` terminal (`client.py:106-126`) raises a `StatusError` subclass on 4xx/5xx — the middleware chain receives an exception, not a `Response` object with a non-2xx status. Retry's status-code check therefore lives in an `except StatusError as exc:` branch, inspecting `exc.response.status_code`. On exhaustion, the original `StatusError` subclass is re-raised unwrapped (preserving consumer `except NotFoundError:` patterns).
184
202
185
203
## Testing
186
204
@@ -197,8 +215,9 @@ Per `planning/engineering.md §6` (test patterns):
197
215
-`Retry-After` capped at `max_delay`
198
216
- skips non-idempotent methods by default (POST returns 503 → not retried)
199
217
- honors `attempt_timeout` (slow mock transport → `httpware.TimeoutError`)
200
-
- retries on `httpware.ConnectError` / `httpware.TimeoutError`
218
+
- retries on `httpware.NetworkError` / `httpware.TimeoutError`
201
219
- does NOT retry on `httpware.NotFoundError` (404)
220
+
- does NOT retry on bare `httpware.TransportError` (e.g., `InvalidURL`) — only on the `NetworkError` subclass
202
221
-`RetryBudgetExhaustedError` raised when budget refuses
0 commit comments