runtime, d3d12: both runtimes write an import call trace, and a tool compares two (RT-CALL-TRACE, D3D12-CALL-TRACE) #2807

Open
ubiquitarianism wants to merge 9 commits from upstream-pr/2807 into main
ubiquitarianism commented 2026-12-01 00:31:48 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ubiquitarianism on 2026-12-01T00:31:48Z.


Claimed in the coordination issue as: RT-CALL-TRACE and D3D12-CALL-TRACE (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7296419849)

What and why

When gta6rt and leonida.exe stop at different places in the boot, there is no record of which import call they first handled differently. With LEONIDA_CALL_TRACE=<new file> set, both runtimes now record every call through the import tables of the title's image and its DLLs (normal and delay-load) in one shared v1 text format. Unset, nothing changes: wrap returns the import's address and no thunk block is allocated.

  • tools/call_trace_rules.def: the rules both runtimes read (gta6rt includes it, leonida-loader parses it), so the two traces are comparable. Stack walks and RtlCaptureContext2 are entry-only (a wrap frame would end the title's stack walk at the stub), and __vdecl vector math is skipped (its YMM arguments are not kept by the stubs).
  • Each import slot gets a 24-byte thunk to one of two common stubs: entry-only (E line, real return address) or wrapped (C and R lines with the return class). The stubs are registered for unwinding; the entry stub's unwind range ends before its final jump.
  • The file is written through 4 MiB mapped views, capped by LEONIDA_CALL_TRACE_MAX_MB (default 4096). The writer lock is taken with a bound of about 10 ms; a record that cannot get it is dropped and the next one writes # dropped N.
  • gta6rt shims read their caller through RT_CALLER(), which sees through the wrap frame.
  • tools/call_trace_diff.py pairs the two traces' threads (main first, then by start address and common call prefix), aligns each pair's calls and reports the first divergences: calls one side never makes, different return classes, different call counts, threads on one side only and calls still open at the end. It streams its input (two synthetic 1M-call traces: 14.0 s, 336 MB peak).

Not run in game.

Tested

Windows 11 (26200), Visual Studio 18 (2026) MSVC, AMD Radeon RX 6800 (driver 32.0.21030.2001), rebased on main at 66b5d0433:

  • cargo test --profile diag -p leonida-loader --lib -- call_trace: 29 passed
  • runtime RelWithDebInfo build; ctest: 205 of 205 passed, 2 disabled (gameinput, gameinput_script, no SDL3 here)
  • python -I tests/test_call_trace_diff.py, tests/test_call_trace_rules.py: OK; python -m compileall -q tools tests: OK
  • scripts/check_no_game_data.py on the changed files: OK

One full ctest -j 8 run failed call_trace (and the unrelated windows_crash_monitor); both passed alone and in the next full -j 8 run. case_dropped_record checks that a dropped call takes under 100 ms of wall time, which a machine running eight test jobs can exceed. The failing run's output was not kept, so that cause is likely, not confirmed.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5576410046 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2807). Originally posted by [ubiquitarianism](https://github.com/ubiquitarianism) on 2026-12-01T00:31:48Z. --- Claimed in the coordination issue as: RT-CALL-TRACE and D3D12-CALL-TRACE (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7296419849) ### What and why When gta6rt and leonida.exe stop at different places in the boot, there is no record of which import call they first handled differently. With `LEONIDA_CALL_TRACE=<new file>` set, both runtimes now record every call through the import tables of the title's image and its DLLs (normal and delay-load) in one shared v1 text format. Unset, nothing changes: `wrap` returns the import's address and no thunk block is allocated. - `tools/call_trace_rules.def`: the rules both runtimes read (gta6rt includes it, leonida-loader parses it), so the two traces are comparable. Stack walks and `RtlCaptureContext2` are entry-only (a wrap frame would end the title's stack walk at the stub), and `__vdecl` vector math is skipped (its YMM arguments are not kept by the stubs). - Each import slot gets a 24-byte thunk to one of two common stubs: entry-only (`E` line, real return address) or wrapped (`C` and `R` lines with the return class). The stubs are registered for unwinding; the entry stub's unwind range ends before its final jump. - The file is written through 4 MiB mapped views, capped by `LEONIDA_CALL_TRACE_MAX_MB` (default 4096). The writer lock is taken with a bound of about 10 ms; a record that cannot get it is dropped and the next one writes `# dropped N`. - gta6rt shims read their caller through `RT_CALLER()`, which sees through the wrap frame. - `tools/call_trace_diff.py` pairs the two traces' threads (main first, then by start address and common call prefix), aligns each pair's calls and reports the first divergences: calls one side never makes, different return classes, different call counts, threads on one side only and calls still open at the end. It streams its input (two synthetic 1M-call traces: 14.0 s, 336 MB peak). Not run in game. ### Tested Windows 11 (26200), Visual Studio 18 (2026) MSVC, AMD Radeon RX 6800 (driver 32.0.21030.2001), rebased on `main` at `66b5d0433`: - `cargo test --profile diag -p leonida-loader --lib -- call_trace`: 29 passed - runtime RelWithDebInfo build; `ctest`: 205 of 205 passed, 2 disabled (`gameinput`, `gameinput_script`, no SDL3 here) - `python -I tests/test_call_trace_diff.py`, `tests/test_call_trace_rules.py`: OK; `python -m compileall -q tools tests`: OK - `scripts/check_no_game_data.py` on the changed files: OK One full `ctest -j 8` run failed `call_trace` (and the unrelated `windows_crash_monitor`); both passed alone and in the next full `-j 8` run. `case_dropped_record` checks that a dropped call takes under 100 ms of wall time, which a machine running eight test jobs can exceed. The failing run's output was not kept, so that cause is likely, not confirmed.
OreoFR commented 2026-12-01 00:37:32 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-12-01T00:37:32Z.


Verified by OreoFR on macOS 27.2.1, Apple M5, head e2572082c, main b7a1be296. Partial check: the Python tools, plus a Windows type-check of the D3D12 side. leonida-loader does not build natively on macOS (it uses windows_sys and core::arch::x86_64, on main as well), and the runtime side (gta6rt, runtime/shims/call_trace*.h, call_trace_test.cpp) was not built here.

MEASURED

  • git merge-tree onto main gives no conflicts.
  • Python, red (main + only this PR's tests): test_call_trace_diff.py errors at import (tools/call_trace_diff.py doesn't exist on main), and test_call_trace_rules.py fails. Green (main + this PR): test_call_trace_diff.py 79 passed, 42 subtests passed (10.9 s); test_call_trace_rules.py 9 passed.
  • cargo check --target x86_64-pc-windows-msvc (no MSVC; the cc build steps are replaced with stand-ins), main vs main + this PR, exit 0 on both sides. The sorted warning lists are identical: -p leonida-loader --tests 0 / 0 (this compiles call_trace.rs and its 1,474-line test module), -p leonida 19 / 19 (run.rs).

READ IN CODE

  • The switch exists and is opt-in. In d3d12/apps/leonida/src/run.rs, call_trace::open_from_env()? runs only when LEONIDA_CALL_TRACE is set, and add_module is called for the image, the title DLLs and the late-loaded DLLs. With the switch unset, add_module is called but (per the description) wrap returns the import's address unchanged and no thunk block is allocated. I didn't run that path, so "no change when unset" is from the code and your description, not measured here.
  • open_from_env()? propagates an error, so a LEONIDA_CALL_TRACE path that already exists stops the title from starting, as the comment says ("the file must be new").

ASSUMED

  • The Rust unit tests (29), ctest 205/205, and the case_dropped_record flake you describe are from your Windows run. Not reproduced. Not run in game, as you say.

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7296547800 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2807#issuecomment-7296547800). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-12-01T00:37:32Z. --- Verified by OreoFR on macOS 27.2.1, Apple M5, head `e2572082c`, main `b7a1be296`. Partial check: the Python tools, plus a Windows type-check of the D3D12 side. `leonida-loader` does not build natively on macOS (it uses `windows_sys` and `core::arch::x86_64`, on main as well), and the runtime side (gta6rt, `runtime/shims/call_trace*.h`, `call_trace_test.cpp`) was not built here. **MEASURED** - `git merge-tree` onto main gives no conflicts. - Python, red (main + only this PR's tests): `test_call_trace_diff.py` errors at import (`tools/call_trace_diff.py` doesn't exist on main), and `test_call_trace_rules.py` fails. Green (main + this PR): `test_call_trace_diff.py` 79 passed, 42 subtests passed (10.9 s); `test_call_trace_rules.py` 9 passed. - `cargo check --target x86_64-pc-windows-msvc` (no MSVC; the `cc` build steps are replaced with stand-ins), main vs main + this PR, exit 0 on both sides. The sorted warning lists are identical: `-p leonida-loader --tests` 0 / 0 (this compiles `call_trace.rs` and its 1,474-line test module), `-p leonida` 19 / 19 (`run.rs`). **READ IN CODE** - The switch exists and is opt-in. In `d3d12/apps/leonida/src/run.rs`, `call_trace::open_from_env()?` runs only when `LEONIDA_CALL_TRACE` is set, and `add_module` is called for the image, the title DLLs and the late-loaded DLLs. With the switch unset, `add_module` is called but (per the description) `wrap` returns the import's address unchanged and no thunk block is allocated. I didn't run that path, so "no change when unset" is from the code and your description, not measured here. - `open_from_env()?` propagates an error, so a `LEONIDA_CALL_TRACE` path that already exists stops the title from starting, as the comment says ("the file must be new"). **ASSUMED** - The Rust unit tests (29), ctest 205/205, and the `case_dropped_record` flake you describe are from your Windows run. Not reproduced. Not run in game, as you say. AI-assisted: Claude Code
fiestorra commented 2026-12-01 01:35:54 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-01T01:35:54Z.


Verified in all three layers it touches, on Windows, and none of them fails.

main d920d850d plus this head:

Python (the two suites it adds):

python -m pytest tests/test_call_trace_diff.py tests/test_call_trace_rules.py -q
  88 passed, 42 subtests passed   (25.45 s)

C++:

cmake --build runtime/build --target call_trace_test     exit 0
runtime\build\call_trace_test.exe                        exit 0
  error: LEONIDA_CALL_TRACE: the file already exists; the call trace only creates a new file
  error: LEONIDA_CALL_TRACE_MAX_MB: expected a whole number of MiB from 1 to 1048576
  error: LEONIDA_CALL_TRACE: cannot create the file (error 3)
  call_trace_test: ok

Those three error lines are the test doing its job - it drives the refusal paths and prints them - and call_trace_test: ok is the verdict.

Rust (six files under d3d12/):

cargo test --workspace       exit 101
  ... the workspace's own suites all `ok` (403 passed / 5 ignored in the largest)
  FAILED: xtask policy::tests::repository_passes_policy

That failure is not this pull request's: it is main failing its own asset policy on two files over 640 KiB (leonida-gpu/src/host.rs, leonida-shader/src/emit/lower.rs), which #2815 fixes, and it fails identically on main alone. Everything else in the workspace is green with this change, including the crates it touches.

What I could not test: a real import call trace from a title - that needs the game and the two runtimes the note describes, and this is a 24 GB desktop, not the 8 GB laptop the trace was written for. The diff tool and its rules are what the 88 Python tests cover, and they are green.

One thing worth saying about the size: +6,558 across 23 files is a lot to review, and the shape helps - 795 lines of C++ test, 1,189 of Python tests, 731 of tool, 236 of rules, and the rest is the runtime hooks the notes describe. The tests are two thirds of it, which is the right ratio for a diagnostic that has to be trusted.

AI-assisted: yes - DeepSeek v4.1 (flash), which ran all three layers on the machine above.

Written with an AI assistant.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7297682394 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2807#issuecomment-7297682394). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-12-01T01:35:54Z. --- **Verified in all three layers it touches, on Windows, and none of them fails.** **`main` `d920d850d` plus this head:** **Python** (the two suites it adds): ``` python -m pytest tests/test_call_trace_diff.py tests/test_call_trace_rules.py -q 88 passed, 42 subtests passed (25.45 s) ``` **C++**: ``` cmake --build runtime/build --target call_trace_test exit 0 runtime\build\call_trace_test.exe exit 0 error: LEONIDA_CALL_TRACE: the file already exists; the call trace only creates a new file error: LEONIDA_CALL_TRACE_MAX_MB: expected a whole number of MiB from 1 to 1048576 error: LEONIDA_CALL_TRACE: cannot create the file (error 3) call_trace_test: ok ``` **Those three error lines are the test doing its job** - **it drives the refusal paths and prints them** - **and `call_trace_test: ok` is the verdict.** **Rust** (six files under `d3d12/`): ``` cargo test --workspace exit 101 ... the workspace's own suites all `ok` (403 passed / 5 ignored in the largest) FAILED: xtask policy::tests::repository_passes_policy ``` **That failure is not this pull request's**: **it is `main` failing its own asset policy on two files over 640 KiB** (`leonida-gpu/src/host.rs`, `leonida-shader/src/emit/lower.rs`), **which #2815 fixes**, **and it fails identically on `main` alone.** **Everything else in the workspace is green with this change, including the crates it touches.** **What I could not test:** **a real import call trace from a title** - **that needs the game and the two runtimes the note describes**, **and this is a 24 GB desktop, not the 8 GB laptop the trace was written for.** **The diff tool and its rules are what the 88 Python tests cover, and they are green.** **One thing worth saying about the size**: **+6,558 across 23 files is a lot to review, and the shape helps** - **795 lines of C++ test, 1,189 of Python tests, 731 of tool, 236 of rules, and the rest is the runtime hooks the notes describe.** **The tests are two thirds of it, which is the right ratio for a diagnostic that has to be trusted.** **AI-assisted:** yes - DeepSeek v4.1 (flash), which ran all three layers on the machine above. Written with an AI assistant.
KelboLive commented 2026-12-01 05:45:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-01T05:45:24Z.

Review: COMMENTED


The tracer is sound. Off costs nothing — wrap returns the target and allocates no thunk (call_trace.h:700) — and on is one atomic per call plus a bounded writer lock, with the line formatted and sequenced inside the lock (:442-520), so lines cannot interleave. The stream is capped (:361, call_trace.rs:796) and goes through 4 MiB mapped views, so RAM does not grow with the trace. Every test I ran passes: call_trace ctest, 79 test_call_trace_diff tests, 9 test_call_trace_rules, 29 Rust call_trace tests. Mutation: removing the return comparison in compare_thread (tools/call_trace_diff.py:519) fails 12 tests, so the diff's core is genuinely pinned.

One unbounded path, and it is a real inconsistency between the two runtimes:

  • call_trace.rs:865 treats an unparsable or 0 LEONIDA_CALL_TRACE_MAX_MB as 4096 silently, and mb.saturating_mul(1 << 20) turns a parseable but huge value into no cap at all. gta6rt refuses both cases with a message and exit 2, and its test asserts that (call_trace.h:577-590). Make the Rust parser match the C++ one, and never let a value saturate to "unbounded".

Two more, in the tool:

  • rules differ, truncated=yes and a missing header only warn and can still exit 0 (test_differing_rules_print_a_warning asserts exactly that). A script reads 0 as "identical", so give those a distinct exit code — a rules mismatch means the traces are not comparable at all. A warning when both sides report the same stack= would also help.
  • case_dropped_record's wall-clock < 100 ms is load-dependent (the body already saw it fail under -j8); assert the drop count and the # dropped ordering, keep the timing as a print.

Documentation worth one line in the README: the trace records identity and the return class, no arguments and no strings — so a divergence that lives only in an argument is invisible to the diff (a hash of the first argument qwords would be safe, unlike strings). And RT_CALLER's 0x140 duplicates the stub's 0x138 frame by hand — a static_assert against the blob would keep them tied.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6125792321 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2807#pullrequestreview-6125792321). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-12-01T05:45:24Z. **Review:** COMMENTED --- The tracer is sound. Off costs nothing — `wrap` returns the target and allocates no thunk (`call_trace.h:700`) — and on is one atomic per call plus a bounded writer lock, with the line formatted and sequenced **inside** the lock (`:442-520`), so lines cannot interleave. The stream is capped (`:361`, `call_trace.rs:796`) and goes through 4 MiB mapped views, so RAM does not grow with the trace. Every test I ran passes: `call_trace` ctest, 79 `test_call_trace_diff` tests, 9 `test_call_trace_rules`, 29 Rust `call_trace` tests. Mutation: removing the return comparison in `compare_thread` (`tools/call_trace_diff.py:519`) fails 12 tests, so the diff's core is genuinely pinned. One unbounded path, and it is a real inconsistency between the two runtimes: - `call_trace.rs:865` treats an unparsable or `0` `LEONIDA_CALL_TRACE_MAX_MB` as 4096 **silently**, and `mb.saturating_mul(1 << 20)` turns a parseable but huge value into **no cap at all**. `gta6rt` refuses both cases with a message and exit 2, and its test asserts that (`call_trace.h:577-590`). Make the Rust parser match the C++ one, and never let a value saturate to "unbounded". Two more, in the tool: - `rules differ`, `truncated=yes` and a missing header only **warn** and can still exit 0 (`test_differing_rules_print_a_warning` asserts exactly that). A script reads 0 as "identical", so give those a distinct exit code — a rules mismatch means the traces are not comparable at all. A warning when both sides report the same `stack=` would also help. - `case_dropped_record`'s wall-clock `< 100 ms` is load-dependent (the body already saw it fail under `-j8`); assert the drop count and the `# dropped` ordering, keep the timing as a print. Documentation worth one line in the README: the trace records identity and the return *class*, no arguments and no strings — so a divergence that lives only in an argument is invisible to the diff (a hash of the first argument qwords would be safe, unlike strings). And `RT_CALLER`'s `0x140` duplicates the stub's `0x138` frame by hand — a `static_assert` against the blob would keep them tied.
Neutron-0 commented 2026-12-01 10:20:23 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Neutron-0 on 2026-12-01T10:20:23Z.


A heads-up for this pull request: the page of D3D12 switches (d3d12/docs/switches.md) is written by tools/d3d12_switches.py from the sources of d3d12/, and 3 names this pull request reads are not on the page yet: LEONIDA_CALL_TRACE, LEONIDA_CALL_TRACE_MAX_MB, LEONIDA_CT_CHILD.

Nothing checks that today, so the page has drifted before (it was a name behind when this was measured). A test that checks it is waiting to be opened (DOCS-SWITCHES-PAGE-CHECK), and it would make this pull request's CI red until the page is written again. One command does that:

python -I tools/d3d12_switches.py --out d3d12/docs/switches.md

It writes the page with the names in it and nothing else; the diff is the new rows.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7308036455 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2807#issuecomment-7308036455). Originally posted by [Neutron-0](https://github.com/Neutron-0) on 2026-12-01T10:20:23Z. --- A heads-up for this pull request: the page of D3D12 switches (`d3d12/docs/switches.md`) is written by `tools/d3d12_switches.py` from the sources of `d3d12/`, and 3 names this pull request reads are not on the page yet: `LEONIDA_CALL_TRACE`, `LEONIDA_CALL_TRACE_MAX_MB`, `LEONIDA_CT_CHILD`. Nothing checks that today, so the page has drifted before (it was a name behind when this was measured). A test that checks it is waiting to be opened (DOCS-SWITCHES-PAGE-CHECK), and it would make this pull request's CI red until the page is written again. One command does that: ``` python -I tools/d3d12_switches.py --out d3d12/docs/switches.md ``` It writes the page with the names in it and nothing else; the diff is the new rows.
merzleckeier commented 2026-12-01 12:44:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-01T12:44:20Z.


Confirmed the Rust/C++ trace-cap mismatch under Wine on e2572082c + 6c7f6b60c. The stock C++ call_trace_test passed, as did the 79 diff tests and 9 rule tests. In a separate synthetic Rust child-process regression, a cap of 0 returned Ok(true) instead of refusing the setting before creating the trace. A local change to validate the configured range and format before opening the file made the new test pass for 0, 12x, 1048577 and whitespace-prefixed 1. All 31 Rust call_trace::tests passed in that build, including the existing 1 MiB truncation check. I used temporary trace files only.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7311574817 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2807#issuecomment-7311574817). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-12-01T12:44:20Z. --- Confirmed the Rust/C++ trace-cap mismatch under Wine on `e2572082c` + `6c7f6b60c`. The stock C++ `call_trace_test` passed, as did the 79 diff tests and 9 rule tests. In a separate synthetic Rust child-process regression, a cap of `0` returned `Ok(true)` instead of refusing the setting before creating the trace. A local change to validate the configured range and format before opening the file made the new test pass for `0`, `12x`, `1048577` and whitespace-prefixed `1`. All 31 Rust `call_trace::tests` passed in that build, including the existing 1 MiB truncation check. I used temporary trace files only. AI-assisted with OpenAI Codex.
MoonEyes commented 2026-12-02 12:26:40 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T12:26:40Z.


This pull request touches the render path, so it needs an in-game run before it can be merged: unit tests and CI do not catch rendering regressions (a device loss after an earlier merge is why this gate exists).

Could you, or anyone with a working setup, post a run report on the current head merged onto current main:

  • the head SHA and the main SHA it was merged onto;
  • GPU, driver and OS;
  • at least 300 s in the world after loading;
  • device lost / crashes (count), and rendered fps (median) if you have them;
  • the same run on main alone for comparison, if you can.

Please do not attach logs or screenshots that show game content. If a run on this exact head is already posted, a link to it in a reply is enough.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7345347967 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2807#issuecomment-7345347967). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T12:26:40Z. --- This pull request touches the render path, so it needs an in-game run before it can be merged: unit tests and CI do not catch rendering regressions (a device loss after an earlier merge is why this gate exists). Could you, or anyone with a working setup, post a run report on the **current head** merged onto current `main`: - the head SHA and the `main` SHA it was merged onto; - GPU, driver and OS; - at least 300 s in the world after loading; - device lost / crashes (count), and rendered fps (median) if you have them; - the same run on `main` alone for comparison, if you can. Please do not attach logs or screenshots that show game content. If a run on this exact head is already posted, a link to it in a reply is enough. AI-assisted (Claude Code).
Kal0s-design commented 2026-12-02 15:58:15 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-12-02T15:58:15Z.


Ran natively on Windows 11, head e2572082c merged into current main (83046a713, clean merge). This adds what the thread does not have yet: the two writers side by side on the same synthetic calls, cost per call, contention, a kill under load, and malformed input to the tool. The cap parsing and the exit codes for missing headers or differing rules are already covered above, so I left them out.

Stock tests (measured)

Suite Result
cargo test -p leonida-loader (whole crate, dev profile) 119 passed, plus 2 + 1 in the other targets
call_trace filter (dev profile) 29 passed
call_trace_test.cpp, built on its own with MSVC (the CMake target's warning and define flags, plus /std:c++20 /O2) call_trace_test: ok, 3 of 3 runs
python -I tests/test_call_trace_diff.py / test_call_trace_rules.py (unittest) 79 OK / 9 OK
cargo clippy -p leonida-loader -p leonida --all-targets --features leonida/diagnostics no warning in call_trace.rs, windows.rs or run.rs

1. The two runtimes write different names for the same import (reading, then measured)

call_trace.rs caps module!function at 160 bytes and a module name in caller/start at 47. call_trace.h caps them at 172 (Site::name) and 31 (ModEntry::name). Also, for an import bound to an unimplemented stub, Rust skips classify (wrap: bind == Unimpl goes straight to entry-only), while C++ calls decide() first and returns the target untraced on a skip rule.

I ran the same calls through both writers with throwaway children: a 200-character import name, a title module with a 40-character name, and an unimplemented import in api-ms-win-crt-math-l1-1-0.dll (a CT_SKIP_MODULE prefix).

Case leonida-hle writes gta6rt writes
200-char import name 160 bytes in all (module, ! and the name cut short) 172 bytes
40-char module in caller all 40 characters first 31 characters
unimplemented import, skip-rule module E ... unimpl line nothing (wrap returns the target)

To see what the tool makes of each one, I built three pairs of synthetic traces. In each pair, everything is the same except that one field, written the way each runtime writes it:

Pair Exit Report
name 172 vs 160 1 1 only-left + 1 only-right, 2 count differences
caller module 31 vs 40 chars 1 1 only-left + 1 only-right
unimplemented import in a skip-rule module 1 1 only-right, 1 count difference

So each mismatch shows up as a divergence on every call it touches. As an illustration of how long decorated names get (this is not a claim about what the title imports): the system msvcp140.dll has 1,515 exports. 193 of them are longer than 160 bytes as msvcp140.dll!<name> (133 are longer than 172, max 196). Cut to 160 bytes, only 1,407 names are still distinct (1,469 at 172), so truncation also merges different imports into one name on each side. Possible fixes: give both writers one limit, or write a hash suffix when a name is cut. Then apply the skip rules to unimplemented imports in both, or in neither.

2. Cost per call (measured, release build, one thread, 10^6 calls each, a trivial target)

direct wrap stub (C+R) entry stub (E) wrap / entry after the cap
Rust (3 runs) 0.9-1.2 ns 185-196 ns 99-119 ns 10-13 ns / 5 ns
C++ (3 runs) 1.3 ns 108-111 ns 59-68 ns 9-11 ns / 4 ns

With these short names, a wrapped call writes about 72 bytes (115.1 MB for 1.6 M calls) and an entry-only call about 51. At that rate the default 4096 MiB cap holds roughly 60 million wrapped calls.

3. Contention (measured, Rust, production 10 ms lock bound)

There were 1.6 million wrapped calls in total, split over 1 to 64 threads that do nothing but call:

Threads 1 4 8 16 32 64
ns/call (aggregate) 236 374 497 629 644 630
slowest single call 0.7 ms 1.2 ms 1.2 ms 1.6 ms 1.5 ms 1.5 ms
dropped 0 0 0 0 0 0

In every run there were no open C records, and the file had exactly two records per call plus one T line per thread. Throughput levels off at about 1.6 M calls/s for the whole process, and no record was dropped at any thread count.

4. Kill under load (measured, Rust)

A child ran 4 threads calling a wrapped import in a loop, then called TerminateProcess on itself after 300 ms. Over 5 runs, the file held 60-81 MB of lines (15-20 views). Each file had 1-3 open C records, one per thread caught inside a call. I looked at the tail of one of the five: it ended on a complete line, with no NUL inside the content. The tool parsed every file, and a self-diff exited 0.

5. Size on disk (measured, both writers)

The file grows in whole 4 MiB views and is never cut back to its content:

Cap / content Size on disk
MAX_MB=1 (Rust 1,048,507 B, C++ 1,048,558 B) 4,194,304 B on both
MAX_MB=5 (Rust 5,242,792 B) 8,388,608 B
126 KB trace, no cap reached 4,194,304 B

This is harmless for the tool, which strips the NULs. But a 1 MiB cap gives a 4 MiB file, so the README could say the cap counts content, not size on disk.

6. The tool on malformed input (measured, python -I, 16 hand-made cases + 1,000 random mutations of a real 4-thread Rust trace)

Input Exit
random truncation at any byte (200) 1, never a parse error (the partial last line is ignored as documented)
byte flipped (200) 2 in 173, 1 in 25, 0 in 2
line deleted / duplicated / swapped (600) 1 or 2, never a traceback
CRLF line ends 0 (accepted)
UTF-8 BOM 2 (got 1 TAB-separated fields on line 1)
NUL run in the middle 2
second header later in the file, other rules hash 0, ignored silently
two empty files, or two all-NUL files 0
a seq of 5,000 digits uncaught ValueError (Python's 4,300-digit int limit), process exit 1

The last row is the only crash I found. It is artificial, but it exits with 1, the code the tool documents for "divergences". A try/except ValueError around the int() calls in parse_trace, or a digit-length check, would turn it into a 2.

Not checked: whether the title's real module or import names reach these limits, the full CMake build and ctest (I built only call_trace_test on its own), cargo test -p leonida, the gta6rt shims that use RT_CALLER(), and any run in game. The contention numbers come from threads that only call, not from a title's mix.

GPUs tested: n/a (CPU-only tests).

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7351233008 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2807#issuecomment-7351233008). Originally posted by [Kal0s-design](https://github.com/Kal0s-design) on 2026-12-02T15:58:15Z. --- Ran natively on Windows 11, head `e2572082c` merged into current `main` (`83046a713`, clean merge). This adds what the thread does not have yet: the two writers side by side on the same synthetic calls, cost per call, contention, a kill under load, and malformed input to the tool. The cap parsing and the exit codes for missing headers or differing rules are already covered above, so I left them out. **Stock tests (measured)** | Suite | Result | | --- | --- | | `cargo test -p leonida-loader` (whole crate, dev profile) | 119 passed, plus 2 + 1 in the other targets | | `call_trace` filter (dev profile) | 29 passed | | `call_trace_test.cpp`, built on its own with MSVC (the CMake target's warning and define flags, plus `/std:c++20 /O2`) | `call_trace_test: ok`, 3 of 3 runs | | `python -I tests/test_call_trace_diff.py` / `test_call_trace_rules.py` (unittest) | 79 OK / 9 OK | | `cargo clippy -p leonida-loader -p leonida --all-targets --features leonida/diagnostics` | no warning in `call_trace.rs`, `windows.rs` or `run.rs` | **1. The two runtimes write different names for the same import (reading, then measured)** `call_trace.rs` caps `module!function` at 160 bytes and a module name in `caller`/`start` at 47. `call_trace.h` caps them at 172 (`Site::name`) and 31 (`ModEntry::name`). Also, for an import bound to an unimplemented stub, Rust skips `classify` (`wrap`: `bind == Unimpl` goes straight to entry-only), while C++ calls `decide()` first and returns the target untraced on a skip rule. I ran the same calls through both writers with throwaway children: a 200-character import name, a title module with a 40-character name, and an unimplemented import in `api-ms-win-crt-math-l1-1-0.dll` (a `CT_SKIP_MODULE` prefix). | Case | `leonida-hle` writes | `gta6rt` writes | | --- | --- | --- | | 200-char import name | 160 bytes in all (module, `!` and the name cut short) | 172 bytes | | 40-char module in `caller` | all 40 characters | first 31 characters | | unimplemented import, skip-rule module | `E ... unimpl` line | nothing (wrap returns the target) | To see what the tool makes of each one, I built three pairs of synthetic traces. In each pair, everything is the same except that one field, written the way each runtime writes it: | Pair | Exit | Report | | --- | --- | --- | | name 172 vs 160 | 1 | 1 only-left + 1 only-right, 2 count differences | | caller module 31 vs 40 chars | 1 | 1 only-left + 1 only-right | | unimplemented import in a skip-rule module | 1 | 1 only-right, 1 count difference | So each mismatch shows up as a divergence on every call it touches. As an illustration of how long decorated names get (this is not a claim about what the title imports): the system `msvcp140.dll` has 1,515 exports. 193 of them are longer than 160 bytes as `msvcp140.dll!<name>` (133 are longer than 172, max 196). Cut to 160 bytes, only 1,407 names are still distinct (1,469 at 172), so truncation also merges different imports into one name on each side. Possible fixes: give both writers one limit, or write a hash suffix when a name is cut. Then apply the skip rules to unimplemented imports in both, or in neither. **2. Cost per call (measured, release build, one thread, 10^6 calls each, a trivial target)** | | direct | wrap stub (C+R) | entry stub (E) | wrap / entry after the cap | | --- | --- | --- | --- | --- | | Rust (3 runs) | 0.9-1.2 ns | 185-196 ns | 99-119 ns | 10-13 ns / 5 ns | | C++ (3 runs) | 1.3 ns | 108-111 ns | 59-68 ns | 9-11 ns / 4 ns | With these short names, a wrapped call writes about 72 bytes (115.1 MB for 1.6 M calls) and an entry-only call about 51. At that rate the default 4096 MiB cap holds roughly 60 million wrapped calls. **3. Contention (measured, Rust, production 10 ms lock bound)** There were 1.6 million wrapped calls in total, split over 1 to 64 threads that do nothing but call: | Threads | 1 | 4 | 8 | 16 | 32 | 64 | | --- | --- | --- | --- | --- | --- | --- | | ns/call (aggregate) | 236 | 374 | 497 | 629 | 644 | 630 | | slowest single call | 0.7 ms | 1.2 ms | 1.2 ms | 1.6 ms | 1.5 ms | 1.5 ms | | dropped | 0 | 0 | 0 | 0 | 0 | 0 | In every run there were no open C records, and the file had exactly two records per call plus one T line per thread. Throughput levels off at about 1.6 M calls/s for the whole process, and no record was dropped at any thread count. **4. Kill under load (measured, Rust)** A child ran 4 threads calling a wrapped import in a loop, then called `TerminateProcess` on itself after 300 ms. Over 5 runs, the file held 60-81 MB of lines (15-20 views). Each file had 1-3 open C records, one per thread caught inside a call. I looked at the tail of one of the five: it ended on a complete line, with no NUL inside the content. The tool parsed every file, and a self-diff exited 0. **5. Size on disk (measured, both writers)** The file grows in whole 4 MiB views and is never cut back to its content: | Cap / content | Size on disk | | --- | --- | | `MAX_MB=1` (Rust 1,048,507 B, C++ 1,048,558 B) | 4,194,304 B on both | | `MAX_MB=5` (Rust 5,242,792 B) | 8,388,608 B | | 126 KB trace, no cap reached | 4,194,304 B | This is harmless for the tool, which strips the NULs. But a 1 MiB cap gives a 4 MiB file, so the README could say the cap counts content, not size on disk. **6. The tool on malformed input (measured, `python -I`, 16 hand-made cases + 1,000 random mutations of a real 4-thread Rust trace)** | Input | Exit | | --- | --- | | random truncation at any byte (200) | 1, never a parse error (the partial last line is ignored as documented) | | byte flipped (200) | 2 in 173, 1 in 25, 0 in 2 | | line deleted / duplicated / swapped (600) | 1 or 2, never a traceback | | CRLF line ends | 0 (accepted) | | UTF-8 BOM | 2 (`got 1 TAB-separated fields` on line 1) | | NUL run in the middle | 2 | | second header later in the file, other rules hash | 0, ignored silently | | two empty files, or two all-NUL files | 0 | | a seq of 5,000 digits | uncaught `ValueError` (Python's 4,300-digit int limit), process exit **1** | The last row is the only crash I found. It is artificial, but it exits with 1, the code the tool documents for "divergences". A `try`/`except ValueError` around the `int()` calls in `parse_trace`, or a digit-length check, would turn it into a 2. Not checked: whether the title's real module or import names reach these limits, the full CMake build and `ctest` (I built only `call_trace_test` on its own), `cargo test -p leonida`, the gta6rt shims that use `RT_CALLER()`, and any run in game. The contention numbers come from threads that only call, not from a title's mix. GPUs tested: n/a (CPU-only tests). AI-assisted: yes (Claude Code).
MoonEyes commented 2026-12-02 18:14:40 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T18:14:40Z.


Checked the Python side on Linux against current main. Merged with today's main, it now fails the switches-page test, and the Rust/C++ name-cap mismatch reported twice is still in the head. The Rust and C++ were not built here (Windows-only).

head      e2572082c (2026-11-30; nothing pushed since)
base      origin/main 45dc41f95, merge base 66b5d0433 (783 commits behind), merges cleanly (c4b532ebc)
CI        `check` and `linux-python-and-viewer` red on this head (2026-12-01 00:3x). Those failures are in tests the PR does not touch (`test_f.T.test_a`, `EveryToolGuardsStdout`), i.e. old `main`.
Command (on the merge) Result
python -I tests/test_call_trace_diff.py 79 tests, OK
python -I tests/test_call_trace_rules.py 9 tests, OK
python -I tests/test_docs_env_vars.py 5 tests, OK
python -I tests/test_d3d12_switches.py FAILED: test_the_tracked_switches_page_matches_the_sources
python -I scripts/check_no_game_data.py on the 23 changed files exit 0
python -m compileall -q on the changed .py files OK

Defects

  1. The switches page is stale, and main now tests that. d3d12/docs/switches.md is generated from the sources. The PR reads LEONIDA_CALL_TRACE, LEONIDA_CALL_TRACE_MAX_MB and LEONIDA_CT_CHILD, which the page lacks (Neutron-0 pointed this out on 2026-12-01). Since then main gained the check, so CI will go red once it runs on a merge. Fix: merge main, then python -I tools/d3d12_switches.py --out d3d12/docs/switches.md.
  2. The two runtimes still write different names for the same import. d3d12/crates/leonida-loader/src/call_trace.rs caps module!function at 160 bytes and a module name at 47. runtime/shims/call_trace.h caps them at 172 (Site::name) and 31 (ModEntry::name). An import bound to an unimplemented stub also skips classify in Rust (straight to entry-only), while C++ runs decide() first. Both were measured on this head (merzleckeier under Wine on 2026-12-01; Kal0s-design natively today, point 1). Since the whole purpose is a diff of the two traces, a long name or a long module name gives a false divergence at the very first such call. Use one cap and one order, ideally taken from tools/call_trace_rules.def, which both already read.
  3. PR text: no AI-assistance statement and no GPUs tested: line in the template's form (CONTRIBUTING.md, "Disclosure and verification"). The body does give the GPU in prose.

Not checked here: the C++ call_trace_test and cargo test -p leonida-loader (both Windows-only). fiestorra and Kal0s-design ran them green on Windows on this head.

Verdict: defects. Regenerate the switches page on current main and make the two writers' caps and skip order agree. Then it needs a CI run and the requested render-path run.

AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.


Generated by Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7354202574 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2807#issuecomment-7354202574). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T18:14:40Z. --- **Checked the Python side on Linux against current `main`. Merged with today's `main`, it now fails the switches-page test, and the Rust/C++ name-cap mismatch reported twice is still in the head.** The Rust and C++ were not built here (Windows-only). ``` head e2572082c (2026-11-30; nothing pushed since) base origin/main 45dc41f95, merge base 66b5d0433 (783 commits behind), merges cleanly (c4b532ebc) CI `check` and `linux-python-and-viewer` red on this head (2026-12-01 00:3x). Those failures are in tests the PR does not touch (`test_f.T.test_a`, `EveryToolGuardsStdout`), i.e. old `main`. ``` | Command (on the merge) | Result | |---|---| | `python -I tests/test_call_trace_diff.py` | 79 tests, OK | | `python -I tests/test_call_trace_rules.py` | 9 tests, OK | | `python -I tests/test_docs_env_vars.py` | 5 tests, OK | | `python -I tests/test_d3d12_switches.py` | **FAILED**: `test_the_tracked_switches_page_matches_the_sources` | | `python -I scripts/check_no_game_data.py` on the 23 changed files | exit 0 | | `python -m compileall -q` on the changed `.py` files | OK | **Defects** 1. **The switches page is stale, and `main` now tests that.** `d3d12/docs/switches.md` is generated from the sources. The PR reads `LEONIDA_CALL_TRACE`, `LEONIDA_CALL_TRACE_MAX_MB` and `LEONIDA_CT_CHILD`, which the page lacks (Neutron-0 pointed this out on 2026-12-01). Since then `main` gained the check, so CI will go red once it runs on a merge. Fix: merge `main`, then `python -I tools/d3d12_switches.py --out d3d12/docs/switches.md`. 2. **The two runtimes still write different names for the same import.** `d3d12/crates/leonida-loader/src/call_trace.rs` caps `module!function` at 160 bytes and a module name at 47. `runtime/shims/call_trace.h` caps them at 172 (`Site::name`) and 31 (`ModEntry::name`). An import bound to an unimplemented stub also skips `classify` in Rust (straight to entry-only), while C++ runs `decide()` first. Both were measured on this head (merzleckeier under Wine on 2026-12-01; Kal0s-design natively today, point 1). Since the whole purpose is a diff of the two traces, a long name or a long module name gives a false divergence at the very first such call. Use one cap and one order, ideally taken from `tools/call_trace_rules.def`, which both already read. 3. PR text: no AI-assistance statement and no `GPUs tested:` line in the template's form (CONTRIBUTING.md, "Disclosure and verification"). The body does give the GPU in prose. **Not checked here:** the C++ `call_trace_test` and `cargo test -p leonida-loader` (both Windows-only). fiestorra and Kal0s-design ran them green on Windows on this head. **Verdict: defects.** Regenerate the switches page on current `main` and make the two writers' caps and skip order agree. Then it needs a CI run and the requested render-path run. AI-assisted verification: Claude Opus (Claude Code), separate agent per batch. --- _Generated by [Claude Code](https://claude.ai/code)_
MoonEyes commented 2026-12-02 21:34:50 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T21:34:50Z.


RUN (independent run on Windows, head e2572082c02cd261c64b8275447d900a81f9eca8, merged into main b41763227aeed2d23c98af84bcbc1bddc7acdc90 with git merge --no-ff)

The merge is clean (no conflict). Windows 11, release profile, one shared target directory. No game files, no GPU run, no leonida.exe running during the builds.

What the PR is. An opt-in import call trace (LEONIDA_CALL_TRACE) for both runtimes plus a diff tool. It touches leonida-loader, run.rs, the C++ runtime shims and tools/. It does not touch leonida-gpu or any diagnostics-gated code in it, so the GPU lib run below is a regression check on the merge, not a test of the change.

Green

Command (on the merge) Result
cargo test -p leonida-gpu --release --locked --lib first run 702 passed, 1 failed (pool::tests::a_texture_gives_its_piece_back_when_it_goes); the test alone passed twice; the next full run 703 passed, 0 failed
cargo test -p leonida-loader --release --locked --lib call_trace 29 passed
python -I tests/test_call_trace_diff.py 79 OK
python -I tests/test_call_trace_rules.py 9 OK
python -I tests/test_docs_env_vars.py 5 OK
python -I tests/test_d3d12_switches.py 20 run, 1 FAILED: test_the_tracked_switches_page_matches_the_sources

The leonida-gpu failure is a flake in a pool test in code this PR does not touch. I did not run main alone, so I cannot say whether it also flakes there. --features diagnostics was not run: no leonida-gpu file is changed.

Red

  • Rust: with main's lib.rs (no pub mod call_trace), leonida-loader no longer builds, because windows.rs uses the module. Trivially red.
  • Python: with tools/call_trace_diff.py and call_trace_rules.def absent (they do not exist on main), test_call_trace_diff.py fails at import and test_call_trace_rules.py has 4 errors.
  • Mutations of the new code (each restored afterwards), all killed:
    1. call_trace.rs: size-cap check in Writer::line disabled: 2 tests fail (the_size_cap_writes_truncated_once_and_stops, a_cap_between_wrap_and_seal_leaves_callable_thunks), plus the child-process cases.
    2. call_trace.rs: the dropped-record counter not incremented in lock_bounded: 2 fail (a_held_writer_lock_costs_a_record_not_a_hang, child_drop).
    3. call_trace.rs: Bind::Unimpl no longer entry-only: 1 fails (an_unimplemented_import_is_traced_at_entry_with_bind_unimpl).
    4. call_trace_diff.py: return values never compared: 15 failures and 1 error.
    5. call_trace_diff.py: the ignore list for return values dropped: 1 failure.

Review

  1. Default off: OK by reading. open_from_env returns Ok(false) when the variable is unset or empty. wrap returns the target when no common stub is installed, so no thunk block is allocated. I did not measure this in game.
  2. docs/switches.md is stale (defect). LEONIDA_CALL_TRACE, LEONIDA_CALL_TRACE_MAX_MB and LEONIDA_CT_CHILD are missing from the page, and test_d3d12_switches.py now fails on the merge with main. Fix: python -I tools/d3d12_switches.py --out d3d12/docs/switches.md. runtime/README.md does list the two public switches.
  3. The two writers disagree (defect, matches earlier reports).
    • Rust call_trace.rs: NAME_MAX 160, MODULE_NAME_MAX 47. C++ call_trace.h: Site::name[172], module name [31].
    • LEONIDA_CALL_TRACE_MAX_MB: Rust (open_from_env) silently falls back to 4096 on 0 or a non-number (.filter(|&mb| mb > 0).unwrap_or(DEFAULT)); C++ refuses it with an error. The PR text describes the C++ behaviour as the contract.
    • Since the purpose is a diff of the two traces, a long name gives a false divergence. I read these on this head; I did not re-measure them.
  4. Ordering and lifetimes: the writer lock is bounded (about 10 ms) and a drop is counted and reported as # dropped N; a mutation of that counter is caught. Thunks are made after the cap so a bind in progress stays callable; a test covers it. Stub unwinding and fences were not reviewed beyond the tests.
  5. Claim: the body links the claim in issue 2570 (RT-CALL-TRACE and D3D12-CALL-TRACE). No item ID from the coordination issue was checked by me.
  6. Template: the body has no AI-assistance statement and no GPUs tested: line (a prior review also said so).
  7. Open reviewer questions: the switches page and the two mismatches above are still open on this head (nothing pushed since 2026-11-30). One comment noted a possible flake of case_dropped_record (a 100 ms wall-time check) under ctest -j 8.
  8. Overlap with other open PRs: not checked.
  9. In-game run on this exact head: none posted. The maintainer asked for one on 2026-12-02; the author says "Not run in game". Other runs were unit and tool runs only.

Not covered

  • The C++ side (call_trace_test, ctest): not built in this run.
  • Any run of leonida.exe or gta6rt with the switch set, and with it unset, in game.
  • leonida-gpu with diagnostics, and main alone for the pool flake.
  • Overlap check with other open PRs, and the item ID in the coordination issue.
  • d3d12_vulkan.md and findings.md were only searched for call-trace and trace mentions, not read in full.

Verdict

PARTIAL. The new tests and the diff tool pass and the mutations are caught, and the switch is off by default. But the merge with current main fails test_d3d12_switches.py, and the Rust and C++ writers disagree on name caps and on the MAX_MB parsing, which defeats the comparison the PR exists for. In-game run still required (none posted on this head).

AI-assisted (Claude Code), models: Claude Opus 5.5 (checker), separate Claude Opus 5.5 judge.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7359481499 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2807#issuecomment-7359481499). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T21:34:50Z. --- RUN (independent run on Windows, head `e2572082c02cd261c64b8275447d900a81f9eca8`, merged into `main` `b41763227aeed2d23c98af84bcbc1bddc7acdc90` with `git merge --no-ff`) The merge is clean (no conflict). Windows 11, release profile, one shared target directory. No game files, no GPU run, no `leonida.exe` running during the builds. **What the PR is.** An opt-in import call trace (`LEONIDA_CALL_TRACE`) for both runtimes plus a diff tool. It touches `leonida-loader`, `run.rs`, the C++ runtime shims and `tools/`. It does not touch `leonida-gpu` or any diagnostics-gated code in it, so the GPU lib run below is a regression check on the merge, not a test of the change. ## Green | Command (on the merge) | Result | |---|---| | `cargo test -p leonida-gpu --release --locked --lib` | first run 702 passed, 1 failed (`pool::tests::a_texture_gives_its_piece_back_when_it_goes`); the test alone passed twice; the next full run 703 passed, 0 failed | | `cargo test -p leonida-loader --release --locked --lib call_trace` | 29 passed | | `python -I tests/test_call_trace_diff.py` | 79 OK | | `python -I tests/test_call_trace_rules.py` | 9 OK | | `python -I tests/test_docs_env_vars.py` | 5 OK | | `python -I tests/test_d3d12_switches.py` | 20 run, 1 FAILED: `test_the_tracked_switches_page_matches_the_sources` | The `leonida-gpu` failure is a flake in a pool test in code this PR does not touch. I did not run `main` alone, so I cannot say whether it also flakes there. `--features diagnostics` was not run: no `leonida-gpu` file is changed. ## Red - Rust: with `main`'s `lib.rs` (no `pub mod call_trace`), `leonida-loader` no longer builds, because `windows.rs` uses the module. Trivially red. - Python: with `tools/call_trace_diff.py` and `call_trace_rules.def` absent (they do not exist on `main`), `test_call_trace_diff.py` fails at import and `test_call_trace_rules.py` has 4 errors. - Mutations of the new code (each restored afterwards), all killed: 1. `call_trace.rs`: size-cap check in `Writer::line` disabled: 2 tests fail (`the_size_cap_writes_truncated_once_and_stops`, `a_cap_between_wrap_and_seal_leaves_callable_thunks`), plus the child-process cases. 2. `call_trace.rs`: the dropped-record counter not incremented in `lock_bounded`: 2 fail (`a_held_writer_lock_costs_a_record_not_a_hang`, `child_drop`). 3. `call_trace.rs`: `Bind::Unimpl` no longer entry-only: 1 fails (`an_unimplemented_import_is_traced_at_entry_with_bind_unimpl`). 4. `call_trace_diff.py`: return values never compared: 15 failures and 1 error. 5. `call_trace_diff.py`: the ignore list for return values dropped: 1 failure. ## Review 1. **Default off: OK by reading.** `open_from_env` returns `Ok(false)` when the variable is unset or empty. `wrap` returns the target when no common stub is installed, so no thunk block is allocated. I did not measure this in game. 2. **`docs/switches.md` is stale (defect).** `LEONIDA_CALL_TRACE`, `LEONIDA_CALL_TRACE_MAX_MB` and `LEONIDA_CT_CHILD` are missing from the page, and `test_d3d12_switches.py` now fails on the merge with `main`. Fix: `python -I tools/d3d12_switches.py --out d3d12/docs/switches.md`. `runtime/README.md` does list the two public switches. 3. **The two writers disagree (defect, matches earlier reports).** - Rust `call_trace.rs`: `NAME_MAX` 160, `MODULE_NAME_MAX` 47. C++ `call_trace.h`: `Site::name[172]`, module name `[31]`. - `LEONIDA_CALL_TRACE_MAX_MB`: Rust (`open_from_env`) silently falls back to 4096 on `0` or a non-number (`.filter(|&mb| mb > 0).unwrap_or(DEFAULT)`); C++ refuses it with an error. The PR text describes the C++ behaviour as the contract. - Since the purpose is a diff of the two traces, a long name gives a false divergence. I read these on this head; I did not re-measure them. 4. **Ordering and lifetimes:** the writer lock is bounded (about 10 ms) and a drop is counted and reported as `# dropped N`; a mutation of that counter is caught. Thunks are made after the cap so a bind in progress stays callable; a test covers it. Stub unwinding and fences were not reviewed beyond the tests. 5. **Claim:** the body links the claim in issue 2570 (RT-CALL-TRACE and D3D12-CALL-TRACE). No item ID from the coordination issue was checked by me. 6. **Template:** the body has no AI-assistance statement and no `GPUs tested:` line (a prior review also said so). 7. **Open reviewer questions:** the switches page and the two mismatches above are still open on this head (nothing pushed since 2026-11-30). One comment noted a possible flake of `case_dropped_record` (a 100 ms wall-time check) under `ctest -j 8`. 8. **Overlap with other open PRs:** not checked. 9. **In-game run on this exact head:** none posted. The maintainer asked for one on 2026-12-02; the author says "Not run in game". Other runs were unit and tool runs only. ## Not covered - The C++ side (`call_trace_test`, `ctest`): not built in this run. - Any run of `leonida.exe` or `gta6rt` with the switch set, and with it unset, in game. - `leonida-gpu` with `diagnostics`, and `main` alone for the pool flake. - Overlap check with other open PRs, and the item ID in the coordination issue. - `d3d12_vulkan.md` and `findings.md` were only searched for call-trace and trace mentions, not read in full. ## Verdict **PARTIAL.** The new tests and the diff tool pass and the mutations are caught, and the switch is off by default. But the merge with current `main` fails `test_d3d12_switches.py`, and the Rust and C++ writers disagree on name caps and on the MAX_MB parsing, which defeats the comparison the PR exists for. In-game run still required (none posted on this head). AI-assisted (Claude Code), models: Claude Opus 5.5 (checker), separate Claude Opus 5.5 judge.
MoonEyes commented 2026-12-02 23:32:37 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T23:32:37Z.


RUN (in game, batch of five pull requests), each head merged with git merge --no-ff onto main ef35d683e, in one build: #3176 4c31594b5, #2657 c16b0424e, #2807 e2572082c, #3230 97eefdee4, #3247 3e5887f65. RTX 4060 8 GB, driver 610.88, Windows 11. Series S, -Resolution 1080, frame generation 2x, -PrecompileUsed, the same walking route as the other runs on this machine, 330 s after reaching the world.

What Result
Device lost / device removed 0
Exceptions, panics, hang watchdog, GPU stall, title suspended 0
Process alive at the end yes, stopped by the time limit
Rendered fps, last 240 s (47 samples) median 15.8, mean 16.2
Rendered fps, last 120 s median 15.0
Time under 5 fps in the world 1 %

For reference, the same machine and route rendered 13.3 to 17.2 fps on other batches today. These fps are a check that nothing fell over, not a measurement of a gain.

Verdict: PASS for the in-game gate (300 s or more in the world, no device loss) for this batch, on the heads listed above. #3247 has since moved to 3dc6c58b3, which only merges main (81efe4566) into the head above: git diff 3e5887f65 3dc6c58b3 leaves d3d12/scripts/play-nvidia.ps1 and tests/test_win_launchers.py unchanged. If another of these pull requests changes its head, this run no longer covers it.

Limits: one run; arrival in the world was driven by keys and not checked on pictures; -PrecompileUsed was used because main now precompiles every known pipeline by default (88,631 for a new executable, over an hour on this card). The default start was therefore not exercised, and the F1 SAVE AND RESTART path of #3247 was not exercised in game. An earlier attempt of this batch is not counted: the run script gave up waiting while that full precompile ran.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7362132360 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2807#issuecomment-7362132360). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T23:32:37Z. --- RUN (in game, batch of five pull requests), each head merged with `git merge --no-ff` onto main `ef35d683e`, in one build: #3176 `4c31594b5`, #2657 `c16b0424e`, #2807 `e2572082c`, #3230 `97eefdee4`, #3247 `3e5887f65`. RTX 4060 8 GB, driver 610.88, Windows 11. Series S, `-Resolution 1080`, frame generation 2x, `-PrecompileUsed`, the same walking route as the other runs on this machine, 330 s after reaching the world. | What | Result | |---|---| | Device lost / device removed | 0 | | Exceptions, panics, hang watchdog, GPU stall, title suspended | 0 | | Process alive at the end | yes, stopped by the time limit | | Rendered fps, last 240 s (47 samples) | median 15.8, mean 16.2 | | Rendered fps, last 120 s | median 15.0 | | Time under 5 fps in the world | 1 % | For reference, the same machine and route rendered 13.3 to 17.2 fps on other batches today. These fps are a check that nothing fell over, not a measurement of a gain. Verdict: PASS for the in-game gate (300 s or more in the world, no device loss) for this batch, on the heads listed above. #3247 has since moved to `3dc6c58b3`, which only merges `main` (`81efe4566`) into the head above: `git diff 3e5887f65 3dc6c58b3` leaves `d3d12/scripts/play-nvidia.ps1` and `tests/test_win_launchers.py` unchanged. If another of these pull requests changes its head, this run no longer covers it. Limits: one run; arrival in the world was driven by keys and not checked on pictures; `-PrecompileUsed` was used because `main` now precompiles every known pipeline by default (88,631 for a new executable, over an hour on this card). The default start was therefore not exercised, and the F1 SAVE AND RESTART path of #3247 was not exercised in game. An earlier attempt of this batch is not counted: the run script gave up waiting while that full precompile ran. AI-assisted (Claude Code).
fiestorra commented 2026-12-03 07:01:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-03T07:01:12Z.


VERIFY-2807 — el runtime entero compila con esta PR (590 objetivos) y su test de C++ pasa: call_trace_test: ok

Es la PR de C++ más grande de la cola (23 ficheros, +6 558, 13 en runtime/), y la verifiqué compilando y ejecutando, no leyendo:

1. cherry-pick del rango (9 commits) en el checkout principal   → exit 0, sin un conflicto
2. cmake --build runtime/build (con vcvars64)                   → exit 0, 590 objetivos
   incluidos gta6rt.exe, gta6rt_d3d12_com.lib y todos los test executables
3. runtime/build/call_trace_test.exe                            → exit 0, "call_trace_test: ok"
   (por el camino imprime los errores que los tests esperan:
    "the file already exists; the call trace only creates a new file",
    "expected a whole number of MiB from 1 to 1048576")
4. tests/test_call_trace_rules.py                               → 9 passed
5. revertido a main y el runtime reconstruido                   → exit 0

Y el cambio, por su título: los dos runtimes escriben un rastro de las llamadas de importación — un .jsonl de cada función del ejecutable que se llama, con tools/call_trace_diff.py (731 líneas) para comparar dos rastros y call_trace_rules.def (236) para las reglas.

Lo que aporta y por qué es de las importantes: compara el runtime C++ con el port de d3d12/ llamada a llamada, que es la única forma de saber si el port hace lo mismo sin ejecutar el juego dos veces y comparar a ojo. Es instrumentación, y la instrumentación es lo que hace verificable todo lo demás.

Lo que no pude verificar: un rastro real del juego — necesita el título con LEONIDA_CALL_TRACE puesto, y el test de C++ lo simula (y prueba los errores del camino de creación, que es lo que el test sí puede hacer sin el juego).

Y el detalle que me hizo confiar en el test: imprime error: … tres veces y sale 0 — son los casos negativos, y que el ejecutable los imprima y siga es lo que distingue un test de un assert suelto.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7370499503 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2807#issuecomment-7370499503). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-12-03T07:01:12Z. --- ## VERIFY-2807 — **el runtime entero compila con esta PR** (590 objetivos) y su test de C++ pasa: `call_trace_test: ok` **Es la PR de C++ más grande de la cola** (**23 ficheros, +6 558**, **13 en `runtime/`**), **y la verifiqué compilando y ejecutando, no leyendo**: ``` 1. cherry-pick del rango (9 commits) en el checkout principal → exit 0, sin un conflicto 2. cmake --build runtime/build (con vcvars64) → exit 0, 590 objetivos incluidos gta6rt.exe, gta6rt_d3d12_com.lib y todos los test executables 3. runtime/build/call_trace_test.exe → exit 0, "call_trace_test: ok" (por el camino imprime los errores que los tests esperan: "the file already exists; the call trace only creates a new file", "expected a whole number of MiB from 1 to 1048576") 4. tests/test_call_trace_rules.py → 9 passed 5. revertido a main y el runtime reconstruido → exit 0 ``` **Y el cambio, por su título**: **los dos runtimes escriben un rastro de las llamadas de importación** — **un `.jsonl` de cada función del ejecutable que se llama**, **con `tools/call_trace_diff.py` (731 líneas) para comparar dos rastros y `call_trace_rules.def` (236) para las reglas.** **Lo que aporta y por qué es de las importantes**: **compara el runtime C++ con el port de `d3d12/` llamada a llamada**, **que es la única forma de saber si el port hace lo mismo sin ejecutar el juego dos veces y comparar a ojo.** **Es instrumentación, y la instrumentación es lo que hace verificable todo lo demás.** **Lo que no pude verificar**: **un rastro real del juego** — **necesita el título con `LEONIDA_CALL_TRACE` puesto, y el test de C++ lo simula** (**y prueba los errores del camino de creación, que es lo que el test sí puede hacer sin el juego**). **Y el detalle que me hizo confiar en el test**: **imprime `error: …` tres veces y sale 0** — **son los casos negativos, y que el ejecutable los imprima y siga es lo que distingue un test de un `assert` suelto.**
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2807:upstream-pr/2807'
git switch 'upstream-pr/2807'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2807'
git switch 'upstream-pr/2807'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2807'
git switch 'upstream-pr/2807'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2807'
git switch 'main'
git merge --squash 'upstream-pr/2807'
git switch 'main'
git merge --ff-only 'upstream-pr/2807'
git switch 'main'
git merge 'upstream-pr/2807'
git push origin 'main'
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!2807
No description provided.