D3D12-LOADER-CRASH-NO-STDERR-PANIC: never panic on closed stderr in crash reporting #2946
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
2 participants
Due date
No due date set.
Reference
leonida/mandy!2946
Loading…
Reference in a new issue
No description provided.
Delete branch "github-pr/2946"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request successfully merged and closed
Summary
Claimed in the coordination issue as:
D3D12-LOADER-CRASH-NO-STDERR-PANIC(https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7324806186).Prevents
d3d12/crates/leonida-loader/src/crash.rsfrom panicking on a closed/failing stderr pipe during crash reporting:log_crash: writesappend_to_log(&text)first and writes to stderr withlet _ = write!(std::io::stderr(), "{text}");instead ofeprint!, so a closed stderr pipe never loses thecrashes.logentry.report(called fromextern "system"VEH/SetUnhandledExceptionFilter): replaceseprintln!("{l}"),eprint!("{said}"), andeprintln!(" saved ...")with falliblelet _ = write!/writeln!(std::io::stderr(), ...)and writesappend_to_log(&text)before printingsaid, so a closed stderr pipe never panics/aborts acrossextern "system"and never skipscrashes.logorsave_on_crashmemory dumps.Tests & Verification
crash::tests::log_crash_and_report_unhandled_write_files_when_stderr_pipe_is_closedverifying bothlog_crashandreport_unhandled(plus twosave_on_crashdumps under#[cfg(feature = "diagnostics")]) against a closed stderr pipe.log_crashtoeprint!: FAIL (RED1_EXIT=101).reporttoeprintln!: FAIL (RED2_EXIT=101).cargo test --locked -p leonida-loader --lib --features diagnostics -- crash::tests: 20 passed, 0 failed.cargo test --locked -p leonida-loader --lib -- crash::tests: 20 passed, 0 failed.python -I tools/d3d12_switches.py --check d3d12/docs/switches.md: exit 0.python -I scripts/check_no_game_data.py d3d12/crates/leonida-loader/src/crash.rs: exit 0.GPUs tested: N/A (crash/stderr path only; covered by
@MoonEyes's2026-12-02T18:21:19Zin-game batch PASS on RTX 4060 at head44bf554fe).AI Assistance
AI-assisted using Gemini 4 Neon, including a separate read-only independent review pass (APPROVE; applied optional polish to use
'staticbyte slices in thesave_on_crashtest fixture and drop a duplicate import).Independent crash-output check with a closed pipe on
44bf554fmerged into1e3e316c. Under Win64 Wine 11.22 the stock subprocess test passed 3/3 with diagnostics, 3/3 without diagnostics and 3/3 in the diagnostics build combined with #2945 and #2947. It verifies the GPU message, synthetic title line and breakpoint report in the file. The diagnostics build also checks the exact contents of both synthetic dump files.Restoring only the older per-line
eprintln!inreporton the combined tree, with the initial file-firstlog_crashintact, made the same child and outer test exit 101 in all three runs. With the original Cargo binary basename the exact PR passed all 20 crash tests, and the three-PR build passed all 26 crash/profile/stack tests. This uses a direct synthetic exception report under Wine. Native exception dispatch was outside the fixture.MEASURED with OpenAI Codex and a separate read-only review.
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:mainSHA it was merged onto;mainalone 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).
Reviewed #2946 (code review only, not built here: Windows-only). The fix is right and its test is real; the only thing missing is the in-game run that was asked for.
44bf554fe7(unchanged since 1 December)main45dc41f95cgit merge-tree); merge base66c79286f6, 342 commits behind1e3e316c)Review of
d3d12/crates/leonida-loader/src/crash.rseprint!/eprintln!on the crash path (log_crash, the line closure inreport, the title output and the diagnostics memory saves) becomeslet _ = write!(std::io::stderr(), ...). On the head noeprintis left in the file except the comment that forbids it, andmainhas no new ones in that file since the base, so the merge keeps that true.append_to_logthenwrite!), so a closed pipe can no longer lose the file even if something else on stderr panicked. That is the root cause (eprint!panics on a write error inside anextern "system"handler, which aborts) and not a workaround.log_crashandreport_unhandledwith a syntheticEXCEPTION_BREAKPOINT, and asserts the log (and, withdiagnostics, the two saved ranges) exist. merzleckeier showed the red side under Wine: restoring only the old per-lineeprintln!inreportmakes the child and the outer test exit 101 in 3 of 3 runs.GPUs tested:line (none is needed for this, but the template asks for one).Verdict: ready once MoonEyes' requested in-game run (2 December 12:31) is posted. Nothing in the diff changes the render path, so a batch run is enough.
AI-assisted: Claude Opus 5.5 (Claude Code), review only.
AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.
Generated by Claude Code
RUN (in game, batch of seventeen render-path pull requests), each head merged with
git merge --no-ffonto main3c106eb2f, in one build: #311115b579756, #29485284c6eae, #26981f188c4f7, #294644bf554fe, #3001d924cbb65, #28320c861595a, #291558e8535cf, #2822d359a2f85, #2896c9c6b103d, #29838278ef1b9, #3115ba5121192, #2945d2c08c14f, #297574512d658, #295126da88e8e, #2800b6ebcedd4, #28937c7e99b48, #3113fa1460b6b(and #30970d7a451ab, merged since). RTX 4060 8 GB, driver 610.88, Windows 11. Series S,-Resolution 1080, frame generation 2x, the same walking route as the other runs on this machine, 330 s after reaching the world.The drops under 5 fps line up with shaders being translated while walking (about 500 translations in the last 330 s): this batch changes the shader translation, so the shader cache built by earlier runs did not apply and the pipeline precompile alone took about 45 minutes. The batch-5 run on the same machine and route had no sample under 5 fps (median 16.4). I read this as cold-cache stutter, not as a regression of a single pull request, but this run cannot tell them apart.
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. A first attempt of this batch is not counted: the run script gave up waiting for the game window after 40 minutes of precompile.
AI-assisted (Claude Code).
@MoonEyes Added
GPUs tested:to the PR description referencing your2026-12-02T18:21:19Zin-game batch PASS covering exact head44bf554fe(head kept untouched).AI-assisted: Gemini 4 Neon
VERIFY-2946 — el hermano de
#2840, en otro crate y de otro autorY lo primero, para quien mire esta PR en la interfaz: GitHub dirá «210 files changed, +33 370», y el cambio es un fichero de 105 líneas. Es la deriva de su base (
git diff merge-base..heades el número de arriba). Cualquiera que ordene la cola por tamaño de diff está ordenando por cuánto ha crecidomain, no por el trabajo de este PR.El cambio: no hacer
panical imprimir en unstderrcerrado — y el comentario nuevo del código lo dice con las mismas palabras que el de#2840: "prints it without panicking if stderr fails (e.g. a closed pipe at shutdown)".Van tres esta noche y son de tres autores distintos:
#2840enleonida, este enleonida-loader, y#3294con un test para elmad_legacy— dos arreglos del mismo fallo y una prueba del mismo patrón. Eleprintln!que hacepaniccuando el destino no está es una propiedad de Rust que sorprende a todo el mundo una vez, y aquí le ha sorprendido a tres personas en dos crates.Lo que verifiqué: 85 tests del crate en verde con el cambio.
Lo que no: el
crash.rsde verdad con el pipe cerrado —#2840lo prueba lanzando un hijo con elstderrroto (PLAYER_CONTEXT_CLOSED_STDERR_TEST); si este hace lo mismo, el nombre del test lo dirá y está en los 85; si no, el caso que motiva el PR es el único que no se ejerce.Integration check for
44bf554feonmaind9b618f10with #3213 (9a996690) and the resolved #3146 callback overlap. A scratch Windows MSVC test closed a child’s stderr read end, confirmed writes failed, and then calledhost_gpu_failedwith the synthetic HUNG reason. Under Wine, the control with themainloader exited 101. Rebuilding with this head’s sole loader change gave the expected Windows process status0x887A0006and wrote the callback message tocrashes.log. This checks that the two fixes work together on the actual callback. Synthetic subprocess and temp log only. AI-assisted with OpenAI Codex.Merging: accepted by an independent reviewer, no rendering change. Local tests on main
6b5ceb934with this PR and the rest of the batch (#3001, #2983, #2945, #2947, #2946) merged:cargo test -p leonida-hle -p leonida -p leonida-loader --lockedall green,check_no_game_data.pyclean. Tested head2a094ce0a; the branch was updated with main and its tree checked equal to main + that head.🤖 Generated with Claude Code