Skip to content

Complete a chord whose header chain ends in a group - #11186

Open
ChristianMurphy wants to merge 4 commits into
celery:mainfrom
ChristianMurphy:fix/chord-header-chain-ending-in-group
Open

ChristianMurphy wants to merge 4 commits into
celery:mainfrom
ChristianMurphy:fix/chord-header-chain-ending-in-group

Conversation

@ChristianMurphy

@ChristianMurphy ChristianMurphy commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Note: Before submitting this pull request, please review our contributing
guidelines
& Anti AI spamming Guidelines. Before opening an AI based PR make sure you asked
in the discussion forum or in the related open issues first.

Description

This fixes a regression from #11072 (mine), which I found while reviewing #11176. It is not in a release.

On the cache, DynamoDB and GCS result backends, a chord whose header has a chain that ends in a group stays PENDING:

chord([chain(a.si(), group(b.si(), c.si())), d.si()], body.s())

The header entry of that chain is the group. Since #11072 the backend checks that every header result is stored before it completes the chord, and it looked for one under the id of the group. The tasks of the group return to the chord, each with its own result, and nothing is stored under the group's id.

With memcached 1.6 and a Redis broker:

Header Before #11072 main This PR
chain(a, group(b, c)), alone or next to another task, fast or slow tasks body ran, 20 of 20 PENDING, 20 of 20 body ran, 20 of 20
The same with a task of the group failing chord failed, errback ran, 3 of 3 PENDING, 3 of 3 chord failed, errback ran once, 3 of 3
A group of 30 tasks body ran, 3 of 3 PENDING, 3 of 3 body ran, 3 of 3
A group with a chain in it body ran, 3 of 3 PENDING, 3 of 3 body ran, 3 of 3

With this change the backend looks at the tasks of a group in the header. That goes for the check before completion, for the size of the chord when the request has none, for the part keys it deletes and for the results it expires when the chord completes. Flat headers go through the same code as before.

Why #11072 missed it

Every test and every run for #11072 used a flat header, and the new check is only right for a flat header.

  • Its unit tests built a header from a list of task ids, so a group in the header could not be written, in the random model either.
  • My worker runs were chords of 1, 30 and 200 tasks, a failing task, and redelivered and killed tasks. None had a nested canvas.
  • I compared main with the branch on the reported bug. I did not run other kinds of chord on the commit before the change, which is what shows a chord that used to work.
  • CI does not run the memcached integration file. test_chord_expires in it has failed since Complete a chord once on the cache, DynamoDB and GCS backends #11072, and one run of that file would have shown it.

What is different this time

  • The tests can now build a group in the header, and the random model does so for every other chord, up to two levels deep. It checks returns, kills, concurrent returns, retries and a lost group on the memory and pymemcache clients, DynamoDB (moto) and GCS (fakes).
  • Seven integration tests against a memcached server: the chain alone and next to a task, 30 tasks, a chain in the group, a group in the group, a failing task, and a task of the group returning twice. All seven fail on main's source and passed 3 of 3 runs here.
  • One smoke test with a worker in Docker, on the RabbitMQ and the Redis broker.
  • Twenty kinds of chord (flat, nested groups, chains ending in a group, nested chords, failing tasks) on 5.6.3, 5.7.0 and main, with Redis, PostgreSQL and memcached as the result backend. Redis and PostgreSQL give the same result on all three versions. On memcached only the chains ending in a group differ, and with this PR they match 5.6.3 again.
  • DynamoDB Local: the same nested headers complete in 89 of 90 chords with this PR. The one failure was the first chord after the worker started, which fails the same way on the commit before Complete a chord once on the cache, DynamoDB and GCS backends #11072.
  • Each of seven bugs I planted in the change fails at least one test.

Not changed, and the same before #11072: when the chain fails before it reaches its group, the chord stays PENDING.

One thing to know for an upgrade, now in the docs notes: while a 5.7.0 worker and a worker with #11072 share a chord with a group in its header, about half of them stayed PENDING and a few ran the body twice. Flat chords were fine.

Test details
  • Unit tests are in t/unit/backends/test_chord_parts.py. One of them counts calls of _complete_chord_once. The body runs either way, so the call count is the only thing that shows the chord is sized by its tasks.
  • test_chord_expires in t/integration/test_cache_backend.py builds its request by hand without ignore_result. It now builds it as a worker does.
  • t/unit/backends, t/unit/tasks/test_chord.py and t/unit/tasks/test_canvas.py as tox runs them (python -bb): the same five tests fail on main and here, none in this change.
  • Not run: a GCS server, pools other than prefork, Python versions other than 3.13.

On the cache, DynamoDB and GCS backends such a chord stayed pending
since celery#11072. The header entry of a chain that ends in a group is the
group. Before a chord completes, the backend checks that every header
result is stored, and it looked for one under the id of the group:
the tasks of the group return to the chord, each with its own result.

The backend now looks at the tasks of a group in the header: for the
check, for the size of the chord when the request has none, for the
part keys it deletes and for the results it expires when the chord
completes.

Also build the request in test_chord_expires as a worker does: it
failed against memcached since celery#11072.
@codecov

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.83%. Comparing base (ce68a20) to head (3ebe46c).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #11186   +/-   ##
=======================================
  Coverage   91.82%   91.83%           
=======================================
  Files         153      153           
  Lines       22314    22323    +9     
  Branches     2798     2800    +2     
=======================================
+ Hits        20490    20500   +10     
  Misses       1529     1529           
+ Partials      295      294    -1     
Flag Coverage Δ
unittests 91.81% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

Every other chord of test_random_chords now puts some header tasks in
groups, up to two levels deep, so returns, kills, concurrent returns,
retries and a lost group are checked for those headers too.
A header chain ending in a group alone, with 30 tasks, with a chain or
a group in the group, with a failing task, and with a task of the
group that returns twice.

This branch has not been deployed

No deployments
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.

1 participant