Introduce Runtime base class for execution-controlling dependencies#298
Introduce Runtime base class for execution-controlling dependencies#298chrisguidry merged 8 commits intomainfrom
Conversation
Adds a `Runtime` base class for dependencies that control how tasks execute. `Timeout` now inherits from `Runtime` and implements the `run()` method, moving the timeout enforcement logic (~50 lines) out of Worker. The Worker now checks for any `Runtime` dependency and delegates execution to it, falling back to direct function invocation when none is present. This establishes a pattern where execution-controlling behavior lives in the dependency itself rather than requiring the Worker to know about specific dependency types. Co-Authored-By: Claude Opus 4.5 <[email protected]>
|
📚 Documentation has been built for this PR! You can download the documentation directly here: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #298 +/- ##
=======================================
Coverage 99.63% 99.63%
=======================================
Files 96 96
Lines 9591 9608 +17
Branches 459 463 +4
=======================================
+ Hits 9556 9573 +17
Misses 20 20
Partials 15 15
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2bb95a85c4
ℹ️ 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".
The `validate_dependencies` function was only counting by concrete type, so two different Runtime subclasses (e.g., Timeout + CustomRuntime) would slip through validation even though Runtime has `single=True`. Now we also check that for any base class with `single=True`, there's at most one instance across all dependencies. Thanks Codex for catching this. Co-Authored-By: Claude Opus 4.5 <[email protected]>
The CustomRuntime.__aenter__ in the validation test is never called since validation fails before the dependency context is entered.
Uses cancel_task() for proper cancellation handling across Python 3.10/3.11+, adds a descriptive timeout message, and fixes a bug where external cancellation would be incorrectly converted to TimeoutError instead of propagating. Co-Authored-By: Claude Opus 4.5 <[email protected]>
The else branch (timed_out=False) handles external cancellation propagation - correct behavior but a race condition that's hard to test reliably. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Co-Authored-By: Claude Opus 4.5 <[email protected]>
The tight 150ms bound was flaky on slow CI. The test now just verifies the task completed successfully, which is what we're actually demonstrating. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Instead of asserting wall clock time (flaky on slow CI), check that timeout.remaining() > 0 at the end of the task. This directly tests that the timeout wasn't exhausted. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Summary
Adds a
Runtimebase class for dependencies that control how tasks execute.Timeoutnow inherits fromRuntimeand implements therun()method,moving the timeout enforcement logic (~50 lines) out of Worker.
The Worker now checks for any
Runtimedependency and delegates executionto it, falling back to direct function invocation when none is present. This
establishes a pattern where execution-controlling behavior lives in the
dependency itself rather than requiring the Worker to know about specific
dependency types.
This is groundwork for a broader dependency hooks architecture - outcome hooks
(Retry/Perpetual) can follow a similar pattern in the future.
🤖 Generated with Claude Code