tools/game_run_summary: guard stdout encoding, BOM ints, OSError and RecursionError #1837

Merged
kirigayakazima merged 1 commit from upstream-pr/1837 into main 2026-11-30 16:03:03 +00:00
kirigayakazima commented 2026-11-25 12:57:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-25T12:57:08Z.


Claimed in the coordination issue as: GAME-RUN-SUMMARY-STDOUT-BOM-AND-VALIDATION (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7163012307)

What and why

  • Add the standard sys.stdout.reconfigure(errors="replace") guard in tools/game_run_summary.py's __main__ block so redirected Windows python -I runs do not raise UnicodeEncodeError when reporting method names outside the ANSI/OEM code page.
  • Decode exit_code and seconds in _read_int() with encoding="utf-8-sig" so UTF-8 BOM-prefixed files parse cleanly instead of reading as None.
  • Guard the second open() in _lines() against OSError and catch (ValueError, RecursionError) on boot.jsonl json.loads() lines so deeply nested corrupt entries increment startup_bad_lines cleanly.
  • Reject non-positive --limit-seconds values (< 1) in main() via parser.error(...) (exit 2).
  • Add regression tests in tests/test_game_run_summary.py.

Tested

  • python -I tests/test_game_run_summary.py -v -> Ran 12 tests in 0.156s, OK.
  • Detached upstream/main (98c2f777) baseline worktree with updated tests/test_game_run_summary.py -> Ran 12 tests in 0.176s, FAILED (failures=4, errors=2) (all new regression checks fail before the fix).
  • python -I tests/test_ci_registration.py -> Ran 16 tests in 5.198s, OK.
  • python -I tests/test_text_write_line_endings.py -> Ran 3 tests in 12.859s, OK.
  • python -I scripts/check_no_game_data.py tools/game_run_summary.py tests/test_game_run_summary.py -> exit 0.
  • python -I -m compileall -q tools/game_run_summary.py tests/test_game_run_summary.py and git diff --check -> exit 0.

GPUs tested: n/a (CPU/stdlib Python tests on Windows 11 x64)

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)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5491761898 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1837). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-25T12:57:08Z. --- Claimed in the coordination issue as: GAME-RUN-SUMMARY-STDOUT-BOM-AND-VALIDATION (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7163012307) ### What and why - Add the standard `sys.stdout.reconfigure(errors="replace")` guard in `tools/game_run_summary.py`'s `__main__` block so redirected Windows `python -I` runs do not raise `UnicodeEncodeError` when reporting method names outside the ANSI/OEM code page. - Decode `exit_code` and `seconds` in `_read_int()` with `encoding="utf-8-sig"` so UTF-8 BOM-prefixed files parse cleanly instead of reading as `None`. - Guard the second `open()` in `_lines()` against `OSError` and catch `(ValueError, RecursionError)` on `boot.jsonl` `json.loads()` lines so deeply nested corrupt entries increment `startup_bad_lines` cleanly. - Reject non-positive `--limit-seconds` values (`< 1`) in `main()` via `parser.error(...)` (exit `2`). - Add regression tests in `tests/test_game_run_summary.py`. ### Tested - `python -I tests/test_game_run_summary.py -v` -> `Ran 12 tests in 0.156s`, `OK`. - Detached `upstream/main` (`98c2f777`) baseline worktree with updated `tests/test_game_run_summary.py` -> `Ran 12 tests in 0.176s`, `FAILED (failures=4, errors=2)` (all new regression checks fail before the fix). - `python -I tests/test_ci_registration.py` -> `Ran 16 tests in 5.198s`, `OK`. - `python -I tests/test_text_write_line_endings.py` -> `Ran 3 tests in 12.859s`, `OK`. - `python -I scripts/check_no_game_data.py tools/game_run_summary.py tests/test_game_run_summary.py` -> exit `0`. - `python -I -m compileall -q tools/game_run_summary.py tests/test_game_run_summary.py` and `git diff --check` -> exit `0`. GPUs tested: n/a (CPU/stdlib Python tests on Windows 11 x64) 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. - [ ] A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a)
DeadlyChirp commented 2026-11-25 15:50:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DeadlyChirp on 2026-11-25T15:50:20Z.


Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main.

python -m pytest -q tests/test_game_run_summary.py:

  • PR: 12 passed. main: 8 passed. The new tests pass on Windows.
  • Also: with this PR, tools/game_run_summary.py should no longer appear in tests/test_tool_stdout_encoding.py's list (it is one of the two tools still listed after #1673).

(AI-assisted test run; output checked by hand.)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7167357574 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1837#issuecomment-7167357574). Originally posted by [DeadlyChirp](https://github.com/DeadlyChirp) on 2026-11-25T15:50:20Z. --- Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main. `python -m pytest -q tests/test_game_run_summary.py`: - PR: 12 passed. main: 8 passed. The new tests pass on Windows. - Also: with this PR, `tools/game_run_summary.py` should no longer appear in `tests/test_tool_stdout_encoding.py`'s list (it is one of the two tools still listed after #1673). (AI-assisted test run; output checked by hand.)
kirigayakazima commented 2026-11-27 12:11:46 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-27T12:11:46Z.


Thanks @DeadlyChirp — checked current main: tools/game_run_summary.py is already removed from NOT_YET_GUARDED in tests/test_tool_stdout_encoding.py, so #1837 stays conflict-free without modifying that test file.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7217951330 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1837#issuecomment-7217951330). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-27T12:11:46Z. --- Thanks @DeadlyChirp — checked current `main`: `tools/game_run_summary.py` is already removed from `NOT_YET_GUARDED` in `tests/test_tool_stdout_encoding.py`, so `#1837` stays conflict-free without modifying that test file.
TheGeogeo commented 2026-11-29 00:00:41 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T00:00:41Z.


Tested e76cabc17 merged (no commit) with main aa918e5d9. Python 3.12.4, Windows 11 10.0.26300, CPU only. check_no_game_data.py is clean.

Blocker: it breaks once merged with current main. On its own head, tests/test_game_run_summary.py passes (12 tests). Merged with main, test_utf8_bom_exit_code_and_seconds_are_parsed fails: it expects time limit (60 s) reached, and the tool now says process exit 124 (0x0000007c), no exit event in the startup trace. main changed how an exit 124 is reported since this branch, so the PR needs a rebase and either an updated expectation or an updated message.

  • Red: with tools/game_run_summary.py back to main, 3 failures and 2 errors (e.g. None != 124). The rest of the new checks do fail without the fix.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7247810201 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1837#issuecomment-7247810201). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-29T00:00:41Z. --- Tested `e76cabc17` merged (no commit) with `main` `aa918e5d9`. Python 3.12.4, Windows 11 10.0.26300, CPU only. `check_no_game_data.py` is clean. **Blocker: it breaks once merged with current `main`.** On its own head, `tests/test_game_run_summary.py` passes (12 tests). Merged with `main`, `test_utf8_bom_exit_code_and_seconds_are_parsed` fails: it expects `time limit (60 s) reached`, and the tool now says `process exit 124 (0x0000007c), no exit event in the startup trace`. `main` changed how an exit 124 is reported since this branch, so the PR needs a rebase and either an updated expectation or an updated message. - Red: with `tools/game_run_summary.py` back to `main`, 3 failures and 2 errors (e.g. `None != 124`). The rest of the new checks do fail without the fix. AI-assisted (Claude Code).
OreoFR commented 2026-11-29 02:56:15 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T02:56:15Z.


Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main c8bf0e7b6, PR head e76cabc17 : red 5 failures / green 1 failure

python3.12 -I tests/test_game_run_summary.py (12 tests):

  • Merge: clean (git merge-tree). main changed this test file since the PR base (#2028), so red = the merged test file against main's code.
  • Red: 5 failures: test_bad_arguments_fail (--limit-seconds 0 and -5), test_utf8_bom_exit_code_and_seconds_are_parsed, test_deeply_nested_boot_jsonl_line_is_counted_as_bad, test_lines_handles_oserror_on_second_open. test_non_ascii_stdout_is_safe_under_redirected_io already passes on main (4b10cbe91 added errors="replace").
  • Green (main + git merge --no-ff): 11 OK, 1 failure: test_utf8_bom_exit_code_and_seconds_are_parsed — 'time limit (60 s) reached' not found in 'process exit 124 (0x0000007c), no exit event…'.
    • Semantic conflict with #2028: main now tells an early exit from a timeout (finished_before_limit). The test uses seconds=45 with limit=60, which main now treats as an early exit. Setting seconds to >= 60 in the test should fix it (ASSUMED).
  • (MEASURED n=3) the green failure reproduces 3/3 when run alone.
  • No other test imports game_run_summary. Skipped: none.
  • Diff: utf-8-sig in _read_int, the OSError guard in _lines, RecursionError and --limit-seconds validation look right; the reconfigure block duplicates main's but only one remains after merge. No game data.

Verdict: FAILS (needs a rebase on #2028 and the test's seconds value adjusted).

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7249738450 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1837#issuecomment-7249738450). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T02:56:15Z. --- Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main c8bf0e7b6, PR head e76cabc17 : red 5 failures / green 1 failure `python3.12 -I tests/test_game_run_summary.py` (12 tests): - Merge: clean (`git merge-tree`). main changed this test file since the PR base (#2028), so red = the merged test file against main's code. - **Red**: 5 failures: `test_bad_arguments_fail` (`--limit-seconds 0` and `-5`), `test_utf8_bom_exit_code_and_seconds_are_parsed`, `test_deeply_nested_boot_jsonl_line_is_counted_as_bad`, `test_lines_handles_oserror_on_second_open`. `test_non_ascii_stdout_is_safe_under_redirected_io` already passes on main (4b10cbe91 added `errors="replace"`). - **Green** (main + `git merge --no-ff`): 11 OK, **1 failure**: `test_utf8_bom_exit_code_and_seconds_are_parsed` — `'time limit (60 s) reached' not found in 'process exit 124 (0x0000007c), no exit event…'`. - Semantic conflict with #2028: main now tells an early exit from a timeout (`finished_before_limit`). The test uses seconds=45 with limit=60, which main now treats as an early exit. Setting seconds to >= 60 in the test should fix it (ASSUMED). - (MEASURED n=3) the green failure reproduces 3/3 when run alone. - No other test imports `game_run_summary`. Skipped: none. - Diff: `utf-8-sig` in `_read_int`, the OSError guard in `_lines`, RecursionError and `--limit-seconds` validation look right; the `reconfigure` block duplicates main's but only one remains after merge. No game data. **Verdict: FAILS** (needs a rebase on #2028 and the test's seconds value adjusted). AI-assisted: Claude Code
OreoFR commented 2026-11-29 08:34:42 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T08:34:42Z.


Could you merge the current main into this branch? As noted in the verification above, after #2028 main tells an early exit from a timeout (finished_before_limit), so test_utf8_bom_exit_code_and_seconds_are_parsed fails on the merge with seconds=45 / limit=60; using seconds >= 60 in that test should make it pass (ASSUMED). The rest of the PR looked good on macOS. If there is no reply in about 24 h, we may open a follow-up PR that carries your commits (with you as co-author) and links back here.

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7253194968 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1837#issuecomment-7253194968). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T08:34:42Z. --- Could you merge the current `main` into this branch? As noted in the verification above, after #2028 `main` tells an early exit from a timeout (`finished_before_limit`), so `test_utf8_bom_exit_code_and_seconds_are_parsed` fails on the merge with `seconds=45` / `limit=60`; using seconds >= 60 in that test should make it pass (ASSUMED). The rest of the PR looked good on macOS. If there is no reply in about 24 h, we may open a follow-up PR that carries your commits (with you as co-author) and links back here. AI-assisted: Claude Code
OreoFR commented 2026-11-30 14:38:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T14:38:43Z.


Taken over in #2746 (no answer since the request above to merge main). Your commit e76cabc17 is kept as is with you as author; #2746 adds only the main merge and the test update after #2028 (seconds at the limit). If you come back to this one, say so and #2746 can be closed in favour of this PR.

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7281701870 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1837#issuecomment-7281701870). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-30T14:38:43Z. --- Taken over in #2746 (no answer since the request above to merge `main`). Your commit `e76cabc17` is kept as is with you as author; #2746 adds only the `main` merge and the test update after #2028 (seconds at the limit). If you come back to this one, say so and #2746 can be closed in favour of this PR. 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
ProjectLeonida/mandy!1837
No description provided.