Skip to content

Introduce Runtime base class for execution-controlling dependencies#298

Merged
chrisguidry merged 8 commits intomainfrom
runtime-dependency
Jan 25, 2026
Merged

Introduce Runtime base class for execution-controlling dependencies#298
chrisguidry merged 8 commits intomainfrom
runtime-dependency

Conversation

@chrisguidry
Copy link
Owner

Summary

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.

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

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]>
@github-actions
Copy link

github-actions bot commented Jan 25, 2026

📚 Documentation has been built for this PR!

You can download the documentation directly here:
https://github.com/chrisguidry/docket/actions/runs/21334434294/artifacts/5249099262

@codecov-commenter
Copy link

codecov-commenter commented Jan 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.63%. Comparing base (9c5cab5) to head (af9f72e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           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           
Flag Coverage Δ
python-3.10 99.63% <100.00%> (+<0.01%) ⬆️
python-3.11 98.32% <100.00%> (+<0.01%) ⬆️
python-3.12 99.63% <100.00%> (+<0.01%) ⬆️
python-3.13 99.63% <100.00%> (+<0.01%) ⬆️
python-3.14 99.63% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/docket/_cancellation.py 100.00% <ø> (ø)
src/docket/dependencies/__init__.py 100.00% <100.00%> (ø)
src/docket/dependencies/_base.py 100.00% <100.00%> (ø)
src/docket/dependencies/_resolution.py 100.00% <100.00%> (ø)
src/docket/dependencies/_timeout.py 100.00% <100.00%> (ø)
src/docket/worker.py 100.00% <100.00%> (ø)
tests/fundamentals/test_timeouts.py 100.00% <100.00%> (ø)
tests/test_dependencies_core.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

chrisguidry and others added 7 commits January 25, 2026 08:31
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]>
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]>
@chrisguidry chrisguidry merged commit c8b09e7 into main Jan 25, 2026
40 checks passed
@chrisguidry chrisguidry deleted the runtime-dependency branch January 25, 2026 14:53
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