fix(hw-oracle): invalidate cache when compiler changes in place #12821
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12821"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by malekaifa on 2026-10-29T11:21:04Z.
What
The hw-oracle build cache already keys the compiled HSA oracle by the source, compiler command, resolved compiler path, and ROCm root. If the compiler executable is replaced at the same resolved path (for example by an in-place toolchain/package upgrade), that key does not change and
oracle()can silently reuse a binary built by the previous compiler.Include inexpensive file identity for the selected compiler in the cache configuration: resolved path, device/inode, size, mtime and ctime. This catches the normal replacement/update cases without hashing a potentially very large compiler binary on every cache lookup.
The regression keeps
CC,PATH, and the resolved compiler path unchanged, replaces the executable at that path, and verifies that the second call rebuilds instead of returning the first cached oracle.Tested
ba5b5330b37724bca4b99f30faab504653635a04:test_replacing_selected_compiler_invalidates_the_cachefails withb'first' != b'other', proving the old cache key reuses the stale build.tools/hw-oracle/test_hw_oracle.py— 49 tests OK, 5 expected platform skips.tools/hw-oracle/test_hw_oracle.py— 49 tests OK, 5 expected platform skips.tools/hw-oracle/test_compare_results.py— 12 tests OK on each.test_hw_oracle.py— 49 tests OK, 2 expected skips;test_compare_results.py— 12 tests OK.py -3.12 tools/check_conventions.py --base ba5b5330b37724bca4b99f30faab504653635a04— passed.git diff --check— clean.py_compile— passed.oracle()/OracleConfigurationTests; #12812 changesoracle_hip.pyand later HIP tests.Exact head:
b7bdfa8996abe65e60bd6d16d3aaa745d8e7b4ac.Checklist
main; no other open PR implements the same behavior.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-29T11:24:05Z.
Review: COMMENTED
🟢 Approval recommended
No active review issues are recorded for the compiler-aware cache invalidation change.
No open issues 🎉
What changed in this PR
Updates the hardware-oracle build cache to detect compiler changes at the same resolved path, preventing reuse of binaries built with an outdated compiler.
Changes:
tools/hw-oracle/test_hw_oracle.pytools/hw-oracle/hw_oracle.pyReview effort: Balanced
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T11:26:19Z.
Review: APPROVED
Reviewed — approved
The cache key now includes the selected compiler's file identity, the new regression test fails on
mainand passes with the change, and the existing hw-oracle tests still pass.What I ran
b7bdfa8996abe65e60bd6d16d3aaa745d8e7b4acmain:ba5b5330b37724bca4b99f30faab504653635a04--no-ffmerge of head intomain): clean, no conflicts.The change is Python-only and the two ctest entries run the scripts directly, so no C++ build was needed.
Results
maingit diff --checkcheck_conventions.py --base origin/mainAll conventions checks passed.hardware_oracle,hardware_oracle_comparetest_hw_oracle.py -vcomgr from AMD's Windows driver)main'shw_oracle.pyctest
Relevant test lines
Negative control
I restored only
tools/hw-oracle/hw_oracle.pyfrommainand kept the PR's test file. The new test then fails:Output
This matches the result in the description. The test is a good test of the change. It rewrites the fixture in place with
write_text, so the inode stays the same, andb"first"andb"other"are the same length, so the size stays the same too. Only the mtime (set explicitly withos.utime) and the ctime change, which means the test checks the timestamp fields specifically and not just a new inode.Findings
Blocking
None.
Non-blocking
tools/hw-oracle/hw_oracle.py:64-70only statscompiler[0]. WhenCCis a wrapper command such asCC="ccache gcc", the identity recorded is the wrapper's, so a compiler upgraded in place behind it still reuses the stale oracle. The plaincc/gcc/clangcase works because a package upgrade also replaces the driver binary. This limitation already existed for the resolved path, and I don't think it needs to be fixed in this PR. If you want to cover it, you could stat every word ofcompilerthatshutil.whichresolves.st_ctime_nsmeans some metadata-only events also trigger a rebuild, such aschmod, or creating or removing a hard link to the compiler. A rebuild is one compile oforacle.c, so this costs little, and it does catch acp -preplacement that keeps the mtime. Each such event leaves an unused directory under the cache. Again, this behaviour already existed for other configuration changes.Not verified
nt, and I only ran on Linux.Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T13:10:43Z.
Review: APPROVED
Reviewed — approved
Folding the selected compiler's file identity into the cache key fixes the stale-oracle reuse. The new regression fails on
mainand passes on this head, and I found no regressions on macOS.What I ran
Head
b7bdfa8996abe65e60bd6d16d3aaa745d8e7b4ac, currentmain157b02c4f1, macOS arm64 (this adds a platform the body doesn't list; it only covers Windows and WSL).tools/hw-oracle/test_hw_oracle.pyon the head: OK (skipped=3) on Python 3.9.6, 3.13.13 and 3.15.1.main'shw_oracle.py→test_replacing_selected_compiler_invalidates_the_cacheFAILS withb'first' != b'other'. The otherOracleConfigurationTestspass.git merge-tree --write-treeagainstmainis clean. Merging this head with #12815 and with #12812 is also clean.git diff --checkis clean.tools/check_conventions.py --base upstream/mainpasses.tools/pr_overlap.py --branchprobed 1406 PRs: 3 share files and all merge cleanly, so no overlap.Extra probes (outside the PR's test)
os.utimeset to the old timestamp, thenos.replaceover the selected path) → the secondoracle()rebuilds (b'AAAAA'→b'BBBBB'). This is the package-manager orcp -p+ rename case, and inode/ctime catch it even though size and mtime both match.CCnaming a symlink to the fixture compiler resolves to the target and builds as before.Mutants
These are single-field removals from the
selectedtuple, run againstOracleConfigurationTests:int(st_mtime),int(st_ctime)main)The single-field survivors are expected: the fields are deliberately redundant, and an in-place rewrite always moves ctime. I don't think pinning each field is worth a fragile test. If you want a second guard, the atomic-rename row above is cheap. It would make ino/ctime the only signal and would keep a future "size + mtime only" simplification from silently passing. I checked that: with
selected = (str(path), status.st_size, status.st_mtime_ns),OracleConfigurationTestsstill passes, but the atomic-rename probe returns the staleb'AAAAA'. Optional; it's not blocking.AI-assisted: yes