← Back to Pull requests

feat(share-consumer): add explicit acknowledgements #560

Closed
unknown closed this pull request without merging on Dec 02, 2026 10:41 UTC
View on GitHub
unknown unknown commented on Dec 02, 2026 08:22 UTC
Author

Next part of #480, following #545: explicit acknowledgements, and a handler for records that cannot be deserialized. renew comes in a separate PR, since it works differently on the broker.

What it does

  • New option acknowledgementMode, 'implicit' (the default, unchanged) or 'explicit', on the constructor and on consume(). The values are in ShareAcknowledgementModes.

  • In explicit mode, reading a record no longer accepts it. The application calls message.acknowledge(type), with 'accept' (the default), 'release' or 'reject' (ShareAcknowledgementTypes). The acknowledgement goes with the next request to the same broker, like the implicit ones, and also with the heartbeats while the buffer is full.

  • acknowledge() returns nothing, and the broker's errors still arrive as share-consumer:acknowledgement:error. It throws in implicit mode, for an unknown type, and when the message was already acknowledged. Once the stream is closing it does nothing, since closing released the record.

  • A record that is read but never acknowledged stays locked until its lock expires, and is then delivered again. Closing the stream releases it right away, together with the buffered ones.

  • A share session is kept open while one of its records waits for the application, since closing the session would release it.

  • New option onDeserializationError(context), like the one of Consumer. It returns 'reject' or 'release' (ShareDeserializationErrorActions) to acknowledge the record that way and go on, or 'fail' to destroy the stream as today. The context has the error, the payloadType, the raw record, topic, partition, offset, timestamp and deliveryCount. It works in both modes. A handler that throws destroys the stream with its error, and one that returns anything else, like a promise, with an error saying so. The failed offset is no longer acknowledged as a GAP.

  • acknowledge() is a method on the message prototype calling one function shared by the stream, as message.commit() does in Consumer.
  • Choices to check

  • acknowledge() returns nothing rather than a promise. An acknowledgement can wait up to maxWaitTime for the next request to its broker, so awaiting it in a for await loop would stall the loop. Failures come with the event, and a failed acknowledgement means the record is delivered again.

  • Read-but-unacknowledged records do not stop the fetching. The stream could stop after some number of them instead, but that is more code, and the lock already bounds how long they are held.
  • Tests

  • New mocked tests: no acceptance on read in explicit mode; accept, release, reject and the default type; the three errors of acknowledge(); close releases the unacknowledged records and a later acknowledge() is ignored; a session stays open while its record waits for the application; acknowledging from the data event; the handler rejecting, releasing and failing, a failed header, a handler that throws or returns a promise, and a failed offset next to a gap; option validation.

  • One new broker test on cp-kafka:8.2.0: the first member accepts, releases and rejects three records, and the second member gets only the released one, with a delivery count of 2. It passes locally, and the existing broker test still does. It skips itself where share groups are not available, like the existing one.

  • Not run locally: the rest of the suite, which needs the 3-broker cluster, and the other Kafka versions.
  • Diff: 436 lines (+327 / -109) across 5 files Reviewer: ShogunPanda Review duration: 139m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 436 lines diff across 5 files
    0.45
    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.364
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #560"
    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: 45.2% (MEDIUM) · Higher = larger blast radius
    45.2%
    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: 17.9% · Safe to merge
    17.9%