← Back to Pull requests

fix: Kill task groups by partition, not groupId, when a pending completion group fails #20741

Closed
unknown closed this pull request without merging on Nov 17, 2026 01:34 UTC
View on GitHub
unknown unknown commented on Oct 26, 2026 20:38 UTC
Author

Description

When a pending completion task group fails (no task succeeds within completionTimeout, or all of its tasks fail), SeekableStreamSupervisor.checkPendingCompletionTasks resets the group's partitions, kills the actively reading task group with the same groupId, and stops every later pending completion task group in the same list.

The groupId only identifies the same partitions while taskCount is unchanged. After a task count change (for example, by the lag-based autoscaler), the reading task groups that actually started from the failed group's unpublished end offsets have other groupIds. They keep running, and their tasks fail to publish with The new start metadata state[...] is ahead of the last committed end state[...]. The next rollover copies their end offsets into partitionOffsets, so the gap is carried forward and the supervisor does not recover on its own. Resetting the supervisor recovers it, but skips the unpublished data.

The same applies to the later pending completion task groups: after a task count change, the ones that started from the failed group's end offsets are not necessarily in the same list as the failed group, so they are not stopped.

We saw this in production when one task's segment push failed with a transient error at the same moment as an autoscaler scale action.

Stop the pending completion groups that started after a failed group

A pending completion task group is now stopped if it started reading any partition of a failed or stopped group from a later offset. This is the same condition that isTaskReadyToPublishSegments uses to make a task wait for an older task group to publish, so these are exactly the groups whose publish depends on the failed group. The check covers all the pending completion lists, since after a task count change these groups can have any groupId. It is also applied to the groups that started after a stopped group.

The groups are stopped before onCompleted() is called on the failed group, so their publish waits resolve as not ready instead of being released. Otherwise, their publish would fail with the same error. Worse, if metadata storage has no committed offset for a shared partition yet, it would succeed and skip the failed group's data, since the metadata check ignores partitions that are not in the committed metadata.

Groups that started reading the shared partitions before the failed group keep publishing. A later group in the same list is also no longer stopped if it shares only partitions on which the failed group read no data, since its publish does not depend on the failed group.

Kill the reading task groups by partition

The new resetPartitionsAndKillReadingTaskGroups resets the partitions of the failed and stopped task groups and kills every actively reading task group that:

  • reads any of these partitions from an offset other than the committed offset in metadata storage, or

  • is assigned one of these partitions in partitionGroups but is not reading it, such as a closed Kinesis shard whose end offset was never published. Otherwise, that partition would not be re-read until the task group rolls over.
  • Reading task groups that started from the committed offsets are kept. For example, when a pending completion group published its offsets but timed out waiting for handoff, the readers that started from its end offsets keep running, whereas before, the reader with the same groupId was killed.

    The reset and the kills now happen once, after all the pending completion groups are checked and the dependent ones are stopped, and before onCompleted(). This way, the killed tasks' publish waits resolve as not ready before the completion listeners would let them publish.

    Release note

    Fixed Kafka and Kinesis supervisors getting stuck in repeated task failures with "The new start metadata state ... is ahead of the last committed end state" after a publishing task group failed around a task count change, such as during autoscaling.

    <hr>

    ##### Key changed/added classes in this PR
    SeekableStreamSupervisor
    SeekableStreamSupervisorStateTest

    <hr>

    This PR has:

  • been self-reviewed.

  • a release note entry in the PR description.

  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.

  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.

  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • Diff: 589 lines (+441 / -148) across 7 files Reviewer: maytasm Review duration: 30535m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 589 lines diff across 7 files
    0.50
    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.382
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #20741"
    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: 50.0% (MEDIUM) · Higher = larger blast radius
    50.0%
    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.7% · Safe to merge
    19.7%
    Repository