Engine robustness: fewer crashes and hangs around deaths, portals and out-of-memory, plus better crash evidence #8

Closed
AwfulWaffle wants to merge 3 commits from AwfulWaffle/RynthCore:engine-robustness into main
First-time contributor

Closed by the author: this change is already in main (checked against 418d80b). Thanks for taking it in.

What players and bot users saw

  • Crashes right after a death, a portal or a teleport. Bots keep queueing moves, casts, uses and appraisals at full speed while AC is tearing the world down and loading the next one. Those queued actions then ran straight into half-destroyed objects.
  • A client that froze and never came back. When AC shows a modal box on its main thread (for example the OUT OF MEMORY box), plugin ticks kept running against a client that was no longer ticking. The launcher then killed the client as wedged, and nothing was left behind to explain why.
  • Crashes that left no trace. Some native faults were logged once and then deduplicated away, so the fatal repeat never reached the log. An out-of-memory box never produces a crash dump on its own, because the process does not actually crash.
  • Appraisal floods. The same object could be appraised (0xC8) again and again: every client re-create, and every duplicate request from a plugin, went out as its own message.

What changes

World transitions (deaths, portals, teleports, non-adjacent landblock jumps)

  • The main-thread queue holds game-changing work while the player is dead, in portal space, or within 5 s after either. When the window ends, stale casts, uses, selects and appraisals are dropped, and stops and cancels run first, in order. Walking into the next landblock never triggers this.
  • The action ring refuses new non-stop work during a transition and keeps its top 32 slots for stops and cancels, so a stop can never be lost behind held work.
  • Every AC-mutating helper goes through one gate (AcMainThreadQueue.MustQueue). Render-thread actions (ImGui panels, EndScene plugin calls) used to slip around the queue and run into a world AC was tearing down. They now queue or wait like everything else.
  • A cast is refused while a transition is on, so the caller retries instead of filling the single cast slot with something that would only be dropped.

Frozen main thread

  • Plugin ticks pause while AC's main thread is frozen (a main-thread message box, or no heartbeat for the hang watchdog's threshold). Events keep flowing. The pause is shown in GetEngineStatusJson (mainThreadFrozen, mainThreadStallMs, pluginTicksPausedMs) and on the heartbeat line.

Crash and out-of-memory evidence

  • AC's OUT OF MEMORY box: one full-memory dump goes to <install>\Dumps before the box shows, and the newest 3 are kept. The dump writes start and end markers in the log, and the launcher holds its wedge-kill while a dump is in progress, up to 15 min per client.
  • Native crash logger: each entry carries the pid, tid and date. Repeats of an address are relogged at powers of two, after 30 s, or for any code other than an access violation. A 16-entry ring of the latest records is flushed from the last-chance filter and from the engine's exit detours on a crash code, so the fatal repeat of a known address is no longer lost.
  • The crash logger changes need the rebuilt RynthCore.SehTrampoline.dll (native\SehTrampoline\Build-SehTrampoline.ps1) deployed with the engine. With an older DLL the engine logs RC_FlushCrashLog not exported and skips the flush.
  • Crash exit codes now pass straight through the ExitProcess/TerminateProcess detours, so no managed work runs inside a dying process. ExitProcess(-1) is no longer treated as a crash.
  • Usage statistics now count the loader's CoreCLR fatal-error dumps (Logs\dumps\clr_*.dmp) as crashes, alongside crash_*.dmp.

Appraisals

  • A request for an object that already has one pending is merged into it, as the QueryHealth slot already does. One reply answers every caller.
  • AutoId remembers when it last appraised each object across client releases, and does not appraise it again within 10 min while its data is still cached, unless the server deleted the object (0xF747).

Diagnostics

  • The heartbeat shows the largest free address-space block (valargest=) and the transition refusals (qrej=). Free and largest address space are also logged around each plugin load and unload.

Notes for review

  • Built on current main, with no duplicate crash-dump setup. Main already configures CoreCLR crash dumps in Loader.c (ConfigureCrashDumps, Logs\dumps\clr_*.dmp) and keeps createdump.exe and the DAC in Publish-EngineCoreClr.ps1. This PR adds no second setup and leaves Clr.c and the publish script exactly as they are on main.
  • The cast queue combines both sets of changes. Main's "stop queued before the cast goes first" and "pre-cast stop" logic is kept as written. In this PR the cast fields live in CastSlot. Main's per-cast _castStopWaitNoted becomes CastSlot.StopWaitNoted, and it is reset before the Volatile.Write that publishes Pending. The queue time is also written with Volatile.Write, because a plain 64-bit store can tear on x86 and the drain reads it without the lock.
  • The stop check reads the shared ring. The action ring is now ActionRing<T>, so StopQueuedAtOrBefore walks it through a new consumer-only ActionRing.TryPeekAt. An entry's time is taken before the ring's lock, so two producers can land slightly out of time order. The walk therefore checks every queued entry (at most 256) instead of stopping at the first newer one. The check is a pure helper, CastStopRules.AnyStopAtOrBefore, compiled into tools\EngineRobustnessTests; its out-of-order test fails when the walk is changed to stop at the first newer entry.
  • The mutator checker recognises the new gate. tools\check_offthread_mutators.py now accepts the gate's own shape, an if ( that opens with AcMainThreadQueue.MustQueue( (optionally after one flag ||), since MustQueue calls MainThreadGuard.IsOnMainThread() itself. The search skips // comments, so a commented-out gate does not count; the check is still textual, so a string literal that spells the shape would. The checker reports the same 2 findings as on main (DecalBridgeHost.PostNotice, LargeAddressAlignmentPatch.TryWriteHighByte), both already present there.
  • No plugin API change. PluginContractVersion stays at 80.

Testing

Built and run at this branch's head, with main (b0f9d74) as the baseline. Every commit on the branch builds and passes EngineRobustnessTests on its own.

Check main this branch
dotnet build RynthCore.sln -c Release 0 errors 0 errors
tools\EngineRobustnessTests (new) - 943 checks, 0 failed
native\SehTrampoline\tests\Run-CrashLogFilterTests.ps1 (new) - 229 checks, 0 failed
native\SehTrampoline\Build-SehTrampoline.ps1 -NoDeploy - builds
tools\EngineSettingsTests PASS (177) PASS (177)
tools\FlightRecorderTests passed passed
tools\PanelTextScaleTests PASS PASS
tools\LoaderReloadCapTests ALL PASSED ALL PASSED
tools\LoaderStagingTests ALL PASSED ALL PASSED
tools\UsageStatsTests 36/38 (run after 23:00 UTC) 39/39
tools\check_offthread_mutators.py 2 findings the same 2 findings

On main, UsageStatsTests failed 2 checks ("a second check the same day sends nothing", "next day: one more") when run after 23:00 UTC: the test's "same day" is DateTime.UtcNow.AddHours(1), which is the next UTC day at that hour. After 00:00 UTC this branch passes 39/39, the new clr_*.dmp check included.

Not tested here: a live client. Nothing in this PR has been run in game from this branch.

🤖 Generated with Claude Code

Closed by the author: this change is already in main (checked against 418d80b). Thanks for taking it in. ## What players and bot users saw - **Crashes right after a death, a portal or a teleport.** Bots keep queueing moves, casts, uses and appraisals at full speed while AC is tearing the world down and loading the next one. Those queued actions then ran straight into half-destroyed objects. - **A client that froze and never came back.** When AC shows a modal box on its main thread (for example the OUT OF MEMORY box), plugin ticks kept running against a client that was no longer ticking. The launcher then killed the client as wedged, and nothing was left behind to explain why. - **Crashes that left no trace.** Some native faults were logged once and then deduplicated away, so the fatal repeat never reached the log. An out-of-memory box never produces a crash dump on its own, because the process does not actually crash. - **Appraisal floods.** The same object could be appraised (0xC8) again and again: every client re-create, and every duplicate request from a plugin, went out as its own message. ## What changes **World transitions (deaths, portals, teleports, non-adjacent landblock jumps)** - The main-thread queue holds game-changing work while the player is dead, in portal space, or within 5 s after either. When the window ends, stale casts, uses, selects and appraisals are dropped, and stops and cancels run first, in order. Walking into the next landblock never triggers this. - The action ring refuses new non-stop work during a transition and keeps its top 32 slots for stops and cancels, so a stop can never be lost behind held work. - Every AC-mutating helper goes through one gate (`AcMainThreadQueue.MustQueue`). Render-thread actions (ImGui panels, EndScene plugin calls) used to slip around the queue and run into a world AC was tearing down. They now queue or wait like everything else. - A cast is refused while a transition is on, so the caller retries instead of filling the single cast slot with something that would only be dropped. **Frozen main thread** - Plugin ticks pause while AC's main thread is frozen (a main-thread message box, or no heartbeat for the hang watchdog's threshold). Events keep flowing. The pause is shown in `GetEngineStatusJson` (`mainThreadFrozen`, `mainThreadStallMs`, `pluginTicksPausedMs`) and on the heartbeat line. **Crash and out-of-memory evidence** - AC's OUT OF MEMORY box: one full-memory dump goes to `<install>\Dumps` before the box shows, and the newest 3 are kept. The dump writes start and end markers in the log, and the launcher holds its wedge-kill while a dump is in progress, up to 15 min per client. - Native crash logger: each entry carries the pid, tid and date. Repeats of an address are relogged at powers of two, after 30 s, or for any code other than an access violation. A 16-entry ring of the latest records is flushed from the last-chance filter and from the engine's exit detours on a crash code, so the fatal repeat of a known address is no longer lost. - The crash logger changes need the rebuilt `RynthCore.SehTrampoline.dll` (`native\SehTrampoline\Build-SehTrampoline.ps1`) deployed with the engine. With an older DLL the engine logs `RC_FlushCrashLog not exported` and skips the flush. - Crash exit codes now pass straight through the ExitProcess/TerminateProcess detours, so no managed work runs inside a dying process. `ExitProcess(-1)` is no longer treated as a crash. - Usage statistics now count the loader's CoreCLR fatal-error dumps (`Logs\dumps\clr_*.dmp`) as crashes, alongside `crash_*.dmp`. **Appraisals** - A request for an object that already has one pending is merged into it, as the QueryHealth slot already does. One reply answers every caller. - AutoId remembers when it last appraised each object across client releases, and does not appraise it again within 10 min while its data is still cached, unless the server deleted the object (0xF747). **Diagnostics** - The heartbeat shows the largest free address-space block (`valargest=`) and the transition refusals (`qrej=`). Free and largest address space are also logged around each plugin load and unload. ## Notes for review - **Built on current main, with no duplicate crash-dump setup.** Main already configures CoreCLR crash dumps in `Loader.c` (`ConfigureCrashDumps`, `Logs\dumps\clr_*.dmp`) and keeps `createdump.exe` and the DAC in `Publish-EngineCoreClr.ps1`. This PR adds no second setup and leaves `Clr.c` and the publish script exactly as they are on main. - **The cast queue combines both sets of changes.** Main's "stop queued before the cast goes first" and "pre-cast stop" logic is kept as written. In this PR the cast fields live in `CastSlot`. Main's per-cast `_castStopWaitNoted` becomes `CastSlot.StopWaitNoted`, and it is reset before the `Volatile.Write` that publishes `Pending`. The queue time is also written with `Volatile.Write`, because a plain 64-bit store can tear on x86 and the drain reads it without the lock. - **The stop check reads the shared ring.** The action ring is now `ActionRing<T>`, so `StopQueuedAtOrBefore` walks it through a new consumer-only `ActionRing.TryPeekAt`. An entry's time is taken before the ring's lock, so two producers can land slightly out of time order. The walk therefore checks every queued entry (at most 256) instead of stopping at the first newer one. The check is a pure helper, `CastStopRules.AnyStopAtOrBefore`, compiled into `tools\EngineRobustnessTests`; its out-of-order test fails when the walk is changed to stop at the first newer entry. - **The mutator checker recognises the new gate.** `tools\check_offthread_mutators.py` now accepts the gate's own shape, an `if (` that opens with `AcMainThreadQueue.MustQueue(` (optionally after one `flag ||`), since `MustQueue` calls `MainThreadGuard.IsOnMainThread()` itself. The search skips `//` comments, so a commented-out gate does not count; the check is still textual, so a string literal that spells the shape would. The checker reports the same 2 findings as on main (`DecalBridgeHost.PostNotice`, `LargeAddressAlignmentPatch.TryWriteHighByte`), both already present there. - **No plugin API change.** `PluginContractVersion` stays at 80. ## Testing Built and run at this branch's head, with main (b0f9d74) as the baseline. Every commit on the branch builds and passes EngineRobustnessTests on its own. | Check | main | this branch | |---|---|---| | `dotnet build RynthCore.sln -c Release` | 0 errors | 0 errors | | `tools\EngineRobustnessTests` (new) | - | 943 checks, 0 failed | | `native\SehTrampoline\tests\Run-CrashLogFilterTests.ps1` (new) | - | 229 checks, 0 failed | | `native\SehTrampoline\Build-SehTrampoline.ps1 -NoDeploy` | - | builds | | `tools\EngineSettingsTests` | PASS (177) | PASS (177) | | `tools\FlightRecorderTests` | passed | passed | | `tools\PanelTextScaleTests` | PASS | PASS | | `tools\LoaderReloadCapTests` | ALL PASSED | ALL PASSED | | `tools\LoaderStagingTests` | ALL PASSED | ALL PASSED | | `tools\UsageStatsTests` | 36/38 (run after 23:00 UTC) | 39/39 | | `tools\check_offthread_mutators.py` | 2 findings | the same 2 findings | On main, UsageStatsTests failed 2 checks ("a second check the same day sends nothing", "next day: one more") when run after 23:00 UTC: the test's "same day" is `DateTime.UtcNow.AddHours(1)`, which is the next UTC day at that hour. After 00:00 UTC this branch passes 39/39, the new `clr_*.dmp` check included. Not tested here: a live client. Nothing in this PR has been run in game from this branch. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Appraisals
- RequestId slot merges a pending request for the same object (PendingIdQueue), as the
  QueryHealth slot does.
- AutoId: per-object last-sent time kept across client releases; no re-appraisal within
  10 min while the data is cached, unless the server deleted the object (0xF747). Map
  bounded at 8192 with a prune off the create path. The sent mark is set at the real
  send in DrainRequestIds, not at queue time.
- The selected-target priority appraisal is skipped when its data is cached and fresh.

Main thread frozen
- Plugin ticks pause while AC's main thread is frozen (a main-thread message box, or no
  beat for the hang watchdog's threshold); events keep flowing. Exposed through
  GetEngineStatusJson (mainThreadFrozen, mainThreadStallMs, pluginTicksPausedMs) and the
  heartbeat (pump=paused).

Crashes
- AC's OUT OF MEMORY box: one full-memory dump to <install>\Dumps before the box shows,
  newest 3 kept.
- Native crash logger: pid, tid and date per entry; once per address; .NET Framework
  AVs never charged to the limit; last-chance handler; stack overflow and heap
  corruption codes. Build-SehTrampoline gains -NoDeploy.
- ProcessExitHooks: dead fail-fast detours removed; crash exit codes pass straight
  through TerminateProcess/NtTerminateProcess.
- CoreCLR's own crash dump is left to the loader's existing ConfigureCrashDumps
  (Loader.c, Logs\dumps\clr_*.dmp) and Publish-EngineCoreClr's createdump/DAC
  handling; this change adds no second setup.

World transitions
- AcMainThreadQueue holds queued game-mutating work while the player is dead, in portal
  space, or within 5 s after either or after a non-adjacent landblock jump. When the
  window ends, stale casts, uses, selects and appraisals are dropped and stops and
  cancels run in order. Walking across an adjacent landblock border never gates.
  State is re-sampled after AC's tick, before the post-tick drain.
- Inventory panel actions are held during a transition too.

Diagnostics
- Heartbeat valargest= (largest free VA block); free and largest logged before and after
  each plugin load and unload.
- CastSpell comments corrected to the actual main-thread paths.

Tests
- tools\EngineRobustnessTests and native\SehTrampoline\tests\CrashLogFilterTests.c.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Native crash logger
- Per-address slots keep hit counts and a last-write tick; a repeat relogs at powers of
  two, after 30 s, or for any non-AV code. The oldest noise slot is evicted when the
  table is full.
- The logger checks its dedupe first, caches the module table, and opens the log
  handle once at install. Managed-noise bucket (coreclr, clrjit, System.Private.CoreLib).

Main-thread queue
- The action ring (ActionRing) rejects non-teardown work during a world transition and
  reserves its top 32 slots for teardown, so a stop is never lost behind held work.
  IsTeardownKind is shared by the enqueue and drain sides. ActionRing.TryPeekAt lets the
  cast drain's StopQueuedAtOrBefore walk the ring it no longer owns directly; the walk
  now checks every queued entry, since an entry's time is taken before the ring's lock.
- MutatorGate: every AC-mutating helper opens with the same gate,
  AcMainThreadQueue.MustQueue(teardown: X); IsDraining and ShouldDefer added; teardown
  helpers are exempt from the hold. tools\check_offthread_mutators.py accepts MustQueue
  as the gate (it asks MainThreadGuard.IsOnMainThread itself).
- MasteryFeed and VaultFeed pause during a transition. The heading slot drops a stale
  heading; the overlay select is kept.
- RequestId never merges into an entry queued at or before the last transition hold;
  EnqueueRequestId returns false during a transition.
- 0xF751 PlayerTeleport starts the 5 s settle window.
- Cast slot: the queue time and Pending are published with Volatile.Write (a plain 64-bit
  store can tear on x86 and the drain reads both without the lock); the stop-wait flag is
  reset before the publishing store.

Appraisals
- Appraisal data survives a client release for 10 min (bounded at 4096); evicted on
  server delete (0xF747) and at session clear. 0xF747 is detected in SmartBox dispatch,
  independent of capture.

Dumps
- Dump start/end markers in the log; the launcher holds its wedge kill while a dump is
  in progress (DumpInProgressRule). The in-progress flag is cleared only when the writer
  thread exits.
- The OOM dump triggers only on the main thread with AC's exact text, before stacks are
  built. Dumps are pruned only after a successful write, and other live clients' dumps
  are kept. CrashDump reads the file length before Delete.
- ExitProcess/RtlExitUserProcess detours forward crash codes first.
- The message box count is decremented first in a finally; 30 s safety reset when no box
  is visible on the main thread.
- UsageStats counts the loader's CoreCLR fatal-error dumps (Logs\dumps\clr_*.dmp) as
  crashes alongside crash_*.dmp.

Tests: EngineRobustnessTests, CrashLogFilterTests, UsageStatsTests.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- The native crash logger keeps the last 16 first-chance records in a static ring
  (pushed in the VEH: no I/O, no allocation, no loader call). A flush writes the ones
  not yet written, oldest first, each record once. Flushed from the last-chance filter
  and, through the new export RC_FlushCrashLog, from the engine's ExitProcess /
  TerminateProcess / RtlExitUserProcess / NtTerminateProcess detours on a crash code
  (raw unmanaged function pointer, resolved and primed at install). Recovers the fatal
  repeat of an address seen before, which the dedupe skips and which never reaches the
  last-chance filter when a handler terminates the process.
- EnqueueCast refuses during a world transition (CastSlot, pure) and counts the
  refusal in TransitionRejectedCount. The cast slot now owns the stop-wait note the
  cast drain keeps per cast (CastSlot.StopWaitNoted, reset by each queued cast before
  the publishing Volatile.Write of Pending), and DrainCasts reads the queue time once.
- The launcher's dump hold is capped at 15 min per client (DumpInProgressRule.Decide);
  past it the kill checks resume.
- CrashExitRule: ExitProcess(-1) (0xFFFFFFFF) is no longer a crash exit; the rest of
  the 0xC0000000-and-up range is unchanged, so CLR/C++ unhandled-exception exits
  (0xE0434352, 0xE06D7363) still skip managed work.
- The heartbeat line carries qrej=<TransitionRejectedCount>.

Tests: EngineRobustnessTests (adds CastSlot stop-wait and ActionRing.TryPeekAt checks),
CrashLogFilterTests.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
AwfulWaffle closed this pull request 2026-11-07 14:00:16 -05:00

Pull request closed

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.

Dependencies

No dependencies set

Reference
rynth/RynthCore!8
No description provided.