Report: lock-safe crash report persistence under contention and re-entrancy (#106) #237

Open
slopgobblercobbler wants to merge 1 commit from upstream-pr/240 into main
slopgobblercobbler commented 2026-11-23 21:45:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by slopgobblercobbler on 2026-11-23T21:45:47Z.


Addresses #106 Item 4 (Crash reporting lock safety & persistence under contention):
Prevents dropping crash data during process termination or unhandled exceptions:

  1. Mutex poison recovery: lock_within() and build() recover from mutex poisoning via p.into_inner(), guaranteeing the report persists even if a thread panics during exit.
  2. Re-entrancy protection: Thread-local InWriteGuard prevents same-thread recursion if formatting/writing faults, using a fallback path rather than self-deadlocking on WRITE_LOCK.
  3. Lock contention fallback: If WRITE_LOCK cannot be acquired within timeout during process termination, writes a direct fallback report or refreshes the existing report file rather than discarding crash data.
  4. Late crash refresh: Re-checks CRASH before and after serialization so a concurrent crash is captured before process exit.

What is in it

  • crates/xcl/src/report.rs:
    • lock_within with poison recovery.
    • InWriteGuard re-entrancy tracker.
    • Fallback crash report writing under lock contention.
    • Unit tests covering concurrent exit, re-entrancy, and poison recovery.

Tested

  • cargo test -p xcl -- report (24 passed, 0 failed).
  • Full workspace test suite: cargo test --workspace (608 passed, 0 failed).
  • Windows 11 x64, MSVC toolchain.

Not tested

  • Out of disk space scenarios during report write.

AI use

  • Developed with Antigravity swarm coordinator & dedicated author/verifier agents (author-report, verify-report). Verified and reviewed independently.
<!-- greyfinch-sync:ivall/xcl:issue:5461763324 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/240). Originally posted by [slopgobblercobbler](https://github.com/slopgobblercobbler) on 2026-11-23T21:45:47Z. --- Addresses #106 Item 4 (Crash reporting lock safety & persistence under contention): Prevents dropping crash data during process termination or unhandled exceptions: 1. **Mutex poison recovery:** `lock_within()` and `build()` recover from mutex poisoning via `p.into_inner()`, guaranteeing the report persists even if a thread panics during exit. 2. **Re-entrancy protection:** Thread-local `InWriteGuard` prevents same-thread recursion if formatting/writing faults, using a fallback path rather than self-deadlocking on `WRITE_LOCK`. 3. **Lock contention fallback:** If `WRITE_LOCK` cannot be acquired within timeout during process termination, writes a direct fallback report or refreshes the existing report file rather than discarding crash data. 4. **Late crash refresh:** Re-checks `CRASH` before and after serialization so a concurrent crash is captured before process exit. **What is in it** - `crates/xcl/src/report.rs`: - `lock_within` with poison recovery. - `InWriteGuard` re-entrancy tracker. - Fallback crash report writing under lock contention. - Unit tests covering concurrent exit, re-entrancy, and poison recovery. **Tested** - `cargo test -p xcl -- report` (24 passed, 0 failed). - Full workspace test suite: `cargo test --workspace` (608 passed, 0 failed). - Windows 11 x64, MSVC toolchain. **Not tested** - Out of disk space scenarios during report write. **AI use** - Developed with Antigravity swarm coordinator & dedicated author/verifier agents (`author-report`, `verify-report`). Verified and reviewed independently.
MesshM commented 2026-11-24 07:06:16 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by MesshM on 2026-11-24T04:33:51Z.


Test run of 62cd3bcc6028930ec22237dfbd271fd7a81ba461 on AMD RDNA4. I merged it onto current main 64b3f35 locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 707 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 666 passed, 0 failed, 21 ignored
  • 0 SKIPPED; the report tests pass.

Review: Recovering the report data from a poisoned mutex (into_inner) and the thread-local IN_WRITE guard against re-entry mean a panic or a nested fault while writing no longer loses the report. I found nothing to change.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

<!-- greyfinch-sync:ivall/xcl:comment:7122133709 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/240#issuecomment-7122133709). Originally posted by [MesshM](https://github.com/MesshM) on 2026-11-24T04:33:51Z. --- Test run of `62cd3bcc6028930ec22237dfbd271fd7a81ba461` on AMD RDNA4. I merged it onto current `main` `64b3f35` locally (clean merge) and tested that tree. **Tested** - AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 `stable-x86_64-pc-windows-msvc`, debug - `cargo build --workspace` + `cargo test --workspace -- --test-threads=4` on the merge: **707 passed, 0 failed, 41 ignored**, exit code 0; `xcl` lib tests 666 passed, 0 failed, 21 ignored - **0 `SKIPPED`**; the `report` tests pass. **Review:** Recovering the report data from a poisoned mutex (`into_inner`) and the thread-local `IN_WRITE` guard against re-entry mean a panic or a nested fault while writing no longer loses the report. I found nothing to change. **Not tested:** no retail title or regression run (I have no unpacked game), no `XCL_SAMPLE_*` tests, release build; the PR's head on its old base was not run, only its merge onto `main`. Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
throny commented 2026-11-25 01:10:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-11-25T00:37:53Z.


Two contributors checked independently and found that #1705 solves the same problem in a different way: #1607, group D65. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint from the community triage in #1607, not a maintainer decision.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

<!-- greyfinch-sync:ivall/xcl:comment:7148713993 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/240#issuecomment-7148713993). Originally posted by [throny](https://github.com/throny) on 2026-11-25T00:37:53Z. --- <!-- xcl-1607-hint:D65 --> Two contributors checked independently and found that #1705 solves the same problem in a different way: #1607, group D65. You may want to compare them with the other author and agree on one, or say in the PR why both are needed. This is a hint from the community triage in #1607, not a maintainer decision. AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
DavidM1911 commented 2026-11-25 16:12:03 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T15:14:24Z.


Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

<!-- greyfinch-sync:ivall/xcl:comment:7166523544 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/240#issuecomment-7166523544). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T15:14:24Z. --- Verification on RTX 3060 Ti (Windows 11): **merge conflict with current `main`** — needs a rebase before it can be tested.
github-actions[bot] commented 2026-11-29 20:43:41 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-29T20:43:41Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7262310307 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/240#issuecomment-7262310307). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-29T20:43:41Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 03:01:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:01:40Z.


Triage (#1607) – head 62cd3bc

Overlap: #1705 makes the same core fix: lock_within takes a poisoned lock instead of losing the crash, with a test. This PR adds a same-thread re-entrancy guard, a fallback report, and rechecks of CRASH after build() and after the write. Neither is on main.
Problem in report.rs: write_final: when WRITE_LOCK times out, the fallback path loads and rewrites the report file without the lock while the holder may be writing it. load can then read a half-written file and fall back to build_fallback, overwriting the full report with a minimal one.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7299244147 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/240#issuecomment-7299244147). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T03:01:40Z. --- **Triage (#1607)** – head 62cd3bc Overlap: #1705 makes the same core fix: `lock_within` takes a poisoned lock instead of losing the crash, with a test. This PR adds a same-thread re-entrancy guard, a fallback report, and rechecks of `CRASH` after `build()` and after the write. Neither is on main. Problem in `report.rs: write_final`: when `WRITE_LOCK` times out, the fallback path loads and rewrites the report file without the lock while the holder may be writing it. `load` can then read a half-written file and fall back to `build_fallback`, overwriting the full report with a minimal one. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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/240:upstream-pr/240'
git switch 'upstream-pr/240'

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