Skip to content

Fix committed-offset bookkeeping advancing when commit fails#692

Open
wbarnha wants to merge 1 commit into
masterfrom
claude/fix-316-commit-offset-bookkeeping
Open

Fix committed-offset bookkeeping advancing when commit fails#692
wbarnha wants to merge 1 commit into
masterfrom
claude/fix-316-commit-offset-bookkeeping

Conversation

@wbarnha

@wbarnha wbarnha commented Jul 19, 2026

Copy link
Copy Markdown
Member

Note: Before submitting this pull request, please review our contributing guidelines.

Description

Fixes #316.

Consumer._commit_offsets (faust/transport/consumer.py) updated self._committed_offset and fired self.app.monitor.on_tp_commit(...) unconditionally, outside the if did_commit: guard that already existed for the tables.on_commit(...) call two lines above.

On any transient commit failure (e.g. UnknownMemberIdError during a rebalance — the scenario in the original report), Faust's internal bookkeeping silently advanced to record those offsets as committed even though the underlying Kafka commit never happened. A later _should_commit() check (committed = self._committed_offset[tp]; return committed is None or offset > committed) would then see those offsets as already committed and skip retrying them — risking real offset loss under the default at-least-once guarantee.

Fix

Move self._committed_offset.update(...) and self.app.monitor.on_tp_commit(...) inside the existing if did_commit: block, so bookkeeping only advances when the commit actually succeeded.

Tests

  • Extended test_commit_offsets__did_not_commit to assert monitor.on_tp_commit is not called and _committed_offset is unchanged when the commit fails (did_commit=False).
  • Extended test_commit_offsets (happy path) to assert monitor.on_tp_commit is called and _committed_offset is updated when the commit succeeds, so both branches of the guard are covered.
  • Verified the new negative-path assertions actually catch the bug: reverting the fix while keeping the new test makes it fail with AssertionError: Expected 'on_tp_commit' to not have been called. Called 1 times. — confirming the test is not vacuous.
  • flake8, black --check, isort --check-only clean on both changed files.

🤖 Generated with Claude Code


Generated by Claude Code

Consumer._commit_offsets updated self._committed_offset and fired
monitor.on_tp_commit() unconditionally, outside the `if did_commit:` guard.
On any transient commit failure (e.g. UnknownMemberIdError during a
rebalance), Faust's internal view of "what's committed" silently advanced
anyway, risking offset loss under the default at-least-once guarantee: a
later _should_commit() check would see those offsets as already committed
and skip retrying them.

Move both calls inside the `if did_commit:` block so bookkeeping only
advances when the commit actually succeeded.

Fixes #316.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HHPL4VFWQRQPpjR1gXSKyL
@codecov

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.15%. Comparing base (3073eb9) to head (39fb1f8).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #692   +/-   ##
=======================================
  Coverage   94.14%   94.15%           
=======================================
  Files         104      104           
  Lines       11136    11136           
  Branches     1201     1201           
=======================================
+ Hits        10484    10485    +1     
+ Misses        551      550    -1     
  Partials      101      101           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

self._committed_offset.update(committable_offsets) if did_commit==False

1 participant