← Back to Pull requests

fix(inkless:switch): answer epoch 0 from the diskless log in OffsetsForLeaderEpoch [KC-852] #888

Closed
unknown closed this pull request without merging on Nov 24, 2026 10:12 UTC
View on GitHub
unknown unknown commented on Nov 20, 2026 09:38 UTC
Author

A consumer that reads past the seal of a switched partition resets to the seal the next time it validates its position. It then re-reads every record from the seal to that position.

Problem

Diskless produce stamps every batch with leader epoch 0 (UnifiedLog.LEADER_EPOCH), and FetchHandler returns the batches with that epoch. A consumer that tails a switched partition therefore holds a position past the seal with offsetEpoch=0.

The consumer validates a position with OffsetsForLeaderEpoch in two cases: when it resumes from a committed offset that carries a leader epoch, and when a metadata update shows a different leader or leader epoch for the partition. The request carries the epoch of the position and no offset.

For a switched partition, ReplicaManager.lastOffsetForLeaderEpoch asks the local classic log first. If the classic end offset is at or below classicToDisklessStartOffset, the broker returns it. In the classic log, epoch 0 is a real epoch that ends at or below the seal, so the broker answers the diskless placeholder with a classic end offset. The consumer treats an end offset below its position as a truncation.

Example on main

The setup matches testLastOffsetForLeaderEpochKeepsPlaceholderEpochPositionPastSeal:

| Item | Value |
| ---- | ----- |
| Classic prefix | Offsets 0 to 9, leader epoch 0 |
| Seal (classicToDisklessStartOffset) | 10 |
| Diskless leader epoch | 5 |
| Local log of the answering broker | Offsets 0 to 12, epoch cache [(epoch 0, start 0), (epoch 5, start 10)] |
| Diskless end offset | 200 |
| Consumer position | Offset 200, offsetEpoch=0 |

The validation runs in this order:

1. The consumer sends OffsetsForLeaderEpoch with leaderEpoch=0.
2. The broker asks the local classic log. LeaderEpochFileCache.endOffsetFor(0) returns the start offset of the next cached epoch, which is 10.
3. The classic answer, 10, is at or below the seal, so the broker returns endOffset=10.
4. The consumer compares the end offset with its position. 10 is less than 200, so the consumer logs Truncation detected and seeks to offset 10.
5. The consumer reads offsets 10 to 199 a second time.

Fix

For a switched partition, the broker answers a request for epoch 0 with the diskless end offset. The classic log still answers every other epoch that ends at or below the seal.

The diskless answer for a switched partition is at least the committed seal. A control-plane placeholder row reports end offset 0, and without the floor a consumer in the classic prefix would truncate to 0. DisklessLeaderEndPoint.atLeastCommittedSeal applies the same floor for consolidating followers.

The local lookup still runs first, so its errors, such as NOT_LEADER_OR_FOLLOWER, reach the client as before.

The rule keys on the requested epoch, not on the classic answer. If the classic log had leader changes before the switch, classic epoch 0 ends at the start of classic epoch 1, which is below the seal. A check that compares the classic answer with the seal doesn't catch that case.

The same example with the fix

1. The consumer sends OffsetsForLeaderEpoch with leaderEpoch=0.
2. The requested epoch is 0, so the broker doesn't use the classic answer. It asks the control plane for the end offset, which is 200.
3. 200 is above the seal, 10, so the floor doesn't apply. The broker returns endOffset=200.
4. The consumer compares the end offset with its position. 200 isn't less than 200, so the validation completes and the consumer keeps position 200.

Trade-offs

  • A consumer whose position is in the classic prefix with a real epoch 0 gets the diskless end offset, which is never below its position. That consumer doesn't detect a truncation of the classic log.

  • Validating a position with epoch 0 needs the control plane. If the control plane lookup fails, the broker returns the error for that partition instead of a local answer.

  • Batches that FetchHandler returns still carry epoch 0.
  • Test plan

  • testLastOffsetForLeaderEpochKeepsPlaceholderEpochPositionPastSeal builds the example and expects end offset 200 for epoch 0. On main it fails with expected: <200> but was: <10>.

  • testLastOffsetForLeaderEpochHybridFloorsDisklessEndOffsetAtSeal has the control plane report end offset 0 for a partition sealed at 101 and expects end offset 101.

  • testLastOffsetForLeaderEpochHybridAtSwitchBoundaryUsesLocalLog and testLastOffsetForLeaderEpochHybridAtSwitchBoundaryUsesFollowerLocalLog asserted that the classic log answers epoch 0. They now build the classic prefix with epoch 1 and request epoch 1, so they still cover the classic answer at the seal.

  • ReplicaManagerInklessTest (309 tests) and InklessDisklessListOffsetsTest (5 tests) pass.

  • On a 3-broker cluster with the InklessTopicTypeSwitcherClusterTest setup, a consumer tails a switched partition sealed at offset 20 and commits offset 50 with leaderEpoch=0. A second consumer in the same group starts at offset 20 on main and at offset 50 with this change. That test isn't part of this PR, because its precondition depends on timing: a consumer that starts after consolidation catches up reads the local log, commits leaderEpoch=2, and resumes at its committed offset on main.

  • make vale reports no inkless-owned prose to lint in this change.

  • The system test test_switch_succeeds_with_degraded_network, where the failure first showed, passes in 3 local runs on this change. In 2 of the runs, the consumer validates a position with epoch 0 about 3 seconds after phase 2 starts, on 3 partitions in total. Each answer is above the partition's seal: 1836 for seal 1674, 1908 for seal 1742, and 1757 for seal 1625. In the third run, the consumer validates only at the seal. The test wasn't run on main locally.
  • 🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: giuseppelillo Review duration: 5793m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    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.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #888"
    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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 20.5% · Safe to merge
    20.5%
    Repository