fix(tools): wait for macOS replay process groups to disappear #27860

Merged
mcarkade merged 1 commit from upstream-pr/27860 into main 2026-11-30 15:59:42 +00:00
mcarkade commented 2026-11-27 15:48:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mcarkade on 2026-11-27T15:48:05Z.


What

On macOS, a replay process group can still exist after SIGKILL while its last members are being reaped. Darwin can return EPERM for a zero-signal probe of that group. The minimizer reported cleanup failure immediately in both descendant lifecycle cases on #27690. Failing macOS job · Darwin signal handling

Keep probing within the existing cleanup deadline on macOS. Cleanup succeeds once the group disappears. A denied initial kill or a group that is still present at the deadline remains a cleanup error.

Tested

  • macOS 26.7.2, Python 3.15.2 on GitHub Actions. The replay lifecycle suite passed, with 16 passed and six Windows-only skips. This includes the two descendant-cleanup cases that failed in #27690. The verification branch had identical versions of the two files in this PR. Native run
  • Both new cases fail against the previous implementation and pass with the fix. On Windows the replay lifecycle suite passed 22/22. On Ubuntu 24.04 WSL the replay lifecycle suite passed with 16 passed and six skips, and the minimizer suite passed 45/45.
  • Conventions and git diff --check passed.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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

Summary by CodeRabbit

  • Bug Fixes
    • Improved replay process cleanup on macOS by handling permission errors while checking whether a process group still exists. Cleanup continues retrying until the group disappears or the deadline is reached.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5529395672 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27860). Originally posted by [mcarkade](https://github.com/mcarkade) on 2026-11-27T15:48:05Z. --- ### What On macOS, a replay process group can still exist after `SIGKILL` while its last members are being reaped. Darwin can return `EPERM` for a zero-signal probe of that group. The minimizer reported cleanup failure immediately in both descendant lifecycle cases on #27690. [Failing macOS job](https://github.com/boykopovar/AnyPS5/actions/runs/45919699816/job/140325694464) · [Darwin signal handling](https://github.com/apple-oss-distributions/xnu/blob/f6217f891ac0bb64f3d375211650a4c1ff8ca1ea/bsd/kern/kern_sig.c#L1699-L1718) Keep probing within the existing cleanup deadline on macOS. Cleanup succeeds once the group disappears. A denied initial kill or a group that is still present at the deadline remains a cleanup error. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> - macOS 26.7.2, Python 3.15.2 on GitHub Actions. The replay lifecycle suite passed, with 16 passed and six Windows-only skips. This includes the two descendant-cleanup cases that failed in #27690. The verification branch had identical versions of the two files in this PR. [Native run](https://github.com/mcarkade/AnyPS5/actions/runs/46027038096/job/140600988241) - Both new cases fail against the previous implementation and pass with the fix. On Windows the replay lifecycle suite passed 22/22. On Ubuntu 24.04 WSL the replay lifecycle suite passed with 16 passed and six skips, and the minimizer suite passed 45/45. - Conventions and `git diff --check` passed. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Improved replay process cleanup on macOS by handling permission errors while checking whether a process group still exists. Cleanup continues retrying until the group disappears or the deadline is reached. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
arcwiser commented 2026-11-27 15:51:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by arcwiser on 2026-11-27T15:51:28Z.

Review: APPROVED


Reviewed exact head dde92d5b1734c659b0c67cd14ea5d374b8cacb43.

I inspected the complete two-file diff and the surrounding process-group cleanup paths. Apple XNU's killpg1 can find the process group, filter exited members from iteration, and then return EPERM when the POSIX probe finds no signalable member; treating Darwin EPERM as “still present” and continuing the existing bounded probe is consistent with that behavior. The initial SIGKILL permission failure remains fatal, non-Darwin PermissionError still fails immediately, and persistent Darwin denial still fails closed at the deadline.

Independent checks on Windows:

  • replay lifecycle suite: 22/22 passed;
  • frame-capture minimizer suite: 45/45 passed;
  • tools/check_conventions.py --base upstream/main: passed;
  • git diff --check: passed.

I could not reproduce the native Darwin process-state transition locally, but the implementation is bounded and the PR links a successful native macOS run covering both descendant-cleanup cases. I found no blocking issue.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6090608759 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27860#pullrequestreview-6090608759). Originally posted by [arcwiser](https://github.com/arcwiser) on 2026-11-27T15:51:28Z. **Review:** APPROVED --- Reviewed exact head `dde92d5b1734c659b0c67cd14ea5d374b8cacb43`. I inspected the complete two-file diff and the surrounding process-group cleanup paths. Apple XNU's `killpg1` can find the process group, filter exited members from iteration, and then return `EPERM` when the POSIX probe finds no signalable member; treating Darwin `EPERM` as “still present” and continuing the existing bounded probe is consistent with that behavior. The initial `SIGKILL` permission failure remains fatal, non-Darwin `PermissionError` still fails immediately, and persistent Darwin denial still fails closed at the deadline. Independent checks on Windows: - replay lifecycle suite: 22/22 passed; - frame-capture minimizer suite: 45/45 passed; - `tools/check_conventions.py --base upstream/main`: passed; - `git diff --check`: passed. I could not reproduce the native Darwin process-state transition locally, but the implementation is bounded and the PR links a successful native macOS run covering both descendant-cleanup cases. I found no blocking issue.
MarcZX10 commented 2026-11-27 16:07:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T16:07:37Z.

Review: APPROVED


Reviewed — looks good

The reviewed change at dde92d5b1734c659b0c67cd14ea5d374b8cacb43 retries Darwin process-group probes after PermissionError until the group disappears or the cleanup deadline expires; no blocking defects were found in the changed code.

What I ran

Read the prepared description, commit list, manifest, diff, and both changed files through repo_read.py. No commands or tests were run.

Results

Check Result Note
Changed code review passed Both changed files read
Tests not run Author-reported results were not independently run

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author reports passing replay lifecycle and minimizer suites on macOS, Windows, and Ubuntu WSL, and a passing git diff --check; these results were not independently verified. No files were excluded from the manifest, and both reviewed files were read.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6090779143 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27860#pullrequestreview-6090779143). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-27T16:07:37Z. **Review:** APPROVED --- # Reviewed — looks good The reviewed change at `dde92d5b1734c659b0c67cd14ea5d374b8cacb43` retries Darwin process-group probes after `PermissionError` until the group disappears or the cleanup deadline expires; no blocking defects were found in the changed code. ## What I ran Read the prepared description, commit list, manifest, diff, and both changed files through `repo_read.py`. No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | Both changed files read | | Tests | not run | Author-reported results were not independently run | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The author reports passing replay lifecycle and minimizer suites on macOS, Windows, and Ubuntu WSL, and a passing `git diff --check`; these results were not independently verified. No files were excluded from the manifest, and both reviewed files were read. ## To get this to a good state Nothing is required.
JJenkx commented 2026-11-27 16:55:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-11-27T16:55:31Z.

Review: COMMENTED


I checked the exact PR head and its parent with eight simulated signal/readback sequences on Linux Python. The updated Darwin path drains successfully after a transient permission denial, including when a mixed sequence of successful and denied probes ends with the group disappearing at the deadline. Persistent denial reaches the existing deadline and still reports a cleanup error.

The initial denied group kill still takes the root-only fallback and reports an error, a timeout while waiting for the root still fails before any group probe, and Linux still reports a denied probe immediately. All process and clock operations in this comparison were mocked.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6091254968 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27860#pullrequestreview-6091254968). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-11-27T16:55:31Z. **Review:** COMMENTED --- I checked the exact PR head and its parent with eight simulated signal/readback sequences on Linux Python. The updated Darwin path drains successfully after a transient permission denial, including when a mixed sequence of successful and denied probes ends with the group disappearing at the deadline. Persistent denial reaches the existing deadline and still reports a cleanup error. The initial denied group kill still takes the root-only fallback and reports an error, a timeout while waiting for the root still fails before any group probe, and Linux still reports a denied probe immediately. All process and clock operations in this comparison were mocked.
NobleBrains commented 2026-11-30 13:52:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NobleBrains on 2026-11-30T13:52:18Z.

Review: APPROVED


Looks good. Reviewed head dde92d5b1734c659b0c67cd14ea5d374b8cacb43: read both changed files' diff and ran the tests natively on macOS (15.7.9, Apple M4, Python 3.14.7).

test_frame_capture_minimize_replay.py, 100 runs per row. "Old" is the PR's tests with tools/frame_capture_minimize.py from the merge base:

Code Load Failures of the existing tests
old 28 yes processes 2 of 100 runs: test_owned_descendant_is_drained_after_parent_exit, cannot confirm replay process group cleanup: [Errno 1] Operation not permitted
this PR 28 yes processes 0 of 100 runs
old 12 yes processes 0 of 100 runs
this PR little or none 0 of 100 runs

So the failure reproduces on a real Mac under load, not only on the hosted runner, and did not recur with the fix. 2 against 0 is a small sample on its own; it agrees with the mechanism the description gives.

The two new tests fail against the old code in all 200 old-code runs, as they should.

Also passed: test_frame_capture_minimize.py (45/45), tools/check_conventions.py --base <merge base>, git diff --check.

Not run: Windows, Linux, the C++ build.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6113366065 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27860#pullrequestreview-6113366065). Originally posted by [NobleBrains](https://github.com/NobleBrains) on 2026-11-30T13:52:18Z. **Review:** APPROVED --- Looks good. Reviewed head `dde92d5b1734c659b0c67cd14ea5d374b8cacb43`: read both changed files' diff and ran the tests natively on macOS (15.7.9, Apple M4, Python 3.14.7). `test_frame_capture_minimize_replay.py`, 100 runs per row. "Old" is the PR's tests with `tools/frame_capture_minimize.py` from the merge base: | Code | Load | Failures of the existing tests | |---|---|---| | old | 28 `yes` processes | 2 of 100 runs: `test_owned_descendant_is_drained_after_parent_exit`, `cannot confirm replay process group cleanup: [Errno 1] Operation not permitted` | | this PR | 28 `yes` processes | 0 of 100 runs | | old | 12 `yes` processes | 0 of 100 runs | | this PR | little or none | 0 of 100 runs | So the failure reproduces on a real Mac under load, not only on the hosted runner, and did not recur with the fix. 2 against 0 is a small sample on its own; it agrees with the mechanism the description gives. The two new tests fail against the old code in all 200 old-code runs, as they should. Also passed: `test_frame_capture_minimize.py` (45/45), `tools/check_conventions.py --base <merge base>`, `git diff --check`. Not run: Windows, Linux, the C++ build. *AI-assisted (Claude Code).*
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!27860
No description provided.