Repository navigation
Keep subclasses of Retry and the other behavioral dependencies - #619
Conversation
Retry.__aenter__ and ExponentialRetry.__aenter__ each constructed their own class by name, so a task that declared a subclass received a plain Retry or ExponentialRetry, and the subclass's handle_failure override and constructor state were dropped. Both now copy the declared instance, which keeps the subclass and its state without calling a constructor whose arguments may differ from the base class's. The docs now say that with Perpetual or Cron a retry applies within one run and each run starts again at attempt 1, and they show how to subclass Retry for a custom policy. docket-rs has no subclassing and already behaves the same way with Perpetual; it gains a test of that and the same sentence in Retry's documentation. Closes #441 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01P7t1QdnTYnAA3UXK25adCM
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Documentation build overview
3 files changed± api-reference/index.html± dependency-injection/index.html± task-behaviors/index.html |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9695c2ba45
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
A review of the previous commit found that Retry.forever() and ExponentialRetry.forever() were still typed as the base class, so a subclass's forever() did not type-check as that subclass. Both now return Self. The docs said a task stops its cycle by calling perpetual.cancel(), but each attempt has its own Perpetual, so a cancel on an attempt that is retried is discarded; they now show the cancel on the last attempt. They also said a failing hourly task makes its attempts "each hour", when the next run is scheduled from the last attempt's start, and they now say the per-attempt copy is shallow and what that means for subclass state. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01P7t1QdnTYnAA3UXK25adCM
Perpetual, Cron, Timeout, and ConcurrencyLimit constructed their own class by name on entry, and ConcurrencyLimit, Cooldown, RateLimit, and Debounce did the same when bound to a parameter through Annotated, so a subclass's overrides and constructor state were dropped the same way Retry's were. Each now makes a shallow copy of the declared instance. Cron builds a new iterator for each copy, because the declared instance's iterator counts from when the task was declared. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01P7t1QdnTYnAA3UXK25adCM
The fundamentals suite shows each feature's happy path, and its AGENTS.md sends edge cases to the other test files. The tests of retry subclasses now sit with the other dependencies' subclass tests, and the tests of each attempt's copy have their own module. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01P7t1QdnTYnAA3UXK25adCM
docket-rs 0.6.0 adds `cancel_many` (#621) and re-authenticates subscribed connections when credentials rotate (#624), and it carries the retry fix from #619. The new API makes it a minor version. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01P7t1QcafMiwAyqmd1EdpQg Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Since #619, `Perpetual.__aenter__` returns `copy.copy()` of the declared instance, and the copy keeps `cancelled` and `_next_when`. A task function called directly, outside a worker, receives the declared default itself. A `cancel()`, `after()`, or `at()` from that call then carried into every later worker run of the task in the same process. After a direct call that cancelled, each worker run stopped the perpetual instead of rescheduling it. `__aenter__` now resets `cancelled` to `False` and `_next_when` to `None` on the copy. Cron's `__aenter__` already does the same for its `_iterator`. This matches 0.29, where each run built a new `Perpetual(every=..., automatic=...)`. A changed `every` still carries over, as it did in 0.29, because 0.29 also read `self.every`. The other dependencies that #619 moved to `copy.copy()` don't have this problem: - `Retry` and `ExponentialRetry` set `attempt` and `delay` from the execution on each copy. `Retry.after()` writes `delay`, but 0.29 also copied `self.delay`. - `Timeout.run()` calls `start()` on the copy, which sets `_deadline`. - `ConcurrencyLimit` sets every per-run field on its copy. The new test calls a perpetual task directly with `after(1h)` and `cancel()`, then runs it on a worker and checks that it runs three times. Without the fix, it runs once. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Chris Guidry <chris@theguidrys.us>
RetryandExponentialRetryeach constructed their own class by name in__aenter__, so a task that declared a subclass received a plainRetryorExponentialRetry, and the subclass'shandle_failureoverride and constructor state were dropped.Perpetual,Cron,Timeout, andConcurrencyLimitdid the same on entry, andConcurrencyLimit,Cooldown,RateLimit, andDebouncedid it when bound to a parameter throughAnnotated. Each now makes a shallow copy of the declared instance, which keeps the subclass and its state without calling a constructor whose arguments may differ from the base class's.Cronbuilds a new iterator for each copy. These methods andforever()now returnSelf.The docs now say that with
PerpetualorCrona retry applies within one run and each run starts again at attempt 1, that exhausted retries do not stop the cycle, and how a task stops it by callingperpetual.cancel()on its last attempt. They also show how to subclassRetryfor a custom policy. docket-rs has no subclassing and already behaves the same way withPerpetual; it gains a test of that and the same sentence in the documentation ofRetryandExponentialRetry.Three things change for existing subclasses. A subclass that did not override
__aenter__was replaced by its base class and now reaches the task and the worker as itself, so its overrides ofhandle_failure,on_complete, orrunstart to run. A subclass that overrides__aenter__and annotates its return as the base class no longer matches the base signature under mypy; annotate it as the subclass orSelf. A subclass ofExponentialRetrythat definesdelayas a read-only property now fails on its second attempt, because the per-attempt delay is assigned on the subclass's copy.Neither FastMCP nor Prefect subclasses these classes, and their test suites that use docket pass against this branch: 525 tests in FastMCP and 377 in Prefect.
Closes #441
🤖 Generated with Claude Code
https://claude.ai/code/session_01P7t1QdnTYnAA3UXK25adCM