← Back to Pull requests

fix(consumer): prevent data loss on rebalance #540

Closed
unknown closed this pull request without merging on Nov 26, 2026 12:08 UTC
View on GitHub
unknown unknown commented on Nov 26, 2026 11:24 UTC
Author

Continues #428 by @W1sdomPanda, rebased on main with their commits kept, plus the two changes I proposed there.

What it does

From #428:

  • A cooperative rebalance of the classic protocol pauses only the streams consuming a revoked topic, instead of every stream.

  • After a rebalance, queued commits for partitions which are no longer assigned are dropped, and committing such a partition resolves without sending anything. The broker accepts the commit with the new generation, and it would overwrite the position of the member which now owns the partition.
  • Added on top:

  • The consumer group protocol (groupProtocol: 'consumer') revokes partitions through #revokePartitions, which still paused every stream. It now pauses only the streams consuming a revoked topic too. All the streams are still flushed before the revocation, as before.

  • A new consumer:group:commit:skipped event, with groupId, generationId, topic, partition and offset, emitted when a commit is skipped. The commit still resolves, but without the event nothing shows why the new owner consumes those messages again. Documented in docs/consumer.md.

  • The review comments on #428: the cooperative rebalance test uses mockMethod, and the stray line in consumer.test.ts is gone after the rebase.
  • Tests

  • The two mocked tests from #428 (a queued autocommit dropped on rejoin, and message.commit() of a buffered message from a revoked partition) now also check the event.

  • One broker test per protocol: after another member takes a topic, the stream of the other topic is never paused but still flushed. The consumer group protocol one skips itself on Kafka versions without it, like the other tests of that protocol.

  • Removing any of the fixes makes its test fail.

  • Locally against a single cp-kafka:8.2.0 broker: the messages-stream*.test.ts files (126 tests), consumer.test.ts and the commit, revocation and protocol suites (305 tests) pass. Not run locally: the 3-broker cluster and the other Kafka versions.
  • Diff: 253 lines (+189 / -64) across 3 files Reviewer: ShogunPanda Review duration: 43m
    All Vouch review confidence checks passed
    Residual risk 0.15 = Change Risk (0.39) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 253 lines diff across 3 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.331
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #540"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.1% (MEDIUM) · Higher = larger blast radius
    39.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.4% · Safe to merge
    15.4%