From ccfa22af092c87d0a355b9bd3c35c2ab6f39c362 Mon Sep 17 00:00:00 2001 From: BlankenshipG Date: Sun, 4 Oct 2026 23:46:20 -0400 Subject: [PATCH] fix(engine): keep off-thread int reads current with server property updates Patch the appraisal cache from PublicUpdateProperty messages and fall back to the update cache off-thread, so a refilled pet essence no longer reads 0 charges from a stale ID snapshot. Co-authored-by: Cursor --- Changelog/2026-10-04-pet-refill-loop-fix.md | 52 +++++++++++++++++++ .../Compatibility/AppraisalHooks.cs | 24 +++++++++ .../Compatibility/ClientObjectHooks.cs | 5 +- .../Compatibility/PropertyUpdateHooks.cs | 4 ++ 4 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 Changelog/2026-10-04-pet-refill-loop-fix.md diff --git a/Changelog/2026-10-04-pet-refill-loop-fix.md b/Changelog/2026-10-04-pet-refill-loop-fix.md new file mode 100644 index 0000000..17de9bd --- /dev/null +++ b/Changelog/2026-10-04-pet-refill-loop-fix.md @@ -0,0 +1,52 @@ +# Pet essence refill loop fix — RynthAi 0.6.28 + engine + +**Date:** 2026-10-04 +**Components:** RynthCore.Engine (property caches), RynthCore.Plugin.RynthAi 0.6.27 → 0.6.28 + +## Problem + +SilentStorm got stuck refilling the same pet essence (0x9757B329) over and over. The log +(`RynthCore.9568.log.old`) showed `Pet: refilling essence … with spirit …` about every 7 s, +and every 30 s once cooldowns kicked in. Each attempt used an Encapsulated Spirit on the essence. +The server switches the player to peace mode and plays the clap animation for every refill, +so the character kept dropping out of combat. + +## Root cause + +- `PetManager` decides whether an essence is empty by reading its `Structure` (charges) through + `TryGetObjectIntProperty`. The plugin pump runs off the main thread, so that read was + served **only** from the appraisal cache. That cache is a snapshot from the last time the item was ID'd. +- When the server refills an essence it sends a `PublicUpdatePropertyInt(Structure = MaxStructure)`. + The engine stored that in the property-update cache, but the off-thread read never consulted + that cache, and the appraisal snapshot was never patched. So the essence kept reading 0 charges. +- The server's reply ("You add the spirit to the essence." / "This essence is already full.") + sent `PetManager` back to Idle without recording anything. On the next tick it read 0 again + and issued another refill. + +## Fix + +### Engine +- `PropertyUpdateHooks.CacheInt` / `CacheBool` now also patch the appraisal cache entry for that + object, if one exists (`AppraisalHooks.PatchCachedInt` / `PatchCachedBool`). Off-thread reads + now see live server updates (Structure after a refill or summon, etc.) instead of the last ID's value. +- `ClientObjectHooks.TryGetObjectIntProperty`: off the main thread, an appraisal-cache miss now + falls back to the property-update cache (a thread-safe managed dictionary) instead of failing. + +### RynthAi plugin (also protects against older engines) +- The server's success and already-full replies now mark the essence as confirmed full for up to 30 min. + While that mark is set, a stale 0-charge read is ignored and the essence is used for summoning. + The mark clears as soon as a summon reports "not enough charges". +- After a confirmed refill the plugin requests a fresh ID of the essence, so the cached charges and the + ILT pet roster agree. +- Loop guard: once an essence has been refilled twice within 2 min and still reads empty, it + is parked for 5 min with a log line, rather than burning more spirits. +- New log lines: `Pet: refill complete (essence …, server confirmed).`, + `Pet: essence … is already full; charge read was stale.`, and the parking message. + +## Files +- `RynthCore/src/RynthCore.Engine/Compatibility/AppraisalHooks.cs` +- `RynthCore/src/RynthCore.Engine/Compatibility/PropertyUpdateHooks.cs` +- `RynthCore/src/RynthCore.Engine/Compatibility/ClientObjectHooks.cs` +- `RynthSuite/Plugins/RynthCore.Plugin.RynthAi/Combat/PetManager.cs` +- `RynthSuite/Plugins/RynthCore.Plugin.RynthAi/RynthCore.Plugin.RynthAi.csproj` (0.6.28) +- `RynthSuite/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.cs` (VersionPointer 0.6.28) diff --git a/src/RynthCore.Engine/Compatibility/AppraisalHooks.cs b/src/RynthCore.Engine/Compatibility/AppraisalHooks.cs index b827f6d..ac3daf0 100644 --- a/src/RynthCore.Engine/Compatibility/AppraisalHooks.cs +++ b/src/RynthCore.Engine/Compatibility/AppraisalHooks.cs @@ -129,6 +129,30 @@ internal static class AppraisalHooks } } + /// + /// Applies a later server property update to an already-appraised object so the cache + /// doesn't keep serving the value from the last ID. Objects never appraised are left + /// alone (the update cache covers them). + /// + public static void PatchCachedInt(uint guid, uint stype, int value) + { + lock (_cacheLock) + { + if (_intCache.TryGetValue(guid, out Dictionary? props)) + props[stype] = value; + } + } + + /// Bool counterpart of . + public static void PatchCachedBool(uint guid, uint stype, bool value) + { + lock (_cacheLock) + { + if (_boolCache.TryGetValue(guid, out Dictionary? props)) + props[stype] = value; + } + } + /// /// Returns a bool property from the last server appraisal for this object. /// Only populated after the player has identified the item (RequestId). diff --git a/src/RynthCore.Engine/Compatibility/ClientObjectHooks.cs b/src/RynthCore.Engine/Compatibility/ClientObjectHooks.cs index b8e4812..a04659a 100644 --- a/src/RynthCore.Engine/Compatibility/ClientObjectHooks.cs +++ b/src/RynthCore.Engine/Compatibility/ClientObjectHooks.cs @@ -1991,9 +1991,10 @@ internal static class ClientObjectHooks // Deep-audit finding #24 (2026-06-18): never touch AC memory off-thread here. PWD-backed // stypes were handled above (live on the main thread, snapshot off-thread); InqInt - // walks qualities and stays main-thread-only. + // walks qualities and stays main-thread-only. Off-thread, the network update cache + // (a managed ConcurrentDictionary) still answers for never-appraised objects. if (!MainThreadGuard.IsOnMainThread()) - return false; + return PropertyUpdateHooks.TryGetCachedIntProperty(objectId, stype, out value); // CBaseQualities::InqInt for stypes not in PWD. if (_inqInt == null) diff --git a/src/RynthCore.Engine/Compatibility/PropertyUpdateHooks.cs b/src/RynthCore.Engine/Compatibility/PropertyUpdateHooks.cs index 90fe456..9452629 100644 --- a/src/RynthCore.Engine/Compatibility/PropertyUpdateHooks.cs +++ b/src/RynthCore.Engine/Compatibility/PropertyUpdateHooks.cs @@ -325,11 +325,15 @@ internal static class PropertyUpdateHooks { var props = _intCache.GetOrAdd(guid, _ => new ConcurrentDictionary()); props[stype] = value; + // The appraisal snapshot is read first off-thread; keep it current (e.g. an essence's + // Structure after a refill or summon) instead of serving the value from the last ID. + AppraisalHooks.PatchCachedInt(guid, stype, value); } private static void CacheBool(uint guid, uint stype, int value) { var props = _boolCache.GetOrAdd(guid, _ => new ConcurrentDictionary()); props[stype] = value; + AppraisalHooks.PatchCachedBool(guid, stype, value != 0); } }