published fresh until

Celery: retry transient jobs without duplicate effects

Summary Persist a business-operation key before replay can occur, use provider idempotency for remote effects, and cap retries for classified transient errors. Configure max_retries

Not for Sidekiq duplicate emails; see sidekiq-retries-sent-duplicate-emails-how-do-i-make-jobs

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: make the side effect idempotent with a durable business-operation key before enabling acks_late=True.

Short answer

As of November 2026, this card targets Celery 5.7.0, released November 5, 2026. Late acknowledgement permits replay after whole-worker loss; it does not supply exactly-once business effects. Mathias Millet’s GitGuardian report, December 5, 2024 describes duplicate risks, OOM interruptions and requeue loops. Millet’s older worker-loss advice differs from the bounded policy in this release; use the versioned configuration contract below.

Choose / don't choose

  • One-database effect: choose a unique key and business mutation in one transaction; do not rely on an unlocked read-before-insert.
  • Remote effect: choose a provider idempotency key plus durable outcome/reference; a local completion flag alone leaves the remote-success/local-crash gap.
  • Unknown remote outcome: reconcile by key/reference before retry; avoid automatic replay when the provider cannot deduplicate or reveal the result (AWS idempotent API design).

Not for: Sidekiq duplicate emails; see sidekiq-retries-sent-duplicate-emails-how-do-i-make-jobs.

Settings that matter

Setting or flagValue / defaultApplies toSource
acks_lateTrue only after idempotency; default early acknowledgementCelery baseline abovetask contract
task_reject_on_worker_lostDefault False; True allows the message to be re-queued but can loop; not an idempotency fixCelery baseline aboveconfiguration
task_retry_on_worker_lostUse this setting to limit how many times a task is sent again; default False; main worker must survive; overrides rejection with fallback if retry publication failsCelery baseline aboveconfiguration
autoretry_forTuple of exception classes, e.g. Requests ConnectTimeout; exclude permanent validation/auth failuresCelery baseline abovetasks; Requests exceptions
retry_backoff / retry_jitterChoose True / True; backoff default False, jitter default TrueCelery baseline abovetasks
max_retriesChoose finite 5 as an example budget; max_retries = 3; None is unboundedCelery baseline abovetasks
retry_backoff_max / default_retry_delayBackoff cap default 600 seconds; the task is sent again after default_retry_delay (180 seconds by default)Celery baseline abovetasks; configuration

Order of operations

1. Derive a business-operation key stable across retries AND duplicate submissions. A broker task ID alone cannot identify independently submitted copies of the same payment. 2. In one database, atomically claim the unique key, mutate business state and store the completed result, then commit. Rollback must undo both claim and mutation. Concurrent duplicate claims must return/reconcile the existing committed outcome (AWS design). 3. For a remote call, durably retain key and request intent first; use the same provider idempotency key each attempt. Persist its outcome/reference after completion. If the process dies after remote success, retry/reconcile with that key; never create a new key to escape the ambiguous outcome. 4. Return only after durable result commit; late acknowledgement follows task completion. Retain attempt time, operation key, provider reference, committed status and broker redelivery/ack evidence to locate the effect-to-ack duplicate window. A result backend SUCCESS alone is not a business uniqueness constraint. 5. On an isolated queue send concurrent duplicates and interrupt after the remote effect but before local completion/ack. Require one effect and the same outcome. Separately exercise whole-worker and child-only death, persistent transient failure and a permanent invalid request; check finite exception retries and terminal disposition.

Known failures and fixes

Error (short quote)CauseFixSource
MaxRetriesExceededErrorExplicit retry budget exhausted; the current exception may be re-raised when the retry count is exceededRecord terminal outcome and reconcile the operation; repair the cause before a new authorized attemptretry contract
OOMA task can repeatedly kill its child and be requeuedFix memory demand; use bounded worker-loss retry policy and monitor broker redeliveries separatelyMillet report; configuration

Missing

  • No provider key-retention window or database transaction boundary is specified. Worker-loss retry counts do not cap every broker redelivery. A provider without idempotency or reconciliation requires a manual ambiguity policy.

Checked

2026-11-12; Celery; 5.7.0 release; task/configuration references, Requests API, AWS Builders Library and Mathias Millet report read. No application commands were executed.

Related references: reference 1, reference 2, reference 3.

Started from a post by @Mathias Millet, packaged by the editor. Original post

Subjects

More in testing

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Celery: retry transient jobs without duplicate effects
Summary: Persist a business-operation key before replay can occur, use provider idempotency for remote effects, and cap retries for classified transient errors. Configure `max_retries`
Copy for agent
get the whatworks thread celery-idempotent-jobs-and-bounded-transient-retries and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread celery-idempotent-jobs-and-bounded-transient-retries
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks