AutoId limit: login is a transition, inventory capped at 5 sends a second

A client crashed at login inside AC's CreateObject handling during the login create burst,
47 s after start, while pack items were being appraised at about 30 a second. Pack
appraisals now stay out of that burst.

- Login-complete counts as a transition. LoginLifecycleHooks.LoginCompleteAtMs (0 before
  login and after a logout; a hot reload marks it at the reload). Container and Inventory
  appraisals wait until 30 s after the later of login-complete and the last settle window
  (AutoIdPolicy.TransitionEndMs), and are deferred while login has not completed. A
  container opened after that point is still not deferred. The selected target is exempt.
- Inventory sends are capped at one per 200 ms (5 a second; AutoIdPolicy.InventoryRateAllows,
  Verdict.WaitRate). Limited mode only; containers, the target and All mode are not capped.
- "rate" skip counter in /rc autoid and the per-minute line.

Tests: login defer (before, at, through and after login-complete; later-of with a portal;
the opened-container exemption; target exempt), the inventory rate (interval boundary and a
simulated drain never exceeding 5 in any second while reaching 5), the decision table with
the rate input.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Daniel Wallace 2026-10-12 16:29:53 -07:00
commit 44765436cd
4 changed files with 166 additions and 44 deletions

View file

@ -17,8 +17,8 @@
// - AutoIdPolicy (on drain): the AutoIdMode (engine.json "AutoIdMode", /rc autoid).
// Limited (the default) appraises only the selected target, the
// items in the container the player has open, and items in the player's own
// inventory with nothing cached; the last two wait for a minimum object age and a
// post-transition defer. All is the old behaviour; Off sends nothing.
// inventory with nothing cached (at most 5 a second); the last two wait for a
// minimum object age and a defer after login and after every world transition. All is the old behaviour; Off sends nothing.
//
// Every send is queued with who asked (Net/IdRequester.cs), so the flight recorder tags
// it [eng:autoid-target|autoid-container|autoid-inventory|autoid-world].
@ -69,7 +69,7 @@ internal static class AutoIdService
{
public uint Id;
public long AtMs; // created (or moved, or its container opened) at
public byte Counted; // waits already counted: 1 = age, 2 = defer
public byte Counted; // waits already counted: 1 = age, 2 = defer, 4 = rate
}
private static readonly List<Pending> _pending = new(256);
private static readonly HashSet<uint> _pendingIds = new();
@ -87,7 +87,8 @@ internal static class AutoIdService
private static long _rescanDueMs;
private static long _skippedPriorityFresh;
private static long _skipMode, _skipAge, _skipDefer, _skipFresh, _overflow;
private static long _skipMode, _skipAge, _skipDefer, _skipFresh, _skipRate, _overflow;
private static long _lastInventorySendMs; // drain timer only: the Inventory send cap
/// <summary>Re-creates not appraised because a recent appraisal is still cached.</summary>
public static long SkippedRecentCount
@ -364,8 +365,9 @@ internal static class AutoIdService
long openedAt = open != 0 && unchecked((uint)Volatile.Read(ref _openedContainerId)) == open
? Interlocked.Read(ref _openedAtMs) : 0;
long settleUntil = PlayerLifecycleLog.SettleUntilMs;
bool inDefer = AutoIdPolicy.InDefer(now, settleUntil, inTransition: false);
bool openedAfterSettle = AutoIdPolicy.OpenedAfterSettle(openedAt, settleUntil);
long loginAt = LoginLifecycleHooks.LoginCompleteAtMs;
bool inDefer = AutoIdPolicy.InDefer(now, settleUntil, loginAt, inTransition: false);
bool openedAfterSettle = AutoIdPolicy.OpenedAfterSettle(openedAt, AutoIdPolicy.TransitionEndMs(settleUntil, loginAt));
int keep = 0, evaluated = 0;
for (int i = 0; i < _pending.Count; i++)
@ -395,7 +397,10 @@ internal static class AutoIdService
bool cached = AppraisalHooks.HasAppraisalData(p.Id);
bool fresh = cached && AutoIdEligibility.IsAppraisalFresh(
cached, AppraisalHooks.GetLastIdTime(p.Id), nowUnixSec, ReappraiseWindowMs);
AutoIdPolicy.Verdict v = AutoIdPolicy.Decide(mode, cls, now - p.AtMs, inDefer, openedAfterSettle, fresh, cached);
bool rateOk = AutoIdPolicy.InventoryRateAllows(now, _lastInventorySendMs);
AutoIdPolicy.Verdict v = AutoIdPolicy.Decide(mode, cls, now - p.AtMs, inDefer, openedAfterSettle, fresh, cached, rateOk);
if (v == AutoIdPolicy.Verdict.Send && cls == AutoIdPolicy.Class.Inventory && mode == AutoIdMode.Limited)
_lastInventorySendMs = now;
switch (v)
{
case AutoIdPolicy.Verdict.Send:
@ -416,6 +421,10 @@ internal static class AutoIdService
if ((p.Counted & 2) == 0) { p.Counted |= 2; Interlocked.Increment(ref _skipDefer); }
_pending[keep++] = p;
break;
case AutoIdPolicy.Verdict.WaitRate:
if ((p.Counted & 4) == 0) { p.Counted |= 4; Interlocked.Increment(ref _skipRate); }
_pending[keep++] = p;
break;
case AutoIdPolicy.Verdict.SkipFresh:
Interlocked.Increment(ref _skipFresh);
_pendingIds.Remove(p.Id);
@ -459,7 +468,7 @@ internal static class AutoIdService
IdRequester.Plugin, IdRequester.Self, IdRequester.Ui, IdRequester.None,
};
private static readonly long[] _lastSent = new long[IdRequesters.Count];
private static long _lastForeign, _lastSkipMode, _lastSkipAge, _lastSkipDefer, _lastSkipFresh;
private static long _lastForeign, _lastSkipMode, _lastSkipAge, _lastSkipDefer, _lastSkipFresh, _lastSkipRate;
/// <summary>
/// The last minute's IdentifyObject counts (heartbeat thread, once a minute): sent per
@ -471,7 +480,7 @@ internal static class AutoIdService
{
long foreign = FlightRecorder.ForeignIdentifyTotal;
long sm = Interlocked.Read(ref _skipMode), sa = Interlocked.Read(ref _skipAge);
long sd = Interlocked.Read(ref _skipDefer), sf = Interlocked.Read(ref _skipFresh);
long sd = Interlocked.Read(ref _skipDefer), sf = Interlocked.Read(ref _skipFresh), sr = Interlocked.Read(ref _skipRate);
var sb = new System.Text.StringBuilder(160);
sb.Append("autoid 60s: mode=").Append(AutoIdPolicy.Name(Mode)).Append(" sent");
long total = 0;
@ -497,9 +506,9 @@ internal static class AutoIdService
}
sb.Append(" tot=").Append(total);
sb.Append(" skip mode=").Append(sm - _lastSkipMode).Append(" age=").Append(sa - _lastSkipAge)
.Append(" defer=").Append(sd - _lastSkipDefer).Append(" fresh=").Append(sf - _lastSkipFresh);
.Append(" defer=").Append(sd - _lastSkipDefer).Append(" fresh=").Append(sf - _lastSkipFresh).Append(" rate=").Append(sr - _lastSkipRate);
sb.Append(" pend=").Append(Volatile.Read(ref _pendingCount));
_lastSkipMode = sm; _lastSkipAge = sa; _lastSkipDefer = sd; _lastSkipFresh = sf;
_lastSkipMode = sm; _lastSkipAge = sa; _lastSkipDefer = sd; _lastSkipFresh = sf; _lastSkipRate = sr;
return sb.ToString();
}
@ -530,14 +539,14 @@ internal static class AutoIdService
{
AutoIdMode.All => "all (every created object, the old behaviour)",
AutoIdMode.Off => "off (no background appraisals, not even the selected target)",
_ => $"limited (selected target; open container and own inventory after {AutoIdPolicy.MinAgeMs / 1000} s, {AutoIdPolicy.DeferMs / 1000} s after a portal/death/teleport)",
_ => $"limited (selected target; open container and own inventory after {AutoIdPolicy.MinAgeMs / 1000} s, {AutoIdPolicy.DeferMs / 1000} s after login or a portal/death/teleport; inventory at most {1000 / AutoIdPolicy.InventoryMinIntervalMs}/s)",
};
return new[]
{
$"AutoId: {modeText}. Saved in engine.json; /rc autoid all|limited|off switches it now. Plugins' own identifies are never limited.",
$"Identifies sent since start: {sent}; by AC or Decal: {(foreign >= 0 ? foreign.ToString() : "? (flight recorder off)")}.",
$"AutoId skipped: mode {Interlocked.Read(ref _skipMode)}, fresh {Interlocked.Read(ref _skipFresh)}, recent re-create {SkippedRecentCount}; " +
$"waited: age {Interlocked.Read(ref _skipAge)}, defer {Interlocked.Read(ref _skipDefer)}; pending now {Volatile.Read(ref _pendingCount)}" +
$"waited: age {Interlocked.Read(ref _skipAge)}, defer {Interlocked.Read(ref _skipDefer)}, rate {Interlocked.Read(ref _skipRate)}; pending now {Volatile.Read(ref _pendingCount)}" +
(Interlocked.Read(ref _overflow) > 0 ? $", overflow {Interlocked.Read(ref _overflow)}" : "") + ".",
};
}