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:
parent
aaaa0a94b4
commit
44765436cd
4 changed files with 166 additions and 44 deletions
|
|
@ -16,6 +16,8 @@ internal static partial class Program
|
|||
AutoIdDecisionTable();
|
||||
AutoIdDecisionSpotCases();
|
||||
AutoIdDeferWindow();
|
||||
AutoIdLoginDefer();
|
||||
AutoIdInventoryRate();
|
||||
AutoIdClassify();
|
||||
AutoIdModeParse();
|
||||
IdMarkerScopes();
|
||||
|
|
@ -28,7 +30,7 @@ internal static partial class Program
|
|||
private static readonly long[] Ages = { 0, AutoIdPolicy.MinAgeMs - 1, AutoIdPolicy.MinAgeMs, 60_000 };
|
||||
|
||||
/// <summary>The rule as the spec states it, written out independently of AutoIdPolicy.Decide.</summary>
|
||||
private static V Expected(AutoIdMode mode, C cls, long age, bool defer, bool openedAfter, bool fresh, bool cached)
|
||||
private static V Expected(AutoIdMode mode, C cls, long age, bool defer, bool openedAfter, bool fresh, bool cached, bool rateOk)
|
||||
{
|
||||
if (mode == AutoIdMode.Off) return V.SkipMode;
|
||||
if (mode == AutoIdMode.All) return cls == C.Target && fresh ? V.SkipFresh : V.Send;
|
||||
|
|
@ -37,7 +39,7 @@ internal static partial class Program
|
|||
{
|
||||
C.Target => fresh ? V.SkipFresh : V.Send,
|
||||
C.Container => fresh ? V.SkipFresh : young ? V.WaitAge : defer && !openedAfter ? V.WaitDefer : V.Send,
|
||||
C.Inventory => cached ? V.SkipFresh : young ? V.WaitAge : defer ? V.WaitDefer : V.Send,
|
||||
C.Inventory => cached ? V.SkipFresh : young ? V.WaitAge : defer ? V.WaitDefer : !rateOk ? V.WaitRate : V.Send,
|
||||
C.Unknown => young ? V.WaitAge : V.SkipMode,
|
||||
_ => V.SkipMode,
|
||||
};
|
||||
|
|
@ -54,16 +56,17 @@ internal static partial class Program
|
|||
foreach (bool opened in new[] { false, true })
|
||||
foreach (bool cached in new[] { false, true })
|
||||
foreach (bool fresh in new[] { false, true })
|
||||
foreach (bool rateOk in new[] { false, true })
|
||||
{
|
||||
if (fresh && !cached) continue; // fresh implies cached
|
||||
rows++;
|
||||
V got = AutoIdPolicy.Decide(mode, cls, age, defer, opened, fresh, cached);
|
||||
V want = Expected(mode, cls, age, defer, opened, fresh, cached);
|
||||
V got = AutoIdPolicy.Decide(mode, cls, age, defer, opened, fresh, cached, rateOk);
|
||||
V want = Expected(mode, cls, age, defer, opened, fresh, cached, rateOk);
|
||||
if (got != want && wrong++ < 10)
|
||||
Check(false, $"{mode} {cls} age={age} defer={defer} opened={opened} cached={cached} fresh={fresh}: want {want}, got {got}");
|
||||
Check(false, $"{mode} {cls} age={age} defer={defer} opened={opened} cached={cached} fresh={fresh} rateOk={rateOk}: want {want}, got {got}");
|
||||
}
|
||||
Check(wrong == 0, $"{wrong} of {rows} rows wrong");
|
||||
Check(rows == 3 * 5 * 4 * 2 * 2 * 3, $"row count {rows}");
|
||||
Check(rows == 3 * 5 * 4 * 2 * 2 * 3 * 2, $"row count {rows}");
|
||||
}
|
||||
|
||||
/// <summary>The same rules as named cases, so a mutation is easy to read off a failure.</summary>
|
||||
|
|
@ -96,6 +99,10 @@ internal static partial class Program
|
|||
Check(AutoIdPolicy.Decide(AutoIdMode.Limited, C.Inventory, AutoIdPolicy.MinAgeMs - 1, false, false, false, false) == V.WaitAge, "pack item waits for the minimum age");
|
||||
Check(AutoIdPolicy.Decide(AutoIdMode.Limited, C.Inventory, Old, true, true, false, false) == V.WaitDefer, "pack item deferred (the opened-container exemption does not apply)");
|
||||
Check(AutoIdPolicy.Decide(AutoIdMode.Limited, C.Inventory, Old, false, false, false, false) == V.Send, "uncached pack item sent");
|
||||
Check(AutoIdPolicy.Decide(AutoIdMode.Limited, C.Inventory, Old, false, false, false, false, inventoryRateOk: false) == V.WaitRate, "pack item over the rate waits");
|
||||
Check(AutoIdPolicy.Decide(AutoIdMode.Limited, C.Container, Old, false, true, false, false, inventoryRateOk: false) == V.Send, "the rate cap is the inventory's only (container)");
|
||||
Check(AutoIdPolicy.Decide(AutoIdMode.Limited, C.Target, 0, true, false, false, false, inventoryRateOk: false) == V.Send, "the rate cap never holds the selected target");
|
||||
Check(AutoIdPolicy.Decide(AutoIdMode.All, C.Inventory, 0, false, false, false, false, inventoryRateOk: false) == V.Send, "All mode keeps the old behaviour (no cap)");
|
||||
// Limited: unknown place.
|
||||
Check(AutoIdPolicy.Decide(AutoIdMode.Limited, C.Unknown, 100, false, false, false, false) == V.WaitAge, "unknown place waits while young");
|
||||
Check(AutoIdPolicy.Decide(AutoIdMode.Limited, C.Unknown, Old, false, false, false, false) == V.SkipMode, "still unknown when old: skipped");
|
||||
|
|
@ -109,26 +116,30 @@ internal static partial class Program
|
|||
_case = "autoid defer window";
|
||||
const long D = AutoIdPolicy.DeferMs;
|
||||
const long S = WorldTransitionState.SettleMs;
|
||||
// Login completed long before (at 1); every time below is shifted past its defer.
|
||||
const long B = 1_000_000;
|
||||
static bool Def(long now, long settle, bool inTransition) =>
|
||||
AutoIdPolicy.InDefer(now + B, settle == 0 ? 0 : settle + B, 1, inTransition);
|
||||
|
||||
// No transition yet: nothing is deferred.
|
||||
var w = new WorldTransitionState();
|
||||
w.Sample(1000, dead: false, portaling: false, landblock: 0xA9B4);
|
||||
Check(!AutoIdPolicy.InDefer(1000, w.SettleUntilMs, w.InTransition(1000)), "no transition, no defer");
|
||||
Check(!Def(1000, w.SettleUntilMs, w.InTransition(1000)), "no transition, no defer");
|
||||
|
||||
// Walking into the next landblock never defers.
|
||||
w.Sample(2000, false, false, 0xAAB4);
|
||||
w.Sample(3000, false, false, 0xAAB5);
|
||||
Check(w.SettleUntilMs == 0, "an adjacent walk sets no settle window");
|
||||
Check(!AutoIdPolicy.InDefer(3000, w.SettleUntilMs, w.InTransition(3000)), "adjacent walk: no defer");
|
||||
Check(!Def(3000, w.SettleUntilMs, w.InTransition(3000)), "adjacent walk: no defer");
|
||||
|
||||
// A portal: deferred through portal space, the settle window, and DeferMs after it.
|
||||
w.Sample(10_000, false, true, 0xAAB5);
|
||||
Check(AutoIdPolicy.InDefer(10_000, w.SettleUntilMs, w.InTransition(10_000)), "in portal space: deferred");
|
||||
Check(Def(10_000, w.SettleUntilMs, w.InTransition(10_000)), "in portal space: deferred");
|
||||
w.Sample(12_000, false, false, 0x0007);
|
||||
long settleEnd = w.SettleUntilMs;
|
||||
Check(settleEnd == 12_000 + S, $"settle ends {S} ms after the portal exit, got {settleEnd}");
|
||||
Check(AutoIdPolicy.InDefer(settleEnd + D - 1, settleEnd, w.InTransition(settleEnd + D - 1)), "deferred until DeferMs after the settle");
|
||||
Check(!AutoIdPolicy.InDefer(settleEnd + D, settleEnd, w.InTransition(settleEnd + D)), "not deferred at DeferMs after the settle");
|
||||
Check(Def(settleEnd + D - 1, settleEnd, w.InTransition(settleEnd + D - 1)), "deferred until DeferMs after the settle");
|
||||
Check(!Def(settleEnd + D, settleEnd, w.InTransition(settleEnd + D)), "not deferred at DeferMs after the settle");
|
||||
|
||||
// A container opened after the settle ended is exempt; one opened before is not.
|
||||
Check(AutoIdPolicy.OpenedAfterSettle(settleEnd + 1, settleEnd), "opened after the settle: exempt");
|
||||
|
|
@ -140,24 +151,91 @@ internal static partial class Program
|
|||
d.Sample(1000, false, false, 0x1234);
|
||||
d.Sample(2000, true, false, 0x1234);
|
||||
d.Sample(3000, false, false, 0x1234);
|
||||
Check(AutoIdPolicy.InDefer(3000 + S + D - 1, d.SettleUntilMs, false), "death: deferred");
|
||||
Check(!AutoIdPolicy.InDefer(3000 + S + D, d.SettleUntilMs, false), "death: defer ends");
|
||||
Check(Def(3000 + S + D - 1, d.SettleUntilMs, false), "death: deferred");
|
||||
Check(!Def(3000 + S + D, d.SettleUntilMs, false), "death: defer ends");
|
||||
|
||||
// A landblock jump without portal space defers.
|
||||
var j = new WorldTransitionState();
|
||||
j.Sample(1000, false, false, 0x00AE);
|
||||
j.Sample(1100, false, false, 0xA9B4);
|
||||
Check(AutoIdPolicy.InDefer(1100 + S + D - 1, j.SettleUntilMs, false), "landblock jump: deferred");
|
||||
Check(Def(1100 + S + D - 1, j.SettleUntilMs, false), "landblock jump: deferred");
|
||||
|
||||
// A PlayerTeleport message (a recall into the next landblock) defers.
|
||||
var t = new WorldTransitionState();
|
||||
t.Sample(1000, false, false, 0x1234);
|
||||
t.OnTeleportMessage(5000);
|
||||
Check(AutoIdPolicy.InDefer(5000 + S + D - 1, t.SettleUntilMs, false), "teleport message: deferred");
|
||||
Check(!AutoIdPolicy.InDefer(5000 + S + D, t.SettleUntilMs, false), "teleport message: defer ends");
|
||||
Check(Def(5000 + S + D - 1, t.SettleUntilMs, false), "teleport message: deferred");
|
||||
Check(!Def(5000 + S + D, t.SettleUntilMs, false), "teleport message: defer ends");
|
||||
|
||||
// In a transition right now: deferred whatever the settle time says.
|
||||
Check(AutoIdPolicy.InDefer(1, 0, inTransition: true), "in a transition: deferred");
|
||||
Check(Def(1, 0, inTransition: true), "in a transition: deferred");
|
||||
}
|
||||
|
||||
// ---- login is a transition (a client crashed in the login create burst) ----------------
|
||||
|
||||
private static void AutoIdLoginDefer()
|
||||
{
|
||||
_case = "autoid login defer";
|
||||
const long D = AutoIdPolicy.DeferMs;
|
||||
const long Login = 500_000;
|
||||
|
||||
// Before login completes (the create burst): everything background is deferred.
|
||||
Check(AutoIdPolicy.InDefer(Login - 1, 0, 0, false), "login not complete: deferred");
|
||||
Check(AutoIdPolicy.InDefer(10_000_000, 0, 0, false), "login never completed: still deferred");
|
||||
// After: DeferMs past login-complete, exactly like the post-teleport defer.
|
||||
Check(AutoIdPolicy.InDefer(Login, 0, Login, false), "at login-complete: deferred");
|
||||
Check(AutoIdPolicy.InDefer(Login + D - 1, 0, Login, false), "deferred until DeferMs after login");
|
||||
Check(!AutoIdPolicy.InDefer(Login + D, 0, Login, false), "not deferred at DeferMs after login");
|
||||
// The later of login and the last settle window decides.
|
||||
Check(AutoIdPolicy.TransitionEndMs(0, Login) == Login, "no transition yet: the login is the last one");
|
||||
Check(AutoIdPolicy.TransitionEndMs(Login + 9_000, Login) == Login + 9_000, "a portal after login: the portal's settle");
|
||||
Check(AutoIdPolicy.TransitionEndMs(Login - 9_000, Login) == Login, "a portal before login: the login");
|
||||
Check(AutoIdPolicy.InDefer(Login + 9_000 + D - 1, Login + 9_000, Login, false), "portal after login: its own defer");
|
||||
Check(AutoIdPolicy.InDefer(Login + D - 1, Login - 9_000, Login, false), "a settle before login does not shorten the login defer");
|
||||
// A container the player opens after login-complete is exempt; one opened before it is not.
|
||||
Check(AutoIdPolicy.OpenedAfterSettle(Login + 1, AutoIdPolicy.TransitionEndMs(0, Login)), "opened after login: exempt");
|
||||
Check(!AutoIdPolicy.OpenedAfterSettle(Login - 1, AutoIdPolicy.TransitionEndMs(0, Login)), "opened before login completed: not exempt");
|
||||
// The decision during the login defer: pack and container items wait, the target does not.
|
||||
bool inDefer = AutoIdPolicy.InDefer(Login + 1_000, 0, Login, false);
|
||||
Check(AutoIdPolicy.Decide(AutoIdMode.Limited, C.Inventory, 60_000, inDefer, false, false, false) == V.WaitDefer, "login: pack item waits");
|
||||
Check(AutoIdPolicy.Decide(AutoIdMode.Limited, C.Container, 60_000, inDefer, false, false, false) == V.WaitDefer, "login: container item waits");
|
||||
Check(AutoIdPolicy.Decide(AutoIdMode.Limited, C.Target, 0, inDefer, false, false, false) == V.Send, "login: the selected target is exempt");
|
||||
}
|
||||
|
||||
private static void AutoIdInventoryRate()
|
||||
{
|
||||
_case = "autoid inventory rate";
|
||||
const long I = AutoIdPolicy.InventoryMinIntervalMs;
|
||||
Check(I == 200, "5 a second");
|
||||
Check(AutoIdPolicy.InventoryRateAllows(1_000, 0), "the first send is allowed");
|
||||
Check(!AutoIdPolicy.InventoryRateAllows(1_000 + I - 1, 1_000), "not again inside the interval");
|
||||
Check(AutoIdPolicy.InventoryRateAllows(1_000 + I, 1_000), "again at the interval");
|
||||
|
||||
// Simulate the drain: a 100 ms timer, 3 sends a tick at most, 50 uncached pack items
|
||||
// past their age and the defer. Sends per second never pass 5.
|
||||
long last = 0;
|
||||
int pending = 50;
|
||||
var sendTimes = new List<long>();
|
||||
for (long now = 100; now <= 20_000 && pending > 0; now += 100)
|
||||
{
|
||||
int sentThisTick = 0;
|
||||
for (int k = 0; k < pending && sentThisTick < 3; k++)
|
||||
{
|
||||
bool ok = AutoIdPolicy.InventoryRateAllows(now, last);
|
||||
V v = AutoIdPolicy.Decide(AutoIdMode.Limited, C.Inventory, 60_000, false, false, false, false, ok);
|
||||
if (v != V.Send) continue;
|
||||
last = now;
|
||||
sentThisTick++;
|
||||
sendTimes.Add(now);
|
||||
}
|
||||
pending -= sentThisTick;
|
||||
}
|
||||
Check(pending == 0, $"all 50 sent eventually, {pending} left");
|
||||
int worst = 0;
|
||||
foreach (long t0 in sendTimes)
|
||||
worst = Math.Max(worst, sendTimes.Count(t => t >= t0 && t < t0 + 1_000));
|
||||
Check(worst <= 5, $"at most 5 inventory sends in any second, got {worst}");
|
||||
Check(worst == 5, $"and the cap is reached (5), got {worst}");
|
||||
}
|
||||
|
||||
// ---- where an object is ------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Reference in a new issue