feat(run-report): recover the report of a run that ended without writing one #15973

Open
oneandonlydean wants to merge 6 commits from upstream-pr/15973 into main
oneandonlydean commented 2026-11-05 04:59:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-11-05T04:59:46Z.


What

Recovers the report of a run that ended without writing one. Builds on the writer in #14235 and the counters in #15705, and contains both. Writing a report from abort(), std::terminate and failed assertions is a separate follow-up PR.

Recovery.

  • A run keeps a checkpoint of its report (anyps5-report.<run id>.ckpt) and a lock file next to the report, written when the run starts and refreshed every five seconds by a worker thread. A normal end writes the report, removes the checkpoint and releases the lock.
  • At the next start the runtime scans the run folder (and the data folder's reports/<run id>/ folders) for checkpoints whose lock is free, parses each one strictly (it must be exactly what the runtime would have written for that run, and every text value must pass the same filter) and writes a report from it: exit: killed, recovered: true, incomplete: true, stop.kind: other, stop.reason: unclean-unknown. That means the run ended without writing its report; it does not say what ended it. A checkpoint that fails the check is renamed .invalid and no report is made, never published in part.
  • A relaunch (sceSystemServiceLoadExec) hands the report over before the process is replaced and reopens it if the replacement fails; the choice made with --aps5-report survives the relaunch through APS5_REPORT. Linux, macOS and Windows code paths.
  • On Windows the worker is not started while the libraries load (a thread under the loader lock); the video output starts it later, and the checkpoint and lock are removed at process exit.
  • The game bring-up discussion template gets a field for the report.

Not here: stop kinds for an unsupported shader instruction and an unsupported image format (they need the shader diagnostics of the counters PR and come after it).

Tested

Linux (workstation). run_report_tests run directly on the final build (d5fcdf84db): 72 passed, 0 failed, 3 not run (the Windows-only detach test is reported as not run on Linux) (environment skips); ctest -R '^(run_report|guest_loadexec_fd_isolation|guest_system_relaunch|loadexec_arguments)': 5 of 5 passed.
Each new behaviour was checked by removing it: with the recovery scan switched off recovery, child-kill-and-recover and fallback-recovery fail; with the checkpoint lock made shared finish-recover-stress, removal-before-unlock and recovery fail; with the report never marked as handed over handoff-outcome and resume fail. The last fix is checked the same way: with the publish lock off resume-does-not-race-away-another-report fails; with descriptor isolation off guest_loadexec_fd_isolation fails. Each passes with the code restored.

Fix on review (round 2: a final write needs the acquired publish lock, so a timed-out run leaves its checkpoint to the next start (finish-needs-publish-lock, red with the check removed); on Windows a detach without a finished report keeps the checkpoint (detach-without-finish-keeps-checkpoint, Windows only, not run)): the relaunch hand-off no longer leaks run-report descriptors into the replacement process (descriptor isolation), Resume takes a publish lock so it cannot remove a report another run is publishing (the lock file is removed again while held, none is left behind), and the Windows checkpoint is kept on the paths that need it.
Cost: report on adds 0.47 ms per run at start-up (1.47 ms off, 1.94 ms on, 300 runs x3, checkpoint written at start and removed at the end included); over a 12 s run the checkpoint thread adds 1.46 ms of cpu; one checkpoint write takes 0.029 ms. (Measured on 69ab87cf6f, which has the same recovery code; the review fix changes only the hand-off, the publish lock and tests.)
Not run: Windows and macOS (the platform code, the LoadExec.cpp hand-off on all three systems, the Windows checkpoint cleanup), a relaunch of a real title, a real crash of a title.

Things reviewers may question

  • A background thread and a lock file in every run for a diagnostic feature (default on). The thread wakes every five seconds; measured cost above.
  • LoadExec.cpp changes on three systems (the hand-off and the reopen when the replacement fails); none of the open PRs touch it today.
  • Honest limits. A report is recovered at the next start, not at the moment of the crash; a fatal signal, SIGKILL or a power loss leave only the checkpoint (up to five seconds old), and no report is written if the game is never started again from that folder. The recovered report says only that the run ended without writing one. A run killed between writing its report and removing its checkpoint can leave a second, "killed" report beside the real one (not handled here).
  • Windows and macOS are not run (see Tested).
  • Open PRs touching the same files: libSceVideoOut/src/VideoOutDriver.cpp (8); none touch LoadExec.cpp or RunReport.cpp.
  • Stacked on #15705. This branch contains #15705, so the checkpoint carries its fields (gpu, milestones, frames, shaders), and privacy-sweep-everything and kill-and-recover run with them.

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: #14235, #15705
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5166405945 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15973). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-11-05T04:59:46Z. --- ### What Recovers the report of a run that ended without writing one. Builds on the writer in #14235 and the counters in #15705, and contains both. Writing a report from `abort()`, `std::terminate` and failed assertions is a separate follow-up PR. **Recovery.** - A run keeps a checkpoint of its report (`anyps5-report.<run id>.ckpt`) and a lock file next to the report, written when the run starts and refreshed every five seconds by a worker thread. A normal end writes the report, removes the checkpoint and releases the lock. - At the next start the runtime scans the run folder (and the data folder's `reports/<run id>/` folders) for checkpoints whose lock is free, parses each one strictly (it must be exactly what the runtime would have written for that run, and every text value must pass the same filter) and writes a report from it: `exit: killed`, `recovered: true`, `incomplete: true`, `stop.kind: other`, `stop.reason: unclean-unknown`. That means the run ended without writing its report; it does not say what ended it. A checkpoint that fails the check is renamed `.invalid` and no report is made, never published in part. - A relaunch (`sceSystemServiceLoadExec`) hands the report over before the process is replaced and reopens it if the replacement fails; the choice made with `--aps5-report` survives the relaunch through `APS5_REPORT`. Linux, macOS and Windows code paths. - On Windows the worker is not started while the libraries load (a thread under the loader lock); the video output starts it later, and the checkpoint and lock are removed at process exit. - The game bring-up discussion template gets a field for the report. Not here: stop kinds for an unsupported shader instruction and an unsupported image format (they need the shader diagnostics of the counters PR and come after it). ### Tested Linux (workstation). `run_report_tests` run directly on the final build (`d5fcdf84db`): 72 passed, 0 failed, 3 not run (the Windows-only detach test is reported as not run on Linux) (environment skips); `ctest -R '^(run_report|guest_loadexec_fd_isolation|guest_system_relaunch|loadexec_arguments)'`: 5 of 5 passed. Each new behaviour was checked by removing it: with the recovery scan switched off `recovery`, `child-kill-and-recover` and `fallback-recovery` fail; with the checkpoint lock made shared `finish-recover-stress`, `removal-before-unlock` and `recovery` fail; with the report never marked as handed over `handoff-outcome` and `resume` fail. The last fix is checked the same way: with the publish lock off `resume-does-not-race-away-another-report` fails; with descriptor isolation off `guest_loadexec_fd_isolation` fails. Each passes with the code restored. Fix on review (round 2: a final write needs the acquired publish lock, so a timed-out run leaves its checkpoint to the next start (`finish-needs-publish-lock`, red with the check removed); on Windows a detach without a finished report keeps the checkpoint (`detach-without-finish-keeps-checkpoint`, Windows only, not run)): the relaunch hand-off no longer leaks run-report descriptors into the replacement process (descriptor isolation), `Resume` takes a publish lock so it cannot remove a report another run is publishing (the lock file is removed again while held, none is left behind), and the Windows checkpoint is kept on the paths that need it. Cost: report on adds 0.47 ms per run at start-up (1.47 ms off, 1.94 ms on, 300 runs x3, checkpoint written at start and removed at the end included); over a 12 s run the checkpoint thread adds 1.46 ms of cpu; one checkpoint write takes 0.029 ms. (Measured on `69ab87cf6f`, which has the same recovery code; the review fix changes only the hand-off, the publish lock and tests.) Not run: Windows and macOS (the platform code, the `LoadExec.cpp` hand-off on all three systems, the Windows checkpoint cleanup), a relaunch of a real title, a real crash of a title. ### Things reviewers may question - **A background thread and a lock file in every run** for a diagnostic feature (default on). The thread wakes every five seconds; measured cost above. - **`LoadExec.cpp`** changes on three systems (the hand-off and the reopen when the replacement fails); none of the open PRs touch it today. - **Honest limits.** A report is recovered at the next start, not at the moment of the crash; a fatal signal, `SIGKILL` or a power loss leave only the checkpoint (up to five seconds old), and no report is written if the game is never started again from that folder. The recovered report says only that the run ended without writing one. A run killed between writing its report and removing its checkpoint can leave a second, "killed" report beside the real one (not handled here). - **Windows and macOS** are not run (see Tested). - Open PRs touching the same files: `libSceVideoOut/src/VideoOutDriver.cpp` (8); none touch `LoadExec.cpp` or `RunReport.cpp`. - **Stacked on #15705.** This branch contains #15705, so the checkpoint carries its fields (gpu, milestones, frames, shaders), and `privacy-sweep-everything` and `kill-and-recover` run with them. ### Checklist - [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: #14235, #15705 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-11-20 11:10:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T11:10:24Z.

Review: COMMENTED


Reviewed — no blocking findings

The recovery and relaunch changes appear sound in the inspected Linux paths; Windows and macOS behavior and several changed test and documentation files were not independently verified.

What I ran

Read the prepared diff and pinned repository sources at e8be7be0f99500703663a4f81347ccbd8991f8e5. No build or tests were run; repo_read.py was not run because its required plain shell command is unavailable here.

Results

Check Result Note
Diff and targeted source review passed Recovery, publishing, relaunch paths
Build and tests not run Author-reported runs only
Windows and macOS paths not run Not independently verified

Findings

Blocking

None found in the inspected paths.

Non-blocking

None.

Not verified

The changed files listed as reviewed in the manifest were not all read. The inspected files were core/libs/prx/libc/src/RunReport.cpp, core/libs/prx/libSceSystemService/LoadExec.cpp, and core/libs/tests/RunReport.cpp (selected ranges). The prepared diff, description, commits, and manifest were read. The full contents of core/libs/prx/libSceSystemService/CMakeLists.txt, core/libs/prx/libSceSystemService/LoadExec.hpp, core/libs/prx/libSceVideoOut/src/VideoOutDriver.cpp, core/libs/prx/libc/include/RunReport.hpp, core/libs/tests/GuestSystemExit.cpp, .github/DISCUSSION_TEMPLATE/game-bring-up.yml, docs/dev/debt/libc.md, docs/user/USAGE.md, docs/user/run-report.md, and tools/tests/test_run_report_docs.py were not read. files.json was not listed in the prepared review folder, so exclusions by rule were not verified. The author reports Linux tests and performance measurements; these were not reproduced. Windows, macOS, real-title relaunch, and real-crash behavior were not verified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5991737179 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15973#pullrequestreview-5991737179). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T11:10:24Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The recovery and relaunch changes appear sound in the inspected Linux paths; Windows and macOS behavior and several changed test and documentation files were not independently verified. ## What I ran Read the prepared diff and pinned repository sources at `e8be7be0f99500703663a4f81347ccbd8991f8e5`. No build or tests were run; `repo_read.py` was not run because its required plain shell command is unavailable here. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted source review | passed | Recovery, publishing, relaunch paths | | Build and tests | not run | Author-reported runs only | | Windows and macOS paths | not run | Not independently verified | ## Findings ### Blocking None found in the inspected paths. ### Non-blocking None. ## Not verified The changed files listed as reviewed in the manifest were not all read. The inspected files were `core/libs/prx/libc/src/RunReport.cpp`, `core/libs/prx/libSceSystemService/LoadExec.cpp`, and `core/libs/tests/RunReport.cpp` (selected ranges). The prepared diff, description, commits, and manifest were read. The full contents of `core/libs/prx/libSceSystemService/CMakeLists.txt`, `core/libs/prx/libSceSystemService/LoadExec.hpp`, `core/libs/prx/libSceVideoOut/src/VideoOutDriver.cpp`, `core/libs/prx/libc/include/RunReport.hpp`, `core/libs/tests/GuestSystemExit.cpp`, `.github/DISCUSSION_TEMPLATE/game-bring-up.yml`, `docs/dev/debt/libc.md`, `docs/user/USAGE.md`, `docs/user/run-report.md`, and `tools/tests/test_run_report_docs.py` were not read. `files.json` was not listed in the prepared review folder, so exclusions by rule were not verified. The author reports Linux tests and performance measurements; these were not reproduced. Windows, macOS, real-title relaunch, and real-crash behavior were not verified. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 16:15:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T16:15:26Z.

Review: COMMENTED


Recovery can replace a complete report. Normal finalization writes the final JSON and then removes the checkpoint. If the run ends in between, RecoverOne finds the old checkpoint and writes a recovered report over the complete file. Please check for a completed report before replacing it. The branch also conflicts in the current run-report sources. All 14 documentation checks passed on Linux.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6173698096 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15973#pullrequestreview-6173698096). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T16:15:26Z. **Review:** COMMENTED --- Recovery can replace a complete report. Normal finalization writes the final JSON and then removes the checkpoint. If the run ends in between, `RecoverOne` finds the old checkpoint and writes a recovered report over the complete file. Please check for a completed report before replacing it. The branch also conflicts in the current run-report sources. All 14 documentation checks passed on Linux. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/15973:upstream-pr/15973'
git switch 'upstream-pr/15973'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/15973'
git switch 'upstream-pr/15973'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/15973'
git switch 'upstream-pr/15973'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/15973'
git switch 'main'
git merge --squash 'upstream-pr/15973'
git switch 'main'
git merge --ff-only 'upstream-pr/15973'
git switch 'main'
git merge 'upstream-pr/15973'
git push origin 'main'
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!15973
No description provided.