Medium: switching GGUF model directories can reuse stale metadata and file paths from the prior root
Impact
Medium / incorrect model metadata — switching the configured GGUF directory can reuse stale cached metadata and a stale absolute file path from the previous directory when both roots contain a same-named file with the same size and preserved mtime. The inventory then describes file A even though inference resolves and loads file B.
Evidence
model_directory.py:212–218: one long-livedGGUFModelDirectoryinstance holds_cacheacross scans.model_directory.py:234–252: its cache key is only the relative filename, and its fingerprint is only file size and mtime_ns. Changingrootwithout changing either reuses the previousInstalledModel.model_directory.py:334–377:InstalledModelretainspath=str(path), architecture, context length, and quantization metadata from whichever root produced it.app_factory.py:115–143: the directory is a dynamic settings getter, but the samegguf_model_directoryinstance remains in use across changes.- Existing
test_scan_cache_is_invalidated_by_mtime_and_sizetests changes within one directory; it doesn't test changing the directory while both files have the same stat signature.
Deterministic reproduction
- Create two folders A and B, each containing
model.gguf. Give them different valid GGUF metadata/contents but the same byte count. Copy or setmtime_nsto exactly the same value (common aftershutil.copy2, backup restore, or metadata-preserving moves). - Construct
GGUFModelDirectory(lambda: selected_root), whereselected_root=A, and scan. Metadata andpathrefer to A. - Change
selected_root=B, scan again through the same directory object. - Actual: the
(relative,size,mtime_ns)cache hit returns A'sInstalledModel, includingpath=A/model.ggufand its context/quantization, whileresolve_pathpoints to B. - Expected: a settings-root switch always invalidates the cache or uses the canonical root/file identity as part of its key.
Fix / regression
Track the resolved directory root and clear cached entries on change, or include it in the key; consider per-file identity for conservative replacement detection. Add two-root fixture with equal names/sizes/mtimes but different GGUF metadata, assert the second scan reports B's actual path, architecture, and context length.
Reviewed revision: e824fe2dcba0d1be127c9fff165f776186dc37e9. Source-level deterministic cache-key proof; two-root test not executed.