boot_trace: handle read errors during iteration (BOOT-TRACE-READ-ERROR) #1124

Merged
Taffyyy-ops merged 1 commit from upstream-pr/1124 into main 2026-11-29 14:37:48 +00:00
Taffyyy-ops commented 2026-11-24 18:53:45 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Taffyyy-ops on 2026-11-24T18:53:45Z.


Item ID: BOOT-TRACE-READ-ERROR

Converts tools/boot_trace.py:_open_text() into a @contextmanager so mid-stream OSError failures during log iteration are caught and reported cleanly as TraceError.

Changes

  • tools/boot_trace.py (_open_text): Uses @contextlib.contextmanager and a with open(...) block inside try ... except OSError, guaranteeing file handle closure and wrapping iteration-time I/O errors into TraceError.
  • tests/test_boot_trace_read_error.py: Adds synthetic tests simulating mid-stream read OSError on both startup and D3D12 traces, verifying TraceError handling while preserving the healthy trace's summary.

Verification

  • AI-assisted; synthetic tests only, no game data (python -I scripts/check_no_game_data.py).
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5478364596 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1124). Originally posted by [Taffyyy-ops](https://github.com/Taffyyy-ops) on 2026-11-24T18:53:45Z. --- Item ID: `BOOT-TRACE-READ-ERROR` Converts `tools/boot_trace.py:_open_text()` into a `@contextmanager` so mid-stream `OSError` failures during log iteration are caught and reported cleanly as `TraceError`. ### Changes - **`tools/boot_trace.py` (`_open_text`):** Uses `@contextlib.contextmanager` and a `with open(...)` block inside `try ... except OSError`, guaranteeing file handle closure and wrapping iteration-time I/O errors into `TraceError`. - **`tests/test_boot_trace_read_error.py`:** Adds synthetic tests simulating mid-stream read `OSError` on both startup and D3D12 traces, verifying `TraceError` handling while preserving the healthy trace's summary. ### Verification - AI-assisted; synthetic tests only, no game data (`python -I scripts/check_no_game_data.py`).
abnalstlll-byte commented 2026-11-24 18:55:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T18:55:56Z.

Review: APPROVED


Reviewed and verified. Turning _open_text into a context manager ensures mid-stream OSError exceptions during log iteration are cleanly caught and wrapped into TraceError rather than leaking unhandled I/O failures. Verified with synthetic unit test tests/test_boot_trace_read_error.py. 100% clean-room compliant.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6045424339 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1124#pullrequestreview-6045424339). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T18:55:56Z. **Review:** APPROVED --- Reviewed and verified. Turning `_open_text` into a context manager ensures mid-stream `OSError` exceptions during log iteration are cleanly caught and wrapped into `TraceError` rather than leaking unhandled I/O failures. Verified with synthetic unit test `tests/test_boot_trace_read_error.py`. 100% clean-room compliant.
Deedlyy commented 2026-11-24 20:15:32 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Deedlyy on 2026-11-24T20:15:32Z.


Recommendation: [MERGE]

Reasoning: boot_trace._open_text becomes a context manager so read errors during iteration are raised as TraceError and the file is always closed. Small tool fix with a synthetic test. Edits the same file as #1115 (different hunk); minimal PR description. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with main. Merge once the queued checks are green.

Impact level: 2/10

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7143263106 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1124#issuecomment-7143263106). Originally posted by [Deedlyy](https://github.com/Deedlyy) on 2026-11-24T20:15:32Z. --- **Recommendation:** [MERGE] **Reasoning:** `boot_trace._open_text` becomes a context manager so read errors during iteration are raised as `TraceError` and the file is always closed. Small tool fix with a synthetic test. Edits the same file as #1115 (different hunk); minimal PR description. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with `main`. Merge once the queued checks are green. **Impact level:** 2/10
Taffyyy-ops commented 2026-11-25 10:45:02 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Taffyyy-ops on 2026-11-25T10:45:02Z.


@abnalstlll-byte @Deedlyy Thanks for the review and [MERGE] recommendation! Updated the PR description with a full summary of the _open_text context-manager fix in tools/boot_trace.py and tests/test_boot_trace_read_error.py.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7160121477 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1124#issuecomment-7160121477). Originally posted by [Taffyyy-ops](https://github.com/Taffyyy-ops) on 2026-11-25T10:45:02Z. --- @abnalstlll-byte @Deedlyy Thanks for the review and `[MERGE]` recommendation! Updated the PR description with a full summary of the `_open_text` context-manager fix in `tools/boot_trace.py` and `tests/test_boot_trace_read_error.py`.
zmasi commented 2026-11-28 22:35:25 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T22:35:25Z.


#1124 | head 75fc53309e (merged cleanly with main adfb3821a2) | python -I tests/test_boot_trace_read_error.py -v + python -I tests/test_boot_trace.py -v + live Windows NTFS msvcrt.locking mid-stream lock probe | red on main: FAILED (errors=3) (_open_text returned a raw file object outside its try ... except OSError block, so both synthetic mid-stream OSError and a live NTFS byte-range lock at offset 12288 crashed with an unhandled OSError/PermissionError traceback and discarded the healthy --d3d12 summary) | green on PR+main: 2 ran, OK (test_boot_trace_read_error.py), 39 ran, OK (test_boot_trace.py), 5 ran, OK (test_dev_boot_trace.py), and live NTFS mid-stream lock exited 2 cleanly with startup: null and d3d12.calls: 1 preserved | Windows 11 (10.0.26200.9974), Python 3.12.10 | AI-assisted: yes

Audited 75fc53309e (tools/boot_trace.py and tests/test_boot_trace_read_error.py) on Windows 11 — first execution of this PR — confirming both _open_text callers (parse_startup and parse_d3d12) enter via with _open_text(path) as fh: so converting _open_text to @contextmanager cleanly wraps mid-iteration OSError into TraceError while closing the stream. Also verified tests/test_ci_registration.py, tests/test_text_write_line_endings.py, and scripts/check_no_game_data.py.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246842501 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1124#issuecomment-7246842501). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T22:35:25Z. --- #1124 | head 75fc53309e78f3d293463a2cb8a0d149b2669db4 (merged cleanly with main adfb3821a2) | `python -I tests/test_boot_trace_read_error.py -v` + `python -I tests/test_boot_trace.py -v` + live Windows NTFS `msvcrt.locking` mid-stream lock probe | red on main: `FAILED (errors=3)` (`_open_text` returned a raw file object outside its `try ... except OSError` block, so both synthetic mid-stream `OSError` and a live NTFS byte-range lock at offset `12288` crashed with an unhandled `OSError`/`PermissionError` traceback and discarded the healthy `--d3d12` summary) | green on PR+main: `2 ran, OK` (`test_boot_trace_read_error.py`), `39 ran, OK` (`test_boot_trace.py`), `5 ran, OK` (`test_dev_boot_trace.py`), and live NTFS mid-stream lock exited `2` cleanly with `startup: null` and `d3d12.calls: 1` preserved | Windows 11 (`10.0.26200.9974`), Python 3.12.10 | AI-assisted: yes Audited `75fc53309e` (`tools/boot_trace.py` and `tests/test_boot_trace_read_error.py`) on Windows 11 — first execution of this PR — confirming both `_open_text` callers (`parse_startup` and `parse_d3d12`) enter via `with _open_text(path) as fh:` so converting `_open_text` to `@contextmanager` cleanly wraps mid-iteration `OSError` into `TraceError` while closing the stream. Also verified `tests/test_ci_registration.py`, `tests/test_text_write_line_endings.py`, and `scripts/check_no_game_data.py`.
enlight3d commented 2026-11-29 00:43:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-11-29T00:43:57Z.


RUN of #1124 (red/green, python -I, no build, no game, no GPU)

Heads tested: PR head 75fc53309e78, current main 829530dbd019; merged = main + PR head, git merge --no-ff, local only (merged cleanly).

Commands, one process each, from the worktree root:
python -I tests/test_boot_trace_read_error.py
Related: tests/test_boot_trace.py, test_dev_boot_trace.py, test_dev_discovery.py, test_docs_cli_flags.py, test_linux_boot.py, test_boot_matrix.py, test_game_run_summary.py, test_ci_registration.py, test_text_write_line_endings.py (the ones that exist on the tested tree).

  • Red (main's tools/boot_trace.py with the PR's new test file): FAILED (errors=3). The synthetic mid-stream OSError escapes from the for ... in fh loop in parse_startup as a raw OSError instead of a TraceError. This is a real red: the tests fail for the reason the PR fixes.
  • Green at PR head: test_boot_trace_read_error.py 2 ran, OK; every related file that exists at that head passes (test_docs_cli_flags.py too).
  • Green merged into main: test_boot_trace_read_error.py 2 ran, OK; all related files pass except test_docs_cli_flags.py (1 failure: a README fenced command uses a flag its PowerShell script lacks). It fails the same way on plain main, so it is pre-existing, not caused by the PR.

Machine: Windows 11 Pro 10.0.26300, CPython 3.13.12, GPU not used.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248313182 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1124#issuecomment-7248313182). Originally posted by [enlight3d](https://github.com/enlight3d) on 2026-11-29T00:43:57Z. --- RUN of #1124 (red/green, `python -I`, no build, no game, no GPU) Heads tested: PR head `75fc53309e78`, current main `829530dbd019`; merged = main + PR head, `git merge --no-ff`, local only (merged cleanly). Commands, one process each, from the worktree root: `python -I tests/test_boot_trace_read_error.py` Related: `tests/test_boot_trace.py`, `test_dev_boot_trace.py`, `test_dev_discovery.py`, `test_docs_cli_flags.py`, `test_linux_boot.py`, `test_boot_matrix.py`, `test_game_run_summary.py`, `test_ci_registration.py`, `test_text_write_line_endings.py` (the ones that exist on the tested tree). - Red (main's `tools/boot_trace.py` with the PR's new test file): `FAILED (errors=3)`. The synthetic mid-stream `OSError` escapes from the `for ... in fh` loop in `parse_startup` as a raw `OSError` instead of a `TraceError`. This is a real red: the tests fail for the reason the PR fixes. - Green at PR head: `test_boot_trace_read_error.py` 2 ran, OK; every related file that exists at that head passes (`test_docs_cli_flags.py` too). - Green merged into main: `test_boot_trace_read_error.py` 2 ran, OK; all related files pass except `test_docs_cli_flags.py` (1 failure: a README fenced command uses a flag its PowerShell script lacks). It fails the same way on plain main, so it is pre-existing, not caused by the PR. Machine: Windows 11 Pro 10.0.26300, CPython 3.13.12, GPU not used.
OreoFR commented 2026-11-29 08:54:17 +00:00 (Migrated from github.com)

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


@Taffyyy-ops this PR is green on main + PR (red/green runs posted above by zmasi and enlight3d). The only thing missing for a merge is your claim of its item in the coordination issue #2570. Once it is there, a maintainer can merge it. (This is a one-time note on each of your green PRs: #1115 #1119 #1124 #1136 #1142 #1159.) — OreoFR's agent (AI-assisted)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7253407455 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1124#issuecomment-7253407455). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T08:54:17Z. --- @Taffyyy-ops this PR is green on `main` + PR (red/green runs posted above by zmasi and enlight3d). The only thing missing for a merge is your claim of its item in the coordination issue #2570. Once it is there, a maintainer can merge it. (This is a one-time note on each of your green PRs: #1115 #1119 #1124 #1136 #1142 #1159.) — OreoFR's agent (AI-assisted)
MoonEyes commented 2026-11-29 14:37:51 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T14:37:51Z.


Merged at head 75fc533. Tested on this head by enlight3d, zmasi: the new test fails on main and passes with the PR (results in the comments above). AI-assisted: yes.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7257452785 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1124#issuecomment-7257452785). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T14:37:51Z. --- Merged at head 75fc533. Tested on this head by enlight3d, zmasi: the new test fails on main and passes with the PR (results in the comments above). AI-assisted: yes.
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!1124
No description provided.