{"record":{"id":"71c592285a864e37","repo":"facebook/flow","slug":"invalid-file-index","errorCode":null,"errorMessage":"invalid file index","messagePattern":"invalid file index","errorType":"exception","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"rust_port/crates/flow_heap/src/transaction.rs","lineNumber":919,"sourceCode":"        }\n\n        self.with_committed_state(|state| {\n            let mut gc_state = state.gc_state.lock();\n            gc_state.new_alloc_size = gc_state.new_alloc_size.saturating_add(count);\n        });\n    }\n\n    fn file_index(file_to_index: &BTreeMap<FileKey, u32>, file: &FileKey) -> u32 {\n        *file_to_index\n            .get(file)\n            .expect(\"file should have been collected in heap file table\")\n    }\n\n    fn file_from_index(files: &[FileKey], index: u32) -> io::Result<FileKey> {\n        files\n            .get(index as usize)\n            .map(Dupe::dupe)\n            .ok_or_else(|| io::Error::new(io::ErrorKind::InvalidData, \"invalid file index\"))\n    }\n\n    fn collect_dependency_file_keys(dependency: &Dependency, file_keys: &mut BTreeSet<FileKey>) {\n        match dependency.target() {\n            DependencyTarget::HasteModule(_) => {}\n            DependencyTarget::File(file) => {\n                file_keys.insert(file.dupe());\n            }\n        }\n    }\n\n    fn collect_resolved_module_file_keys(\n        module: &crate::resolved_requires::ResolvedModule,\n        file_keys: &mut BTreeSet<FileKey>,\n    ) {\n        if let Some(dependency) = module.as_dependency() {\n            Self::collect_dependency_file_keys(&dependency, file_keys);\n        }","sourceCodeStart":901,"sourceCodeEnd":937,"githubUrl":"https://github.com/facebook/flow/blob/f88ac94bcf6992f5d5a158854d94613ebb92c6e6/rust_port/crates/flow_heap/src/transaction.rs#L901-L937","documentation":"Serialized Flow heaps reference files by index into a heap file table. When the heap is loaded and a dependency is resolved back to a FileKey, file_from_index bounds-checks the index against the table; an index outside it yields ErrorKind::InvalidData \"invalid file index\". In practice the heap bytes and the file table disagree — a corrupted, truncated, or version-mismatched saved heap.","triggerScenarios":"Loading a saved-state heap whose serialized indices were written against a different file table than the one supplied at read time (format or version change between writer and reader), or a heap file truncated/corrupted by a crash or full disk during save.","commonSituations":"Upgrading Flow across a heap-format change while reusing saved state from the older build; a process killed mid-save leaving a half-written heap; disk-full during the save leaving truncated shards.","solutions":["Delete the saved-state/heap artifacts for that project so Flow rebuilds the heap from sources.","Make sure the process reading the heap is the same Flow build that wrote it (no mixed versions on PATH or in CI caches).","If it recurs, check for disk-full or filesystem corruption during the save path."],"exampleFix":"# before: stale heap written by an older build keeps failing to load\nflow check\n\n# after: drop saved state so the heap is rebuilt from sources\nrm -rf .flow-saved-state   # or your configured saved-state directory\nflow check","handlingStrategy":"fallback","validationCode":null,"typeGuard":"fn is_invalid_file_index(e: &std::io::Error) -> bool {\n    e.kind() == std::io::ErrorKind::InvalidData && e.to_string().contains(\"invalid file index\")\n}","tryCatchPattern":"Treat InvalidData 'invalid file index' as a disposable-cache failure: catch it, delete the saved heap/saved-state directory, and rebuild from sources. The heap is derived data — never surface it to users as unrecoverable.","preventionTips":["Invalidate saved state whenever the Flow version changes (include the version in the saved-state path or cache key).","Keep saved state out of shared caches across versions.","Let the server shut down cleanly; avoid killing it mid-save."],"tags":["heap","serialization","corruption","index-out-of-bounds","rust"],"backgroundTag":"index-out-of-bounds","analyzedSha":"f88ac94bcf6992f5d5a158854d94613ebb92c6e6","analyzedAt":"2026-08-20T10:41:37.992Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}