RynthAi: a refused combat mode change is not a sent request

ChangeCombatModeFor called host.ChangeCombatMode, began a paced action only on
success, and then returned true either way. BuffManager and the Combat stance
paths read that true as a sent request: they advanced their attempt clocks,
counted a failed try and logged a retry. With the engine turning non-teardown
actions away around a teleport or a death, chained refusals could reach
NoWandFlipMaxFails and set _magicModeBlocked / _wandSwapExhausted.

- ChangeCombatModeFor returns false on a refusal, without Begin. The other
  *For helpers already return the host result. The no-ChangeCombatMode host
  case still returns true (nothing to send or pace).
- Callers stamp their bookkeeping only on true: BuffManager peace-for-kit
  paths (_lastCastAttempt, _healWaitKind); CorpseOpenController's peace
  before an open and MissileCraftingManager's peace before the first combine
  are asked again until accepted, inside their 2.5 s ceiling counted from the
  first ask; the stuck-stance clocks (BuffManager, CombatManager) start only
  once a stance request has gone out; ExpressionEngine's cast-stance flip
  throttle; the CombatManager stall-watchdog toggle, whose ladder step is
  taken back (CombatStallWatchdog.Unfire) when the toggle is refused.
- ActionPacer tracks a streak of consecutive engine refusals (one log line
  when it starts, one when an accepted call ends it). After
  EngineRefusalFailOpenMs (30 s) ChangeCombatModeFor returns true again, so a
  permanent refusal (missing hook, full ring) is counted by the callers' own
  failure paths instead of retrying forever. A gap of more than RefuseGapMs
  (10 s) starts a new streak; Reset() and Forget() end it.
- ActionPacer.LastEngineRefusalMs: a refusal newer than a stuck-stance
  clock's start restarts that clock, so a request accepted and then dropped
  by a teleport does not end in a re-equip UseObject on the wielded weapon.

Tests: FakeHost.CombatModeRefuse; ActionPacingTests (refusals burn no try or
backoff, streak, fail-open, expiry and Forget, stuck clock restart, 20 s
no-wand loop never reaches _magicModeBlocked, peace-before-open retry,
MissileCraftingManager), WeaponTests (equip pass keeps its backoff),
CombatHookTests, CombatStallWatchdogTests (Unfire).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Daniel Wallace 2026-10-12 16:26:55 -07:00
commit 2e8258b079
12 changed files with 570 additions and 34 deletions

View file

@ -768,6 +768,8 @@ public sealed partial class RynthAiPlugin
private const long PeaceBeforeOpenMaxMs = 2500;
private int _peaceBeforeOpenFor;
private long _peaceBeforeOpenSince;
/// <summary>The peace request for _peaceBeforeOpenFor was accepted by the engine (a refusal is retried).</summary>
private bool _peaceSent;
/// <summary>True while the open should wait for the peace-mode swap it just asked for.</summary>
private bool WantsPeaceBeforeOpen(LegacyUiSettings settings, long now)
@ -781,10 +783,13 @@ public sealed partial class RynthAiPlugin
if (_peaceBeforeOpenFor != _targetCorpseId)
{
_peaceBeforeOpenFor = _targetCorpseId;
_peaceBeforeOpenSince = now;
Host.ChangeCombatModeFor(CombatMode.NonCombat, "Loot", "peace before opening the corpse (Peace Mode When Idle)");
return true;
_peaceBeforeOpenSince = now; // the ceiling counts from the first ask
_peaceSent = false;
}
// One accepted request per corpse. A refusal (the engine turns stance changes away around a
// teleport) or a pacing hold is asked again on the next call, inside the same ceiling.
if (!_peaceSent)
_peaceSent = Host.ChangeCombatModeFor(CombatMode.NonCombat, "Loot", "peace before opening the corpse (Peace Mode When Idle)");
return now - _peaceBeforeOpenSince < PeaceBeforeOpenMaxMs;
}
// Wait for busy to genuinely clear before opening the next corpse. The backstop