Skip to content

Commit 56a09ad

Browse files
Apply the planned 0.5.0 resilience defaults
1 parent bbb6c24 commit 56a09ad

40 files changed

Lines changed: 250 additions & 323 deletions

‎CHANGELOG.md‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,19 @@ Breaking changes are listed under **Breaking changes**, each with its migration.
4242
- HTTP policies cap cached host state with `max_hosts` (default 1000), accept
4343
limiter and bulkhead mappings, and share 429 pauses through Redis.
4444

45-
### Deprecated
45+
### Changed
4646

47-
- Implicit shared backend error handling warns that the default switches from `"raise"`
48-
to `"local"` in 0.5.0. Set `on_backend_error=` or `configure(backend_errors=...)`
49-
to pin the desired mode. The 0.4.x behavior stays the same.
47+
- Retry defaults use exponential backoff, equal jitter, and a 30-second scheduled delay cap.
48+
Pass `backoff=1, jitter=0, max_delay=None` to restore 0.4.x timing. Explicit delay schedules
49+
keep their values. HTTP and Celery backoff use equal jitter by default.
50+
- Shared Redis caches default to JSON. Existing pickle entries are read as misses.
51+
Choose an explicit codec if you need to cache exceptions or other Python objects.
52+
- Shared backends fall back to local state during an outage. Set
53+
`configure(backend_errors="raise")` for 0.4.x behavior. Strict leases and idempotency
54+
retain their existing error behavior.
55+
- Policy watches reject an invalid initial load by default. Pass `strict=False` to keep polling.
56+
- Celery idempotency defaults to the delivery ID. Pass `scope="arguments"` to retain the
57+
0.4.x cache key and behavior.
5058

5159
### Fixed
5260

‎docs/cookbook/framework-integrations.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ def sync_orders(self, account_id: int) -> None: ...
173173
instead of sleeping, so the task waits in the queue and never holds a worker slot.
174174
- `idempotent_task(scope=..., store=..., ttl=...)` runs the body once per key. `scope="delivery"`
175175
keys on the task's id, so redeliveries and retries of one task run once while two tasks with
176-
the same arguments each run. `scope="arguments"` keys on task name plus arguments (the 0.4.x
177-
default, with a `FutureWarning`; it becomes `"delivery"` in 0.5.0). `key=` overrides both.
176+
the same arguments each run. Delivery scope is the default. Pass `scope="arguments"` to
177+
keep the 0.4.x key based on task name and arguments. `key=` overrides both.
178178
A delivery that finds the task running is re-queued after about `requeue_delay` seconds (with
179179
jitter); those re-queues are counted in the message headers and do not use the task's own
180180
`max_retries` by default. An explicit `max_retries=` uses Celery's standard retry counting.
@@ -191,7 +191,7 @@ def sync_orders(self, account_id: int) -> None: ...
191191
cases that matter; a crash between an external effect and its recorded result is the one case
192192
that can still run an effect twice (see the transactional store for that).
193193

194-
| Situation | `scope="delivery"` | `scope="arguments"` (0.4.x default) |
194+
| Situation | `scope="delivery"` (default) | `scope="arguments"` |
195195
|---|---|---|
196196
| Broker delivers one task id twice (late ack, visibility timeout) | runs once | runs once |
197197
| Application retries a task after a failure (same id) | runs (a failed run stores no result) | runs (same) |

‎docs/features/caching/async-stores.md‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ threads.
148148

149149
## Serialization and trust
150150

151-
Entries are stored as `(value, expires_at)` pairs. The default serializer is pickle,
152-
and unpickling bytes an attacker can write to Redis can execute arbitrary code, so use
153-
pickle only with a Redis instance you fully trust. For anything else pass
154-
`json_codec()`; values must then be JSON-serializable and tuples come back as lists.
151+
Entries are stored as `(value, expires_at)` pairs. The default serializer is JSON.
152+
Values must be JSON-serializable, and tuples come back as lists. Use a codec that
153+
supports exceptions if you set `cache_exceptions=`.

‎docs/features/caching/stores-and-credentials.md‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,11 @@ from python_wrap import configure
5050
configure(cache_codec=("signed-pickle", "APP_CACHE_SECRET"))
5151
```
5252

53-
A store built with no codec and no `cache_codec` default still uses plain pickle, which
54-
is the implicit default. It emits a `FutureWarning` (visible under the default warning
55-
filters) that names the fix. **In 0.5.0 the implicit default becomes JSON**, so a
56-
store that relies on pickle must name a codec before then. `doctor` reports a `memoize`
57-
on a store with plain pickle as PW026. Until 0.5.0, entries written with plain pickle
58-
still load; after it, pickle entries fail to decode and are treated as misses. Use
59-
`version=` to retire old entries at once.
53+
Shared Redis caches default to JSON. After upgrading, old pickle entries fail JSON
54+
decoding and are treated as misses. Set `version=` to retire the old namespace at once.
55+
JSON values must be serializable, and tuples decode as lists. To use `cache_exceptions`,
56+
select a codec that can serialize exceptions, such as a signed pickle codec.
57+
Doctor reports use of plain pickle as PW026.
6058

6159
### Failure modes
6260

‎docs/features/concurrency/shared-limits.md‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ Default limiters, breakers and bulkheads are in-process. Optional Redis backends
44
coordination across workers; they take a client created by your application.
55

66
When a shared store is down, breakers, rate windows, quotas, bulkheads and retry budgets
7-
raise by default (`on_backend_error="raise"`). Caches allow, and token windows fall back to
8-
a local bucket; see [store-down rules](#when-the-shared-store-is-down). Release 0.5.0 changes
9-
the default for these backends to `"local"`; set `configure(backend_errors="raise")` to keep
10-
today's behaviour after upgrading.
7+
fall back to process-local state by default. Set `configure(backend_errors="raise")`
8+
to restore error propagation. See [store-down rules](#when-the-shared-store-is-down).
119

1210
## A run quota
1311

@@ -168,12 +166,12 @@ Every shared backend takes the same option, `on_backend_error`:
168166

169167
| Value | Effect |
170168
|---|---|
171-
| `"raise"` (0.4.x default) | The store error propagates. |
172-
| `"local"` | Use this process's own breaker, window, quota or bulkhead cap until the store answers. |
169+
| `"raise"` | The store error propagates. |
170+
| `"local"` (default) | Use this process's own breaker, window, quota or bulkhead cap until the store answers. |
173171
| `"allow"` | Admit the call and skip accounting. |
174172

175-
The shared backend default changes from `"raise"` to `"local"` in 0.5.0. Set the mode
176-
explicitly on the backend or in `configure(backend_errors=...)` to pin it across releases.
173+
Set the mode explicitly on the backend or in `configure(backend_errors=...)` to override
174+
the built-in default.
177175

178176
Caches take `on_backend_error` too: `"allow"` (a miss, writes dropped) is their default, and
179177
`"local"` behaves like `"allow"`. Token windows default to `"local"`. Leases

‎docs/features/configuration.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ call retains the settings it started with. A watched policy changes behaviour
5050
on every replica without a restart, for example to lower a rate limit or stop retries for one
5151
dependency during an incident. See [named policies](resilience/named-policies.md).
5252

53-
A policy watch accepts `strict=True` to raise on a failed initial read or invalid mapping. Use `jitter=0.1` to vary the poll interval by up to 10 percent in either direction.
53+
A policy watch raises on a failed first read or invalid mapping by default. Pass `strict=False`
54+
to keep polling after a failed initial load. Use `jitter=0.1` to vary the poll interval by up
55+
to 10 percent in either direction.
5456

5557
## Keys
5658

‎docs/features/resilience/presets-and-doctor.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ The doctor reports codes PW001 to PW025 (the table lists them by group, not stri
156156
| PW023 | warning | `python_wrap.celery.check_visibility`: a blocking limiter, unbounded bulkhead queue, retry `max_time`, or an `idempotent_task` lease (`lease_ttl`) can outlive the broker's visibility timeout, so the broker delivers the task again while it still runs (for a lease: a redelivery finds the lease held and is re-queued until it expires). |
157157
| PW024 | warning | A retry layer has no backoff or jitter (`backoff=1` or no `jitter`): callers that fail together retry together, and with `--multiprocess` every worker does. Use `backoff=2, jitter="full"`. |
158158
| PW025 | warning | A retry on every `Exception` with neither `retry_if=` nor `retry_if_result=`: programming errors and non-transient failures are retried. Narrow `on=` or add a predicate. Fires together with PW003, which also covers a broad `on=` with only `retry_if_result=`. |
159-
| PW026 | warning | `memoize` with a shared store that uses plain pickle (the implicit default, or `pickle.dumps`): anyone who can write the namespace can run code in every reader. Pass `dumps=`/`loads=` (for example `json_codec()`) or `configure(cache_codec="json")`. See [Shared caches](../caching/stores-and-credentials.md#codecs). |
159+
| PW026 | warning | `memoize` with a shared store that uses plain pickle: anyone who can write the namespace can run code in every reader. Use `json_codec()` or `configure(cache_codec="json")`. See [Shared caches](../caching/stores-and-credentials.md#codecs). |
160160
| PW018 | warning | A python-wrap LLM retry wraps an SDK client (`llm_retry(client=...)`) whose own retries are still on: attempts multiply (4 x 3 = 12). See [OpenAI and Anthropic SDK clients](../ai/openai-anthropic.md#doctor-checks). |
161161
| PW019 | warning | A retry wraps a streamed LLM call (`stream_timeout`) without `resume_safe`: a replay after output started repeats text and half-done tool calls. |
162162

‎docs/features/resilience/retry.md‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ For several workers, set a project default before decorating functions:
4646
chooses between half and all of it. A numeric jitter still adds up to that many
4747
seconds.
4848

49-
!!! warning "Bare `@retry` defaults change in 0.5.0"
50-
A bare `@retry` (or `retrying()`) with no `delay`, `backoff` or `jitter` waits 1 s, three times, with no jitter. This release emits one `FutureWarning` per process saying so. In 0.5.0 the fallback becomes `backoff=2`, `jitter="equal"` and `max_delay=30`. To keep today's behaviour, pass `delay=`, `backoff=` or `jitter=` explicitly, or set the values with `configure(retry={...})`. An explicit `delays=` schedule does not warn. The `doctor` reports PW024 (no backoff or jitter) and PW025 (retries every `Exception` with no `retry_if=` or `retry_if_result=`) for such retries.
49+
A bare `@retry` or `retrying()` uses exponential backoff and equal jitter. The first
50+
retry waits 0.5 to 1 second, and the second waits 1 to 2 seconds. Scheduled backoff is
51+
capped at 30 seconds. A server hint keeps its separate ceiling unless you set
52+
`max_delay=` explicitly. Explicit `delays=` schedules keep their exact values unless
53+
you configure a cap or jitter.
5154

5255
## When to use it
5356

@@ -68,9 +71,9 @@ The wait before attempt `n + 1` is `min(delay * backoff ** (n - 1), max_delay) +
6871
| `max_attempts` | `3` | Total calls allowed. `None` retries forever. |
6972
| `delay` | `1.0` | Base wait in seconds. |
7073
| `delays` | `None` | Explicit nonempty delay sequence; repeat the last entry. Overrides `delay`/`backoff`, with the same cap and jitter. |
71-
| `backoff` | `1.0` | Multiplier applied after each failure (use `2` for exponential). |
72-
| `max_delay` | `None` | Cap on the backoff wait (before jitter). |
73-
| `jitter` | `0.0` | Up to this many random extra seconds, so many clients do not retry in lockstep. |
74+
| `backoff` | `2.0` | Multiplier applied after each failure (use `2` for exponential). |
75+
| `max_delay` | `30.0` | Cap on the backoff wait (before jitter). |
76+
| `jitter` | `"equal"` | Choose between half and all of the capped wait. A numeric value adds up to that many seconds. |
7477
| `max_time` | `None` | Total time budget in seconds from the first attempt. |
7578
| `on` | `Exception` | Exception type(s) that trigger a retry. Anything else propagates immediately. |
7679
| `retry_if` | `None` | Extra predicate on the exception; retry only if it returns `True`. May be `async def` for async functions. |
@@ -518,18 +521,16 @@ Sentry breadcrumbs so an error report shows what happened before the failure.
518521

519522
Set `max_attempts`, `delay`, `backoff`, `max_delay`, `jitter`, `max_time`, `log_level` and `budget` once for the whole project with `python_wrap.config.configure(retry={...})`. See [Configuration](../configuration.md).
520523

521-
To try the 0.5.0 timing defaults in a scoped block:
524+
To restore the 0.4.x timing defaults in a scoped block:
522525

523526
```python
524527
from python_wrap.config import configured
525528

526-
with configured(retry={"backoff": 2, "jitter": "equal", "max_delay": 30}):
529+
with configured(retry={"backoff": 1, "jitter": 0, "max_delay": None}):
527530
# Decorate functions here to use these defaults.
528531
...
529532
```
530533

531-
Setting any of `delay`, `backoff` or `jitter` here also silences the default-change warning.
532-
533534
## Logging
534535

535536
Each retry logs one message at `log_level` (default `WARNING`) on `logger`. Use `log_level=logging.INFO` to quiet it, `log_level=None` to turn it off, and `log_exc_info=True` to attach the traceback.

0 commit comments

Comments
 (0)