← Back to Pull requests

fix: types: honour AddNode.overriding and stop stamping the unused time_ms #13

Closed
unknown closed this pull request without merging on Nov 03, 2026 07:30 UTC
View on GitHub
unknown unknown commented on Oct 31, 2026 16:17 UTC
Author

Finding

P2 — a command field that changes behaviour is ignored, and a log field that
nothing reads is stamped with a misleading contract.

Two dead/lying pieces of the state-machine input:

1. Cmd::AddNode { node, overriding } is documented as "Whether to override
existing record"
, but apply_add_node ignored it and always called
add_node, which overwrites
(src/raft/store/statemachine.rs, apply_cmd / apply_add_node).
LeaderHandler::add_node writes the sync of existing members with
overriding: true and the joining node with overriding: false, so the two
cases were meant to differ.
2. LogEntry::time_ms is set on every write
(do_write: entry.time_ms = Some(now_millis())) and read by nobody — the
TTL support that used it was deleted. Its doc still claims "State machine
depends on clock time to expire values. The time to use has to be consistent
on leader and followers. Otherwise an apply results in different state on
leader and followers."
— a description of a determinism hazard that no
longer exists, attached to a value that costs bytes in every log entry.

How to reproduce

sm.add_node(Node { node_id: 3, endpoint: Endpoint::new("127.0.0.1", 7003) })?;

// the join path writes this: "do not override an existing record"
sm.apply_add_node(&Node { node_id: 3, endpoint: Endpoint::new("127.0.0.1", 9999) }, false)?;

assert_eq!(sm.get_nodes()?.get(&3).unwrap().endpoint.port(), 7003);  // fails: it is 9999

For time_ms: grep -rn 'time_ms' src/ shows one writer and zero readers.

The fix

  • apply_add_node(node, overriding) inserts only when overriding is true or

  • the node is not in the table yet, matching the flag's documentation and
    databend's semantics for the same command.
  • do_write no longer stamps time_ms; entries written now carry None.
  • The field itself stays: log entries already persisted in RocksDB were
    encoded with it, so dropping it would make existing logs undecodable. Its doc
    now says it is reserved and not consumed, and warns that a leader-stamped clock
    must never drive apply().

    Test: test_apply_add_node_honours_overriding covers both flag values.

    Diff: 276 lines (+207 / -69) across 3 files Reviewer: lichuang Review duration: 3792m
    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 · 276 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.336
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #13"
    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: 39.6% (MEDIUM) · Higher = larger blast radius
    39.6%
    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.6% · Safe to merge
    15.6%