fix(tools): decode timeline JSON with utf-8-sig in pad_timeline #9258

Merged
emirplus merged 3 commits from upstream-pr/9258 into main 2026-11-03 08:09:38 +00:00
emirplus commented 2026-10-21 16:44:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by emirplus on 2026-10-21T16:44:48Z.


What

When controller timeline JSON files contain a UTF-8 byte-order mark (BOM) (e.g. created or saved by text editors on Windows), reading them with read_text(encoding="utf-8") results in json.decoder.JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig).

  1. Read timeline files using encoding="utf-8-sig" in pad_timeline.py so leading BOMs are cleanly stripped prior to JSON parsing.
  2. Accept optional argv argument in main(argv=None) with standard UTF-8 stream reconfiguration for programmatic and cross-platform CLI invocation.

Tested

python tools/check_conventions.py --base origin/main
python -m unittest tools/tests/test_pad_timeline.py

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • 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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4955106082 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9258). Originally posted by [emirplus](https://github.com/emirplus) on 2026-10-21T16:44:48Z. --- ### What When controller timeline JSON files contain a UTF-8 byte-order mark (BOM) (e.g. created or saved by text editors on Windows), reading them with `read_text(encoding="utf-8")` results in `json.decoder.JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig)`. 1. Read timeline files using `encoding="utf-8-sig"` in `pad_timeline.py` so leading BOMs are cleanly stripped prior to JSON parsing. 2. Accept optional `argv` argument in `main(argv=None)` with standard UTF-8 stream reconfiguration for programmatic and cross-platform CLI invocation. ### Tested `python tools/check_conventions.py --base origin/main` `python -m unittest tools/tests/test_pad_timeline.py` ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [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
xXPBSXx commented 2026-10-21 17:53:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T17:53:13Z.


Linux data point for ef1c8d5ca2 (WSL2, Ubuntu 24.04, kernel 6.18 - a virtualised kernel, not bare-metal Linux; Python 3.12.3), this head merged onto main 950388bfd (clean merge), python3 -I tools/tests/test_pad_timeline.py:

  • With the PR: 17 tests OK.
  • Without it (the PR's test_pad_timeline.py on top of main without the PR's source change): FAILED (1 failure).
    Not tested: macOS, Windows.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6322781254 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9258#issuecomment-6322781254). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-21T17:53:13Z. --- Linux data point for `ef1c8d5ca2` (WSL2, Ubuntu 24.04, kernel 6.18 - a virtualised kernel, not bare-metal Linux; Python 3.12.3), this head merged onto `main` `950388bfd` (clean merge), `python3 -I tools/tests/test_pad_timeline.py`: - With the PR: 17 tests OK. - Without it (the PR's `test_pad_timeline.py` on top of `main` without the PR's source change): FAILED (1 failure). Not tested: macOS, Windows. AI-assisted (Claude Code).
THEMANnt commented 2026-10-24 23:47:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-24T23:47:10Z.

Review: CHANGES_REQUESTED


Reviewed c512089cc840 against 938812df1403. Changes requested for a Unicode output regression introduced by the stream reconfiguration.

tools/pad_timeline.py:81–83 — Keep safe error handling when configuring UTF-8

stream.reconfigure(encoding="utf-8") resets the error handler to strict, replacing a configured safe policy. I reproduced this on Windows with an actual command-file name containing U+DCFF and PYTHONIOENCODING=utf-8:backslashreplace. The baseline queues the command and exits 0. The exact PR head also writes the command, then raises UnicodeEncodeError at the success-message print and exits 1 because the path contains the surrogate. This reports failure after the command was already queued and can prompt an unnecessary retry. The reproduction uses real CLI subprocesses and temporary files; no production source is amended.

Please preserve an appropriate safe error policy when changing the encoding, for example explicit backslashreplace, and add a subprocess regression that checks the successful status after writing a command to such a filename. Keep BOM acceptance coverage.

Validation: Windows x64 / CPython 3.11: timeline suite 18 passed, 1 POSIX skip; 19 total. Neighboring pad-input suite 12 passed, 2 POSIX skips; 14 total. Baseline timeline suite: 17 passed, 1 skip. The new BOM test fails on old production with exit 2 and passes at the head; the independent surrogate-filename reproduction above exposes the new regression. Conventions, whitespace and registration pass. Hosted relinker matrix/ASan and conventions succeed; product jobs are skipped.

Scope: Python CLI/file behavior only; no real controller or title was run. Local POSIX permission cases remain skipped.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5640640527 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9258#pullrequestreview-5640640527). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-24T23:47:10Z. **Review:** CHANGES_REQUESTED --- Reviewed [c512089cc840](https://github.com/boykopovar/AnyPS5/commit/c512089cc840508805fef7070dafdd711eab44db) against [938812df1403](https://github.com/boykopovar/AnyPS5/commit/938812df1403f9616dba71744216725891ca4979). Changes requested for a Unicode output regression introduced by the stream reconfiguration. **`tools/pad_timeline.py:81–83` — Keep safe error handling when configuring UTF-8** `stream.reconfigure(encoding="utf-8")` resets the error handler to strict, replacing a configured safe policy. I reproduced this on Windows with an actual command-file name containing U+DCFF and `PYTHONIOENCODING=utf-8:backslashreplace`. The baseline queues the command and exits 0. The exact PR head also writes the command, then raises UnicodeEncodeError at the success-message print and exits 1 because the path contains the surrogate. This reports failure after the command was already queued and can prompt an unnecessary retry. The reproduction uses real CLI subprocesses and temporary files; no production source is amended. Please preserve an appropriate safe error policy when changing the encoding, for example explicit backslashreplace, and add a subprocess regression that checks the successful status after writing a command to such a filename. Keep BOM acceptance coverage. **Validation:** Windows x64 / CPython 3.11: timeline suite 18 passed, 1 POSIX skip; 19 total. Neighboring pad-input suite 12 passed, 2 POSIX skips; 14 total. Baseline timeline suite: 17 passed, 1 skip. The new BOM test fails on old production with exit 2 and passes at the head; the independent surrogate-filename reproduction above exposes the new regression. Conventions, whitespace and registration pass. Hosted relinker matrix/ASan and conventions succeed; product jobs are skipped. **Scope:** Python CLI/file behavior only; no real controller or title was run. Local POSIX permission cases remain skipped.
malekaifa commented 2026-10-30 14:01:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by malekaifa on 2026-10-30T14:01:05Z.

Review: COMMENTED


Freshness note for the eventual rebase/integration of this PR: current main now has a second consumer of the same timeline JSON contract, tools/preview_pad_timeline.py, introduced later in 1f563f246e (2026-10-27), so it is not present in this PR's two-file diff.

I independently checked current main b1b5353cfcee098ed17e3ba8a6e616bee97c9215 on Windows/Python 3.12. A valid version-1 timeline encoded with a leading UTF-8 BOM gives:

py -3.12 tools/preview_pad_timeline.py <bom-timeline.json> --json
# exit 2
preview_pad_timeline.py: Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1 (char 0)

The preview tool currently reads the file with encoding="utf-8", while this PR intentionally changes pad_timeline.py to accept the same input with utf-8-sig. So after this PR is refreshed, the two timeline entry points would otherwise disagree about whether the same valid JSON file is accepted.

Please preserve the BOM change here, but when rebasing onto current main also update the preview reader (or coordinate an explicit follow-up) and add a focused preview regression. This is a post-PR main-drift integration gap, not a defect in the original c512089cc840... patch as authored.

AI-assisted: yes. I ran the current-main preview reproduction above; I did not rerun the PR's full test matrix.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5713392661 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9258#pullrequestreview-5713392661). Originally posted by [malekaifa](https://github.com/malekaifa) on 2026-10-30T14:01:05Z. **Review:** COMMENTED --- Freshness note for the eventual rebase/integration of this PR: current `main` now has a second consumer of the same timeline JSON contract, `tools/preview_pad_timeline.py`, introduced later in `1f563f246e` (2026-10-27), so it is not present in this PR's two-file diff. I independently checked current main `b1b5353cfcee098ed17e3ba8a6e616bee97c9215` on Windows/Python 3.12. A valid version-1 timeline encoded with a leading UTF-8 BOM gives: ``` py -3.12 tools/preview_pad_timeline.py <bom-timeline.json> --json # exit 2 preview_pad_timeline.py: Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1 (char 0) ``` The preview tool currently reads the file with `encoding="utf-8"`, while this PR intentionally changes `pad_timeline.py` to accept the same input with `utf-8-sig`. So after this PR is refreshed, the two timeline entry points would otherwise disagree about whether the same valid JSON file is accepted. Please preserve the BOM change here, but when rebasing onto current main also update the preview reader (or coordinate an explicit follow-up) and add a focused preview regression. This is a post-PR main-drift integration gap, not a defect in the original `c512089cc840...` patch as authored. AI-assisted: yes. I ran the current-main preview reproduction above; I did not rerun the PR's full test matrix.
THEMANnt commented 2026-11-02 06:00:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-11-02T06:00:44Z.

Review: APPROVED


Re-reviewed e62a0f26040d95b8fb35200348ef4e8bfc5c01e0. My previous Unicode-output change request on c512089cc840 is addressed.

Explicit errors="backslashreplace" keeps the success message printable when the command-file path contains a lone surrogate. The CLI subprocess regression verifies exit 0, the written command, and the escaped filename; UTF-8 BOM acceptance coverage remains and passes.

Validation: Windows x64 / Python 3.11.9: timeline suite 22 passed, 2 skipped; neighboring pad-input suite 19 passed, 2 skipped. The surrogate regression ran without skipping. As a negative control, the same new regression against the previous head's production code fails with the original UnicodeEncodeError at the success-message print. Diff whitespace check passes.

No remaining blocker found in this two-file patch. Scope: Python CLI/file behavior; no controller or title was run. POSIX permission and unavailable symlink cases remain untested locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5732626424 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9258#pullrequestreview-5732626424). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-11-02T06:00:44Z. **Review:** APPROVED --- Re-reviewed `e62a0f26040d95b8fb35200348ef4e8bfc5c01e0`. My previous Unicode-output change request on `c512089cc840` is addressed. Explicit `errors="backslashreplace"` keeps the success message printable when the command-file path contains a lone surrogate. The CLI subprocess regression verifies exit 0, the written command, and the escaped filename; UTF-8 BOM acceptance coverage remains and passes. **Validation:** Windows x64 / Python 3.11.9: timeline suite **22 passed, 2 skipped**; neighboring pad-input suite **19 passed, 2 skipped**. The surrogate regression ran without skipping. As a negative control, the same new regression against the previous head's production code fails with the original `UnicodeEncodeError` at the success-message print. Diff whitespace check passes. No remaining blocker found in this two-file patch. Scope: Python CLI/file behavior; no controller or title was run. POSIX permission and unavailable symlink cases remain untested locally.
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!9258
No description provided.