From 6216bf870a88c322f3ee760b1ed90c7f8e7232ef Mon Sep 17 00:00:00 2001 From: Thomas Korrison Date: Tue, 24 Feb 2026 15:10:09 +0000 Subject: [PATCH 1/2] Apply suggested fix to src/store/weight.rs from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> --- src/store/weight.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/store/weight.rs b/src/store/weight.rs index 4199ede..6565bea 100644 --- a/src/store/weight.rs +++ b/src/store/weight.rs @@ -551,6 +551,7 @@ where /// ``` pub fn remove(&mut self, key: &K) -> Option> { let entry = self.map.remove(key)?; + debug_assert!(self.total_weight >= entry.weight, "total_weight underflow in remove"); self.total_weight = self.total_weight.saturating_sub(entry.weight); self.metrics.inc_remove(); Some(entry.value) From 047bb8800a824971c4722b53eb0bcaf2b24310b1 Mon Sep 17 00:00:00 2001 From: Thomas Korrison Date: Tue, 24 Feb 2026 15:10:09 +0000 Subject: [PATCH 2/2] Apply suggested fix to src/store/weight.rs from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> --- src/store/weight.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/store/weight.rs b/src/store/weight.rs index 6565bea..11ef612 100644 --- a/src/store/weight.rs +++ b/src/store/weight.rs @@ -501,7 +501,16 @@ where pub fn try_insert(&mut self, key: K, value: Arc) -> Result>, StoreFull> { let new_weight = self.compute_weight(value.as_ref()); if let Some(entry) = self.map.get_mut(&key) { - let next_total = self.total_weight - entry.weight + new_weight; + debug_assert!( + self.total_weight >= entry.weight, + "WeightStore invariant violated: total_weight ({}) is less than entry.weight ({})", + self.total_weight, + entry.weight + ); + let next_total = self + .total_weight + .saturating_sub(entry.weight) + .saturating_add(new_weight); if next_total > self.capacity_weight { return Err(StoreFull); }