fix(inkless:switch): don't answer a classic epoch from a log that ends below the seal [KC-866] #901
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
viktorsomogyi
A phase 2 leader whose local log ends below the seal answers
OffsetsForLeaderEpochfor 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.makeLeadermaps the new leader epoch to the log end offset in the leader epoch cache, andReplicaManager.maybeReconcileSwitchedLeaderkeeps the partition online so that consolidation rebuilds the log.Until then,
ReplicaManager.lastOffsetForLeaderEpochanswers a classic epoch from that cache.LeaderEpochFileCache.endOffsetForfinds 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.hasCompleteLocalClassicPrefixonly makes a follower with a high watermark below the seal answerNOT_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:
OffsetsForLeaderEpochfor the classic epoch with end offset 0 for about 6 ms, and with 20 afterward.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
ReplicaManagerInklessTesthas 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 toReplicaManager. The class passes with 316 tests.OffsetsForLeaderEpochfor the classic epoch to the new leader. The leader answeredNOT_LEADER_OR_FOLLOWERand 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:spotbugsMainpass.make valereports no alerts on the added lines.🤖 Generated with Claude Code