game_run_summary: record the run cgroup's memory peak #2845

Closed
leonida/mandy
aznohonza wants to merge 0 commits from tools/cgroup-memory-peak into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

aznohonza commented 2026-12-01 07:26:08 +00:00

Claimed in the coordination issue as: WINE-RUN-MEMORY-PEAK

What and why

scripts/run_game_wine.sh runs the title in a cgroup of its own when it is started in a systemd scope, and that scope usually also carries MemoryMax (e.g. systemd-run --user --scope -p MemoryMax=24G), but the run folder and the summary said nothing about how close the run came to that limit. The wrapper now reads the cgroup's memory.peak once the session has ended and writes it to <out>/memory_peak (bytes), and tools/game_run_summary.py prints cgroup memory peak: 23.6 GiB after the run time.

  • cgroup v2 only (kernel 5.19+), and only when the file is readable: cgroup v1 or an older kernel leaves no file and no line.
  • The peak is the whole cgroup's: the run's own scope when one is used, else the caller's cgroup since it was created. docs/linux_proton.md says so.
  • The two path overrides (LEONIDA_SELF_CGROUP_PATH, LEONIDA_CGROUP_ROOT) use the names and defaults of scripts/linux-boot/boot-inner.sh; they are also what the tests point at a fake proc file and cgroup tree.
  • No game data: the file holds one integer, and the summary still never prints a log line.

Open #2436 touches the same wrapper, so one of the two may need a rebase (a textual conflict in the environment block); this change adds no option.

Tested

CPU only, no game files, no Wine, no GPU:

  • python -I tests/test_game_run_summary.py — 13 tests pass, one new: 25,316,786,176 bytes prints as cgroup memory peak: 23.6 GiB, and a folder without memory_peak gets no line.
  • python -I tests/test_run_game_wine.py — 11 tests pass, two new: a stubbed run with a fake /proc/self/cgroup and memory.peak writes memory_peak and prints the line; a cgroup-v1 proc file leaves both out.
  • python -I tests/test_run_game_wine_safety.py — 3 tests pass.
  • python -m compileall -q on the changed Python files, scripts/check_no_game_data.py on all changed files, and the docs-only checks (tests/test_docs_*.py, tests/test_i18n_index.py, tests/test_design_contract_rows.py).

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)
Claimed in the coordination issue as: [WINE-RUN-MEMORY-PEAK](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7303967030) ### What and why `scripts/run_game_wine.sh` runs the title in a cgroup of its own when it is started in a systemd scope, and that scope usually also carries `MemoryMax` (e.g. `systemd-run --user --scope -p MemoryMax=24G`), but the run folder and the summary said nothing about how close the run came to that limit. The wrapper now reads the cgroup's `memory.peak` once the session has ended and writes it to `<out>/memory_peak` (bytes), and `tools/game_run_summary.py` prints `cgroup memory peak: 23.6 GiB` after the run time. - cgroup v2 only (kernel 5.19+), and only when the file is readable: cgroup v1 or an older kernel leaves no file and no line. - The peak is the whole cgroup's: the run's own scope when one is used, else the caller's cgroup since it was created. `docs/linux_proton.md` says so. - The two path overrides (`LEONIDA_SELF_CGROUP_PATH`, `LEONIDA_CGROUP_ROOT`) use the names and defaults of `scripts/linux-boot/boot-inner.sh`; they are also what the tests point at a fake proc file and cgroup tree. - No game data: the file holds one integer, and the summary still never prints a log line. Open #2436 touches the same wrapper, so one of the two may need a rebase (a textual conflict in the environment block); this change adds no option. ### Tested CPU only, no game files, no Wine, no GPU: - `python -I tests/test_game_run_summary.py` — 13 tests pass, one new: 25,316,786,176 bytes prints as `cgroup memory peak: 23.6 GiB`, and a folder without `memory_peak` gets no line. - `python -I tests/test_run_game_wine.py` — 11 tests pass, two new: a stubbed run with a fake `/proc/self/cgroup` and `memory.peak` writes `memory_peak` and prints the line; a cgroup-v1 proc file leaves both out. - `python -I tests/test_run_game_wine_safety.py` — 3 tests pass. - `python -m compileall -q` on the changed Python files, `scripts/check_no_game_data.py` on all changed files, and the docs-only checks (`tests/test_docs_*.py`, `tests/test_i18n_index.py`, `tests/test_design_contract_rows.py`). GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change)
ecox982745 commented 2026-12-01 08:22:19 +00:00

Independent Windows compatibility check with #2844. I combined 4edb90521 (#2844) and d9c470cd3 (#2845) with main cd73ddab7. Both changes merged without conflicts into tree fd4ea35ce.

  • All 16 stock summary tests and all three cross-platform launcher safety tests passed on Windows 11 with Python 3.13 and Git Bash.
  • A scratch extension of the launcher test set up a synthetic cgroup v2 path with spaces in both the root and scope names. The real wrapper copied the peak byte for byte. With a v2 scope lacking memory.peak, it left the output absent and propagated the stub summary's exit code. Wine and session tooling were stubs.
  • The real summary CLI passed 16 synthetic combinations in both text and JSON. Device loss, title breakpoint, guest return and time limit each kept the correct ending with a nonzero, zero, invalid or missing peak. Valid peaks printed the expected GiB value. The summary omitted the synthetic raw log text in every case.

CPU only. This exercises the parser and the wrapper's file handling. Live Linux cgroup sampling is outside this check.

AI-assisted with OpenAI Codex (GPT-6.2 Sol).

Independent Windows compatibility check with #2844. I combined `4edb90521` (#2844) and `d9c470cd3` (#2845) with main `cd73ddab7`. Both changes merged without conflicts into tree `fd4ea35ce`. - All 16 stock summary tests and all three cross-platform launcher safety tests passed on Windows 11 with Python 3.13 and Git Bash. - A scratch extension of the launcher test set up a synthetic cgroup v2 path with spaces in both the root and scope names. The real wrapper copied the peak byte for byte. With a v2 scope lacking `memory.peak`, it left the output absent and propagated the stub summary's exit code. Wine and session tooling were stubs. - The real summary CLI passed 16 synthetic combinations in both text and JSON. Device loss, title breakpoint, guest return and time limit each kept the correct ending with a nonzero, zero, invalid or missing peak. Valid peaks printed the expected GiB value. The summary omitted the synthetic raw log text in every case. CPU only. This exercises the parser and the wrapper's file handling. Live Linux cgroup sampling is outside this check. AI-assisted with OpenAI Codex (GPT-6.2 Sol).
aznohonza commented 2026-12-01 08:36:12 +00:00

Thanks — that matches what can be checked off Linux: on this box /proc/self/cgroup resolves to the shell's scope, which has memory.peak (20546236416 bytes), so the path and the parser agree. A real title run under a MemoryMax scope was not made.

AI-assisted.

Thanks — that matches what can be checked off Linux: on this box `/proc/self/cgroup` resolves to the shell's scope, which has `memory.peak` (20546236416 bytes), so the path and the parser agree. A real title run under a `MemoryMax` scope was not made. AI-assisted.
aznohonza commented 2026-12-01 11:56:09 +00:00

Merged current main (8497337b4) into the branch: #2436 landed meanwhile and also edits tests/test_run_game_wine.py. The conflict was only the helper signature — kept #2436's run_script(..., **extra) and pass the two cgroup overrides as keyword environment variables, as its cache tests do. The code diff against main is otherwise unchanged.

Re-run after the merge: 13 summary tests, 16 launcher tests (the 5 new #2436 ones included), 3 safety tests, the docs tests and check_no_game_data.py all pass. AI-assisted.

Merged current `main` (`8497337b4`) into the branch: #2436 landed meanwhile and also edits `tests/test_run_game_wine.py`. The conflict was only the helper signature — kept #2436's `run_script(..., **extra)` and pass the two cgroup overrides as keyword environment variables, as its cache tests do. The code diff against `main` is otherwise unchanged. Re-run after the merge: 13 summary tests, 16 launcher tests (the 5 new #2436 ones included), 3 safety tests, the docs tests and `check_no_game_data.py` all pass. AI-assisted.
aznohonza commented 2026-12-01 12:11:23 +00:00

The linux-python-and-viewer red is not from this branch: tests/test_chain_check.py fails on its own here too, and the fragment it pins was changed on main by 7acf84d38 ("...compute pipeline %s took %.1f s to obtain from %s..." at runtime/shims/d3d12_vulkan_device.cpp:17843), while the test still expects "...to build" (tests/test_chain_check.py:294). Nothing in this PR touches runtime/ or tests/test_chain_check.py; its own three suites (13 summary, 16 launcher, 3 safety) pass on the merged tree, as do the docs tests. The other jobs of this run are green (windows, linux-gpu-tools, semantic-tests).

No action from this branch; a one-line update to the test on main clears it. AI-assisted.

The `linux-python-and-viewer` red is not from this branch: `tests/test_chain_check.py` fails on its own here too, and the fragment it pins was changed on `main` by `7acf84d38` ("...compute pipeline %s took %.1f s to obtain from %s..." at `runtime/shims/d3d12_vulkan_device.cpp:17843`), while the test still expects "...to build" (`tests/test_chain_check.py:294`). Nothing in this PR touches `runtime/` or `tests/test_chain_check.py`; its own three suites (13 summary, 16 launcher, 3 safety) pass on the merged tree, as do the docs tests. The other jobs of this run are green (windows, linux-gpu-tools, semantic-tests). No action from this branch; a one-line update to the test on `main` clears it. AI-assisted.
aznohonza commented 2026-12-01 12:23:18 +00:00

main now carries the fix for the stale fragment (#2870), so I merged it in: tests/test_chain_check.py passes here, as do the three suites and the docs tests. CI is re-running on 8a72e40d8. AI-assisted.

`main` now carries the fix for the stale fragment (#2870), so I merged it in: `tests/test_chain_check.py` passes here, as do the three suites and the docs tests. CI is re-running on `8a72e40d8`. AI-assisted.
aegish-zagi commented 2026-12-01 14:34:52 +00:00

Verification — VERIFY-2845

Verdict: PASS

  • PR: #2845 | head sha: 8a72e40d8793085f31b284c6026ea421ad2f42a4 | merge state vs main: clean merge with current main cd0c52fcf in a scratch worktree (docs/linux_proton.md auto-merged, no conflicts)
  • Diff audited: tools/game_run_summary.py records the run cgroup's memory.peak (cgroup v2) and prints it in GiB, absent file = no line; scripts/run_game_wine.sh captures memory.peak from the run's systemd scope into the run folder; docs/linux_proton.md updated. No game data.
  • Tests run (Linux, Python 3.12.3, python -I):
    • PR (merged with main): tests/test_game_run_summary.py — 13 tests OK; tests/test_run_game_wine.py — 16 tests OK
    • Main code with the PR's test files: test_game_run_summary FAILED (errors=1 — the new memory-peak case), test_run_game_wine FAILED (errors=1 — the new cgroup-peak capture case). Genuine red-on-main / green-on-PR pair, MEASURED.

AI-assisted: yes (Muse Wonder, Muse by Meta)

## Verification — VERIFY-2845 **Verdict: PASS** - PR: #2845 | head sha: `8a72e40d8793085f31b284c6026ea421ad2f42a4` | merge state vs main: clean merge with current main `cd0c52fcf` in a scratch worktree (docs/linux_proton.md auto-merged, no conflicts) - Diff audited: tools/game_run_summary.py records the run cgroup's `memory.peak` (cgroup v2) and prints it in GiB, absent file = no line; scripts/run_game_wine.sh captures `memory.peak` from the run's systemd scope into the run folder; docs/linux_proton.md updated. No game data. - Tests run (Linux, Python 3.12.3, `python -I`): - PR (merged with main): tests/test_game_run_summary.py — 13 tests OK; tests/test_run_game_wine.py — 16 tests OK - Main code with the PR's test files: test_game_run_summary FAILED (errors=1 — the new memory-peak case), test_run_game_wine FAILED (errors=1 — the new cgroup-peak capture case). Genuine red-on-main / green-on-PR pair, MEASURED. AI-assisted: yes (Muse Wonder, Muse by Meta)
aznohonza commented 2026-12-01 14:36:51 +00:00

Thanks — the red-on-main / green-on-PR pair matches what we see here (the same 13 and 16 tests; tests/test_run_game_wine_safety.py's 3 also pass). One limit worth restating: the wrapper only has a memory.peak when its cgroup is v2 with the file (systemd --user --scope here, PID 1 of the scope); a plain shell gets the caller's cgroup since creation, and cgroup v1 gets no file and no line, which the second test covers. Nothing further from us on this one. AI-assisted.

Thanks — the red-on-main / green-on-PR pair matches what we see here (the same 13 and 16 tests; `tests/test_run_game_wine_safety.py`'s 3 also pass). One limit worth restating: the wrapper only has a `memory.peak` when its cgroup is v2 with the file (systemd `--user --scope` here, PID 1 of the scope); a plain shell gets the caller's cgroup since creation, and cgroup v1 gets no file and no line, which the second test covers. Nothing further from us on this one. AI-assisted.
KelboLive reviewed 2026-12-01 16:26:45 +00:00
KelboLive left a comment
No description provided.
Verified end to end: `scripts/run_game_wine.sh:332-334` takes the cgroup-v2 `0::` path, reads `$CGROUP_ROOT$cg_rel/memory.peak` after teardown, and `tools/game_run_summary.py:141`, `:185-186` renders it as GiB only when present. The v1 case writes nothing, as it should. Summary tests 13, launcher tests 16 (run under WSL — they skip on Windows by design), safety 3, all 13 docs test files, i18n and design-contract, plus `check_no_game_data` — all pass. The v2 selection is pinned: mutating `s/^0:://p` to `s/^0://p` makes `test_records_the_cgroup_memory_peak` error. Two nits, neither blocking: 1. **Without a systemd scope, this is the caller cgroup's lifetime peak, not the run's.** `docs/linux_proton.md` says so, but the one-line summary ("cgroup memory peak: 23.6 GiB") reads as if it were the run's peak — a word there would prevent a wrong conclusion in a comparison table. 2. **The `[ -n "$cg_rel" ]` guard is untested**: removing it still passes the v1 test, because the fake root has no `memory.peak` to pick up. A decoy `memory.peak` at the fake root would make the guard real. Merge-tree against current `origin/main` is clean; the branch is 210 commits behind but the only nearby edit is the adjacent *Traces* bullet in `docs/linux_proton.md`, and the merged tree passes the docs and summary tests.
aznohonza commented 2026-12-01 16:56:07 +00:00

Both nits addressed in ace83ae11:

  1. The line says whose peak it is. It now reads cgroup memory peak: 23.6 GiB (the run's scope, else the caller's cgroup), so a comparison table cannot read a caller-cgroup lifetime peak as the run's own. docs/linux_proton.md already explains the two cases; the tests that pin the text (tests/test_game_run_summary.py, tests/test_run_game_wine.py) are updated with it.
  2. The guard bites. The v1 case now writes a decoy memory.peak at the fake LEONIDA_CGROUP_ROOT itself, so an empty v2 path must read nothing. Checked the mutation: with [ -n "$cg_rel" ] dropped, that test errors (it would otherwise record 999 from the root).

Re-run here: 13 summary tests pass, 16 launcher tests pass (python3 -m unittest tests.test_game_run_summary tests.test_run_game_wine), and the guard mutation gives 1 failure. Nothing else changed; the merge tree against current origin/main still applies. AI-assisted.

Both nits addressed in `ace83ae11`: 1. **The line says whose peak it is.** It now reads `cgroup memory peak: 23.6 GiB (the run's scope, else the caller's cgroup)`, so a comparison table cannot read a caller-cgroup lifetime peak as the run's own. `docs/linux_proton.md` already explains the two cases; the tests that pin the text (`tests/test_game_run_summary.py`, `tests/test_run_game_wine.py`) are updated with it. 2. **The guard bites.** The v1 case now writes a decoy `memory.peak` at the fake `LEONIDA_CGROUP_ROOT` itself, so an empty v2 path must read nothing. Checked the mutation: with `[ -n "$cg_rel" ]` dropped, that test errors (it would otherwise record `999` from the root). Re-run here: 13 summary tests pass, 16 launcher tests pass (`python3 -m unittest tests.test_game_run_summary tests.test_run_game_wine`), and the guard mutation gives 1 failure. Nothing else changed; the merge tree against current `origin/main` still applies. AI-assisted.
aznohonza commented 2026-12-01 17:10:45 +00:00

One CI note on ace83ae11: the windows job came back red on loader only, and it is the runner's disk/AV timing heuristic, not this change — PE images written to ...\leonida_loader_test\7296 are not readable straight away: writing and reading one back took 71 ms on average (over 25 ms means each is being scanned), with the rest of the 551 tests passing. Nothing in this PR touches the runtime; re-running that job is not possible from here (run 46697161399 cannot be rerun; its workflow file may be broken — main changed the workflow), so the next push or base update will pick it up.

Local, on this branch: 13 summary tests and 16 launcher tests pass. AI-assisted.

One CI note on `ace83ae11`: the `windows` job came back red on `loader` only, and it is the runner's disk/AV timing heuristic, not this change — `PE images written to ...\leonida_loader_test\7296 are not readable straight away: writing and reading one back took 71 ms on average (over 25 ms means each is being scanned)`, with the rest of the 551 tests passing. Nothing in this PR touches the runtime; re-running that job is not possible from here (`run 46697161399 cannot be rerun; its workflow file may be broken` — main changed the workflow), so the next push or base update will pick it up. Local, on this branch: 13 summary tests and 16 launcher tests pass. AI-assisted.
Sign in to join this conversation.
No description provided.