Repository navigation
Description
A task that waits in the worker for its rate limit is in none of inspect active, reserved and scheduled, and a new limit from control.rate_limit() doesn't reach it. Both date from 3.1.0 and are the same on 5.4.0 and 5.5.3. I'd list the waiting tasks under inspect reserved and move them to the new limit when it changes. #11075 changes the same functions, so I'd send the PR after it is merged.
| Main (9c2f238), prefork, 4 tasks sent at once | Waiting in the worker | Listed by inspect |
|---|---|---|
rate_limit="6/m": one ran, three wait for the limit |
3 | 0 |
| No rate limit, 8 s each, one process: one runs, three wait for it | 3 | 4 |
The limit raised from 6/m to 600/m after 9 s |
Ran at |
|---|---|
| Tasks sent before the change | 0 s, 10 s, 20 s and 30 s |
| A task sent after the change | 9 s |
Each row is 3 of 3 runs.
Cause
A rate limited request goes into its task's token bucket (Consumer._limit_task(), celery/worker/consumer/consumer.py:374). task_reserved() is only called when the request leaves the bucket (_limit_move_to_pool(), consumer.py:346), so nothing inspect reads knows the request before that (afb75ef, 2013). control.rate_limit() calls reset_rate_limits() (consumer.py:317), which makes a new bucket for every task (f104349, 2013). The old bucket keeps its requests and its timer, at the old rate.
The same cause has two more effects, 3 of 3 runs each. inspect query_task doesn't find a waiting task, and a waiting task that is revoked still uses its turn. With 6/m, the two tasks behind a revoked one ran at 20 s and 30 s where 10 s and 20 s were due.
Checklist
Checklist
- I have verified that the issue exists against the
mainbranch of Celery. - This has already been asked to the discussions forum first.
- I have read the relevant section in the
contribution guide
on reporting bugs. - I have checked the issues list
for similar or identical bug reports. - I have checked the pull requests list
for existing proposed fixes. - I have checked the commit log
to find out if the bug was already fixed in the main branch. - I have included all related issues and possible duplicate issues in this issue (If there are none, check this box anyway).
- I have tried to reproduce the issue with pytest-celery and added the reproduction script below.
Mandatory Debugging Information
- I have included the output of
celery -A proj reportin the issue. - I have verified that the issue exists against the
mainbranch of Celery. - I have included the contents of
pip freezein the issue. - I have included all the versions of all the external dependencies required to reproduce this bug.
Optional Debugging Information
- I have tried reproducing the issue on more than one Python version and/or implementation.
- I have tried reproducing the issue on more than one message broker and/or result backend.
- I have tried reproducing the issue on more than one version of the message broker and/or result backend.
- I have tried reproducing the issue on more than one operating system.
- I have tried reproducing the issue on more than one workers pool.
- I have tried reproducing the issue with autoscaling, retries, ETA/Countdown & rate limits disabled.
- I have tried reproducing the issue after downgrading and/or upgrading Celery and its dependencies.
Related Issues and Possible Duplicates
Related Issues
rate_limitlimits other tasks in the queue as well #8119 is about a rate limited task holding back other tasks of the same queue.- Rate limit not working as expect with redis in celery 4.2.x, 4.3.x and 4.4.x #5927 and Arm one rate limit timer per bucket, not one per waiting task #11075 are about the timer that drains a bucket.
Possible Duplicates
- None
Environment & Settings
Celery version: 5.7.0 (9c2f238)
celery report Output:
software -> celery:5.7.0 (collider) kombu:5.7.0 py:3.14.6
billiard:4.3.2 redis:8.1.0
platform -> system:Linux arch:64bit, ELF
kernel version:6.18.44-fc-v378 imp:CPython
loader -> celery.loaders.app.AppLoader
settings -> transport:redis results:disabled
broker_url: 'redis://:********@localhost:6379/0'
deprecated_settings: None
Steps to Reproduce
Required Dependencies
- Minimal Python Version: N/A or Unknown
- Minimal Celery Version: 5.4.0 tested (3.1.0 by the code)
- Minimal Kombu Version: N/A or Unknown
- Minimal Broker Version: Redis 7.4
- Minimal Result Backend Version: N/A or Unknown
- Minimal OS and/or Kernel Version: N/A or Unknown
- Minimal Broker Client Version: N/A or Unknown
- Minimal Result Backend Client Version: N/A or Unknown
Python Packages
pip freeze Output:
billiard==4.3.2
celery @ main (9c2f238)
kombu @ main (445027e)
redis==8.1.0
Other Dependencies
Services
N/A
Minimally Reproducible Test Case
tasks.py, run.py and output
# tasks.py
import time
import redis
from celery import Celery
app = Celery("tasks", broker="redis://localhost:6379/0")
app.conf.worker_prefetch_multiplier = 4
log = redis.Redis(db=2)
@app.task(rate_limit="6/m")
def limited(i):
log.rpush("ran", f"{i} at {time.time() - float(log.get('t0')):.0f} s")
@app.task
def slow(i):
time.sleep(8)# run.py
import sys
import time
import redis
from tasks import app, limited, log, slow
task = slow if "slow" in sys.argv else limited
log.delete("ran")
start = time.time()
log.set("t0", start)
for i in range(4):
task.delay(i)
time.sleep(2)
inspect = app.control.inspect(timeout=2)
listed = sum(len(tasks) for reply in (inspect.active(), inspect.reserved(),
inspect.scheduled())
for tasks in reply.values())
print(f"{task.name}: {redis.Redis(db=0).hlen('unacked')} unacked messages,"
f" {listed} tasks in inspect active, reserved and scheduled")
if "raise" in sys.argv:
app.control.rate_limit("tasks.limited", "600/m", reply=True)
print(f"limit raised to 600/m at {time.time() - start:.0f} s")
limited.delay("sent after the change")
time.sleep(32)
print("ran:", ", ".join(x.decode() for x in log.lrange("ran", 0, -1)))$ celery -A tasks worker -c 2 -l warning
$ python run.py raise
tasks.limited: 3 unacked messages, 0 tasks in inspect active, reserved and scheduled
limit raised to 600/m at 9 s
ran: 0 at 0 s, sent after the change at 9 s, 1 at 10 s, 2 at 20 s, 3 at 30 s
$ celery -A tasks worker -c 1 -l warning
$ python run.py slow
tasks.slow: 2 unacked messages, 4 tasks in inspect active, reserved and scheduledExpected Behavior
inspect reserved lists the waiting tasks, and a new rate limit applies to them.
Actual Behavior
A worker that holds rate limited tasks looks idle, and raising the limit doesn't release them.
Activity
auvipy commentedon Nov 12, 2026
@ChristianMurphy arent you spammin with agents? and isnt it a duplicate issue?
ChristianMurphy commentedon Nov 12, 2026
I run a fairly large Celery deployment on Redis, large enough that edge cases like these come up, and that is why I care.
The latest issues come out of robustness testing I've been doing on Celery and kombu: Jepsen-style fault injection against real brokers and backends, and Quint models of the worker and result paths (#11041). I'm looking for ways tasks get lost, run twice or get stuck. I do use an agent to help with that work. I read each report before I post it and can explain it.
I don't agree that this makes them spam. Each one has a reproduction that was run on main, the release or commit where the behaviour started, and a proposed fix.
You wrote on celery/kombu#2840 that you're worried CI and AI agents can't catch regressions yet. This testing is aimed at that. Several of this week's issues are regressions it traced to one change: #10778 and #10226 in 5.7.0, #9083 with #9213 in 5.5.0, and #7734 in 5.3.0. Better tests and a specification catch these before a release, whoever or whatever wrote the code.
Reports found with agents aren't going to stop, and most of what they find is old debt. Greg Kroah-Hartman says the kernel's are real now and "not slowing down", and curl merged about 50 fixes from one batch. I'd rather help Celery get ahead of that with tests and a spec.
On the duplicate: I looked and couldn't find one. #8119 and #10972 are about waiting tasks holding prefetch slots, #5927 and #11075 are about the timer that drains the bucket, and #5321 was
query_taskfor ETA tasks. If you have another issue in mind, point me to it and I'll close this.I did post a lot in one go. I'll space them out from here.
auvipy commentedon Nov 12, 2026
it would be better if you can handle relevant or related issues in a single pr. this will help to avoid issue flooding...
ChristianMurphy commentedon Nov 12, 2026
That works for me. I don't want to add to your load, so I'd like to do this the way that is easiest for you to review. Two questions.
For new findings, would you still like an issue first, with a PR after you've confirmed it? Or should I skip the issue and put the report in a PR with the related fixes? My lean is an issue first when the fix needs a decision from you, such as a new event or a change in behaviour, and straight to a PR for a small fix.
For what is already open, I'd group the fixes like this. Each group is one PR, with one commit per issue so any part can be dropped, and I'd keep only one in review at a time:
#11087, #11089, #11093 and celery/kombu#2848 are small and unrelated to each other, so each would be its own PR, and they can wait.
Does that grouping fit how you'd review them? I won't open anything new until the PRs I already have open are reviewed.
auvipy commentedon Nov 18, 2026
sure
Register rate-limited tasks as reserved and migrate pending tasks on …