Fix #606: never commit past an in-flight (unacked) message#707
Open
wbarnha wants to merge 3 commits into
Open
Conversation
With concurrency, the message at the head of a partition can still be processing while later offsets are already acked, so the acked run jumps right over it. _new_offset then returned a commit offset past the in-flight message; on restart the consumer resumed after it and the message was silently lost. The head-gap guard did not catch this: it only bails when min(acked) - committed > 1, but for the very next expected offset the gap is exactly 1 (min(acked) == committed + 1), so it committed anyway. Enforce the at-least-once invariant directly: cap the committable batch at the smallest offset that has been read but not yet acked for the topic-partition (_smallest_unacked_offset). Offsets acked before an in-flight message are still committed; the in-flight offset and everything after it wait until it is acked. Compacted-topic gaps are unaffected -- skipped offsets are never in _unacked_messages -- and the existing _new_offset tests keep passing (they have no in-flight messages). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HHPL4VFWQRQPpjR1gXSKyL
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #707 +/- ##
=======================================
Coverage 94.15% 94.15%
=======================================
Files 104 104
Lines 11136 11144 +8
Branches 1201 1203 +2
=======================================
+ Hits 10485 10493 +8
Misses 550 550
Partials 101 101 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
wbarnha
added a commit
that referenced
this pull request
Jul 19, 2026
Per review, the v0.12.0 changelog/release notes should describe only what is already on master, not work still in open PRs. - Remove the not-yet-merged items: the offset-commit data-loss fixes (#606/#707, #316/#692), the optional OpenTracing/OpenTelemetry extras (#685/#686, #688/#681), web_application_options (#704), and the reported-issue fix stack (#693-#703, #705). These will be added back as they merge. - Add a Dependencies section noting the current runtime/client libraries: mode-streaming >= 0.4.0, aiokafka >= 0.10.0 (compatible with recent 0.13/0.14 releases), the new confluent-kafka >= 2.0.0 for faust[ckafka], and the faust-cchardet fork replacing unmaintained cchardet. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HHPL4VFWQRQPpjR1gXSKyL
Add tests/integration/broker/test_offset_commit.py, which drives faust's real aiokafka consumer against a live Kafka broker (the #706 CI harness): - test_does_not_commit_past_inflight_message reproduces #606 -- offset 2 is in-flight (tracked, unacked) while 3 and 4 are acked out of order -- and asserts the broker's committed offset never advances past 2. Verified to fail without the fix (the buggy _new_offset returns 5 and commits it). - test_commits_contiguous_acks is a positive control proving the real commit path does persist offset 5 to the broker when nothing is in-flight. Both skip when no broker is reachable and run in the dedicated CI integration job. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HHPL4VFWQRQPpjR1gXSKyL
Collapse a wait_for call to one line so black --check (the lint job) passes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HHPL4VFWQRQPpjR1gXSKyL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Under concurrency, faust could commit an offset past a message that was still being processed, silently losing it on the next restart.
Reproduction from the issue (
concurrency=2): message 1 is slow (sleep(100)) while messages 2–5 process in ~1s and ack. faust commits the offset of message 5, and after aSIGKILL/restart the consumer resumes after message 1 — message 1 is never processed.Fixes #606.
Root cause
In
Consumer._new_offset, the head-gap guard only withholds when there's a gap larger than one:When the still-processing message sits at exactly the committed head, the acked run starts one past it, so
min(acked) - committed == 1— not> 1— and faust commits straight over it. It's an off-by-one against the in-flight case: a single missing offset at the head is treated as a compacted-topic gap (safe to skip) when it's actually an event still being processed (must not skip).Deterministic reproduction (before the fix):
_new_offsetwithcommitted=2585,acked=[2586,2587,2588,2589]returns 2590 → offset 2585 lost.Fix
Enforce the at-least-once invariant directly rather than inferring it from the acked run: cap the committable batch at the smallest offset that has been read but not yet acked for the topic-partition (
_smallest_unacked_offset, computed from the_unacked_messagesfaust already tracks).committed=100, acked=[100,101,102], 101 in-flight → commits 100, returns101)._unacked_messages, so those still advance as before.Tests
test_new_offset__withheld_for_inflight_message— the exact Wrong offset commit in case of gaps #606 state; asserts_new_offsetreturnsNoneinstead of2590(verified to fail before the fix withassert 2590 is None).test_new_offset__commits_up_to_inflight_message— earlier acked offsets before the in-flight one are still committable.test_new_offset/test_new_offset_with_gaps/_add_gaptests pass unchanged (they carry no in-flight messages, so the cap is inert). Fulltests/unit/transport/test_consumer.py: 115 passed, 2 skipped.Note on end-to-end verification
The bug lives entirely in
_new_offset's arithmetic, which these deterministic tests exercise at exactly the failing state. A full live-broker end-to-end reproduction (produce → slow-consume head → kill → restart → assert no message lost), on top of the new Kafka-in-CI harness from #706, is planned as a follow-up once the in-process faustAppE2E fixture is hardened.🤖 Generated with Claude Code
Generated by Claude Code