facebook/flow · error · std::io::Error
invalid file index
Error message
invalid file index
What it means
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.
Source
Thrown at rust_port/crates/flow_heap/src/transaction.rs:919
}
self.with_committed_state(|state| {
let mut gc_state = state.gc_state.lock();
gc_state.new_alloc_size = gc_state.new_alloc_size.saturating_add(count);
});
}
fn file_index(file_to_index: &BTreeMap<FileKey, u32>, file: &FileKey) -> u32 {
*file_to_index
.get(file)
.expect("file should have been collected in heap file table")
}
fn file_from_index(files: &[FileKey], index: u32) -> io::Result<FileKey> {
files
.get(index as usize)
.map(Dupe::dupe)
.ok_or_else(|| io::Error::new(io::ErrorKind::InvalidData, "invalid file index"))
}
fn collect_dependency_file_keys(dependency: &Dependency, file_keys: &mut BTreeSet<FileKey>) {
match dependency.target() {
DependencyTarget::HasteModule(_) => {}
DependencyTarget::File(file) => {
file_keys.insert(file.dupe());
}
}
}
fn collect_resolved_module_file_keys(
module: &crate::resolved_requires::ResolvedModule,
file_keys: &mut BTreeSet<FileKey>,
) {
if let Some(dependency) = module.as_dependency() {
Self::collect_dependency_file_keys(&dependency, file_keys);
}View on GitHub (pinned to f88ac94bcf)
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.
Example fix
# before: stale heap written by an older build keeps failing to load flow check # after: drop saved state so the heap is rebuilt from sources rm -rf .flow-saved-state # or your configured saved-state directory flow check
Defensive patterns
Strategy: fallback
Type guard
fn is_invalid_file_index(e: &std::io::Error) -> bool {
e.kind() == std::io::ErrorKind::InvalidData && e.to_string().contains("invalid file index")
} Try / catch
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.
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- hh_load_heap: invalid magic number
- hh_load_heap: invalid shard count
- Can't decode daemon parameters: {}
- failed to decompress
- failed to deserialize AST
AI-assisted analysis of facebook/flow@f88ac94bcf (2026-08-20).
Data as JSON: /api/errors/71c592285a864e37.
Report an issue: GitHub.