From ec606d5fe9ca49800645d348a013724357a92043 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 12 Feb 2026 03:35:02 +0000 Subject: [PATCH] fix: correct edge cases in delta buffer and sync metrics - DeltaBuffer.push: Only increment drops counter when pop_front() actually evicts an element. Fixes false positive drops at zero capacity where pop_front() returns None on empty deque. - SyncComplete handler: Add record_write() call for replayed operations to match GossipDelta and apply_actions behavior. Ensures write metrics are consistent across all code paths. --- crates/node/primitives/src/delta_buffer.rs | 6 ++++-- crates/node/tests/sync_sim/sim_runtime.rs | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/node/primitives/src/delta_buffer.rs b/crates/node/primitives/src/delta_buffer.rs index 171c583a9..68987ad91 100644 --- a/crates/node/primitives/src/delta_buffer.rs +++ b/crates/node/primitives/src/delta_buffer.rs @@ -92,8 +92,10 @@ impl DeltaBuffer { pub fn push(&mut self, delta: BufferedDelta) -> bool { if self.deltas.len() >= self.capacity { // Evict oldest delta (front of queue) - let _evicted = self.deltas.pop_front(); - self.drops += 1; + // Only increment drops if we actually evicted something + if self.deltas.pop_front().is_some() { + self.drops += 1; + } self.deltas.push_back(delta); false } else { diff --git a/crates/node/tests/sync_sim/sim_runtime.rs b/crates/node/tests/sync_sim/sim_runtime.rs index e9bb9136d..76b108e05 100644 --- a/crates/node/tests/sync_sim/sim_runtime.rs +++ b/crates/node/tests/sync_sim/sim_runtime.rs @@ -622,6 +622,7 @@ impl SimRuntime { for (_delta_id, operations) in buffered_ops { for op in operations { n.apply_storage_op(op); + self.metrics.work.record_write(); } }