# Fix the Celery broker_connection_retry Deprecation Warning

Yes. An agent starts the worker in its sandbox, quotes the CPendingDeprecationWarning, sets broker_connection_retry_on_startup in the Celery config and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/fix-broker-connection-retry-deprecation-warning/celery/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent clones the repository into its own cloud sandbox and reads how the worker is configured. In a Flask and Celery app like FanaHOVA/smol-podcaster, `tasks.py` builds `Celery('tasks')` and calls `app.config_from_object('celeryconfig')`, and `celeryconfig.py` is two lines: `broker_url = 'amqp://guest:guest@localhost:5672/'` and `result_backend = 'rpc://'`. The two tasks, `run_smol_podcaster` and `run_video_chapters`, wrap functions in `smol_podcaster.py`, and `web.py` queues them with `.delay(...)` from two Flask routes. The `Procfile` runs `web: gunicorn web:app` and `worker: celery -A tasks worker --loglevel=INFO -E -n smol_podcaster@%h`; the README says to run both with `honcho start` against a RabbitMQ broker. `requirements.txt` pins `celery==5.3.6` with `kombu==5.3.5`, `amqp==5.2.0` and `billiard==4.2.0`, beside `Flask==3.0.1`, `openai==1.13.3`, `anthropic==0.20.0` and `replicate==0.15.4`.

It installs the pins into a fresh environment and starts the worker with the `Procfile` command. Importing `tasks` imports `smol_podcaster`, which builds its API clients at import time and raises `OpenAIError` without `OPENAI_API_KEY`, so the agent sets placeholder values for that and the other two keys, which the worker never uses before it reaches the broker. The banner prints `v5.3.6 (emerald-rush)`, transport `amqp://guest:**@localhost:5672//`, results `rpc://`, concurrency 2 (prefork), task events on and the `celery` queue, and then the line the title is about: `[WARNING/MainProcess] .../celery/worker/consumer/consumer.py:507: CPendingDeprecationWarning: The broker_connection_retry configuration setting will no longer determine whether broker connection retries are made during startup in Celery 6.0 and above. If you wish to retain the existing behavior for retrying connections on startup, you should set broker_connection_retry_on_startup to True.` It is followed by `consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 111] Connection refused. Trying again in 2.00 seconds... (1/100)`, since the sandbox has no RabbitMQ, which is the retry behaviour the warning is about.

The warning names its fix. The agent adds `broker_connection_retry_on_startup = True` to `celeryconfig.py`, the explicit form of what the worker does today, and starts it again: the banner is the same, the warning is gone, and the connection attempts and their `Trying again` lines are unchanged, which is the point of the setting. It does not touch `broker_connection_retry`, so retries after a connection is lost mid-run keep their current behaviour too.

It also checks the version question, because the warning is tied to a release range. Pinning each release in turn and starting a minimal worker shows the line in 5.3.6 and 5.4.0 and nothing in 5.5.3, 5.6.0 or 5.7.0, the latest today. The pull request says so, and keeps the config line anyway: it costs nothing, states the intended behaviour, and means the next upgrade does not change how the worker starts.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "The Celery worker in this repository prints \"CPendingDeprecationWarning: The broker_connection_retry configuration setting will no longer determine whether broker connection retries are made during startup in Celery 6.0 and above\". Read the Celery app module, its configuration (config_from_object target, settings module or inline conf), the Procfile or process manager config and requirements first. Install the pinned versions, start the worker with the same command the Procfile uses, with placeholder environment variables if imports need them, and quote the warning. Add broker_connection_retry_on_startup = True to the configuration next to broker_url, start the worker again to show the warning is gone and the connection retries are unchanged, and check which Celery releases print the warning so the pull request can say whether an upgrade alone would silence it. Open a pull request with the before and after worker output.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request adding one line to `celeryconfig.py`, `broker_connection_retry_on_startup = True`, with nothing else changed. The description quotes the worker banner and the full `CPendingDeprecationWarning` from the first start, the clean start after the change with the same `Trying again in 2.00 seconds... (1/100)` retry line to show behaviour did not move, and the per-release check: present in 5.3.6 and 5.4.0, absent from 5.5.3, 5.6.0 and 5.7.0.

A reviewer reads one line and the two startup logs and merges. The run's record holds both worker sessions and the version probes, so the release range in the description can be checked rather than believed.

## Run it on every terminal hand-off

You see the warning scroll past when the worker starts and do not want to chase it now. In the console, open the Project that has the repository, paste this prompt into the composer and start it; or send this body to `POST /o/{org}/sessions` with `curl` from your terminal, with a `request_id` that is a UUID v5 of the branch name so a repeated command returns the run already started, and follow it on `GET /o/{org}/sessions/{id}/events`.

The key's `webhook_url` receives `run.completed` or `run.failed` with the session URL when the run ends, and the pull request link is on the session.

## Why run it on Rush?

A worker warning is easy to read and tedious to prove: you need the pinned versions in a clean environment, the real start command, and a second start after the change to show retries behave the same. The agent does all of it in its own sandbox, with placeholder keys so import-time API clients do not stop it, and both worker sessions stay in the run's record, so the pull request quotes the worker's own words before and after.

It is also a question of which release you are on, and the answer is cheap in a sandbox and annoying on a laptop: install five Celery releases in turn and start a worker under each. The agent does that in the same run and writes the range into the pull request, so the reviewer knows the config line is the fix today and the upgrade is the fix later.

## Frequently asked questions

### Does setting broker_connection_retry_on_startup change how the worker behaves?

Not on Celery 5. Today the startup retries follow `broker_connection_retry`, which defaults to on, and the new setting makes that explicit; the agent's second start shows the same `Trying again` lines at the same intervals. What changes is Celery 6, where the old setting stops governing startup, so the line keeps the worker's behaviour across that upgrade.

### Would upgrading Celery make the warning go away on its own?

The agent checks rather than assumes: the line prints in 5.3.6 and 5.4.0 and not in 5.5.3, 5.6.0 or 5.7.0. An upgrade past 5.4 silences it, but the pull request still adds the setting, because it states what the worker should do at startup instead of relying on a default that the warning says will change.

### The worker cannot start in a sandbox without my broker. How does it reproduce the warning?

The warning is printed before the first connection attempt, and the connection refused that follows is exactly the startup retry the setting controls. The agent needs no RabbitMQ to see both; it sets placeholder environment variables only where the app constructs API clients at import time, and never sends a request with them.

### My config is in a Django settings module, not celeryconfig.py.

The agent reads wherever `config_from_object` or `app.conf` points, and adds the setting there with the same name, or as `CELERY_BROKER_CONNECTION_RETRY_ON_STARTUP` when the app uses a namespace. The before and after worker starts are the proof either way.

## More Celery jobs

- [Fix "Error: No such option '-A'" when a Celery worker starts after moving to Celery 5](https://getrush.ai/run/fix-celery-no-such-option-a/celery/)
- [Upgrade Celery 4 to Celery 5](https://getrush.ai/run/upgrade-celery/celery/)
- [Write pytest Tests for Celery Tasks](https://getrush.ai/run/write-pytest-tests/celery/)

## More jobs like this: Hand off a long task

- [Fix Deprecations in an Ember App](https://getrush.ai/run/fix-deprecated-apis/ember/)
- [Replace Deprecated Flutter APIs Across an App and Make the Analyzer Catch the Next Ones](https://getrush.ai/run/fix-deprecated-apis/flutter/)
- [Fix Deprecated APIs in a LangChain.js App](https://getrush.ai/run/fix-deprecated-apis/langchain/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
