{"record":{"id":"b60e1544a26cdb67","repo":"RyanCodrai/turbovec","slug":"duplicate-ids-in-v7-file","errorCode":null,"errorMessage":"duplicate ids in v7 file","messagePattern":"duplicate ids in v7 file","errorType":"validation","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"turbovec/src/id_map.rs","lineNumber":934,"sourceCode":"        }\n        Ok(Self {\n            inner,\n            slot_to_id,\n            id_to_slot: std::sync::OnceLock::new(),\n            sorted_ids: std::sync::Mutex::new(sorted),\n            deferred_added: std::sync::Mutex::new(Default::default()),\n        })\n    }\n\n    /// Shared tail of the path and byte v7 loaders. `path` is `None` for\n    /// a byte image, which is not a sync destination.\n    fn from_v7_load(mut l: crate::io_v7::V7Load, path: Option<&Path>) -> std::io::Result<Self> {\n        let slot_to_id = std::mem::take(&mut l.ids);\n        let inner = TurboQuantIndex::from_v7(l, path)?;\n        let mut sorted = slot_to_id.clone();\n        sorted.sort_unstable();\n        if sorted.windows(2).any(|w| w[0] == w[1]) {\n            return Err(std::io::Error::new(\n                std::io::ErrorKind::InvalidData,\n                \"duplicate ids in v7 file\",\n            ));\n        }\n        Ok(Self {\n            inner,\n            slot_to_id,\n            id_to_slot: std::sync::OnceLock::new(),\n            sorted_ids: std::sync::Mutex::new(sorted),\n            deferred_added: std::sync::Mutex::new(Default::default()),\n        })\n    }\n\n    /// Serialize the index in the `.tvim` byte format to any\n    /// [`std::io::Write`] sink. Emits exactly the bytes [`Self::write`]\n    /// would put in the file.\n    ///\n    /// Unlike [`Self::write`] there is no atomic-replace behaviour: the","sourceCodeStart":916,"sourceCodeEnd":952,"githubUrl":"https://github.com/RyanCodrai/turbovec/blob/ccab9f325e6ce2a270a87daf01ae4e443bcf2d49/turbovec/src/id_map.rs#L916-L952","documentation":"from_v7_load validates ids read from a version-7 persisted file: after TurboQuantIndex::from_v7 loads the index, the id vector is sorted and checked for adjacent duplicates. Duplicates mean the file's id table is corrupt or was written by buggy code, so loading fails with an InvalidData io::Error rather than creating an ambiguous map.","triggerScenarios":"Loading a v7 file whose stored ids vector contains the same id twice — produced by a writer bug, corrupted/truncated-then-hand-edited file, or an ids artifact from a different build mixed in.","commonSituations":"Reading v7 files produced by an older/buggy turbovec version; files transferred or edited manually; mixing index and id side-files from different saves.","solutions":["Re-export the store in a current version from source data so the id table is written correctly.","Locate the duplicate ids (sort + compare adjacent) to identify the corrupted artifact, then restore from backup.","If migrating from an old version, run a dedup/repair pass on the ids before load and rebuild the file with the current writer."],"exampleFix":"// before\nlet map = IdMap::from_v7_load(v7_load, Some(path))?; // Err: duplicate ids in v7 file\n// after\nlet mut sorted = v7_load.ids.clone(); sorted.sort_unstable();\nif sorted.windows(2).any(|w| w[0] == w[1]) { /* repair or restore file first */ }\nlet map = IdMap::from_v7_load(v7_load, Some(path))?;","handlingStrategy":"try-catch","validationCode":"let mut s = l.ids.clone(); s.sort_unstable();\nif s.windows(2).any(|w| w[0] == w[1]) {\n    return Err(io::Error::new(io::ErrorKind::InvalidData, \"v7 ids not unique\"));\n}","typeGuard":null,"tryCatchPattern":"let map = IdMap::from_v7_load(l, Some(path)).map_err(|e| {\n    if e.kind() == io::ErrorKind::InvalidData { LoadError::CorruptV7 } else { LoadError::Io(e) }\n})?;","preventionTips":["Migrate v7 files by re-exporting with the current writer, not by editing ids.","Keep the ids table and index from the same save generation.","Validate the id table right after reading, before constructing the map."],"tags":["rust","id-map","persistence","duplicate-keys","corruption"],"backgroundTag":"duplicate-ids","analyzedSha":"ccab9f325e6ce2a270a87daf01ae4e443bcf2d49","analyzedAt":"2026-09-06T08:39:18.516Z","contentChangedAt":"2026-09-06T08:39:18.516Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}