← Back to Pull requests

fix: node: bound the number of hops a forwarded request may take #11

Closed
unknown closed this pull request without merging on Nov 03, 2026 10:46 UTC
View on GitHub
unknown unknown commented on Oct 31, 2026 16:15 UTC
Author

Finding

P2 — a forwarded request has no hop limit, so two confused nodes can bounce it forever.

handle_forward_request re-enters execute_or_forward. If node A's metrics say the leader is B and node B's say it is A (stale metrics after a partition, or a leader that has not noticed its demotion), the request bounces between them. RETRY_TOTAL_BUDGET is per hop and the request carries no hop information, so client-visible latency is unbounded and every bounce holds a pooled connection.

The fix

  • MAX_FORWARD_HOPS = 3; the hop count travels in the gRPC RaftRequest envelope (uint32 hops = 2), not in the postcard ForwardRequest.

  • The budget is spent when forwarding: a node that can serve the request (for example, it is the leader) always does; a node that would have to pass it on at the limit returns the retryable LeaderTransition error, so the origin re-resolves leadership instead of extending the chain.

  • Local requests start at hops = 0, so the bound only applies to the forwarding chain.

  • RaftNode::handle_forward_request is now pub(crate): the gRPC service is its only meaningful caller.

  • Removed the dead NetworkConnection::forward, which hardcoded hops: 0 and would have silently reset the counter.
  • Why the envelope, not ForwardRequest

    postcard decodes structs by fixed field count: an old request (no hops) fails on a new node with DeserializeUnexpectedEnd, and #[serde(default)] does not help there. The reverse direction ignores trailing bytes, so compatibility was asymmetric. The protobuf envelope is additive: old nodes ignore the unknown field and new nodes default to hops = 0, so mixed versions keep decoding in both directions.

    Rolling upgrades

    An old node does not propagate the field, so it resets the count to 0. During a rolling upgrade the 3-hop bound is therefore enforced only between nodes that understand it; once every node is upgraded it is fully effective. There are no decode failures in either direction.

    Tests

  • test_hop_budget_is_finite covers may_forward, including u32::MAX from a peer.

  • test_hop_count_roundtrips_in_the_envelope checks the postcard body stays independently decodable and the protobuf envelope carries hops.

  • test_old_envelope_decodes_with_zero_hops decodes an envelope with only field 1 and verifies hops = 0.
  • cargo fmt --check, cargo clippy --all-features --all-targets -- -D warnings and cargo test pass.

    Diff: 311 lines (+233 / -78) across 3 files Reviewer: lichuang Review duration: 3990m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 311 lines diff across 3 files
    0.40
    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.344
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #11"
    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: 40.3% (MEDIUM) · Higher = larger blast radius
    40.3%
    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.9% · Safe to merge
    15.9%