Repository navigation
fix(cache): keep Windows cache keys case-preserving (#4925) - #4937
Deepjyoti-Sarmah wants to merge 4 commits into
Conversation
…4925) The regression needs Windows normalization and a case-sensitive filesystem. The fixture takes the win32 branch on a case-sensitive temp dir, then checks hashing, semantic cache round trips, case-variant siblings, aliases and the word-count stat index.
os.path.normcase lowercases a path on Windows, but case sensitivity belongs to the volume. A Windows process can reach a case-sensitive WSL share, where README.md and readme.md are two files. Normalize separators and strip the extended-length prefix, then keep the caller case in the key and salt.
A cache key is not a file handle. Keep the raw caller path for is_file(), stat() and read_bytes(), and add the Windows long-path prefix only on that I/O path. The stat-index key comes from the normalized identity.
…#4925) cached_word_count() had the same key-path-as-file-path mistake. Stat the raw long-path-safe file, key the index by the case-preserving identity, and pass the caller path to compute().
|
Thanks for the pull request, @Deepjyoti-Sarmah. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify reviewed this change.
No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.
Not checked: tests were not run; formal verification proved 0 of 3 changed function(s) (1 sampled, not proven, 2 not verified).
Formal verification. PR-changed functions: 1/3 verified (0 proven, 1 may-equivalent, 0 distinguished) · 2 not verified (2 unsupported).
Not verified on this run: cached\_word\_count (unsupported), file\_hash (unsupported).
Graphify review — findings
Stops lowercasing paths on Windows when computing cache keys in file_hash and cached_word_count, so files with uppercase names or roots open correctly on case-sensitive volumes (#4925). _normalize_path now only normalizes separators and the extended-length prefix (normpath instead of normcase), and the digest salt no longer calls .lower(). Filesystem access goes through _os_long_path using the caller's original spelling. The tradeoff is that case-variant spellings of the same file on a case-insensitive Windows volume now get distinct cache keys instead of sharing one, which can cost a cache miss. Adds a Linux-runnable test file that fakes the win32 branch on a case-sensitive temp dir. It covers uppercase file and root hashing, semantic cache round-trips, no cross-hits between case variants, hardlink and symlink aliases keeping distinct hashes, and the word-count stat fastpath.
No blocking issues surfaced. 2 lower-confidence candidates did not survive cross-model review.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 2942 functions depend on the 105 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
load_cached()— 66 callers, 10 callees - worse:
save_cached()— 60 callers, 10 callees - worse:
file_hash()— 59 callers, 7 callees - worse:
cached_word_count()— 6 callers, 6 callees
Verification — 2942 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 1495 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
49 of 490 test file(s) selected (10%) via static blast radius.
tests/test_binary_media_words.py— impacttests/test_cache.py— impacttests/test_cache_long_paths.py— impacttests/test_cache_stale_import_target.py— impacttests/test_cache_windows_case_4925.py— impact, changed-testtests/test_charmap_encoding.py— impacttests/test_chunking.py— impacttests/test_csharp_partial_classes.py— impacttests/test_definition_file_portability.py— impacttests/test_detect.py— impacttests/test_extract.py— impacttests/test_extract_cache_location.py— impacttests/test_extract_cli.py— impacttests/test_grammar_cache_key.py— impacttests/test_ignore_file_encoding.py— impacttests/test_incremental_mtime_collision.py— impacttests/test_java_member_calls.py— impacttests/test_js_member_collisions.py— impacttests/test_language_override_lifecycle.py— impacttests/test_language_overrides.py— impacttests/test_llm_backends.py— impacttests/test_manifest_ingest.py— impacttests/test_msbuild_dir_evidence.py— impacttests/test_objc_field_table_remap.py— impacttests/test_out_dir_evidence.py— impacttests/test_partial_cache.py— impacttests/test_pipeline.py— impacttests/test_python_inherited_method_calls.py— impacttests/test_python_injected_factory_calls.py— impacttests/test_python_property_reads.py— impacttests/test_python_pytest_fixture_receivers.py— impacttests/test_rust_self_member_calls.py— impacttests/test_rust_use_trees.py— impacttests/test_semantic_cache_basename_recovery.py— impacttests/test_semantic_cache_out_root.py— impacttests/test_skill_persisted_scan_options.py— impacttests/test_skill_semantic_all_cached.py— impacttests/test_skillgen.py— impacttests/test_stale_prune.py— impacttests/test_stat_index_husk.py— impacttests/test_stat_index_multi_root.py— impacttests/test_stat_index_portability.py— impacttests/test_terraform_modules.py— impacttests/test_update_no_change_gate.py— impacttests/test_vbnet_extractor.py— impacttests/test_watch.py— impacttests/test_watch_manifest_location.py— impacttests/test_word_count_cache.py— impacttests/test_zero_node_no_cache.py— impact
Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.
Formal verification
No difference found (not proven): No behavior difference found in \_normalize\_path (not a proof).
The verifier ran both versions of \_normalize\_path on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.
Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.
Note: An input the sampler did not try could still differ.
Could not verify: Could not verify cached\_word\_count.
The verifier did not have enough to check cached\_word\_count, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: parameter `cache_root` is annotated `'Path | None'` — outside the synthesizable primitive/collection set
Could not verify: Could not verify file\_hash.
The verifier did not have enough to check file\_hash, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: parameter `cache_root` is annotated `'Path | None'` — outside the synthesizable primitive/collection set
· 1 grounded finding(s) anchored inline below; 3 more finding(s) on lines outside this diff (see the check run).
| return Path(os.path.normpath(s)) | ||
|
|
||
|
|
||
| def file_hash(path: Path, root: Path = Path("."), cache_root: "Path | None" = None) -> str: |
There was a problem hiding this comment.
file_hash()
fans out to 7 callees (efferent coupling); 59 callers depend on it (afferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.
…ase-preserving cache fixes #4944 resolves Rust module-qualified calls, #4945 links calls inside expression-macro arguments, and #4937 keeps cache keys case-preserving (which also shifts the POSIX salt digest for uppercase-bearing paths). All three change cached output, so warm caches must re-run. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…keys #4937 made the file_hash salt case-preserving (dropped the .lower() on the absolute-path fallback), but the existing order-independence test still asserted the lowercased salt. Update its exp_abs to match the written-case salt so it pins the new behavior instead of the retired one (#4925, #4937). Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Landed in 0.9.101 (published to PyPI), cherry-picked with your authorship preserved. Follow-up: updated an existing order-independence test (test_word_count_cache) to expect the case-preserving salt, since the digest now changes for any relative path carrying an uppercase char on POSIX too. Fixes #4925. Thanks @Deepjyoti-Sarmah. |
99b8da7 and ff8ddf5 (#4925, #4937) open files through os_long_path(), but on Windows its \\?\ spelling also leaked into cache identity. file_hash() and cached_word_count() bound the stat index to the prefixed root, so the plain cache_root that extract() passes read as a second root. Every Windows `graphify update` that re-extracts warned "stat index switched" (#3989) and flushed mid-run, and since no key was relative to the prefixed anchor, stat-index.json was written with absolute keys and a moved checkout re-hashed every file (#2199). The walked-parent match compared a plain path with the prefixed root and never matched, so under a junctioned or symlinked scan root an in-root alias took its target's salt and digest (#2832), and the out-of-root salt carried a //?/ prefix. _normalize_path() also stripped only \\?\, so the UNC form \\?\UNC\server\share became a relative key that the flush pruned, and a corpus on a network or WSL share always wrote an empty stat index. Bind the index to the normalized root as before #4925, normalize the resolved path and root before they become keys, salts or comparisons, and map \\?\UNC\ back to \\. File I/O still goes through os_long_path(). CI runs on Linux, where both helpers are the identity, so this only showed on Windows. Co-Authored-By: Claude <[email protected]> (cherry picked from commit 49616eb)
What does this PR do?
Fixes #4925.
On Windows,
file_hash()ran the caller path through_normalize_path(), which calledos.path.normcase(). That lowercased the path used foris_file(),stat()andread_bytes(). On a case-sensitive WSL share,README.mdbecamereadme.md, so the rebuild failed.The same value was also the cache key. Lowercasing made
README.mdandreadme.mdshare a digest and a semantic cache entry. When both files exist, that turns the crash into a wrong cache hit.This change separates the path used for I/O from the path used for the cache key:
_normalize_path()now keeps case.file_hash()andcached_word_count()useos_long_path()for the filesystem path. The stat-index key is case-preserving.On POSIX,
_normalize_path()still returns the path unchanged. On Windows, a case-only spelling change may now miss the cache. That is safer than returning another file's cache entry.Type of change
Evidence
Before: on
v8at 0.9.100.The reported failure:
The quieter failure, with both
README.mdandreadme.mdpresent:After:
The full suite was run with
PYTHONPATH=.so subprocess CLI tests imported this worktree instead of the installed package.Verification & Invariants
The invariant: a cache key may miss, but it must not name a different file.
The tests pin:
save_cached()andload_cached()round trip an uppercase path.cached_word_count()writes and uses the stat index for an uppercase path.Known limitations:
Path.relative_to()on Windows compares case-insensitively. Two WSL directories differing only by case can still be conflated. That is separate hardening and is not required for this issue.How was this tested?
Branch
fix/4925-windows-case-sensitive-pathis based onupstream/v8(32e5efe9, v0.9.100). It has four commits:Merge Danger
Door: Two-way.
The default path is unchanged. No cache schema bump and no graph format change. Reverting restores the old cache keys.
Blast Radius: Cache.
After merge, old lowercased cache entries on Windows become unreachable and are rebuilt. A user who spells the same file with different case may see a cache miss. That costs time and returns the correct result. Ignore rules, secret filtering, extraction and graph writing are unchanged.
Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments. No source fragments changed.