d3d12: a lost device ends the run with 75 and a marker, not a crash #3151

Open
KelboLive wants to merge 2 commits from upstream-pr/3151 into main
KelboLive commented 2026-12-02 14:20:28 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-02T14:20:28Z.


What and why

A lost D3D12 device currently kills the process. Present and ResizeBuffers results are discarded, resource/heap creation treats DXGI_ERROR_DEVICE_REMOVED as a refusal, and host::fail calls TerminateProcess(0x887A0005) — so a driver/PnP stop looks like a crash and the launcher can only report a failure.

This makes the loss a defined, recoverable event:

  • Present, ResizeBuffers, resource and heap creation now classify DXGI_ERROR_DEVICE_REMOVED/_RESET; host::fail uses the new exit 75 only when GetDeviceRemovedReason actually reports a loss. OOM and other GPU failures keep the legacy 0x887A0005, so they are not mistaken for a loss.
  • On a loss the runtime writes <Data>/device-lost.txt atomically (temp → sync_all → rename), capped at 4 KiB, and logs device lost: reason=… hresult=0x… luid=….
  • The marker carries leonida-device-lost/1, code=75, reason, hresult, unix, pid, plus luid, adapter, frame, what. Free text is percent-encoded.
  • LEONIDA_TEST_DEVICE_LOST_AFTER=<frames> forces the same path for tests, gated to test/diagnostics builds; release binaries ignore it.
  • Play scripts pass LEONIDA_DEVICE_LOST_FILE=<Data>\device-lost.txt (with a <parent of data_dir> fallback), so the launcher and runtime agree on the location. The marker is cleared at run start.

The launcher side (separate PR) reads the marker and restarts at most twice (10 s, 60 s), cancellable, and never restarts a title crash.

Evidence

On Windows 11, RTX 4070 Ti SUPER:

  • cargo test -p leonida-gpu --locked lost → 16 passed, 3 ignored.
  • cargo test -p leonida-gpu --locked -- --test-threads=1 → 705 passed, 59 ignored.
  • cargo test -p leonida -p leonida-hle --locked pass.
  • tools/d3d12_switches.py --check passes (683 names; 643 with comments); check_no_game_data is clean.
  • The exact marker produced parses through the launcher's read_device_lost (verified against the launcher branch).

Scope / notes

  • Runtime only; the launcher changes are a follow-up so each half is reviewable.
  • The parallel texture::alias_cast_tests::… flake is pre-existing (2 of 4 runs on clean main) and is not this change.
  • host.rs/queue.rs/resource.rs overlap open #2670/#2847/#2765; the edits are surgical, expect textual rebases.
  • No game data: the marker contains only DXGI reason/HRESULT, adapter name/LUID and a frame number.

GPUs tested: RTX 4070 Ti SUPER, driver 621.01 (marker and exit path only; no game run)
AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5608316095 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3151). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-12-02T14:20:28Z. --- ### What and why A lost D3D12 device currently kills the process. `Present` and `ResizeBuffers` results are discarded, resource/heap creation treats `DXGI_ERROR_DEVICE_REMOVED` as a refusal, and `host::fail` calls `TerminateProcess(0x887A0005)` — so a driver/PnP stop looks like a crash and the launcher can only report a failure. This makes the loss a defined, recoverable event: - `Present`, `ResizeBuffers`, resource and heap creation now classify `DXGI_ERROR_DEVICE_REMOVED`/`_RESET`; `host::fail` uses the new exit **75** only when `GetDeviceRemovedReason` actually reports a loss. OOM and other GPU failures keep the legacy `0x887A0005`, so they are not mistaken for a loss. - On a loss the runtime writes `<Data>/device-lost.txt` **atomically** (temp → `sync_all` → rename), capped at 4 KiB, and logs `device lost: reason=… hresult=0x… luid=…`. - The marker carries `leonida-device-lost/1`, `code=75`, `reason`, `hresult`, `unix`, `pid`, plus `luid`, `adapter`, `frame`, `what`. Free text is percent-encoded. - `LEONIDA_TEST_DEVICE_LOST_AFTER=<frames>` forces the same path for tests, gated to `test`/`diagnostics` builds; release binaries ignore it. - Play scripts pass `LEONIDA_DEVICE_LOST_FILE=<Data>\device-lost.txt` (with a `<parent of data_dir>` fallback), so the launcher and runtime agree on the location. The marker is cleared at run start. The launcher side (separate PR) reads the marker and restarts at most twice (10 s, 60 s), cancellable, and never restarts a title crash. ### Evidence On Windows 11, RTX 4070 Ti SUPER: - `cargo test -p leonida-gpu --locked lost` → 16 passed, 3 ignored. - `cargo test -p leonida-gpu --locked -- --test-threads=1` → 705 passed, 59 ignored. - `cargo test -p leonida -p leonida-hle --locked` pass. - `tools/d3d12_switches.py --check` passes (`683 names; 643 with comments`); `check_no_game_data` is clean. - The exact marker produced parses through the launcher's `read_device_lost` (verified against the launcher branch). ### Scope / notes - Runtime only; the launcher changes are a follow-up so each half is reviewable. - The parallel `texture::alias_cast_tests::…` flake is pre-existing (2 of 4 runs on clean `main`) and is not this change. - `host.rs`/`queue.rs`/`resource.rs` overlap open #2670/#2847/#2765; the edits are surgical, expect textual rebases. - No game data: the marker contains only DXGI reason/HRESULT, adapter name/LUID and a frame number. GPUs tested: RTX 4070 Ti SUPER, driver 621.01 (marker and exit path only; no game run) AI-assisted: yes
merzleckeier commented 2026-12-02 14:49:42 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-02T14:49:42Z.

Review: COMMENTED


Concurrent device-loss notifications can exit with 75 before the marker is published. In lost.rs, WRITTEN.swap(true, …) claims the write before file() and write_to(). The next caller returns false immediately. In host::device_lost, that caller still reaches the terminating callback or lost::end(75). The launcher can receive the retry exit code without the marker it needs.

I reproduced this on 4e9f179a merged onto main acc350745 under Wine 11.22. A child process paused its first device_lost call just after it took the writer claim, then called device_lost again on another thread. The submitted implementation exited with 75 and left no marker. With a local synchronization guard covering the marker write through rename, the same test exited with 75 and retained the first report. All 10 targeted tests passed in that local variant. Please make marker publication finish before any parallel caller is allowed to terminate.

All nine stock lost:: tests and 49 CLI tests passed. The wider lost filter also matched a write-watch test that failed separately on both revisions under Wine. Git also reports a merge conflict with #3146 (ebc0253f) in modules/d3d12x.rs. The merged callback should flush the pipeline book before either exit path. Synthetic tests only. AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6153143335 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3151#pullrequestreview-6153143335). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-12-02T14:49:42Z. **Review:** COMMENTED --- **Concurrent device-loss notifications can exit with 75 before the marker is published.** In `lost.rs`, `WRITTEN.swap(true, …)` claims the write before `file()` and `write_to()`. The next caller returns `false` immediately. In `host::device_lost`, that caller still reaches the terminating callback or `lost::end(75)`. The launcher can receive the retry exit code without the marker it needs. I reproduced this on `4e9f179a` merged onto `main` `acc350745` under Wine 11.22. A child process paused its first `device_lost` call just after it took the writer claim, then called `device_lost` again on another thread. The submitted implementation exited with 75 and left no marker. With a local synchronization guard covering the marker write through rename, the same test exited with 75 and retained the first report. All 10 targeted tests passed in that local variant. Please make marker publication finish before any parallel caller is allowed to terminate. All nine stock `lost::` tests and 49 CLI tests passed. The wider `lost` filter also matched a write-watch test that failed separately on both revisions under Wine. Git also reports a merge conflict with #3146 (`ebc0253f`) in `modules/d3d12x.rs`. The merged callback should flush the pipeline book before either exit path. Synthetic tests only. AI-assisted with OpenAI Codex.
lixonik commented 2026-12-02 15:03:13 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-12-02T15:03:13Z.


Verified PR #3151 (4e9f179a8) merged cleanly onto main (acc350745) on Windows 10 x64 (RTX 5070 12 GB, driver 595.79, Rust 1.98.1):

  • Clean-room & switch-table checks:
    • python -I scripts/check_no_game_data.py PASS.
    • python -I tools/d3d12_switches.py --check d3d12/docs/switches.md PASS.
  • Unit tests:
    • cargo test -p leonida-gpu --features diagnostics --lib --locked lost:: -- 9 passed, 0 failed.
  • Live end-to-end device-lost test (LEONIDA_TEST_DEVICE_LOST_AFTER=20, diag + diagnostics,dlss,mimalloc, Series S, RTX 5070):
    • Invoking leonida.exe run ... --execute --console series-s directly exited cleanly at frame 20 with ExitCode = 75 (no crash dialog) and wrote the expected marker file:
      leonida-device-lost/1
      code=75
      reason=DXGI_ERROR_DEVICE_REMOVED
      hresult=0x887A0005
      luid=<adapter luid>
      adapter=NVIDIA%20GeForce%20RTX%205070
      frame=20
      what=LEONIDA_TEST_DEVICE_LOST_AFTER%3D20
      
    • Log recorded ERROR leonida_gpu::host: device lost: reason=DXGI_ERROR_DEVICE_REMOVED hresult=0x887A0005 ... frame=20 what="LEONIDA_TEST_DEVICE_LOST_AFTER=20".

One concrete finding (launcher exit-code propagation)

  • When launched through scripts/play-d3d12.ps1 -> d3d12/scripts/play-nvidia.ps1, the marker file is written properly, but play-nvidia.ps1 returns exit code 0 instead of 75 because d3d12/scripts/play-nvidia.ps1:966-968 calls Start-Process -FilePath $leonida ... -NoNewWindow -Wait without -PassThru and without propagating $proc.ExitCode (e.g. $p = Start-Process ... -PassThru; exit $p.ExitCode). If callers/harnesses invoke play-d3d12.ps1 expecting exit code 75, propagating $p.ExitCode there closes that gap.
  • Minor coordination note: #3146 also touches host_gpu_failed in d3d12/crates/leonida-hle/src/modules/d3d12x.rs.

Verdict: PASS on the core exit-75 + marker behavior (note this was a targeted 20-frame injection run, not a 300 s render-path stability run).

AI-assisted: yes (Antigravity).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7349626221 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3151#issuecomment-7349626221). Originally posted by [lixonik](https://github.com/lixonik) on 2026-12-02T15:03:13Z. --- Verified PR #3151 (`4e9f179a8`) merged cleanly onto `main` (`acc350745`) on Windows 10 x64 (RTX 5070 12 GB, driver 595.79, Rust 1.98.1): - **Clean-room & switch-table checks:** - `python -I scripts/check_no_game_data.py` PASS. - `python -I tools/d3d12_switches.py --check d3d12/docs/switches.md` PASS. - **Unit tests:** - `cargo test -p leonida-gpu --features diagnostics --lib --locked lost::` -- **9 passed, 0 failed**. - **Live end-to-end device-lost test (`LEONIDA_TEST_DEVICE_LOST_AFTER=20`, `diag` + `diagnostics,dlss,mimalloc`, Series S, RTX 5070):** - Invoking `leonida.exe run ... --execute --console series-s` directly exited cleanly at frame 20 with **`ExitCode = 75`** (no crash dialog) and wrote the expected marker file: ```text leonida-device-lost/1 code=75 reason=DXGI_ERROR_DEVICE_REMOVED hresult=0x887A0005 luid=<adapter luid> adapter=NVIDIA%20GeForce%20RTX%205070 frame=20 what=LEONIDA_TEST_DEVICE_LOST_AFTER%3D20 ``` - Log recorded `ERROR leonida_gpu::host: device lost: reason=DXGI_ERROR_DEVICE_REMOVED hresult=0x887A0005 ... frame=20 what="LEONIDA_TEST_DEVICE_LOST_AFTER=20"`. ### One concrete finding (launcher exit-code propagation) - When launched through `scripts/play-d3d12.ps1` -> `d3d12/scripts/play-nvidia.ps1`, the marker file is written properly, **but `play-nvidia.ps1` returns exit code `0` instead of `75`** because `d3d12/scripts/play-nvidia.ps1:966-968` calls `Start-Process -FilePath $leonida ... -NoNewWindow -Wait` without `-PassThru` and without propagating `$proc.ExitCode` (e.g. `$p = Start-Process ... -PassThru; exit $p.ExitCode`). If callers/harnesses invoke `play-d3d12.ps1` expecting exit code `75`, propagating `$p.ExitCode` there closes that gap. - Minor coordination note: #3146 also touches `host_gpu_failed` in `d3d12/crates/leonida-hle/src/modules/d3d12x.rs`. Verdict: **PASS** on the core exit-75 + marker behavior (note this was a targeted 20-frame injection run, not a 300 s render-path stability run). AI-assisted: yes (Antigravity).
merzleckeier commented 2026-12-02 15:10:54 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-02T15:10:54Z.


I reproduced the exit-code finding with the exact two launch tails from 4e9f179a, executed in PowerShell 7.5.4 on Linux against a synthetic child returning 0, 3, or 75. I ran each case with and without -Log and checked that stderr still went to the same destination.

For a child returning 75, the unchanged scripts returned 0 from both entry points. Adding -PassThru and exit $proc.ExitCode to play-nvidia.ps1 made its direct invocation return 75, but play-d3d12.ps1 still returned 0 when launched with -File. Adding exit $LASTEXITCODE immediately after the inner call preserved the child status through both levels, in all six status/log combinations. The launcher invokes the outer entry point, so both boundaries matter. PowerShell exit-code semantics

The fixture exercised the launch wrappers only. The native Windows injection run above supplies the runtime evidence. AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7349875481 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3151#issuecomment-7349875481). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-12-02T15:10:54Z. --- I reproduced the exit-code finding with the exact two launch tails from `4e9f179a`, executed in PowerShell 7.5.4 on Linux against a synthetic child returning `0`, `3`, or `75`. I ran each case with and without `-Log` and checked that stderr still went to the same destination. For a child returning `75`, the unchanged scripts returned `0` from both entry points. Adding `-PassThru` and `exit $proc.ExitCode` to `play-nvidia.ps1` made its direct invocation return `75`, but `play-d3d12.ps1` still returned `0` when launched with `-File`. Adding `exit $LASTEXITCODE` immediately after the inner call preserved the child status through both levels, in all six status/log combinations. The launcher invokes the outer entry point, so both boundaries matter. [PowerShell exit-code semantics](https://learn.microsoft.com/en-us/PowerShell/module/microsoft.PowerShell.core/about/about_automatic_variables?view=powershell-5.1) The fixture exercised the launch wrappers only. The native Windows injection run above supplies the runtime evidence. AI-assisted with OpenAI Codex.
Kal0s-design commented 2026-12-02 15:55:51 +00:00 (Migrated from github.com)

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


Ran natively on Windows 11, head 4e9f179a8 merged into current main (3c106eb2f, clean merge). Debug test builds. This adds a real device removal (not the env injection) and a native measurement of the double-report race raised above.

Suites on the merge

Command Result
cargo test -p leonida-gpu --lib -- lost 16 passed, 3 ignored, 3 runs in a row
cargo test -p leonida-gpu 705 passed, 59 ignored
cargo test -p leonida-gpu --features diagnostics 786 passed, 59 ignored (+1 passed, 1 ignored in the other binaries)
cargo test -p leonida -p leonida-hle all passed (leonida 44 + 2 + 2 + 1, leonida-hle 248 + 1 + 1, 2 ignored)
cargo clippy -p leonida-gpu -p leonida-hle -p leonida --all-targets (also with --features leonida/diagnostics) no warning in the changed lines (the known unused_mut in host.rs is elsewhere)

A real removed device

Throwaway tests, not pushed. A child process makes the host device, calls ID3D12Device5::RemoveDevice(), then goes through the PR's code. GetDeviceRemovedReason then returns 0x887A0005.

Case Device Exit Marker Time from the call to the exit
host::fail(...) NVIDIA card, 3 runs 75 complete, reason=DXGI_ERROR_DEVICE_REMOVED, hresult=0x887A0005, luid and adapter filled, frame=0 57-63 ms
host::fail(...) WARP, 3 runs 75 same (adapter is the WARP adapter) 14 ms
pool::small::buffer (a heap creation) NVIDIA card 75 what=host small-buffer heap creation ... not timed
pool::small::buffer WARP 75 same not timed

The same child on main (3c106eb2f), card and WARP alike.

Case Exit What happens
pool::small::buffer on the removed device 0 (the child exits itself) returns None twice, the run would go on
host::fail(...), with on_failure set to what host_gpu_failed does on main 0x887A0005 no marker

So the classification works with a real removal, and process::exit did not hang after it here. These children had no on_failure set, so the real host_gpu_failed was not part of this table.

The double report, native rate

Child processes where threads call host::device_lost for the same loss, marker in a fresh temp folder each time, no pause injected. The second table sets an on_failure that does what host_gpu_failed does before exiting (two lines to stderr and two appends to a crash-log file, then lost::end), as a stand-in for the app's callback.

Threads reporting at once Runs Exit 75 Marker written (no on_failure) Marker written (crash-log stand-in)
1 200 200 200 200
2 200 200 0 0
8 200 200 0 16

One 2-thread run (in an earlier batch of 200) also left a device-lost.txt.tmp-<pid> behind. With the second report delayed after the first (requested sleep, 100 runs each, no on_failure):

Second report after 0 0.5 ms 1 ms 2 ms 5 ms 10 ms and more
Marker written 0 0 1 2 99 100

So on this machine the write (create, write, sync_all, rename) takes a few ms, and a second report inside that window ends the process with 75 and no marker. Whether two threads really report within a few ms of each other in a game run is my reading, not measured. A removed device fails every call made on it, so the presenter and the list threads can easily hit it together. A loser that waits for the writer to finish before it exits (or parks and lets the writer end the process) would close it.

When the marker cannot be written

Single report, exit code always 75.

Setup Marker after the run
parent of the path is a file absent
a directory sits at the path still a directory, no marker
stale read-only marker replaced, new marker
stale marker open in another process that does not share delete stale marker kept (clear() and the rename both fail)
stale marker open with full sharing replaced
bare file name (relative path) with a stale .tmp-1 beside it new marker, the stale .tmp-1 stays (clear_at lists "" and fails)
full path with a stale .tmp-1 new marker, .tmp-1 removed

The stale-marker case means a launcher can read an older run's marker after a 75. Checking pid against the child it started would catch it.

Marker size

20,000 random markers (what up to 3,000 characters of ASCII, quotes, %, =, newlines, CJK and emoji; adapter up to 127 UTF-16 units; maximum luid, pid, unix and frame). The largest was 3,818 bytes, none over 4,096, and every adapter and what decoded back to the input (a prefix of it for what). The 1,024-byte cut on what always kept it under 4 KiB, so this never reached the shrink loop. The PR's own test covers that branch.

From reading only

Without LEONIDA_DEVICE_LOST_FILE, run.rs writes <data_dir>/device-lost.txt. Both play scripts set <parent of data_dir>/device-lost.txt. So a launcher that starts leonida.exe directly, without the variable, looks one folder too high. And run.rs now exits with any nonzero title status, so a title returning 75 gives 75 with no marker. Both are probably fine if the launcher always sets the variable and checks the marker, but no test covers them.

Not checked: the play scripts (they use -ExecutionPolicy Bypass, not run), a real driver reset or TDR, Present and ResizeBuffers on a removed device (no swap chain in these tests), the real on_failure callback in d3d12x.rs (only the stand-in above), and the launcher side.

GPUs tested: one NVIDIA desktop card + WARP.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7351165328 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3151#issuecomment-7351165328). Originally posted by [Kal0s-design](https://github.com/Kal0s-design) on 2026-12-02T15:55:51Z. --- Ran natively on Windows 11, head `4e9f179a8` merged into current `main` (`3c106eb2f`, clean merge). Debug test builds. This adds a real device removal (not the env injection) and a native measurement of the double-report race raised above. **Suites on the merge** | Command | Result | |---|---| | `cargo test -p leonida-gpu --lib -- lost` | 16 passed, 3 ignored, 3 runs in a row | | `cargo test -p leonida-gpu` | 705 passed, 59 ignored | | `cargo test -p leonida-gpu --features diagnostics` | 786 passed, 59 ignored (+1 passed, 1 ignored in the other binaries) | | `cargo test -p leonida -p leonida-hle` | all passed (leonida 44 + 2 + 2 + 1, leonida-hle 248 + 1 + 1, 2 ignored) | | `cargo clippy -p leonida-gpu -p leonida-hle -p leonida --all-targets` (also with `--features leonida/diagnostics`) | no warning in the changed lines (the known `unused_mut` in `host.rs` is elsewhere) | **A real removed device** Throwaway tests, not pushed. A child process makes the host device, calls `ID3D12Device5::RemoveDevice()`, then goes through the PR's code. `GetDeviceRemovedReason` then returns `0x887A0005`. | Case | Device | Exit | Marker | Time from the call to the exit | |---|---|---|---|---| | `host::fail(...)` | NVIDIA card, 3 runs | 75 | complete, `reason=DXGI_ERROR_DEVICE_REMOVED`, `hresult=0x887A0005`, `luid` and `adapter` filled, `frame=0` | 57-63 ms | | `host::fail(...)` | WARP, 3 runs | 75 | same (`adapter` is the WARP adapter) | 14 ms | | `pool::small::buffer` (a heap creation) | NVIDIA card | 75 | `what=host small-buffer heap creation ...` | not timed | | `pool::small::buffer` | WARP | 75 | same | not timed | The same child on `main` (`3c106eb2f`), card and WARP alike. | Case | Exit | What happens | |---|---|---| | `pool::small::buffer` on the removed device | 0 (the child exits itself) | returns `None` twice, the run would go on | | `host::fail(...)`, with `on_failure` set to what `host_gpu_failed` does on `main` | `0x887A0005` | no marker | So the classification works with a real removal, and `process::exit` did not hang after it here. These children had no `on_failure` set, so the real `host_gpu_failed` was not part of this table. **The double report, native rate** Child processes where threads call `host::device_lost` for the same loss, marker in a fresh temp folder each time, no pause injected. The second table sets an `on_failure` that does what `host_gpu_failed` does before exiting (two lines to stderr and two appends to a crash-log file, then `lost::end`), as a stand-in for the app's callback. | Threads reporting at once | Runs | Exit 75 | Marker written (no `on_failure`) | Marker written (crash-log stand-in) | |---|---|---|---|---| | 1 | 200 | 200 | 200 | 200 | | 2 | 200 | 200 | **0** | **0** | | 8 | 200 | 200 | **0** | **16** | One 2-thread run (in an earlier batch of 200) also left a `device-lost.txt.tmp-<pid>` behind. With the second report delayed after the first (requested sleep, 100 runs each, no `on_failure`): | Second report after | 0 | 0.5 ms | 1 ms | 2 ms | 5 ms | 10 ms and more | |---|---|---|---|---|---|---| | Marker written | 0 | 0 | 1 | 2 | 99 | 100 | So on this machine the write (create, write, `sync_all`, rename) takes a few ms, and a second report inside that window ends the process with 75 and no marker. Whether two threads really report within a few ms of each other in a game run is my reading, not measured. A removed device fails every call made on it, so the presenter and the list threads can easily hit it together. A loser that waits for the writer to finish before it exits (or parks and lets the writer end the process) would close it. **When the marker cannot be written** Single report, exit code always 75. | Setup | Marker after the run | |---|---| | parent of the path is a file | absent | | a directory sits at the path | still a directory, no marker | | stale read-only marker | replaced, new marker | | stale marker open in another process that does not share delete | **stale marker kept** (`clear()` and the rename both fail) | | stale marker open with full sharing | replaced | | bare file name (relative path) with a stale `.tmp-1` beside it | new marker, the stale `.tmp-1` stays (`clear_at` lists `""` and fails) | | full path with a stale `.tmp-1` | new marker, `.tmp-1` removed | The stale-marker case means a launcher can read an older run's marker after a 75. Checking `pid` against the child it started would catch it. **Marker size** 20,000 random markers (`what` up to 3,000 characters of ASCII, quotes, `%`, `=`, newlines, CJK and emoji; `adapter` up to 127 UTF-16 units; maximum `luid`, `pid`, `unix` and `frame`). The largest was 3,818 bytes, none over 4,096, and every `adapter` and `what` decoded back to the input (a prefix of it for `what`). The 1,024-byte cut on `what` always kept it under 4 KiB, so this never reached the shrink loop. The PR's own test covers that branch. **From reading only** Without `LEONIDA_DEVICE_LOST_FILE`, `run.rs` writes `<data_dir>/device-lost.txt`. Both play scripts set `<parent of data_dir>/device-lost.txt`. So a launcher that starts `leonida.exe` directly, without the variable, looks one folder too high. And `run.rs` now exits with any nonzero title status, so a title returning 75 gives 75 with no marker. Both are probably fine if the launcher always sets the variable and checks the marker, but no test covers them. Not checked: the play scripts (they use `-ExecutionPolicy Bypass`, not run), a real driver reset or TDR, `Present` and `ResizeBuffers` on a removed device (no swap chain in these tests), the real `on_failure` callback in `d3d12x.rs` (only the stand-in above), and the launcher side. GPUs tested: one NVIDIA desktop card + WARP. AI-assisted: yes (Claude Code).
fiestorra commented 2026-12-02 16:21:34 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-02T16:21:34Z.


Verified here: it applies, the new module's tests pass, and the app's tests still pass.

git apply of <merge-base>..refs/pull/3151/head on main   (13 files)

cargo test -p leonida-gpu --lib -- lost        exit 0, 0.3 min
  lost::tests::injection_switch_parses ... ok
  lost::tests::only_device_loss_codes_are_loss ... ok
  lost::tests::the_exit_code_is_the_documented_one ... ok
  lost::tests::the_injection_reaches_exit_75_and_writes_the_marker ... ok
  lost::tests::the_marker_is_atomic_and_cleared ... ok
  lost::tests::the_marker_cuts_free_text_to_1024_bytes_on_a_character_boundary ... ok
  lost::tests::the_marker_stays_under_the_launchers_read_with_a_long_what_and_adapter ... ok
  lost::tests::marker_values_are_percent_encoded ... ok

cargo test -p leonida --bins                    test result: ok. 44 passed, 0 failed

The one that matters most is the_injection_reaches_exit_75_and_writes_the_marker: it means the loss can be provoked without a GPU - and that is exactly what makes this testable at all. The marker's 1024-byte cut on a character boundary and the atomic clear are the two properties a launcher reading the file would be hurt by if they were wrong, and both have a test that passes.

Why I looked at this one: a real run of the title this week lost its device - frame times flat at 35.7 ms, then three and a half minutes of medians from 145 to 1,899 ms after 22:03:50, with the log noting the recovery. On main that is a killed process with a truncated log; this turns it into exit 75 and a marker that names the adapter and what happened, which is the difference between "it crashed" and a report someone can act on.

What I did not test: a real device removal - the injection switch is as close as this machine gets without the title, and I used it rather than claiming the real path.

AI-assisted: yes - DeepSeek v4.1 (flash).

Written with an AI assistant.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7351826319 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3151#issuecomment-7351826319). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-12-02T16:21:34Z. --- **Verified here: it applies, the new module's tests pass, and the app's tests still pass.** ``` git apply of <merge-base>..refs/pull/3151/head on main (13 files) cargo test -p leonida-gpu --lib -- lost exit 0, 0.3 min lost::tests::injection_switch_parses ... ok lost::tests::only_device_loss_codes_are_loss ... ok lost::tests::the_exit_code_is_the_documented_one ... ok lost::tests::the_injection_reaches_exit_75_and_writes_the_marker ... ok lost::tests::the_marker_is_atomic_and_cleared ... ok lost::tests::the_marker_cuts_free_text_to_1024_bytes_on_a_character_boundary ... ok lost::tests::the_marker_stays_under_the_launchers_read_with_a_long_what_and_adapter ... ok lost::tests::marker_values_are_percent_encoded ... ok cargo test -p leonida --bins test result: ok. 44 passed, 0 failed ``` **The one that matters most is `the_injection_reaches_exit_75_and_writes_the_marker`**: it means **the loss can be provoked without a GPU** - and that is exactly what makes this testable at all. **The marker's 1024-byte cut on a character boundary and the atomic clear are the two properties a launcher reading the file would be hurt by if they were wrong, and both have a test that passes.** **Why I looked at this one**: **a real run of the title this week lost its device** - frame times flat at 35.7 ms, then three and a half minutes of medians from 145 to 1,899 ms after 22:03:50, with the log noting the recovery. **On `main` that is a killed process with a truncated log; this turns it into exit 75 and a marker that names the adapter and what happened**, which is the difference between "it crashed" and a report someone can act on. **What I did not test**: **a real device removal** - the injection switch is as close as this machine gets without the title, and I used it rather than claiming the real path. **AI-assisted:** yes - DeepSeek v4.1 (flash). Written with an AI assistant.
KelboLive commented 2026-12-02 16:42:29 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-02T16:42:29Z.


Temporarily closing to free the single-PR slot for a high-severity fix (PSV0 validator rejection). The branch is preserved at stability/device-loss-exit (0d399d6cf), rebased on current main with all checks green locally; I will reopen this PR once the slot frees. No change in intent or scope.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7352342980 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3151#issuecomment-7352342980). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-12-02T16:42:29Z. --- Temporarily closing to free the single-PR slot for a high-severity fix (PSV0 validator rejection). The branch is preserved at `stability/device-loss-exit` (`0d399d6cf`), rebased on current main with all checks green locally; I will reopen this PR once the slot frees. No change in intent or scope.
fiestorra commented 2026-12-02 23:39:11 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-02T23:39:11Z.


VERIFY-3151 — Windows nativo: red then green, y el código de salida es el de verdad

Own commit 0d399d6cf — leonida-gpu/src/lost.rs (+74 in host.rs), apps/leonida/src/run.rs (+34)

Ran at the head

cargo test -p leonida-gpu --lib lost                                     16 passed; 3 ignored
cargo test -p leonida-gpu --lib only_device_loss_codes                    1 passed
  lost::tests::only_device_loss_codes_are_loss ... ok
cargo test -p leonida the_title_exit_code                                  ok
  run::tests::the_title_exit_code_is_the_process_exit_code ... ok

Negative control (synthetic): I removed one code from is_loss (DXGI_ERROR_DRIVER_INTERNAL_ERROR), rebuilt and ran:

FAILED: only_device_loss_codes_are_loss

It bites, and that is the right shape: the predicate is a list of four codes (DEVICE_REMOVED, DEVICE_HUNG, DEVICE_RESET, DRIVER_INTERNAL_ERROR), and the test enumerates all four plus the ones that must not count — a list is exactly what a mutation can shorten.

What the change is: a lost device ends the run with exit 75 and a marker, instead of crashing — and the second test ties it to the launcher's view: the process exit code is the title's, so a launcher or a game-gate can tell "the game ended" from "the device went away". That number is the whole point: without a distinct code, a device loss reads as a normal exit and every script that checks $LASTEXITCODE says the run was fine.

What I could not test

  • A real device loss: triggering DXGI_ERROR_DEVICE_REMOVED on purpose is a run with a fault injection; the tests drive is_loss with the codes.
  • The marker: it is written by the run path; no title ran.

Written with an AI assistant.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7362263450 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3151#issuecomment-7362263450). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-12-02T23:39:11Z. --- ## VERIFY-3151 — Windows nativo: `red then green`, y el código de salida es el de verdad | | | |---|---| | Own commit | `0d399d6cf` — `leonida-gpu/src/lost.rs` (+74 in `host.rs`), `apps/leonida/src/run.rs` (+34) | **Ran at the head** ``` cargo test -p leonida-gpu --lib lost 16 passed; 3 ignored cargo test -p leonida-gpu --lib only_device_loss_codes 1 passed lost::tests::only_device_loss_codes_are_loss ... ok cargo test -p leonida the_title_exit_code ok run::tests::the_title_exit_code_is_the_process_exit_code ... ok ``` **Negative control (synthetic)**: I removed one code from `is_loss` (`DXGI_ERROR_DRIVER_INTERNAL_ERROR`), rebuilt and ran: ``` FAILED: only_device_loss_codes_are_loss ``` **It bites**, and that is the right shape: the predicate is a **list of four codes** (`DEVICE_REMOVED`, `DEVICE_HUNG`, `DEVICE_RESET`, `DRIVER_INTERNAL_ERROR`), and the test **enumerates all four plus the ones that must not count** — a list is exactly what a mutation can shorten. **What the change is**: **a lost device ends the run with exit 75 and a marker, instead of crashing** — and the second test ties it to the launcher's view: **the process exit code is the title's**, so a launcher or a game-gate can tell "the game ended" from "the device went away". **That number is the whole point**: without a distinct code, a device loss reads as a normal exit and every script that checks `$LASTEXITCODE` says the run was fine. ## What I could not test - **A real device loss**: triggering `DXGI_ERROR_DEVICE_REMOVED` on purpose is a run with a fault injection; the tests drive `is_loss` with the codes. - **The marker**: it is written by the run path; no title ran. Written with an AI assistant.
EdenBendheim commented 2026-12-03 10:47:32 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by EdenBendheim on 2026-12-03T10:47:32Z.

Review: COMMENTED


Independent current-head RTX 3090 compatibility check — PASS (normal path + synthetic exit/marker)

Tested 0d399d6cf1b015f321d685cc1d5a149c9318a667 cleanly merged locally onto main d9b618f10150f275c30088e4769c1acbf1d8d689 (merge 5d2645e0d). Main advanced during the build to 9a7c22f30 with a CI-workflow-only diff; the newer merge tree also applied cleanly. No upstream content changed.

Windows 11 build 26200, RTX 3090 24 GB, NVIDIA 610.88, Ryzen 9 5900X / 32 GiB RAM; Rust 1.98.1, diag build with diagnostics,dlss,mimalloc, executable SHA-256 71a15c5e3c4f8636e2d66f591eb5b78c4d528efbe7bd9f56e027776215db3887 (verified before/after).

Ordinary play, no loss injection: stock game gate, Series S stretch, -NoFrameGen -NoPrecompile, isolated warm cache and save, idle outdoors following a verified control probe and native placement.

Measurement Result
World time / gate 301.392 s / PASS
Actual game exit / stop 0 / target, title suspended, cache saved
Device-loss log / marker / crashes 0 / absent / 0
Frame intervals (world+60 s) 2,170
Median / p5 FPS 13.51 / 3.52
Frame p95 / p99 284.33 / 707.80 ms
Longest in-world present gap 4.799 s
Private bytes peak / end 23,861 / 23,861 MiB
Minimum system commit left 5,656 MiB
VRAM peak / budget 6,840 / 23,558 MiB

No stale/false marker was present at start or after the normal run, no temporary marker remained, and the effective runtime settings had no injection switch. Native control moved 1.43 m; 24 later idle placement checks stayed within 0.2 m of the test spot. World time includes loading/placement; about 247 s were after control, not five full minutes at that spot. Boot was slow (403 s to the gate's world detection).

Separately, no game/driver fault: cargo test -p leonida-gpu --features diagnostics --lib --locked lost:: passed 9/9, including the existing child-process injection test. I ran that existing synthetic child again and directly observed exit 75, fresh 156-byte complete marker with leonida-device-lost/1, code=75, reason=DXGI_ERROR_DEVICE_REMOVED, hresult=0x887A0005, and its synthetic-injection description; no temporary file remained. Frame 0 is expected in the hostless harness. The title-exit regression (the_title_exit_code_is_the_process_exit_code) also passed (1/1). Clean-room and switch-table checks passed. No real device reset, fault injection into the driver, or retail exit-75 launcher propagation was exercised here.

This is a one-run non-faulting compatibility check plus synthetic exit/marker proof, not a matched performance comparison or validation of recovery from actual hardware loss. Independent numerical recomputation agreed with the evidence. AI-assisted (GPT-6.2 Sol tester and separate GPT-6.2 Sol numeric check).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6168252992 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3151#pullrequestreview-6168252992). Originally posted by [EdenBendheim](https://github.com/EdenBendheim) on 2026-12-03T10:47:32Z. **Review:** COMMENTED --- ### Independent current-head RTX 3090 compatibility check — PASS (normal path + synthetic exit/marker) Tested `0d399d6cf1b015f321d685cc1d5a149c9318a667` cleanly merged locally onto main `d9b618f10150f275c30088e4769c1acbf1d8d689` (merge `5d2645e0d`). Main advanced during the build to `9a7c22f30` with a CI-workflow-only diff; the newer merge tree also applied cleanly. No upstream content changed. Windows 11 build 26200, RTX 3090 24 GB, NVIDIA 610.88, Ryzen 9 5900X / 32 GiB RAM; Rust 1.98.1, diag build with `diagnostics,dlss,mimalloc`, executable SHA-256 `71a15c5e3c4f8636e2d66f591eb5b78c4d528efbe7bd9f56e027776215db3887` (verified before/after). **Ordinary play, no loss injection:** stock game gate, Series S stretch, `-NoFrameGen -NoPrecompile`, isolated warm cache and save, idle outdoors following a verified control probe and native placement. | Measurement | Result | |---|---:| | World time / gate | 301.392 s / PASS | | Actual game exit / stop | 0 / target, title suspended, cache saved | | Device-loss log / marker / crashes | 0 / absent / 0 | | Frame intervals (world+60 s) | 2,170 | | Median / p5 FPS | 13.51 / 3.52 | | Frame p95 / p99 | 284.33 / 707.80 ms | | Longest in-world present gap | 4.799 s | | Private bytes peak / end | 23,861 / 23,861 MiB | | Minimum system commit left | 5,656 MiB | | VRAM peak / budget | 6,840 / 23,558 MiB | No stale/false marker was present at start or after the normal run, no temporary marker remained, and the effective runtime settings had no injection switch. Native control moved 1.43 m; 24 later idle placement checks stayed within 0.2 m of the test spot. World time includes loading/placement; about 247 s were after control, not five full minutes at that spot. Boot was slow (403 s to the gate's world detection). **Separately, no game/driver fault:** `cargo test -p leonida-gpu --features diagnostics --lib --locked lost::` passed **9/9**, including the existing child-process injection test. I ran that existing synthetic child again and directly observed exit **75**, fresh 156-byte complete marker with `leonida-device-lost/1`, `code=75`, `reason=DXGI_ERROR_DEVICE_REMOVED`, `hresult=0x887A0005`, and its synthetic-injection description; no temporary file remained. Frame 0 is expected in the hostless harness. The title-exit regression (`the_title_exit_code_is_the_process_exit_code`) also passed (1/1). Clean-room and switch-table checks passed. No real device reset, fault injection into the driver, or retail exit-75 launcher propagation was exercised here. This is a one-run non-faulting compatibility check plus synthetic exit/marker proof, **not** a matched performance comparison or validation of recovery from actual hardware loss. Independent numerical recomputation agreed with the evidence. AI-assisted (GPT-6.2 Sol tester and separate GPT-6.2 Sol numeric check).
merzleckeier commented 2026-12-03 12:20:58 +00:00 (Migrated from github.com)

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


Current-head check of 8894c581 on b053a181. The Windows MSVC synthetic child under Wine exited 75, wrote a complete marker and emitted the canonical device lost: reason=… hresult=… line. All nine lost::tests passed.

Gate follow-up for the new diagnostic. I replayed the exact line and exit status through tools/game_gate.py with generated frame data and game_exited immediately after stop_requested. When the new line is the only loss diagnostic, the gate reports PASS with crash.kind=none and exit.kind=other. The same applies to a launcher-only exit event with #3218’s fallback. The normal HLE callback also emits Leonida: host GPU failure. Including that older line makes the stock gate correctly report FAIL / device_lost, while exit.kind is still other.

A local control that also recognizes the new line reports FAIL / device_lost in the fallback case and correctly labels the corroborated exit 75. It leaves an uncorroborated 75 as other because a title can return that status itself. All 38 gate tests passed with #3218 in the local control. Synthetic gate fixtures and runtime injection only.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7378067072 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3151#issuecomment-7378067072). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-12-03T12:20:58Z. --- Current-head check of `8894c581` on `b053a181`. The Windows MSVC synthetic child under Wine exited 75, wrote a complete marker and emitted the canonical `device lost: reason=… hresult=…` line. All nine `lost::tests` passed. **Gate follow-up for the new diagnostic.** I replayed the exact line and exit status through `tools/game_gate.py` with generated frame data and `game_exited` immediately after `stop_requested`. When the new line is the only loss diagnostic, the gate reports `PASS` with `crash.kind=none` and `exit.kind=other`. The same applies to a launcher-only exit event with #3218’s fallback. The normal HLE callback also emits `Leonida: host GPU failure`. Including that older line makes the stock gate correctly report `FAIL / device_lost`, while `exit.kind` is still `other`. A local control that also recognizes the new line reports `FAIL / device_lost` in the fallback case and correctly labels the corroborated exit 75. It leaves an uncorroborated 75 as `other` because a title can return that status itself. All 38 gate tests passed with #3218 in the local control. Synthetic gate fixtures and runtime injection only. AI-assisted with OpenAI Codex.
MoonEyes commented 2026-12-03 12:46:34 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-03T12:46:34Z.


RUN (in game, third party, batch of four pull requests), each head merged with git merge --no-ff onto main 6e9799050, in one build: #2642 4b4d99a82, #3151 8894c5812, #3323 0c836e32e, #3324 02f37bcf8. 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 (45 samples) median 17.6, mean 17.1
Rendered fps, last 120 s median 17.2
Time under 5 fps in the world 0 %

For reference, the same machine and route rendered 13.3 to 17.4 fps on other runs in the last day: 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. If one 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. The precompile before the world took 529 s, against about 110 s for main alone: the translator change in #3324 left the pipeline cache cold. Switches that are off by default (for example #3323's own-pass timing) were not turned on: this run covers their default path only. #2642 targets Wine and was run on Windows only. #3151 changes what happens on a lost device; no device was lost, so that path was not exercised.

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7378817879 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3151#issuecomment-7378817879). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-03T12:46:34Z. --- RUN (in game, third party, batch of four pull requests), each head merged with `git merge --no-ff` onto main `6e9799050`, in one build: #2642 `4b4d99a82`, #3151 `8894c5812`, #3323 `0c836e32e`, #3324 `02f37bcf8`. 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 (45 samples) | median 17.6, mean 17.1 | | Rendered fps, last 120 s | median 17.2 | | Time under 5 fps in the world | 0 % | For reference, the same machine and route rendered 13.3 to 17.4 fps on other runs in the last day: 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. If one 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. The precompile before the world took 529 s, against about 110 s for main alone: the translator change in #3324 left the pipeline cache cold. Switches that are off by default (for example #3323's own-pass timing) were not turned on: this run covers their default path only. #2642 targets Wine and was run on Windows only. #3151 changes what happens on a lost device; no device was lost, so that path was not exercised. AI-assisted (Claude Code, Claude Opus 5.5).
KelboLive commented 2026-12-03 16:09:18 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-03T16:09:18Z.


Fixed in 5524fdcdc.

The cause was exactly as you described: WRITTEN was an AtomicBool swapped before write_to, so a second caller returned false and could reach lost::end(75) while the first was still writing. It is now a Mutex<bool> held for the whole publication: a losing caller blocks until the marker is renamed into place, then returns false. use_file resets it under the same lock, and I kept the lock order WRITTEN → FILE in both functions to avoid an inversion.

Regression test: a_concurrent_caller_returns_only_after_the_marker_exists runs two threads per iteration (64 iterations); a caller that did not write asserts the marker already exists at the moment it returns. I reproduced the red by temporarily restoring the claim-before-write order with a 20 ms pause after the claim — the test fails there, and passes with the fix. lost:: is now 17/0/3 and the serial leonida-gpu suite is 726/0/59.

Two notes on the rest of your review:

  • #3146 conflict: still open; a merge-tree of the two heads reports the conflict in modules/d3d12x.rs as you said. Whichever lands second needs to rebase that callback; I did not touch it here.
  • Pipeline book flush: agreed it should happen before either exit path; it is not in this change, and I'd rather land the marker ordering first than widen this diff. I'll raise it as a follow-up finding on the PR.

The rebased head is 5524fdcdc on current main with switches.md regenerated (732 names). CI is restarting on it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7384356962 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3151#issuecomment-7384356962). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-12-03T16:09:18Z. --- Fixed in `5524fdcdc`. The cause was exactly as you described: `WRITTEN` was an `AtomicBool` swapped **before** `write_to`, so a second caller returned `false` and could reach `lost::end(75)` while the first was still writing. It is now a `Mutex<bool>` held for the whole publication: a losing caller blocks until the marker is renamed into place, then returns `false`. `use_file` resets it under the same lock, and I kept the lock order `WRITTEN → FILE` in both functions to avoid an inversion. Regression test: `a_concurrent_caller_returns_only_after_the_marker_exists` runs two threads per iteration (64 iterations); a caller that did not write asserts the marker already exists at the moment it returns. I reproduced the red by temporarily restoring the claim-before-write order with a 20 ms pause after the claim — the test fails there, and passes with the fix. `lost::` is now 17/0/3 and the serial `leonida-gpu` suite is 726/0/59. Two notes on the rest of your review: - **#3146 conflict:** still open; a merge-tree of the two heads reports the conflict in `modules/d3d12x.rs` as you said. Whichever lands second needs to rebase that callback; I did not touch it here. - **Pipeline book flush:** agreed it should happen before either exit path; it is not in this change, and I'd rather land the marker ordering first than widen this diff. I'll raise it as a follow-up finding on the PR. The rebased head is `5524fdcdc` on current main with `switches.md` regenerated (732 names). CI is restarting on it.
KelboLive commented 2026-12-03 17:07:58 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-03T17:07:58Z.


Rebased onto current main (fba6f09ce) at 804ac5d7b.

Resolved the modules/d3d12x.rs conflict with #3146 as you suggested: flush_on_gpu_failure() now runs before either exit path, then the 75 path logs and calls lost::end(75), then the legacy TerminateProcess(DXGI_ERROR_DEVICE_REMOVED) for other GPU failures. This also answers your pipeline-book note for the merged callback.

lost:: 17/0/3, serial leonida-gpu 735/0/59, d3d12_switches.py --check clean. CI is restarting on the new head.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7386012611 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3151#issuecomment-7386012611). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-12-03T17:07:58Z. --- Rebased onto current main (`fba6f09ce`) at `804ac5d7b`. Resolved the `modules/d3d12x.rs` conflict with #3146 as you suggested: `flush_on_gpu_failure()` now runs **before either exit path**, then the 75 path logs and calls `lost::end(75)`, then the legacy `TerminateProcess(DXGI_ERROR_DEVICE_REMOVED)` for other GPU failures. This also answers your pipeline-book note for the merged callback. `lost::` 17/0/3, serial `leonida-gpu` 735/0/59, `d3d12_switches.py --check` clean. CI is restarting on the new head.
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/3151:upstream-pr/3151'
git switch 'upstream-pr/3151'

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