fix(hw-oracle): clean up COMGR handles on errors #12812
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12812"
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-29T10:34:42Z.
What
tools/hw-oracle/oracle_hip.pyowns several COMGR handles across multi-step operations. If a later COMGR call fails after acquisition, some of those handles currently escape without cleanup:amd_comgr_action_data_get_datawhen reading the size or payload fails;comgr_stepwhen output or log extraction fails.Move those resources under narrow
finallycleanup while preserving the existing successful ownership transfer: a data set that is successfully returned remains caller-owned, while resources that cannot be returned are destroyed locally.The regression tests inject failures after each relevant acquisition point and assert the corresponding release/destroy call.
Tested
mainnegative control ataaccd0ba39b7d40fdbf19664575a7e567d8542f7: all four new focused tests fail on the missing cleanup calls.tools/hw-oracle/test_hw_oracle.py— 56 tests OK (4 skipped).tools/hw-oracle/test_hw_oracle.py— 56 tests OK (4 skipped).tools/hw-oracle/test_hw_oracle.py— 56 tests OK (2 skipped) on exact head63a73e9b93bcb06de89b1eff3df1fad2f8cfe1d4.63a73e9b93: all six mutants that survived the first review are now killed by the focused regression coverage.tools/hw-oracle/test_compare_results.py— 12 tests OK on each.py -3.12 tools/check_conventions.py --base origin/main— passed.git diff --check origin/main...HEAD— clean.py_compileof the changed hw-oracle Python files — passed.oracle_hip.pyin this area. #12348 sharestest_hw_oracle.pyonly in a separateVulkanRuntimeTestsblock; a synthetic merge with its current head is conflict-free.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-29T10:38:24Z.
Review: COMMENTED
🟢 Approval recommended
No active review issues were identified in the COMGR resource-cleanup changes.
No open issues 🎉
What changed in this PR
This PR fixes COMGR handle leaks in the hardware oracle’s HIP backend when intermediate operations fail, while preserving caller ownership of successfully returned data sets.
Changes:
tools/hw-oracle/test_hw_oracle.pytools/hw-oracle/oracle_hip.pyfinallycleanup around COMGR resource lifetimes.Review effort: Balanced
Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T12:25:04Z.
Review: COMMENTED
Reviewed @
6af6f06ba6on macOS arm64. Everything below was run host-side; I have no ROCm/COMGR here, so the module is only exercised through mocks, the same way your tests do it.Checks
test_hw_oracleOK (skipped=3) on Python 3.9.6, 3.13.13 and 3.15.1.check_conventions --base upstream/main,git diff --checkandmerge-treeagainst main5454cd2e45: all clean.pr_overlapprobed 1398 PRs. 3 share files and all 3 merge cleanly, so no overlap.data_set()returns stays caller-owned,destroy_data_setis only called aftercreate_data_setsucceeded, andinfois still destroyed when the outputs destroy raises.Test gap. The four new tests only cover failure paths. Because of that, the new
try/finallystructure isn't pinned on the success path. I ran 8 single-line mutants oforacle_hip.py, and 6 of them pass the whole suite:data_bytes: release only inexcept(leaks every successful handle)data_bytes:chunks.append(buffer.raw[:size.value - 1])data_set: dropadded = True(destroys the set it returns, use-after-free)data_set: release input data only on errordata_set:create_data_setmoved inside the guardedtrycomgr_step:outputs_created = Truefrom the start (destroys a never-created handle)comgr_step: skip destroying outputs on successcomgr_step: destroyinfooutsidefinallyThe test below kills all 8. It covers the success path of each of the three functions (exact handles released, returned set not destroyed, two chunks read correctly) and a
create_data_setfailure incomgr_step(no destroy of the uncreated outputs,infostill destroyed). It passes on 3.9/3.13/3.15. It also passes against main'soracle_hip.py, which is expected because main already handles the success path correctly. Its job is to guard that behaviour now that the cleanup lives infinallyblocks.