You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cache sometimes gets ignored for unchanged files #22159
I ran into a case where the cache would be marked stale on the second run, despite files not changing!
To Reproduce
This was minimized by an LLM, the original case is significantly more complicated. Additionally, it may still not be fully minimized. The directory structure looks like this:
├── a.py
├── b.py
├── e.py
└── site
└── ns
└── sub
├── __init__.py
└── py.typed
site/ns/sub/__init__.py and site/ns/sub/py.typed are empty.
Expected Behavior
Second run doesn't need to do any work and just reads from cache.
Actual Behavior
Running PYTHONPATH=site uv run mypy -v a.py e.py 2>&1 | rg 'Scheduling SCC', the first run gets:
LOG: Scheduling SCC of size xxx (xxx) as inherently stale
LOG: Scheduling SCC singleton (ns) as inherently stale
LOG: Scheduling SCC singleton (ns.sub) as inherently stale
LOG: Scheduling SCC singleton (a) as inherently stale
LOG: Scheduling SCC singleton (b) as inherently stale
LOG: Scheduling SCC singleton (e) as inherently stale
and the second run gets:
LOG: Scheduling SCC singleton (a) as inherently stale
Your Environment
Mypy version used: 2.4.0
Mypy command-line flags: -v
Mypy configuration options from mypy.ini (and other config files): N/A
Root cause: load_graph()'s up-suppress pass re-adds a suppressed dependency via add_dependency(), which appends it at the end of State.dependencies. That reorders the list without changing its membership, and State.is_fresh() compares the dependency list order-sensitively against the cache — so on a warm run the unchanged module looks "changed" and the cache is ignored (the symptom in the report).
Fix: compare the dependency lists as sets in State.is_fresh() (mypy/build.py, +11/−1) with a regression test in mypy/test/testcache.py (+82). Evidence: the test reproduces the spurious rebuild at the parent commit (RED) and passes with the fix (GREEN); full suite 12,534 passed with one failure proven pre-existing on the parent tree; black and ruff clean.
Happy to rebase it onto current main or split out just the regression test if that helps.
Activity
Shanmukh-l33t commentedon Nov 11, 2026
A tested fix for this is available if it is useful for fold-in: https://github.com/Shanmukh-l33t/mypy/tree/fix-22159-stale-cache-a (commit
4d68fe37d2b213fa5f2b937f7aa850c5cf61ddd1, previously #22403 — closed unmerged, no action needed there).Root cause:
load_graph()'s up-suppress pass re-adds a suppressed dependency viaadd_dependency(), which appends it at the end ofState.dependencies. That reorders the list without changing its membership, andState.is_fresh()compares the dependency list order-sensitively against the cache — so on a warm run the unchanged module looks "changed" and the cache is ignored (the symptom in the report).Fix: compare the dependency lists as sets in
State.is_fresh()(mypy/build.py, +11/−1) with a regression test inmypy/test/testcache.py(+82). Evidence: the test reproduces the spurious rebuild at the parent commit (RED) and passes with the fix (GREEN); full suite 12,534 passed with one failure proven pre-existing on the parent tree;blackandruffclean.Happy to rebase it onto current main or split out just the regression test if that helps.