All problems

Editing a Cold-Chain Packet Changes Earlier Snapshots

Level 2 · node · Data · Historical snapshots share a mutable readings array

Scenario

A fictional cold-chain monitoring system stores timestamped temperature snapshots from device packets. Its collector may reuse memory by changing the readings array after sending a packet. The current capture service retains the same array reference, so a later packet edit silently changes an earlier snapshot. Inspect ownership across the repository, service, and controller.

Requirements

Preserve an independent copy of the readings at capture time. Later changes to the caller's packet must not affect history. Do not mutate the input packet. Preserve per-device isolation, capture order, and empty history for unknown devices. Add no external dependencies.

Acceptance criteria

  • Copy the readings array at capture time so later changes to the source packet cannot alter historical records.
  • Create the capture record without mutating the source packet.
  • Keep records for different devices isolated.
  • Preserve capture order when the same device is recorded multiple times.
  • Return stored values in history queries and an empty array for unknown devices.