← Back to Pull requests

fix: service: keep RaftReply.error a decodable ApiError #8

Closed
unknown closed this pull request without merging on Nov 03, 2026 01:35 UTC
View on GitHub
unknown unknown commented on Oct 31, 2026 16:12 UTC
Author

Finding

P2 — RaftReply.error has two encodings, and the fallback loses the error.

src/service/raft_service_impl.rs::error_reply postcard-encodes an ApiError
into RaftReply.error — except in the branch that runs when that encoding
fails:

Err(e) => {
    tracing::error!("Failed to serialize ApiError: {}", e);
    pb::RaftReply {
        data: Vec::new(),
        error: format!("internal error: {}", err).into(),   // plain UTF-8
    }
}

Every client decodes the field with decode::<ApiError>(...)
(forward.rs::forward_request_to_leader, cluster.rs::join_via,
network/connection.rs::forward). Handed plain text, they fail with

Failed to deserialize error response: ...

so the original error, its kind, and its retryability are all lost — the exact
failure the unified ApiError wire codec was introduced to fix.

The branch is nearly unreachable (the payload is an enum of Strings and an
Option<u64>), but "nearly" is not a wire format: the invariant is that this
field is always a postcard ApiError.

How to reproduce

let reply = RaftServiceImpl::error_reply(&Error::internal("boom"));
// before: reply.error == b"internal error: internal error: boom"
let decoded = decode::<ApiError>(&reply.error);   // Err(...)

The same holds for a redirect: a fallback-encoded ForwardToLeader reply loses
its leader id, so the client can no longer forward.

The fix

The fallback now encodes an ApiError::Internal with the same codec, so the
field always carries the format its readers use; should that ever fail too, the
field stays empty (the client reports a decode error rather than acting on
garbage).

Tests added: test_error_reply_is_a_decodable_api_error and
test_error_reply_keeps_the_redirect_target (leader id survives the wire and
stays forwardable). cargo fmt --check, cargo clippy --all-features -- -D
warnings
and cargo test --lib (84 tests) pass.

Diff: 242 lines (+181 / -61) across 3 files Reviewer: lichuang Review duration: 3443m
All Vouch review confidence checks passed
Residual risk 0.15 = Change Risk (0.39) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 242 lines diff across 3 files
0.39
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.329
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8"
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: 38.8% (MEDIUM) · Higher = larger blast radius
38.8%
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: 15.3% · Safe to merge
15.3%