Skip to content

Keep the 24h barrier TTL when the middleware re-opens a barrier - #17

Merged
pencil merged 2 commits into
mainfrom
claude/dramatiq-workflow-barrier-ttl-h165y9
Nov 16, 2026
Merged

pencil merged 2 commits into
mainfrom
claude/dramatiq-workflow-barrier-ttl-h165y9

Conversation

@pencil

@pencil pencil commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Workflow creates each completion barrier with CALLBACK_BARRIER_TTL (24h), but WorkflowMiddleware._process_completion_callbacks re-opened it without a ttl. Every Barrier.wait() calls backend.decr(key, 1, 1, self.ttl), which rewrites the key (SET ... PX=ttl on Redis) with AtMostOnceBarrier's 15-minute default.

So in Chain(Group(a, b, c), d), if consecutive tasks in the group finish more than 15 minutes apart, the barrier key expires. The next decrement reads it as 0, decr returns False, the barrier counts as released, and d is enqueued while the rest of the group is still running. The _ran key still keeps it to one release, so d runs once, just too early.

Fix

Pass ttl=CALLBACK_BARRIER_TTL when the middleware builds the barrier, matching how Workflow creates it.

Tests

  • New test_barrier_outlives_default_ttl_between_completions advances StubBackend's monotonic clock an hour between completions of a three-task barrier. It fails on main (enqueued after the second completion) and passes with the fix.
  • Full suite: 40 passed on dramatiq 1.17.1 and 2.0.0; mypy and pyright clean; pre-commit hooks pass.

Release

Bumps setup.py to 0.4.1. Merge this before creating the v0.4.1 GitHub release: the release workflow builds from setup.py, so creating the release first would try to upload 0.4.0 to PyPI again.

Reported by Jeetu SK (@JeetuSK0808), with a detailed analysis of the cause.

https://claude.ai/code/session_01CgvUKo69g5ofiU4RbGfWF8


Generated by Claude Code

claude and others added 2 commits November 16, 2026 22:08
Workflow creates each completion barrier with CALLBACK_BARRIER_TTL (24h),
but WorkflowMiddleware re-opened it without a ttl, so every Barrier.wait()
rewrote the key with AtMostOnceBarrier's 15-minute default. If two tasks in
a Group finished more than 15 minutes apart, the key expired, the next
decrement read it as 0, and the barrier released early: the step after the
Group ran while some of its tasks were still running.

Pass ttl=CALLBACK_BARRIER_TTL in the middleware too, and add a regression
test that advances the rate limiter's clock an hour between completions.

Reported by an external contributor by email.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CgvUKo69g5ofiU4RbGfWF8
Co-authored-by: nils <nils@outset.ai>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CgvUKo69g5ofiU4RbGfWF8
Co-authored-by: nils <nils@outset.ai>
@pencil
pencil merged commit f4f22b0 into main Nov 16, 2026
14 checks passed
@pencil
pencil deleted the claude/dramatiq-workflow-barrier-ttl-h165y9 branch November 16, 2026 22:18
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.

3 participants