Hang watch: each game event and semaphore keeps its last operations #47

Manually merged
github merged 2 commits from gh-pr/47/head into gh-pr/47/base 2026-11-27 03:15:14 +00:00
Owner

@⁠Sr-0w on GitHub · 2026-11-25 17:30 UTC · original
Sr-0w:diagnostics/wait-object-history → main · +351 −20 · 8 files · 2 commits · merged 2026-11-25 22:11 UTC

A game run reached the opening cutscene, then hit the game's 30 s watchdog. The wait-object report showed a cycle:

  • the main thread waits on a semaphore that a worker (A) no longer releases;
  • A waits on an auto-reset "idle" event of a second worker (B);
  • B waits on a wake event that only A sets.

B had signaled the idle event 0.2 s before A started waiting on it. So the signal was either taken by another wait or dropped in between. The report couldn't tell which: it kept only the last signal, and the shims saw neither ResetEvent nor WaitForMultipleObjects, though the game imports both.

Change:

  • Each object now keeps its last 12 operations: signaled, reset, wait, wait on any/all of N, woke, timed out. Each comes with the thread, the time before the dump and the game's calling address. The blocked-wait report lists them after the signal count.
  • ResetEvent and WaitForMultipleObjects get pass-through shims under --watch-hang, like the other wait-object calls. They are removed otherwise.

Test: a signal, a multi-object wait that it ends, a reset and a blocked wait are listed in order with their threads, and the wake-up that follows is recorded. Loader tests and architecture rules pass. Docs are in debugging.md.

🤖 Generated with Claude Code

**@⁠Sr-0w** on GitHub · 2026-11-25 17:30 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/47) `Sr-0w:diagnostics/wait-object-history` → `main` · +351 −20 · 8 files · 2 commits · merged 2026-11-25 22:11 UTC A game run reached the opening cutscene, then hit the game's 30 s watchdog. The wait-object report showed a cycle: - the main thread waits on a semaphore that a worker (A) no longer releases; - A waits on an auto-reset "idle" event of a second worker (B); - B waits on a wake event that only A sets. B had signaled the idle event 0.2 s before A started waiting on it. So the signal was either taken by another wait or dropped in between. The report couldn't tell which: it kept only the last signal, and the shims saw neither `ResetEvent` nor `WaitForMultipleObjects`, though the game imports both. **Change:** - Each object now keeps its last 12 operations: signaled, reset, wait, wait on any/all of N, woke, timed out. Each comes with the thread, the time before the dump and the game's calling address. The blocked-wait report lists them after the signal count. - `ResetEvent` and `WaitForMultipleObjects` get pass-through shims under `--watch-hang`, like the other wait-object calls. They are removed otherwise. **Test:** a signal, a multi-object wait that it ends, a reset and a blocked wait are listed in order with their threads, and the wake-up that follows is recorded. Loader tests and architecture rules pass. Docs are in `debugging.md`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A game run reached the opening cutscene, then hit the game's 30 s
watchdog: the main thread waited on a semaphore a worker no longer
released, that worker waited on an auto-reset "idle" event of a second
worker, and the second waited on a wake event only the first sets. The
idle event had been signaled 0.2 s before the first worker started to
wait on it, so the signal was taken or dropped in between, but the
report only kept the last signal and the shims saw neither ResetEvent
nor WaitForMultipleObjects, both of which the game imports.

Each object now keeps its last 12 operations (signaled, reset, wait,
woke, timed out, or a multi-object wait), with the thread, the time and
the game's calling address, and the blocked-wait report lists them.
ResetEvent and WaitForMultipleObjects get pass-through shims under
--watch-hang like the other wait-object calls.

Test: a signal, a multi-object wait that it ends, a reset and a blocked
wait are listed in order with their threads; the wake-up that follows
is recorded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review of #47:
- Signals, resets and wake-ups scan the stack for one game frame only (they run on the paths the hang watch times).
- A wait on several objects that times out, fails or ends on an abandoned mutex records that on its objects
  (the abandoned one, or all), and a wait on all of them records the wake-up on each.
- The blocked line of a wait on several names them all: one of N (or all of N) handles, the first described.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 03:15:13 +00:00
github manually merged commit 60091634c4 into gh-pr/47/base 2026-11-27 03:15:14 +00:00
Author
Owner

@⁠ThatRecompDev on GitHub · 2026-11-25 19:08 UTC · original · edited 2026-11-25 19:09 UTC

this is really useful, the "signaled 0.2 s before the wait" story is exactly what the old report couldn't show.

couple of things before merging though:

Signaled and Done now call Caller(), which does the full 64 KB / 6-frame scan on every SetEvent/ReleaseSemaphore/ResetEvent and every wake, just to keep the first address. with the hang watch on, that adds work to exactly the paths whose timing we're watching. could you scan for 1 frame there (or reuse the frames the wait already found)?

DoneOnSeveral drops timeouts and abandoned results, so a multi-wait that times out leaves nothing, while single waits record "timed out".

the blocked line only names handles[0] for a multi wait, maybe say "one of N".

off-mode is fine, since the shims get removed without --watch-hang.

heads up too: main got a fix in ReturnAddresses.Scan last night (it only reads the call bytes when their page is committed, 98d9727). it crashed a boot from inside the wait shim, so more Caller() calls go through that path now

**@⁠ThatRecompDev** on GitHub · 2026-11-25 19:08 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/47#issuecomment-7171877191) · edited 2026-11-25 19:09 UTC this is really useful, the "signaled 0.2 s before the wait" story is exactly what the old report couldn't show. couple of things before merging though: Signaled and Done now call Caller(), which does the full 64 KB / 6-frame scan on every SetEvent/ReleaseSemaphore/ResetEvent and every wake, just to keep the first address. with the hang watch on, that adds work to exactly the paths whose timing we're watching. could you scan for 1 frame there (or reuse the frames the wait already found)? DoneOnSeveral drops timeouts and abandoned results, so a multi-wait that times out leaves nothing, while single waits record "timed out". the blocked line only names handles[0] for a multi wait, maybe say "one of N". off-mode is fine, since the shims get removed without --watch-hang. heads up too: main got a fix in ReturnAddresses.Scan last night (it only reads the call bytes when their page is committed, 98d9727). it crashed a boot from inside the wait shim, so more Caller() calls go through that path now
Author
Owner

@⁠Sr-0w on GitHub · 2026-11-25 21:21 UTC · original

Thanks, done (rebased on main, so it goes through 98d9727's CallBytesReadable):

  • Caller cost: Signaled, Reset and every wake-up now scan for one frame (GameFrames(1)), stopping at the first game return address. Creations and waits keep 6 frames, and DoneOnSeveral scans once for all its objects.
  • multi-wait results: DoneOnSeveral takes all and records the result on the objects:
    • timeout or failure → "timed out" / "wait returned 0x.." on every object;
    • WAIT_ABANDONED_0 + i → "abandoned" on that object;
    • a successful wait-all → "woke" on each object.
  • blocked line: a wait on several now reads on one of 3 handles (0x.., 0x.., 0x..), the first 0x..: <first described> (or all of).

New test A_wait_on_several_objects_names_them_all_and_its_timeout_stays_on_each. WaitObjects tests 11/11.

**@⁠Sr-0w** on GitHub · 2026-11-25 21:21 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/47#issuecomment-7174974209) Thanks, done (rebased on main, so it goes through 98d9727's `CallBytesReadable`): - **Caller cost**: `Signaled`, `Reset` and every wake-up now scan for **one** frame (`GameFrames(1)`), stopping at the first game return address. Creations and waits keep 6 frames, and `DoneOnSeveral` scans once for all its objects. - **multi-wait results**: `DoneOnSeveral` takes `all` and records the result on the objects: - timeout or failure → "timed out" / "wait returned 0x.." on every object; - `WAIT_ABANDONED_0 + i` → "abandoned" on that object; - a successful wait-all → "woke" on each object. - **blocked line**: a wait on several now reads `on one of 3 handles (0x.., 0x.., 0x..), the first 0x..: <first described>` (or `all of`). New test `A_wait_on_several_objects_names_them_all_and_its_timeout_stays_on_each`. WaitObjects tests 11/11.
Author
Owner

@⁠Sr-0w on GitHub · 2026-11-25 21:57 UTC · original

In game: this history is what found the watchdog cause fixed by #49. The run with it showed:

  • the frame thread waiting on the "last worker done" event;
  • 4 workers asleep;
  • the 5th still Running in CreatePipelineState at 5, 15 and 25 s.

That ruled out a lost wake-up. With #49 on top, runs reach the opening cinematic (loading screens at 30 fps, then the world at 9–14 fps) and last 600 s without the watchdog.

**@⁠Sr-0w** on GitHub · 2026-11-25 21:57 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/47#issuecomment-7175765827) **In game:** this history is what found the watchdog cause fixed by #49. The run with it showed: - the frame thread waiting on the "last worker done" event; - 4 workers asleep; - the 5th still Running in `CreatePipelineState` at 5, 15 and 25 s. That ruled out a lost wake-up. With #49 on top, runs reach the opening cinematic (loading screens at 30 fps, then the world at 9–14 fps) and last 600 s without the watchdog.
Author
Owner

@⁠ThatRecompDev on GitHub · 2026-11-25 22:11 UTC · original

thanks, all three changes are in and they read well. the one-frame scan in Signaled/Done, timeouts and abandoned results recorded for multi-waits, and the "one of N" wording.

merged into main (566a88d). i fixed one architecture rule on the way in (the property pattern in Target became a local and a plain null check), so no need to touch it.

two small things if you ever come back to it: a signal from a thread with no game frames still scans the full 64 KB, and the WaitForMultipleObjects shim reads the handle array before kernel32 does, so a bad pointer would crash instead of returning WAIT_FAILED. not urgent

**@⁠ThatRecompDev** on GitHub · 2026-11-25 22:11 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/47#issuecomment-7176054094) thanks, all three changes are in and they read well. the one-frame scan in Signaled/Done, timeouts and abandoned results recorded for multi-waits, and the "one of N" wording. merged into main (566a88d). i fixed one architecture rule on the way in (the property pattern in Target became a local and a plain null check), so no need to touch it. two small things if you ever come back to it: a signal from a thread with no game frames still scans the full 64 KB, and the WaitForMultipleObjects shim reads the handle array before kernel32 does, so a bad pointer would crash instead of returning WAIT_FAILED. not urgent
github-bot referenced this pull request from a commit 2026-11-28 08:54:00 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.