RynthAi: stuck-cast breaker, no re-send into a busy server, recovery retry, HP failsafe

Two casts were held open 40.8 s and 37 s by ACE's fast-tick turn-to-cast
wait; every later send was answered UseDone 0x1D and a heal was re-sent
every 2.5 s.

- ActionPacer: after a 0x1D UseDone nothing starts until the server answers;
  with no cast of ours open, one probe after 1.5 s, then doubling (max 6 s).
  Attack repeats are not held (ACE sends no UseDone for a swing), and a latch
  with no cast of ours open ends after LatchMaxMs (15 s). A cast still
  unanswered 1 s past its normal cycle (learned per spell, at least 3 s) is
  turned to face its target; 2 s past it (capped by Stuck Cast Break, default
  8000 ms) or on a 0x1D while it has been open 3 s, it is broken with a jump
  (TapJump; ACE fails a cast on a fast-tick jump). Starts wait until landed;
  no UseDone 3 s after landing -> Peace mode; 3 s more -> going on. Every
  hold is bounded: a cast StaleCastMs old, or sent before a frame gap of 5 s
  (keyed on the gap's end), is dropped with the latch, never broken. No
  breaker step in portal space; Forget on portal-enter and the death hold.
  A burst of 5 'too busy' answers in a second holds every start except a
  heal. A refused forced jump with no cast open leaves no breaker stage.
  A cast a script chose (the combat hook) is not jumped before 6 s from its
  send (ScriptCastMinBreakMs, the held-cast nudge's HeldAfterIncantMs).
  Stuck Cast Break is read from the settings once per tick.
- MoveAudit: no start in the tick of a movement change; 150 ms and a clear
  motion queue (or 600 ms) let it go. A held stop sent later by
  FlushPendingStops counts as a movement change too; the forced flush in
  CastSpellFor still goes out in the same tick as the cast that follows it.
- Blacklist: casts answered 0x1D (or unanswered while the server is busy) are
  not no-damage casts.
- Combat hook: ctx.pending is the cast in flight; ctx.last is the most recent
  RESOLVED cast, its err final (the first UseDone after its send; nil only
  when none could be read: 7 s timeout, or another answer came first). The
  casts in flight of both kinds resolve in send order through one queue.
  The send-time UseDone count comes from the pacer (LastCastSeqAtSend).
  CombatRequestV1 appends Resolved*/Pending* fields (StructSize-gated, no
  Version bump); an older RynthAi keeps the old ctx.last.
- HP failsafe (BuffManager.HpFailsafe.cs): at or under Emergency Heal At with
  no heal landing for 3 rounds of 2.5 s, a forced jump; 3 more rounds, the
  macro stops and /lifestone goes out (HP Failsafe Recall, default on).
  Nothing counts in portal space; a pending recall is dropped on death; a
  recall that never starts turns the macro back on (only one the failsafe
  stopped, never past the VTank yield) and re-arms after a 30 s cooldown.

Recovery retry: recovery vitals (Heal Self, Stamina to Health, Revitalize,
Stamina to Mana) refused for "not enough mana" retry after Recovery Retry
(200 ms, a setting) instead of resting the family: ACE rolls Mana Conversion
on every attempt before the windup and a refusal costs nothing. At most 5
recovery casts a second, 20 refusals in a row, stamina and Mana Conversion
checks, an episode with no refusal for 7 s ends; an episode summary line.
Stamina to Mana and Revitalize are still held under their cost by the mana
reserve (AttemptVitalCast), so for them the retry applies when the mana
reading is stale or costs are unknown; Heal Self and Stamina to Health,
which are tried below cost, gain the most.
When the retry stops, the vital rests as the existing mana reserve has it
(LowManaHealRestSec, 2 s). Script heals and other casts are unchanged.

Tests: StuckCastTests (incl. the script cast's break floor), PacerEdgeTests,
RecoveryRetryTests (incl. costs known: Stamina to Mana held), HpFailsafeTests,
CombatHookTests (ctx.last/ctx.pending, send order, an answer during the send,
0x1D blacklist, script heal keeps its rest, script attack and heal not jumped
before 6 s with or without a 'too busy' answer); HealLatencyTests' and ManaReserveTests' low-mana rest
cases pin untrained Mana Conversion; RynthLua compat combathook.lua.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Daniel Wallace 2026-10-12 16:23:37 -07:00
commit 2d8bebb0f4
30 changed files with 3156 additions and 53 deletions

View file

@ -1124,11 +1124,18 @@ public partial class BuffManager : IDisposable
LogPostCastDiff(diag);
}
// A recall the HP failsafe asked for goes out after the macro stop (BuffManager.HpFailsafe.cs).
TickFailsafeRecall();
if (!_settings.IsMacroRunning) return;
// Close casts the server reports finished, and say once when one is being held open.
PollCastTracker();
// Heals failing at Emergency Heal At: break the cast, then recall (BuffManager.HpFailsafe.cs).
TickHpFailsafe();
if (!_settings.IsMacroRunning) return;
// A Magic stance we asked for: watch the client's mode every tick (see ObserveStance).
ObserveStance();
@ -1381,7 +1388,11 @@ public partial class BuffManager : IDisposable
}
}
if ((DateTime.Now - _lastCastAttempt).TotalMilliseconds < _settings.SpellCastIntervalMs)
// A due recovery retry (BuffManager.RecoveryRetry.cs) gets past Spell Interval, for the vitals
// step only: the buffs after it still wait (intervalHeld below). A stale episode ends first.
ExpireRecoveryEpisode();
bool intervalHeld = (DateTime.Now - _lastCastAttempt).TotalMilliseconds < _settings.SpellCastIntervalMs;
if (intervalHeld && !RecoveryRetryDue())
{
Hold("cast interval");
return;
@ -1433,6 +1444,13 @@ public partial class BuffManager : IDisposable
return;
}
// Only a recovery retry got past Spell Interval; nothing else goes inside it.
if (intervalHeld)
{
Hold("cast interval");
return;
}
// The login refresh above held buffs only: the heal had its turn, the buffs wait.
if (buffsHeldForRefresh)
{
@ -1972,6 +1990,9 @@ public partial class BuffManager : IDisposable
&& _buffFailCooldownUntil.TryGetValue(family, out DateTime coolUntil)
&& DateTime.Now < coolUntil)
return VitalNo($"parked for {(coolUntil - DateTime.Now).TotalSeconds:0} s more after a refusal or no-show");
// A recovery vital retried after a mana refusal: its retry gap and the per-second ceiling.
if (IsRecoveryVital(what) && RecoveryRetryHolds(family) is { Length: > 0 } recoveryWhy)
return VitalNo(recoveryWhy);
if (CurrentCombatMode != CombatMode.Magic && DateTime.Now < _vitalSwapBlockedUntil)
return VitalNo("wand swap blocked, retrying shortly");
bool urgentHeal = label == LabelHealing && HealIsUrgent(_vitals.HealthPct, _vitals.StaminaPct);
@ -1989,6 +2010,7 @@ public partial class BuffManager : IDisposable
_pendingSpellId = spellId;
_pendingVitalSpellId = spellId; // instant: confirmed by chat, never by the registry
_pendingVitalLabel = label;
_pendingVitalBase = what;
bool castOk = _host.CastSpellFor(targetId, spellId, "Buff",
SpellTableStub.GetById(spellId)?.Name ?? what);
_lastCastAttempt = DateTime.Now;
@ -1998,6 +2020,7 @@ public partial class BuffManager : IDisposable
return VitalNo($"the client refused the cast (spell {spellId})");
}
sent = true;
if (IsRecoveryVital(what)) NoteRecoveryAttempt();
NoteCastIssued(spellId);
if (_pendingVitalLabel == LabelMana) _manaStarvedLogged = false; // the next starved spell logs again
if (_pendingVitalLabel == LabelHealing)
@ -3554,6 +3577,7 @@ public partial class BuffManager : IDisposable
public void OnChatWindowText(string text, int chatType)
{
string lower = text.ToLowerInvariant();
ObserveRecallLine(lower);
// Diagnostic: log every chat seen while waiting on a cast confirmation,
@ -3723,6 +3747,15 @@ public partial class BuffManager : IDisposable
_lastManaRefusalAt = DateTime.Now; // a combat cast's refusal too: ManaStarved with costs unknown
if (_pendingSpellId == 0) return;
var pendingSpell = SpellTableStub.GetById(_pendingSpellId);
// A recovery vital tries again soon for a better Mana Conversion roll (RecoveryRetry).
if (OnRecoveryManaRefusal(pendingSpell))
{
_host.Log($"[BuffChat] CLEARED pending={_pendingSpellId} - not enough mana; retrying in {RecoveryRetryMs} ms, buffs {LowManaBuffPauseMs / 1000:0}s.");
_pendingSpellId = 0;
_lowManaPauseUntil = DateTime.Now.AddMilliseconds(LowManaBuffPauseMs);
_onCastResolved?.Invoke("not enough mana");
return;
}
double restSec = LowManaFamilyRestSec;
if (pendingSpell != null)
{
@ -3867,6 +3900,7 @@ public partial class BuffManager : IDisposable
// which never fires for instant vitals (Heal/Revitalize/Stamina to Mana), so
// two slow confirmations hours apart parked Heal Self for 30 minutes.
_silentNoShowCounts.Remove(spellInfo.Family);
OnRecoveryCastResult(spellInfo.Family, spellInfo.Name);
NoteCastAccepted(); // AC accepted a cast — end any too-busy backoff
// Chat-authoritative record: only NOW (AC confirmed "you cast X").
// Item/armor enchants live in _itemSpellTimers (what IsBuffActive