Skip to content

Clear known from runs hash on cancel so add() can reschedule#336

Merged
chrisguidry merged 1 commit intomainfrom
fix-perpetual-cancel-reschedule
Feb 14, 2026
Merged

Clear known from runs hash on cancel so add() can reschedule#336
chrisguidry merged 1 commit intomainfrom
fix-perpetual-cancel-reschedule

Conversation

@chrisguidry
Copy link
Owner

When a scheduled task gets cancelled via docket.cancel(), the cancel Lua
script removes it from the stream/queue but leaves the known field in the
runs hash. Later, when _schedule_all_automatic_perpetual_tasks (or any
docket.add()) tries to reschedule the same key, the schedule script sees
known and returns EXISTS. The task stays silently unscheduled until
execution_ttl expires (default 15 min).

The fix adds an HDEL runs_key 'known' 'stream_id' to the cancel script,
clearing the dedup markers while keeping state=cancelled and completed_at
for observability. The schedule script's existing fallback (state == 'running'
→ EXISTS) already handles cancelled tasks correctly once known is gone.

🤖 Generated with Claude Code

When a scheduled task gets cancelled via `docket.cancel()`, the cancel Lua
script removes it from the stream/queue but leaves the `known` field in the
runs hash. Later, when `_schedule_all_automatic_perpetual_tasks` (or any
`docket.add()`) tries to reschedule the same key, the schedule script sees
`known` and returns EXISTS. The task stays silently unscheduled until
`execution_ttl` expires (default 15 min).

The fix adds an `HDEL runs_key 'known' 'stream_id'` to the cancel script,
clearing the dedup markers while keeping `state=cancelled` and `completed_at`
for observability. The schedule script's existing fallback (`state == 'running'`
→ EXISTS) already handles cancelled tasks correctly once `known` is gone.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@github-actions
Copy link

📚 Documentation has been built for this PR!

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

@codecov-commenter
Copy link

codecov-commenter commented Feb 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.68%. Comparing base (0812c86) to head (a2a4c50).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #336   +/-   ##
=======================================
  Coverage   98.67%   98.68%           
=======================================
  Files         103      103           
  Lines       10375    10386   +11     
  Branches      496      496           
=======================================
+ Hits        10238    10249   +11     
  Misses        121      121           
  Partials       16       16           
Flag Coverage Δ
python-3.10 98.68% <100.00%> (+<0.01%) ⬆️
python-3.11 97.35% <100.00%> (+<0.01%) ⬆️
python-3.12 98.68% <100.00%> (+<0.01%) ⬆️
python-3.13 98.68% <100.00%> (+<0.01%) ⬆️
python-3.14 98.67% <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/docket.py 100.00% <ø> (ø)
tests/fundamentals/test_perpetual.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@chrisguidry chrisguidry merged commit 61bc093 into main Feb 14, 2026
40 checks passed
@chrisguidry chrisguidry deleted the fix-perpetual-cancel-reschedule branch February 14, 2026 16:35
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