← Back to Pull requests

fix(inkless:switch): don't answer a classic epoch from a log that ends below the seal [KC-866] #901

Closed
unknown closed this pull request without merging on Nov 26, 2026 12:20 UTC
View on GitHub
unknown unknown commented on Nov 25, 2026 13:55 UTC
Author

A phase 2 leader whose local log ends below the seal answers OffsetsForLeaderEpoch for a classic epoch from that incomplete log, and a consumer at or below the seal rewinds. With this change the leader answers with a retriable error until its log is complete.

Problem

In phase 2 any replica can lead, including one with an empty local log, such as a replica that a reassignment adds. Partition.makeLeader maps the new leader epoch to the log end offset in the leader epoch cache, and ReplicaManager.maybeReconcileSwitchedLeader keeps the partition online so that consolidation rebuilds the log.

Until then, ReplicaManager.lastOffsetForLeaderEpoch answers a classic epoch from that cache. LeaderEpochFileCache.endOffsetFor finds no entry at or below the requested epoch and returns the start offset of the first higher epoch, which is the log end offset. That offset is below the seal, so the broker returns it as the final answer. hasCompleteLocalClassicPrefix only makes a follower with a high watermark below the seal answer NOT_LEADER_OR_FOLLOWER. It doesn't restrict the leader.

A consumer at or below the seal sees an end offset below its position and treats it as a truncation.

Example before this change

On a 3-broker cluster, a phase 2 partition sealed at offset 20 has replicas 1 and 2, and a consumer idles at offset 20 with a classic epoch. The partition is reassigned to broker 0, which has no log:

  • Broker 0 answers OffsetsForLeaderEpoch for the classic epoch with end offset 0 for about 6 ms, and with 20 afterward.

  • In one of three runs, the consumer's validation got the first answer. Its position moved from 20 to 0, and it read offsets 0 to 19 again.
  • Fix

    A replica whose high watermark is below the seal answers a classic epoch with NOT_LEADER_OR_FOLLOWER. This rule already applied to a follower, and now applies to the leader too. The consumer retries the error.

    Consolidation rebuilds the log from remote storage, or starts it at the cross-tier earliest offset if the prefix is already deleted. Both steps set the high watermark to the seal or a later offset, and the lookup then succeeds.

    Phase 1 doesn't change: a leader below the seal marks the partition offline there.

    Test plan

  • ReplicaManagerInklessTest has two new tests, for a phase 2 leader with an empty log and for one whose log ends below the seal. Both fail without the change to ReplicaManager. The class passes with 316 tests.

  • On a 3-broker cluster, a temporary test repeated the reassignment three times with a loop that sends OffsetsForLeaderEpoch for the classic epoch to the new leader. The leader answered NOT_LEADER_OR_FOLLOWER and then the seal, about 1.1 seconds after the reassignment. The idle consumer kept its position and received only the next record.

  • :core:checkstyleMain, :core:checkstyleTest, and :core:spotbugsMain pass. make vale reports no alerts on the added lines.
  • 🤖 Generated with Claude Code

    Diff: 375 lines (+281 / -94) across 4 files Reviewer: viktorsomogyi Review duration: 1345m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 375 lines diff across 4 files
    0.43
    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.355
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #901"
    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: 42.9% (MEDIUM) · Higher = larger blast radius
    42.9%
    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: 16.9% · Safe to merge
    16.9%
    Repository