Return Error::Overflow from WeightedIndex::update_weights on integer overflow #1846
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.36) × (1 − Review Confidence (0.43)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.36 · 201 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 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
Shallow Review Depth
shallow_review_depth
0.344
Diff Size
diff_size
0.318
Real PR Conversation Timeline
1 comments
"Review active on #1846"
general
weight: 0.35
youdie006
CHANGELOG.mdentrySummary
WeightedIndex::update_weightsadds integer weights with a plain+=, whilenewuseschecked_add_assign. An update whose sum overflows panics in debug builds and wraps in release builds, contrary to the documentedError::Overflowand "In case of error,selfis not modified".Motivation
Details
Each weight is now added with
checked_add_assign, asnewdoes, and any overflow returnsError::Overflow, including an intermediate one in a multi-index update. For floatschecked_add_assignnever fails, so the float arithmetic is unchanged.This adds a
Weightbound toupdate_weights.newalready requires it, so only aWeightedIndexobtained throughDeserializecould lack it.The new
update_weights_overflowtest fails on master (debug: the panic; release:Ok(())instead ofErr(Overflow)).cargo test(default,serde,log,--lib --tests --no-default-features [--features=alloc,sys_rng],+nightly --all-features),cargo +1.85 test --lib,cargo fmt --all -- --checkandcargo clippy --workspace --lib --bins --tests -- -D warnings(stable) pass.Written with AI assistance (Claude); I have reviewed the change.