{"record":{"id":"c91e35f328667ae9","repo":"nautechsystems/nautilus_trader","slug":"position-snapshot-frame-snapshot-index-for-posi","errorCode":null,"errorMessage":"position snapshot frame {snapshot_index} for {position_id} already exists with different bytes","messagePattern":"position snapshot frame (.+?) for (.+?) already exists with different bytes","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/common/src/cache/position.rs","lineNumber":276,"sourceCode":"\n    /// Restores the cache-owned snapshot blob stored under `blob_ref`.\n    ///\n    /// Only cache-owned `cache://position-snapshots/...` blobs are currently supported.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the blob reference is unsupported, malformed, skips earlier\n    /// snapshot frames, conflicts with an existing frame, or does not decode to the expected\n    /// position snapshot.\n    pub fn restore_snapshot_blob(&mut self, blob_ref: &str, blob: Bytes) -> anyhow::Result<()> {\n        let (position_id, snapshot_index) = parse_position_snapshot_blob_ref(blob_ref)?;\n        let restored = decode_position_snapshot_blob(&position_id, blob.as_ref())?;\n\n        let frames = self.position_snapshots.entry(position_id).or_default();\n        match frames.get(snapshot_index) {\n            Some(existing) if existing.encoded()? == blob => {}\n            Some(_) => {\n                anyhow::bail!(\n                    \"position snapshot frame {snapshot_index} for {position_id} already exists with different bytes\"\n                );\n            }\n            None if frames.len() == snapshot_index => {\n                frames.push(PositionSnapshotFrame::new(restored, Some(blob.clone())));\n            }\n            None => {\n                anyhow::bail!(\n                    \"position snapshot blob_ref {blob_ref} skips missing frame {}\",\n                    frames.len()\n                );\n            }\n        }\n\n        self.general.insert(blob_ref.to_string(), blob);\n        Ok(())\n    }\n","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/cache/position.rs#L258-L294","documentation":"`restore_snapshot_blob` restores a position snapshot frame at `snapshot_index`. If a frame already exists at that index, it is only accepted when the encoded bytes are identical; different bytes at the same index indicate a conflicting snapshot blob for that position, so the restore bails and leaves state untouched.","triggerScenarios":"Calling `restore_snapshot_blob` twice for the same (position_id, snapshot_index) with different blobs — e.g. restoring snapshots from two sources/replays, a corrupted or truncated blob, or mixing snapshot files from different sessions.","commonSituations":"Recovering a trader from multiple backup files where one snapshot was taken at a different point; re-running a restore without clearing previous snapshot state; a build/version change altering snapshot encoding.","solutions":["Clear the existing position_snapshots state before restoring a different snapshot set.","Verify the blob source: restore only one consistent snapshot lineage per position.","If bytes differ only due to encoding-version drift, re-serialize from the original source with the current version rather than re-restoring old blobs."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// before restoring, confirm no frame exists at this index or that bytes match:\n// compare the incoming blob against any existing snapshot source before calling restore_snapshot_blob","typeGuard":null,"tryCatchPattern":"match cache.restore_snapshot_blob(position_id, blob_ref, blob) {\n    Ok(()) => {},\n    Err(e) if e.to_string().contains(\"already exists with different bytes\") => {\n        // reset snapshot state or switch to a single consistent snapshot lineage\n    },\n    Err(e) => return Err(e),\n}","preventionTips":["Restore from a single snapshot lineage per position.","Clear prior snapshot state before re-running a restore.","Verify snapshot file integrity (hashes) before loading."],"tags":["rust","positions","snapshot","restore","byte-conflict"],"backgroundTag":"checksum-mismatch","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}