← Back to Pull requests

feat(share-consumer): add ShareConsumer group membership (KIP-932) #536

Closed
unknown closed this pull request without merging on Nov 27, 2026 11:13 UTC
View on GitHub
unknown unknown commented on Nov 26, 2026 09:45 UTC
Author

Second step of #480: a ShareConsumer client which manages the membership of a share group. Fetching records and the implicit acknowledgement come in the next PR, to keep this one reviewable.

What it does

  • new ShareConsumer({ groupId, ... }) generates the member id, which is kept for the whole life of the client as ShareGroupHeartbeat requires.

  • joinGroup({ topics }) sends ShareGroupHeartbeat with member epoch 0 and resolves with the member id. After that a heartbeat is sent at the interval the coordinator returns, with the full subscription every time.

  • The assignment arrives as topic ids and is mapped to topic names through the metadata, refreshing it once if an id is unknown (a recreated topic). A null assignment means it did not change. Each subscribed topic is looked up on its own and a missing one is skipped, so a topic can be subscribed before it exists, and a deleted topic just drops out of the assignment. The lookups only run when the assignment changes.

  • Group requests connect to the address returned by FindCoordinator, as Admin does, so heartbeats never load topic metadata and a missing topic cannot block them.

  • UNKNOWN_MEMBER_ID or FENCED_MEMBER_EPOCH resets the epoch to 0, clears the assignment and joins again with the same member id. Other heartbeat errors are emitted and the next heartbeat retries, as the consumer group protocol path of Consumer does.

  • leaveGroup() sends member epoch -1. If it fails, the error is returned but the membership ends anyway, and the coordinator removes the member when its session times out, like the consumer group protocol path of Consumer. Heartbeating again could otherwise join the group again when only the response to the leave was lost.

  • close() leaves through the already open coordinator connection, bounded by leaveGroupTimeout, like Consumer.

  • Join, leave and close each start a new generation, and responses or retries from an older one are ignored. So a heartbeat waiting for a retry is never sent after a leave, joinGroup fails while a leave is in flight, concurrent leaveGroup calls share one request, and close() during a leave sends the leave again instead of skipping it.

  • Events share-consumer:group: and share-consumer:heartbeat:, tracing channels share-consumer:group and share-consumer:heartbeat, and the kafka_share_consumers gauge.
  • Consumer is not touched. #findGroupCoordinator, #handleError and #leaveGroupWhileClosing are copied from it, because they are private to Consumer. I can move them to a shared module instead if you prefer, but that would touch Consumer.

    Questions

    1. Event prefix: I used share-consumer: rather than reusing consumer:, since it is a separate client. OK?
    2. joinGroup and leaveGroup are public so the membership can be used and tested on its own. In the next PR consume({ topics }) will join if needed, like Consumer does. Fine to keep them public, or would you rather hide them until then?
    3. Should the class be marked experimental until acknowledgements land?

    Tests

  • 43 unit tests with the network mocked (no broker needed), covering join, the heartbeat loop, assignment resolution including missing topics, rejoin after UNKNOWN_MEMBER_ID and FENCED_MEMBER_EPOCH, coordinator changes, leave and failed leave, close, leaveGroupTimeout, and the interleavings of join, leave, close and retries. They cover 98.9% of the lines and 98.1% of the branches of share-consumer.ts, so the coverage gate holds on the Kafka versions where the broker test is skipped.

  • One test against the single broker joins a share group, waits for the assignment of a 3-partition topic and leaves. It passes locally on cp-kafka:8.2.0. It skips itself when the broker does not advertise ShareGroupHeartbeat, or answers UNSUPPORTED_VERSION because share groups are disabled, as on cp-kafka:8.1.0 (checked locally).

  • Checked by hand on cp-kafka:8.2.0: subscribing to a topic before it exists and then creating it (its partition gets assigned), deleting another subscribed topic (it leaves the assignment and the heartbeats keep succeeding), then leaving.

  • Not run locally: the rest of the suite, which needs the 3-broker cluster. Only src/diagnostic.ts, src/utils.ts (two debug loggers), the client exports and the validators count changed outside the new files.
  • Diff: 545 lines (+408 / -137) across 6 files Reviewer: ShogunPanda Review duration: 1528m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 545 lines diff across 6 files
    0.48
    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.377
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #536"
    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: 48% (MEDIUM) · Higher = larger blast radius
    48%
    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: 19.0% · Safe to merge
    19.0%