Skip to content

fix(confluent): guard against done future in delivery callback - #3365

Merged
Lancetnik merged 6 commits into
ag2ai:mainfrom
IvanKirpichnikov:fix/#3259
Nov 25, 2026
Merged

Lancetnik merged 6 commits into
ag2ai:mainfrom
IvanKirpichnikov:fix/#3259

Conversation

@IvanKirpichnikov

@IvanKirpichnikov IvanKirpichnikov commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Fixes #3259

Type of change

Please delete options that are not relevant.

  • Documentation (typos, code examples, or any documentation updates)
  • Bug fix (a non-breaking change that resolves an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a fix or feature that would disrupt existing functionality)
  • This change requires a documentation update

Checklist

  • I have read and followed the AI Policy
  • My code adheres to the style guidelines of this project (just lint shows no errors)
  • I have conducted a self-review of my own code
  • I have made the necessary changes to the documentation
  • My changes do not generate any new warnings
  • I have added tests to validate the effectiveness of my fix or the functionality of my new feature
  • Both new and existing unit tests pass successfully on my local environment by running just test-coverage
  • I have ensured that static analysis tests are passing by running just static-analysis
  • I have included code examples to illustrate the modifications

AI assistance

  • I understand these changes and can explain them in my own words.
  • I checked the PR description against the actual diff.
  • If I used AI, I reviewed, tested, and validated its generated code or text before submitting.

@IvanKirpichnikov IvanKirpichnikov self-assigned this Nov 17, 2026
@github-actions github-actions Bot added the Confluent Issues related to `faststream.confluent` module label Nov 17, 2026

@Lancetnik Lancetnik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The quoted review is from Codex. It includes checks against the original implementation and a modified callback to see what the new tests catch.

Please trim the regression tests and exercise delivery from the producer's worker thread. The fix itself addresses #3259 by checking Future.done() on the event loop immediately before completing the future.

The cancellation cases repeat the same check. All nine tests fail on the original code. Moving done() before enqueueing leaves the three late-after-cancellation cases green, while the six queued cases fail. Keep a case that queues the callback before cancelling and a case that checks a duplicate callback preserves the first outcome. Use named pytest.param cases where the outcome differs. Tests · Testing guide

The tests miss the worker thread. Every test invokes on_delivery on the event loop thread, while the producer's poll and flush run in a worker. All nine tests still pass if call_soon_threadsafe is replaced with call_soon, even with asyncio debug enabled. A duplicate delivery test using asyncio.to_thread with debug enabled passes on this PR and fails with that replacement. Please use that setup in one of the retained tests. Duplicate delivery test · Producer poll and flush

Nit for the no_confirm=True tests. Use assert isinstance(future, asyncio.Future) to narrow the result and check what send() returned. First cast · Test typing guide

Commit nit. remove comments is missing the Conventional Commits prefix. Contributing

Verified on 5504a56. Thirteen tests passed without Kafka. Ruff 0.17.2 and mypy 2.4.0 passed on both changed files.

powersemmi
powersemmi previously approved these changes Nov 25, 2026
@Lancetnik
Lancetnik enabled auto-merge November 25, 2026 18:33
@Lancetnik
Lancetnik added this pull request to the merge queue Nov 25, 2026
Merged via the queue into ag2ai:main with commit a468727 Nov 25, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Confluent Issues related to `faststream.confluent` module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: confluent: leftover on_delivery raises InvalidStateError on a done future

4 participants