fix(hw-oracle): reject duplicate JSON report fields #12816

Closed
malekaifa wants to merge 1 commit from upstream-pr/12816 into main
malekaifa commented 2026-10-29 11:07:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by malekaifa on 2026-10-29T11:07:13Z.


What

compare_results.py currently lets Python's JSON decoder silently keep the last value when an object repeats a field name. That can make an ambiguous or corrupted capture look valid and can hide a changed setting, input, or output value.

Reject duplicate JSON object fields during decoding instead. The same rule applies at every object level, including the top-level report, floating_point_modes, and individual row objects.

Tested

  • Exact-main negative control at 1db077e876a839f75d11a56e728e7f56a4a8c25e: all three new duplicate-field cases are accepted and return 0 before the fix.
  • Windows 11, Python 3.12: tools/hw-oracle/test_compare_results.py — 13 tests OK.
  • Windows 11, Python 3.9: tools/hw-oracle/test_compare_results.py — 13 tests OK.
  • WSL, Python 3.12.3: tools/hw-oracle/test_compare_results.py — 13 tests OK on the validated candidate; the final branch transplant changes only the parent commit and preserves the same two file blobs.
  • Windows 11, Python 3.12: tools/hw-oracle/test_hw_oracle.py — 48 tests OK, 4 skipped.
  • tools/check_conventions.py --base origin/main — passed on the candidate.
  • git diff --check and py_compile — clean.
  • Live overlap recheck found no open PR or issue implementing duplicate-field rejection. PR #12348 does not modify compare_results.py.

Final fork head: e8815286019f328c37f3ce23cf7422e813eeb48a, parent 59d7cff571bd01d3b5055e2e36734646f59f0061.

Checklist

  • Based on current main; no other open PR implements the same behavior
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; silent stubs are documented where applicable
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (OpenAI Codex)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5066870268 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12816). Originally posted by [malekaifa](https://github.com/malekaifa) on 2026-10-29T11:07:13Z. --- ### What `compare_results.py` currently lets Python's JSON decoder silently keep the last value when an object repeats a field name. That can make an ambiguous or corrupted capture look valid and can hide a changed setting, input, or output value. Reject duplicate JSON object fields during decoding instead. The same rule applies at every object level, including the top-level report, `floating_point_modes`, and individual row objects. ### Tested - Exact-main negative control at `1db077e876a839f75d11a56e728e7f56a4a8c25e`: all three new duplicate-field cases are accepted and return 0 before the fix. - Windows 11, Python 3.12: `tools/hw-oracle/test_compare_results.py` — 13 tests OK. - Windows 11, Python 3.9: `tools/hw-oracle/test_compare_results.py` — 13 tests OK. - WSL, Python 3.12.3: `tools/hw-oracle/test_compare_results.py` — 13 tests OK on the validated candidate; the final branch transplant changes only the parent commit and preserves the same two file blobs. - Windows 11, Python 3.12: `tools/hw-oracle/test_hw_oracle.py` — 48 tests OK, 4 skipped. - `tools/check_conventions.py --base origin/main` — passed on the candidate. - `git diff --check` and `py_compile` — clean. - Live overlap recheck found no open PR or issue implementing duplicate-field rejection. PR #12348 does not modify `compare_results.py`. Final fork head: `e8815286019f328c37f3ce23cf7422e813eeb48a`, parent `59d7cff571bd01d3b5055e2e36734646f59f0061`. ### Checklist - [x] Based on current `main`; no other open PR implements the same behavior - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; silent stubs are documented where applicable - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (OpenAI Codex)
copilot-pull-request-reviewer[bot] commented 2026-10-29 11:11:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-29T11:11:37Z.

Review: COMMENTED


No active review issues remain for the change that rejects duplicate JSON fields.

No open issues 🎉

What changed in this PR

This PR hardens the hardware-oracle report comparator by rejecting duplicate JSON fields instead of silently keeping the last value, preventing ambiguous captures from appearing valid.

Changes:

  • Rejects duplicate fields at every JSON object level with an error identifying the file and field.
  • Adds regression cases for top-level, floating-point-mode, and row-output duplicates, checking exit status 2 and clean error reporting.
File Description
tools/​hw-oracle/​test_compare_results.py Tests duplicate-field rejection at three object levels.
tools/​hw-oracle/​compare_results.py Adds duplicate-field detection during JSON decoding.

Review effort: Balanced

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5696747246 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12816#pullrequestreview-5696747246). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-29T11:11:37Z. **Review:** COMMENTED --- <!-- ccr-overview-v2 --> ### 🟢 Approval recommended No active review issues remain for the change that rejects duplicate JSON fields. **No open issues** 🎉 <details> <summary><strong>What changed in this PR</strong></summary> This PR hardens the hardware-oracle report comparator by rejecting duplicate JSON fields instead of silently keeping the last value, preventing ambiguous captures from appearing valid. **Changes:** - Rejects duplicate fields at every JSON object level with an error identifying the file and field. - Adds regression cases for top-level, floating-point-mode, and row-output duplicates, checking exit status 2 and clean error reporting. | File | Description | | ---- | ----------- | | `tools/​hw-oracle/​test_compare_results.py` | Tests duplicate-field rejection at three object levels. | | `tools/​hw-oracle/​compare_results.py` | Adds duplicate-field detection during JSON decoding. | </details> <sub>Review effort: Balanced</sub>
rooklz commented 2026-10-29 11:45:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T11:45:48Z.

Review: APPROVED


Verified on macOS arm64 at e881528601 (main ba5b5330b3; merge-tree clean, git diff --check clean, check_conventions --base upstream/main passes, pr_overlap checked 1401 PRs with no overlap).

  • test_compare_results passes 13/13 on Python 3.9.6, 3.13 and 3.15. test_hw_oracle is OK (3 platform skips) on all three.
  • Negative control: with main's compare_results.py and the PR's test, all three subtests (rows, ieee, output) fail. Each one returns 0.
  • Extra CLI probes, run on all three Pythons. Each gives rc 2 with a one-line error: and no traceback:
    • a duplicate written with an escaped key ("\u0072ows" next to "rows"): the hook sees the decoded name, so this is caught
    • a duplicate in the before report (the test only edits after)
    • a duplicate inside an unknown extra object that the validator would otherwise ignore
    • 200k-deep nesting: still reports "JSON nested too deeply", so the hook does not change the RecursionError path
  • compare_results.py is the only json.loads of report input in tools/hw-oracle. The others are in tests and read the tool's own output.

LGTM.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5697136295 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12816#pullrequestreview-5697136295). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-29T11:45:48Z. **Review:** APPROVED --- Verified on macOS arm64 at e881528601 (main ba5b5330b3; merge-tree clean, `git diff --check` clean, `check_conventions --base upstream/main` passes, `pr_overlap` checked 1401 PRs with no overlap). - `test_compare_results` passes 13/13 on Python 3.9.6, 3.13 and 3.15. `test_hw_oracle` is OK (3 platform skips) on all three. - Negative control: with main's `compare_results.py` and the PR's test, all three subtests (`rows`, `ieee`, `output`) fail. Each one returns 0. - Extra CLI probes, run on all three Pythons. Each gives rc 2 with a one-line `error:` and no traceback: - a duplicate written with an escaped key (`"\u0072ows"` next to `"rows"`): the hook sees the decoded name, so this is caught - a duplicate in the *before* report (the test only edits *after*) - a duplicate inside an unknown extra object that the validator would otherwise ignore - 200k-deep nesting: still reports "JSON nested too deeply", so the hook does not change the RecursionError path - `compare_results.py` is the only `json.loads` of report input in `tools/hw-oracle`. The others are in tests and read the tool's own output. LGTM.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!12816
No description provided.