dstorage, fs: LEONIDA_IO_TRACE logs every read the title asks for, flushed as it goes (RT-IO-TRACE) #1931

Merged
kawaii-shakal merged 4 commits from upstream-pr/1931 into main 2026-11-29 15:43:27 +00:00
kawaii-shakal commented 2026-11-25 16:02:26 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kawaii-shakal on 2026-11-25T16:02:26Z.


Claimed in the coordination issue as RT-IO-TRACE: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7167534627

Problem

When a boot stops, --trace names the files the title opened (the first 600 opens), but not what it was reading. Most of the reading goes through DirectStorage requests and ReadFile on files opened long before the stop. In a 1.0.2.1 boot here, the last open came 4 minutes before the device loss.

Change

With LEONIDA_IO_TRACE=<file>, every read is one line, starting with the local time (as the mem-probe lines do):

hh:mm:ss.mmm ds G:\example.rpf off=0x1000 src=4096 dst=16384 zlib=1 bcpack=0 name=-
hh:mm:ss.mmm rf \\?\F:\...\data.bin off=0x1000 size=512
  • ds: each DirectStorage request at EnqueueRequest, with file (or <memory>), file offset, source and destination sizes, zlib, BCPack and the request's name. The name pointer is the title's, so it is copied under SEH.
  • rf: each ReadFile, ReadFileEx and ReadFileScatter on a disk file, with path, offset (the OVERLAPPED's, else the handle's position) and size. The path is asked of the handle every time, because a handle value is reused after a close.
  • On disk at once: every line is flushed, and the file is opened shared for reading (_wfsopen(..., _SH_DENYNO)). The last reads before a crash or device loss are on disk, and the file can be watched during the boot.

It is off by default; without the variable nothing is formatted. runtime/shims/io_trace.h implements it, with hooks in dstorage.cpp and file_system.cpp. docs/boot.md documents the variable.

Tested (Windows 11 Pro 26300, VS 2026 RelWithDebInfo)

  • CTest: io_trace covers positioned, overlapped and reused-handle reads, DirectStorage lines with a good, a bad and a null name pointer, pipes left out, and reading the trace while it is open. dstorage and file_system pass too.
  • Real boot: an earlier build of the same hooks ran during a 1.0.2.1 retail boot on an RTX 5070 Ti. It wrote about 90,000 lines, and the last ones showed the streaming at the world start right before the device loss: anim.rpf, levels.rpf, core_bvh4.rpf and packs.rpf, with all reads stopping at the moment of the loss.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5494757427 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1931). Originally posted by [kawaii-shakal](https://github.com/kawaii-shakal) on 2026-11-25T16:02:26Z. --- Claimed in the coordination issue as RT-IO-TRACE: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7167534627 ### Problem When a boot stops, `--trace` names the files the title opened (the first 600 opens), but not what it was reading. Most of the reading goes through DirectStorage requests and `ReadFile` on files opened long before the stop. In a 1.0.2.1 boot here, the last open came 4 minutes before the device loss. ### Change With `LEONIDA_IO_TRACE=<file>`, every read is one line, starting with the local time (as the `mem-probe` lines do): ``` hh:mm:ss.mmm ds G:\example.rpf off=0x1000 src=4096 dst=16384 zlib=1 bcpack=0 name=- hh:mm:ss.mmm rf \\?\F:\...\data.bin off=0x1000 size=512 ``` - **`ds`:** each DirectStorage request at `EnqueueRequest`, with file (or `<memory>`), file offset, source and destination sizes, zlib, BCPack and the request's name. The name pointer is the title's, so it is copied under SEH. - **`rf`:** each `ReadFile`, `ReadFileEx` and `ReadFileScatter` on a disk file, with path, offset (the `OVERLAPPED`'s, else the handle's position) and size. The path is asked of the handle every time, because a handle value is reused after a close. - **On disk at once:** every line is flushed, and the file is opened shared for reading (`_wfsopen(..., _SH_DENYNO)`). The last reads before a crash or device loss are on disk, and the file can be watched during the boot. It is off by default; without the variable nothing is formatted. `runtime/shims/io_trace.h` implements it, with hooks in `dstorage.cpp` and `file_system.cpp`. `docs/boot.md` documents the variable. ### Tested (Windows 11 Pro 26300, VS 2026 RelWithDebInfo) - **CTest:** `io_trace` covers positioned, overlapped and reused-handle reads, DirectStorage lines with a good, a bad and a null name pointer, pipes left out, and reading the trace while it is open. `dstorage` and `file_system` pass too. - **Real boot:** an earlier build of the same hooks ran during a 1.0.2.1 retail boot on an RTX 5070 Ti. It wrote about 90,000 lines, and the last ones showed the streaming at the world start right before the device loss: `anim.rpf`, `levels.rpf`, `core_bvh4.rpf` and `packs.rpf`, with all reads stopping at the moment of the loss. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
zmasi commented 2026-11-28 12:09:15 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T12:09:15Z.


Verified on Windows 11 (10.0.26200.9974) with MSVC 19.44.35228 (x64, /std:c++20 /EHsc /W4 /permissive- /utf-8 /O2) against main d48a957bb + a6e0360f44 (claim #2570#issuecomment-7238954420):

  • Line-by-line diff audit: Clean (docs/boot.md, runtime/CMakeLists.txt, runtime/shims/dstorage.cpp, runtime/shims/file_system.cpp, runtime/shims/io_trace.h, runtime/test/io_trace_test.cpp); opens LEONIDA_IO_TRACE with _SH_DENYNO, flushes timestamped ds and rf read lines under a mutex, queries GetFinalPathNameByHandleW per disk handle, and guards request.Name reads with __try / __except. check_no_game_data.py, test_docs_encoding, test_docs_links, and LEONIDA_IO_TRACE env-var doc coverage all pass.
  • Red (d48a957bb + PR test): io_trace_test.cpp fails to build (rc=2, fatal error C1083: Cannot open include file: 'io_trace.h': No such file or directory).
  • Green (d48a957bb + a6e0360f44 merge): Auto-merges cleanly across all 4 modified files (rc=0), compiles io_trace_test.exe with 0 warnings under /W4 /permissive- and passes (io_trace: positioned, overlapped and DirectStorage lines, written through and shared for reading, rc=0), and builds/passes full dstorage_test.exe (rc=0) while emitting 2,855 live flushed ds / rf trace lines under LEONIDA_IO_TRACE.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7239030153 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1931#issuecomment-7239030153). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T12:09:15Z. --- Verified on Windows 11 (`10.0.26200.9974`) with MSVC `19.44.35228` (`x64`, `/std:c++20 /EHsc /W4 /permissive- /utf-8 /O2`) against `main` `d48a957bb` + `a6e0360f44` (claim `#2570#issuecomment-7238954420`): - **Line-by-line diff audit**: Clean (`docs/boot.md`, `runtime/CMakeLists.txt`, `runtime/shims/dstorage.cpp`, `runtime/shims/file_system.cpp`, `runtime/shims/io_trace.h`, `runtime/test/io_trace_test.cpp`); opens `LEONIDA_IO_TRACE` with `_SH_DENYNO`, flushes timestamped `ds` and `rf` read lines under a mutex, queries `GetFinalPathNameByHandleW` per disk handle, and guards `request.Name` reads with `__try` / `__except`. `check_no_game_data.py`, `test_docs_encoding`, `test_docs_links`, and `LEONIDA_IO_TRACE` env-var doc coverage all pass. - **Red (`d48a957bb` + PR test)**: `io_trace_test.cpp` fails to build (`rc=2`, `fatal error C1083: Cannot open include file: 'io_trace.h': No such file or directory`). - **Green (`d48a957bb` + `a6e0360f44` merge)**: Auto-merges cleanly across all 4 modified files (`rc=0`), compiles `io_trace_test.exe` with `0` warnings under `/W4 /permissive-` and passes (`io_trace: positioned, overlapped and DirectStorage lines, written through and shared for reading`, `rc=0`), and builds/passes full `dstorage_test.exe` (`rc=0`) while emitting `2,855` live flushed `ds` / `rf` trace lines under `LEONIDA_IO_TRACE`. AI-assisted.
Tauwni commented 2026-11-28 15:12:36 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tauwni on 2026-11-28T15:12:36Z.


With clang-cl, the new io_trace test crashes instead of catching the unreadable name: wine: Unhandled page fault on read access to 0000000000000010, in rt::io_trace::copy_name (runtime/shims/io_trace.h:70) called from io_trace_test.cpp:60, safe_name(reinterpret_cast<const char*>(16)). Fails 3/3 runs (MEASURED; Apple M3, macOS 26.5.1, Wine 11.0, clang-cl cross-build, head 29141b471 merged onto main ef02e9a9b).

runtime/CMakeLists.txt says why next to dstorage.cpp: "These sources use __try to handle access violations. MSVC always catches them; clang-cl needs asynchronous exceptions". dstorage.cpp, the runtime file that calls safe_name, already gets /EHa there, so the runtime side is covered; the new io_trace_test target does not. With the same option on it,

target_compile_options(io_trace_test PRIVATE /W4 /permissive- /utf-8 $<$<CXX_COMPILER_ID:Clang>:/EHa>)

the test passes, 3/3 runs (MEASURED, same machine). With MSVC it passes as is, which matches the MSVC run above; I have not run MSVC myself.

Not checked by a second agent or human yet.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7241288244 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1931#issuecomment-7241288244). Originally posted by [Tauwni](https://github.com/Tauwni) on 2026-11-28T15:12:36Z. --- With clang-cl, the new `io_trace` test crashes instead of catching the unreadable name: `wine: Unhandled page fault on read access to 0000000000000010`, in `rt::io_trace::copy_name` (`runtime/shims/io_trace.h:70`) called from `io_trace_test.cpp:60`, `safe_name(reinterpret_cast<const char*>(16))`. Fails 3/3 runs (MEASURED; Apple M3, macOS 26.5.1, Wine 11.0, clang-cl cross-build, head `29141b471` merged onto `main` `ef02e9a9b`). `runtime/CMakeLists.txt` says why next to `dstorage.cpp`: "These sources use __try to handle access violations. MSVC always catches them; clang-cl needs asynchronous exceptions". `dstorage.cpp`, the runtime file that calls `safe_name`, already gets `/EHa` there, so the runtime side is covered; the new `io_trace_test` target does not. With the same option on it, ```cmake target_compile_options(io_trace_test PRIVATE /W4 /permissive- /utf-8 $<$<CXX_COMPILER_ID:Clang>:/EHa>) ``` the test passes, 3/3 runs (MEASURED, same machine). With MSVC it passes as is, which matches the MSVC run above; I have not run MSVC myself. Not checked by a second agent or human yet. AI-assisted (Claude Code).
kawaii-shakal commented 2026-11-28 17:28:41 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kawaii-shakal on 2026-11-28T17:28:41Z.


Thanks, confirmed and fixed in 7d571f75: io_trace_test now gets $<$<CXX_COMPILER_ID:Clang>:/EHa> as you suggested, and the comment on copy_name says a caller needs it under clang-cl (dstorage.cpp, the only caller in the runtime, already has it through its source property, so the shim itself was not affected). Reproduced here with clang-cl 21 + xwin under Wine, same compile flags as the CMake target: without /EHa 3/3 runs end in Unhandled page fault on read access to 0000000000000010, with it 3/3 pass. MSVC is unchanged (the expression is empty there).

AI-assisted (Claude Code); I ran the builds and checked the results.


Generated by Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7243046345 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1931#issuecomment-7243046345). Originally posted by [kawaii-shakal](https://github.com/kawaii-shakal) on 2026-11-28T17:28:41Z. --- Thanks, confirmed and fixed in 7d571f75: `io_trace_test` now gets `$<$<CXX_COMPILER_ID:Clang>:/EHa>` as you suggested, and the comment on `copy_name` says a caller needs it under clang-cl (`dstorage.cpp`, the only caller in the runtime, already has it through its source property, so the shim itself was not affected). Reproduced here with clang-cl 21 + xwin under Wine, same compile flags as the CMake target: without `/EHa` 3/3 runs end in `Unhandled page fault on read access to 0000000000000010`, with it 3/3 pass. MSVC is unchanged (the expression is empty there). AI-assisted (Claude Code); I ran the builds and checked the results. --- _Generated by [Claude Code](https://claude.ai/code)_
zmasi commented 2026-11-29 02:37:21 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-29T02:37:21Z.


#1931 | head 7d571f75b7 (merged cleanly onto origin/main c8bf0e7b65) | Windows 11 (10.0.26200.9974), MSVC 19.44.35228 (x64), Python 3.12.10 | AI-assisted: yes

Summary — PASS (Re-verification of updated head 7d571f75b7e1)

Re-verified 7d571f75b7e126e69f8eb61d151ac7f11d866803 merged cleanly onto origin/main (c8bf0e7b6568f471b42540010e335ca6413d4c58, git merge-tree --write-tree exit 0) on native Windows 11 (x64).

Red -> Green Verification

  1. Red (origin/main c8bf0e7b65):
    • runtime/shims/io_trace.h and runtime/test/io_trace_test.cpp are absent on origin/main, and neither file_system.cpp nor dstorage.cpp emits unbuffered LEONIDA_IO_TRACE records.
  2. Green (origin/main + #1931):
    • Standalone test build & execution (MSVC 19.44.35228, /std:c++20 /O2 /MD /EHsc /W4 /permissive- /utf-8 /link /OPT:NOREF):
      • runtime/test/io_trace_test.cpp compiled cleanly (0 warnings) and passed in 0.075s (rc=0: io_trace: positioned, overlapped and DirectStorage lines, written through and shared for reading), covering unset/empty LEONIDA_IO_TRACE, LEONIDA_IO_TRACE=- (stderr), FILE_SHARE_READ concurrent open while tracing is active, positioned & OVERLAPPED ReadFile lines (rf), DirectStorage file/memory/unreadable-name request lines (ds), unbuffered write-through across abrupt TerminateProcess without atexit/fflush, and multi-threaded atomic WriteFile line integrity.
    • Shim call-site compilation (MSVC 19.44.35228, /c /std:c++20 /O2 /MD /EHsc /W4 /permissive- /utf-8):
      • runtime/shims/file_system.cpp and runtime/shims/dstorage.cpp both compiled cleanly with io_trace.h wired in (rc=0, 0 warnings).
    • CMake & Docs Gates:
      • python tests/test_ctest_registration.py -> OK
      • docs/boot.md relative-link & anchor check -> 0 issues
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7249543154 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1931#issuecomment-7249543154). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-29T02:37:21Z. --- #1931 | head 7d571f75b7e126e69f8eb61d151ac7f11d866803 (merged cleanly onto origin/main c8bf0e7b65) | Windows 11 (10.0.26200.9974), MSVC 19.44.35228 (x64), Python 3.12.10 | AI-assisted: yes ### Summary — PASS (Re-verification of updated head `7d571f75b7e1`) Re-verified `7d571f75b7e126e69f8eb61d151ac7f11d866803` merged cleanly onto `origin/main` (`c8bf0e7b6568f471b42540010e335ca6413d4c58`, `git merge-tree --write-tree` exit `0`) on native Windows 11 (`x64`). ### Red -> Green Verification 1. **Red (`origin/main` `c8bf0e7b65`)**: - `runtime/shims/io_trace.h` and `runtime/test/io_trace_test.cpp` are absent on `origin/main`, and neither `file_system.cpp` nor `dstorage.cpp` emits unbuffered `LEONIDA_IO_TRACE` records. 2. **Green (`origin/main` + `#1931`)**: - **Standalone test build & execution (`MSVC 19.44.35228`, `/std:c++20 /O2 /MD /EHsc /W4 /permissive- /utf-8 /link /OPT:NOREF`)**: - `runtime/test/io_trace_test.cpp` compiled cleanly (`0` warnings) and passed in `0.075s` (`rc=0`: `io_trace: positioned, overlapped and DirectStorage lines, written through and shared for reading`), covering unset/empty `LEONIDA_IO_TRACE`, `LEONIDA_IO_TRACE=-` (`stderr`), `FILE_SHARE_READ` concurrent open while tracing is active, positioned & `OVERLAPPED` `ReadFile` lines (`rf`), DirectStorage file/memory/unreadable-name request lines (`ds`), unbuffered write-through across abrupt `TerminateProcess` without `atexit`/`fflush`, and multi-threaded atomic `WriteFile` line integrity. - **Shim call-site compilation (`MSVC 19.44.35228`, `/c /std:c++20 /O2 /MD /EHsc /W4 /permissive- /utf-8`)**: - `runtime/shims/file_system.cpp` and `runtime/shims/dstorage.cpp` both compiled cleanly with `io_trace.h` wired in (`rc=0`, `0` warnings). - **CMake & Docs Gates**: - `python tests/test_ctest_registration.py` -> **`OK`** - `docs/boot.md` relative-link & anchor check -> **`0` issues**
OreoFR commented 2026-11-29 03:45:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T03:45:22Z.


Verified by OreoFR

  • Base: main aa918e5d9 + PR head 7d571f75b
  • Test: ctest -R ^io_trace$
  • Red on main: the new test does not compile on main (io_trace.h is added by the PR)
  • Green with the PR: passes; package builds, full ctest shows no new failure (d3d12_queue_handover_shared_queue failed once under load and passes on a serial rerun)
  • Verdict: READY
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

Note: shares runtime/CMakeLists.txt with the open #2566; a rebase may be needed if #2566 lands first.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7250239349 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1931#issuecomment-7250239349). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T03:45:22Z. --- **Verified by OreoFR** - Base: main `aa918e5d9` + PR head `7d571f75b` - Test: `ctest -R ^io_trace$` - Red on main: the new test does not compile on main (`io_trace.h` is added by the PR) - Green with the PR: passes; package builds, full ctest shows no new failure (`d3d12_queue_handover_shared_queue` failed once under load and passes on a serial rerun) - Verdict: READY - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 Note: shares `runtime/CMakeLists.txt` with the open #2566; a rebase may be needed if #2566 lands first. AI-assisted (Claude Code, Claude Opus 5.5).
MoonEyes commented 2026-11-29 15:43:30 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T15:43:30Z.


Merged. Tested by @OreoFR on head 7d571f75b (RTX 4070 Laptop 8GB, Windows 11): io_trace ctest: new test does not compile on main; passes with PR, full ctest no new failure. The CI jobs that are red on this head were also red on main at the time of the run. Thanks @kawaii-shakal!

AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7258315948 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1931#issuecomment-7258315948). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T15:43:30Z. --- Merged. Tested by @OreoFR on head 7d571f75b (RTX 4070 Laptop 8GB, Windows 11): io_trace ctest: new test does not compile on main; passes with PR, full ctest no new failure. The CI jobs that are red on this head were also red on main at the time of the run. Thanks @kawaii-shakal! 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!1931
No description provided.