eden/.llms/rules/ACR_case_sensitivity.md
Severity: HIGH
sort() or sort_by() call in directory entry constructionBTreeMap (ordered) to HashMap (unordered) for path → entry mappings// case-sensitive only or gated on platform checksBAD (optimization changes collision resolution — matches S566000):
// "Optimization": build Vec directly instead of sorted insertion
fn build_tree_entries(raw: Vec<(PathComponent, TreeEntry)>) -> Vec<TreeEntry> {
raw.into_iter().map(|(_, entry)| entry).collect()
// Without sorting, which entry wins for "README" vs "readme" is
// now dependent on iteration order, not deterministic.
// Result gets written to RocksDB → corruption persists after rollback.
}
GOOD (deterministic ordering, case-aware dedup):
fn build_tree_entries(mut raw: Vec<(PathComponent, TreeEntry)>) -> Vec<TreeEntry> {
// Sort deterministically, then dedup case-insensitively for macOS/Windows
raw.sort_by(|a, b| a.0.as_bytes().cmp(b.0.as_bytes()));
raw.dedup_by(|a, b| a.0.eq_ignore_ascii_case(&b.0));
raw.into_iter().map(|(_, entry)| entry).collect()
}
When optimizing path-handling or tree construction code, always verify behavior on case-insensitive filesystems. Add tests for case collision scenarios ("foo" vs "Foo"). If results are written to a persistent cache (RocksDB, on-disk), include a schema version so corrupted entries can be detected and re-derived on upgrade. Be especially cautious with optimizations that change ordering — the performance win is rarely worth the correctness risk.