AI Notes
Failing Test
tests/lsp/test_reference_macro_find_all.py::test_multi_repo_macro_references
What's Wrong
The on-disk model cache is not written atomically. FileCache.put opens the cache file with "wb", which truncates it, then pickle/gzip writes the contents.
With xdist, two workers can share the same cache file. A reader can open the file after truncate and before the write finishes. pickle.load then fails with “Ran out of input”. In this run, silver.d never made it into the LSP map.
This is a cache race, not a bad assertion in the LSP test.
Possible Fix
In sqlmesh/utils/cache.py FileCache.put, stop writing the cache file in place ("wb" truncates it first).
- Write the gzip/pickle to a temp file in the same directory.
os.replace that temp file onto the real cache path.
That way another pytest-xdist worker never reads a half-written models__d entry.
Optionally retry FileCache.get once if pickle hits EOF / “Ran out of input”, then load from SQL.
Don’t xfail the LSP test. The test is fine; the cache write is the bug.
AI Notes
Failing Test
tests/lsp/test_reference_macro_find_all.py::test_multi_repo_macro_referencesWhat's Wrong
The on-disk model cache is not written atomically.
FileCache.putopens the cache file with"wb", which truncates it, then pickle/gzip writes the contents.With xdist, two workers can share the same cache file. A reader can open the file after truncate and before the write finishes.
pickle.loadthen fails with “Ran out of input”. In this run,silver.dnever made it into the LSP map.This is a cache race, not a bad assertion in the LSP test.
Possible Fix
In
sqlmesh/utils/cache.pyFileCache.put, stop writing the cache file in place ("wb"truncates it first).os.replacethat temp file onto the real cache path.That way another pytest-xdist worker never reads a half-written
models__dentry.Optionally retry
FileCache.getonce if pickle hits EOF / “Ran out of input”, then load from SQL.Don’t xfail the LSP test. The test is fine; the cache write is the bug.