{"record":{"id":"145fdf42463d9d7b","repo":"clockworklabs/SpacetimeDB","slug":"no-valid-commit-found-in-index-up-to-key-candida","errorCode":null,"errorMessage":"No valid commit found in index up to key: {candidate_last_key}","messagePattern":"No valid commit found in index up to key: (.+?)","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"crates/commitlog/src/segment.rs","lineNumber":745,"sourceCode":"                        },\n                        size_in_bytes: byte_offset + commit.size_in_bytes,\n                        max_epoch: commit.epoch,\n                        max_commit_offset: commit.tx_range.start,\n                        max_commit: Some(commit),\n                    });\n                }\n\n                // `TxOffset` at `byte_offset` is not valid, so try with previous entry\n                Err(_) => {\n                    candidate_last_key = key.saturating_sub(1);\n                    if candidate_last_key == 0 {\n                        break;\n                    }\n                }\n            }\n        }\n\n        Err(io::Error::new(\n            ErrorKind::InvalidData,\n            format!(\"No valid commit found in index up to key: {candidate_last_key}\"),\n        ))\n    }\n\n    /// Validates and decodes a commit at `byte_offset` in the segment.\n    ///\n    /// # Returns\n    /// * `Ok(commit::Metadata)` - If a valid commit is found with matching transaction offset\n    /// * `Err` - If commit can't be decoded or has mismatched transaction offset\n    fn validate_commit_at_offset<R: io::Read + io::Seek>(\n        reader: &mut R,\n        tx_offset: TxOffset,\n        byte_offset: u64,\n    ) -> io::Result<commit::Metadata> {\n        reader.seek(SeekFrom::Start(byte_offset))?;\n        let commit = commit::Metadata::extract(reader)?\n            .ok_or_else(|| io::Error::new(ErrorKind::InvalidData, \"failed to decode commit\"))?;","sourceCodeStart":727,"sourceCodeEnd":763,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/commitlog/src/segment.rs#L727-L763","documentation":"While validating/rebuilding an offset index, the code walked candidate keys downward (decrementing on every entry that failed validation) and reached 0 without finding a single valid commit (InvalidData). The index contains no entry consistent with the segment data - typically an empty-but-present index, or one that belongs to different segment contents.","triggerScenarios":"The segment was rewritten or truncated while its old .idx file was kept; an .idx from a different segment was copied in; wholesale index corruption so every candidate entry fails validation.","commonSituations":"Manual file surgery on the data directory; backup/restore procedures that mix index files and segments; crashes during initial index creation.","solutions":["Delete the segment's .idx file - it is a rebuildable cache - and let the log regenerate it from segment data","If validation still fails after the rebuild, the segment data itself is damaged: quarantine/restore it","Prevent external modification of the directory while the log is open"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":"fn is_index_unusable(e: &io::Error) -> bool {\n    e.kind() == io::ErrorKind::InvalidData\n        && e.to_string().contains(\"No valid commit found in index\")\n}","tryCatchPattern":"match rebuild_index_for(&segment) {\n    Ok(idx) => idx,\n    Err(e) if is_index_unusable(&e) => {\n        // no index entry matches the data: delete .idx and rebuild from the segment itself\n        std::fs::remove_file(index_path_for(&segment))?;\n        rebuild_index_for(&segment)?\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Remember .idx files are rebuildable caches: deleting them (log closed) is always safe","Keep backup/restore procedures from mixing .idx files of one segment with another","Forbid external tools from rewriting segment files in the log directory"],"tags":["rust","commitlog","offset-index","index-corruption","rebuild","invalid-data"],"backgroundTag":"index-corruption","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}