From af7fd4033e085de17207905c3089a5bfd479ee69 Mon Sep 17 00:00:00 2001 From: Kang Zhang Date: Wed, 26 Aug 2026 19:12:59 +0800 Subject: [PATCH] fix: report transferred bytes on the remote-deliver path Every other tier records blocks and bytes as a pair through `_KVCRCore._record_transfer`, which emits `TRANSFER_BLOCKS_METRIC` and `TRANSFER_BYTES_METRIC` for the same scope. The peer path records its counters individually instead, and the destination only ever recorded blocks. `TRANSFER_BYTES_METRIC` was emitted from exactly one place, hardcoded to the `source_write` scope. So a completed peer transfer reported: kvcr_transfer_bytes:('source_write',) = 51380224 kvcr_transfer_blocks:('source_write',) = 7 kvcr_transfer_blocks:('remote_deliver',) = 7 with no byte counter on the destination at all. That makes the verification step in `docs/quick-start.md` impossible to carry out as written: their block and byte counts must agree Only the block half could be checked. Record the delivered byte count next to the existing block count. The destination's `dst_descriptors` are positionally aligned with `ordered_keys` (both are populated together at the single construction site), so summing the spans for the completed keys covers exactly the keys the block counter reports. The two sides count different things by design: the source reports the bytes NIXL moved for the transfer, the destination reports the spans it committed. They line up on a fully completed transfer, which is the case the quick-start tells users to verify. Extend the existing remote-target test, which already asserted the source byte counter and the destination block counter, to cover the new counter. Signed-off-by: Kang Zhang Co-Authored-By: Claude Opus 5 (1M context) --- src/kvcr/remote_fw_dram.py | 14 ++++++++++++++ tests/unit/test_kvcr_remote_target.py | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/src/kvcr/remote_fw_dram.py b/src/kvcr/remote_fw_dram.py index ed44509..974d73f 100644 --- a/src/kvcr/remote_fw_dram.py +++ b/src/kvcr/remote_fw_dram.py @@ -162,6 +162,20 @@ def progress( len(completed_keys), (scope,), ) + # Descriptors are positionally aligned with ordered_keys, so + # the delivered span sizes give the byte count for the same + # keys the block counter above reports. + backend._record_progress_counter( + TRANSFER_BYTES_METRIC, + sum( + descriptor.size + for key, descriptor in zip( + self.ordered_keys, self.dst_descriptors + ) + if key in completed_keys + ), + (scope,), + ) result = ( "success" if all_completed diff --git a/tests/unit/test_kvcr_remote_target.py b/tests/unit/test_kvcr_remote_target.py index 25a32bd..34dac13 100644 --- a/tests/unit/test_kvcr_remote_target.py +++ b/tests/unit/test_kvcr_remote_target.py @@ -650,3 +650,9 @@ def test_remote_framework_dram_transfers_available_prefix( completed_count, ("remote_deliver",), ) in target_stats.records + assert ( + "counter", + TRANSFER_BYTES_METRIC, + completed_count * _mem_descriptor().size, + ("remote_deliver",), + ) in target_stats.records