← Back to Pull requests

fix(consumer): Bounded the records delivered from a single fetch response. #552

Closed
unknown closed this pull request without merging on Nov 30, 2026 16:47 UTC
View on GitHub
unknown unknown commented on Nov 30, 2026 14:43 UTC
Author

Summary

A single Fetch response can carry far more records than the highWaterMark of a MessagesStream. The stream checked the result of push() only after deserializing and pushing every record of a response, so with 2,000 small records and highWaterMark: 16, readableLength grew to about 2,000.

This change suspends delivery inside a response as soon as push() returns false, before the next record is deserialized, and resumes it from _read() and resume() before any new fetch is issued. It supersedes #426 with a smaller approach.

Changes

  • #pushRecords stops at the first record after push() returns false and keeps the response by reference, without copying or deserializing anything ahead. The existing requestedOffsets map acts as the cursor: records before the suspension point are skipped as duplicates, batches already delivered are skipped whole, and completed partitions are removed from it.

  • Responses received while a delivery is suspended are queued behind it. #fetch resumes them in order and fetches again only once the last one completes with room left in the queue. Responses issued before a refresh or a revocation are discarded, and close() and _destroy() release them.

  • Fetch and autocommit offsets advance only after every record of a partition has been delivered, including a trailing control batch. On suspension they are set to the first undelivered record, so a revocation or a close commits exactly the delivered prefix.

  • In batch mode a full pending batch is pushed before suspending, with the next record as its commit boundary, so no deserialized message is retained.

  • maxFetches counts a response only once it has been fully delivered, so the stream does not end while records are still retained.
  • Notes

  • The bound applies to the queue and to deserialization. The raw response stays referenced until it has been fully delivered, and beforeDeserialization hooks still run on the whole response up front.

  • In batch mode the queue can exceed highWaterMark by up to about two batches.
  • Additional Informations

    AI-assisted work. All changes reviewed by a human.

    Diff: 268 lines (+201 / -67) across 3 files Reviewer: mcollina Review duration: 123m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.44) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.44 · 268 lines diff across 3 files
    0.44
    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.335
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #552"
    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: 44.4% (MEDIUM) · Higher = larger blast radius
    44.4%
    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.5% · Safe to merge
    17.5%