feat(runtime): first-entry conductor sequences local-player world entry

Cutover slice C3a: the resumable transaction that dissolves the C3
flip's circularity finding. RuntimeLocalPlayerFirstEntryState drives the
local player's complete entry in retail's own order — authored-mover
preparation (the makeObject/set_description shape analog, via a pure
no-submit extraction TryPrepareAuthoredMover), the publication chain's
off-canonical Prepare + atomic body Commit against the residence's exact
placement token, the Evaluate/CommitActivation enter-world analog, the
Place-receipt acknowledgement as that act's virtualized completion, and
only then the executor's FIFO drain (retail: enter_world at 93824
strictly precedes ProcessObjectNetBlobs at 93831). Five stages, eight
typed statuses, exactly-once per stage under retry, no second token
copies, and an acknowledge-stage discriminator that separates
not-yet-FIFO-head (retryable) from authority-moved (typed abandonment) —
a mid-flight delete can no longer strand a retry-forever entry.

The residence retirement notification becomes an ordered multicast
(snapshot-iterated per the event-stream precedent), the lifetime
constructs the conductor with a late-bind Publication seam (transactional
unbound failure — no mutation before the throw), deletion/reset converge
the conductor automatically through the same choke points as the
executor, and its active count is in the ownership snapshot and
IsConverged. Dormant: no production Advance caller; GameRuntime binding
is C3c's first act.

Reviewed: retail-conformance PASS (the stage order verified
step-for-step against retail's entry sequence; the live-controller-on-
abandonment invariant proven structurally enforced and retail-correct —
retail has no entry-flow rollback) + architecture/adversarial PASS after
one fix round (acknowledge-stage authority discrimination; the wiring
fold; two prescribed pre-C3c hardenings). Runtime 948/948; complete
Release solution green across all nine projects.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-08-02 09:43:15 +02:00
parent 874d94bf34
commit 960373df2e
6 changed files with 1816 additions and 29 deletions

View file

@ -4,6 +4,7 @@ using AcDream.Core.Items;
using AcDream.Core.Net;
using AcDream.Core.Net.Messages;
using AcDream.Core.Physics;
using AcDream.Runtime.Gameplay;
using AcDream.Runtime.Physics;
namespace AcDream.Runtime.Entities;
@ -56,7 +57,14 @@ public readonly record struct RuntimeEntityObjectOwnershipSnapshot(
/// SAME underlying receipt stream - unlike ReplayFailureCount above,
/// this is NOT a diagnostic-only counter.
/// </summary>
int PendingCompletionReceiptCount = 0)
int PendingCompletionReceiptCount = 0,
/// <summary>
/// C3a/F2: outstanding <c>AcDream.Runtime.Gameplay.RuntimeLocalPlayerFirstEntryState</c>
/// tracked keys - dormant (no production caller of its own
/// <c>Advance</c>), but fully constructed/wired like every other owner
/// here, so its own ownership must converge to zero the same way.
/// </summary>
int LocalPlayerFirstEntryActiveCount = 0)
{
public bool IsConverged =>
IsDisposed
@ -78,6 +86,7 @@ public readonly record struct RuntimeEntityObjectOwnershipSnapshot(
&& InitialCreateResidenceLeaseCount == 0
&& InitialCreateExecutorProgressCount == 0
&& PendingCompletionReceiptCount == 0
&& LocalPlayerFirstEntryActiveCount == 0
&& StreamSubscriberCount == 0
&& PlacementStreamSubscriberCount == 0
&& PendingDispatchCount == 0
@ -157,6 +166,16 @@ public sealed class RuntimeEntityObjectLifetime : IDisposable
RegisterEntityWithInitialResidence(spawn, isLocalPlayer),
(canonical, version, spawn, replaceGeneration) =>
ApplyAcceptedSpawn(canonical, version, spawn, replaceGeneration));
// C3a/F2: dormant - no production caller of its own Advance - but
// constructed and wired exactly like the executor above so its
// ownership converges the same way. RuntimeLocalPlayerPhysicsPublicationState
// does not exist yet at this point (GameRuntime builds
// RuntimeLocalPlayerMovementState, then attaches its publication,
// only after this lifetime); BindPublication supplies it later.
LocalPlayerFirstEntry = new RuntimeLocalPlayerFirstEntryState(
InitialCreateResidences,
InitialCreateExecution,
Physics);
// Round 3 B3: every residence retirement path - not only the
// executor's own DiscardProgress calls - must converge the
// executor's progress AND its separately-tracked pending
@ -165,6 +184,12 @@ public sealed class RuntimeEntityObjectLifetime : IDisposable
// residence state referencing the executor type directly.
InitialCreateResidences.BindRetirementNotification(
key => InitialCreateExecution.DiscardProgress(key));
// C3a/F2: the SAME multicast retirement notification also reaps the
// first-entry conductor's tracked progress - see
// RuntimeInitialCreateResidenceState.BindRetirementNotification's
// updated doc comment for why this is now multicast.
InitialCreateResidences.BindRetirementNotification(
key => LocalPlayerFirstEntry.Forget(key));
// F2: reaps the executor's completion-receipt correlation entry
// exactly when a host acknowledges the ExecutorCompleted receipt it
// correlates - mirrors the residence-retirement binding immediately
@ -210,6 +235,16 @@ public sealed class RuntimeEntityObjectLifetime : IDisposable
RegisterEntityWithInitialResidence(spawn, isLocalPlayer),
(canonical, version, spawn, replaceGeneration) =>
ApplyAcceptedSpawn(canonical, version, spawn, replaceGeneration));
// C3a/F2: dormant - no production caller of its own Advance - but
// constructed and wired exactly like the executor above so its
// ownership converges the same way. RuntimeLocalPlayerPhysicsPublicationState
// does not exist yet at this point (GameRuntime builds
// RuntimeLocalPlayerMovementState, then attaches its publication,
// only after this lifetime); BindPublication supplies it later.
LocalPlayerFirstEntry = new RuntimeLocalPlayerFirstEntryState(
InitialCreateResidences,
InitialCreateExecution,
Physics);
// Round 3 B3: every residence retirement path - not only the
// executor's own DiscardProgress calls - must converge the
// executor's progress AND its separately-tracked pending
@ -218,6 +253,12 @@ public sealed class RuntimeEntityObjectLifetime : IDisposable
// residence state referencing the executor type directly.
InitialCreateResidences.BindRetirementNotification(
key => InitialCreateExecution.DiscardProgress(key));
// C3a/F2: the SAME multicast retirement notification also reaps the
// first-entry conductor's tracked progress - see
// RuntimeInitialCreateResidenceState.BindRetirementNotification's
// updated doc comment for why this is now multicast.
InitialCreateResidences.BindRetirementNotification(
key => LocalPlayerFirstEntry.Forget(key));
// F2: reaps the executor's completion-receipt correlation entry
// exactly when a host acknowledges the ExecutorCompleted receipt it
// correlates - mirrors the residence-retirement binding immediately
@ -263,6 +304,16 @@ public sealed class RuntimeEntityObjectLifetime : IDisposable
RegisterEntityWithInitialResidence(spawn, isLocalPlayer),
(canonical, version, spawn, replaceGeneration) =>
ApplyAcceptedSpawn(canonical, version, spawn, replaceGeneration));
// C3a/F2: dormant - no production caller of its own Advance - but
// constructed and wired exactly like the executor above so its
// ownership converges the same way. RuntimeLocalPlayerPhysicsPublicationState
// does not exist yet at this point (GameRuntime builds
// RuntimeLocalPlayerMovementState, then attaches its publication,
// only after this lifetime); BindPublication supplies it later.
LocalPlayerFirstEntry = new RuntimeLocalPlayerFirstEntryState(
InitialCreateResidences,
InitialCreateExecution,
Physics);
// Round 3 B3: every residence retirement path - not only the
// executor's own DiscardProgress calls - must converge the
// executor's progress AND its separately-tracked pending
@ -271,6 +322,12 @@ public sealed class RuntimeEntityObjectLifetime : IDisposable
// residence state referencing the executor type directly.
InitialCreateResidences.BindRetirementNotification(
key => InitialCreateExecution.DiscardProgress(key));
// C3a/F2: the SAME multicast retirement notification also reaps the
// first-entry conductor's tracked progress - see
// RuntimeInitialCreateResidenceState.BindRetirementNotification's
// updated doc comment for why this is now multicast.
InitialCreateResidences.BindRetirementNotification(
key => LocalPlayerFirstEntry.Forget(key));
// F2: reaps the executor's completion-receipt correlation entry
// exactly when a host acknowledges the ExecutorCompleted receipt it
// correlates - mirrors the residence-retirement binding immediately
@ -295,6 +352,7 @@ public sealed class RuntimeEntityObjectLifetime : IDisposable
{ get; }
internal RuntimeInitialCreateContinuationExecutor InitialCreateExecution
{ get; }
internal RuntimeLocalPlayerFirstEntryState LocalPlayerFirstEntry { get; }
public RuntimeEntityObjectOwnershipSnapshot CaptureOwnership()
{
@ -330,7 +388,8 @@ public sealed class RuntimeEntityObjectLifetime : IDisposable
parents.DeferredAcceptedRelationCount,
InitialCreateExecution.ReplayFailureCount,
InitialCreateExecution.LastReplayFailure is not null,
InitialCreateExecution.PendingCompletionReceiptCount);
InitialCreateExecution.PendingCompletionReceiptCount,
LocalPlayerFirstEntry.CaptureOwnership().ActiveCount);
}
public void BindEventContext(
@ -1674,6 +1733,7 @@ public sealed class RuntimeEntityObjectLifetime : IDisposable
RuntimeEntityRecord[] active = Entities.ActiveRecords.ToArray();
InitialCreateResidences.Clear();
InitialCreateExecution.DiscardAll();
LocalPlayerFirstEntry.DiscardAll();
Physics.CollisionReports.LeaveWorldBatch(active);
Physics.ResetSessionPhysics();
Entities.BeginSessionClear();

View file

@ -489,7 +489,7 @@ internal sealed class RuntimeInitialCreateResidenceState
private readonly Dictionary<RuntimeEntityKey, Entry> _entries = [];
private readonly Dictionary<RuntimeEntityKey, CompletedEntry> _completed = [];
private Func<RuntimeGenerationToken>? _generation;
private Action<RuntimeEntityKey>? _retirementNotification;
private readonly List<Action<RuntimeEntityKey>> _retirementNotifications = [];
private ulong _nextLeaseId;
internal RuntimeInitialCreateResidenceState(
@ -524,17 +524,36 @@ internal sealed class RuntimeInitialCreateResidenceState
/// leave the executor's progress AND its separately-tracked pending
/// continuation placement token orphaned - this class owns no reference
/// to the executor type, so the lifetime binds a plain delegate here
/// instead.
/// instead. Multicast (ordered invocation list, registration order) so a
/// second independent per-key owner (e.g. the local-player first-entry
/// conductor) can subscribe to the SAME retirements the executor already
/// does, without either overwriting the other's binding.
/// </summary>
internal void BindRetirementNotification(Action<RuntimeEntityKey> notify)
{
ArgumentNullException.ThrowIfNull(notify);
if (_retirementNotification is not null)
{
throw new InvalidOperationException(
"The initial Create residence retirement notification is already bound.");
}
_retirementNotification = notify;
_retirementNotifications.Add(notify);
}
/// <summary>
/// H1: snapshots the subscriber list before invoking anything, mirroring
/// <see cref="RuntimeEntityObjectEventStream"/>'s own copy-on-write
/// dispatch precedent. A subscriber binding a NEW notification from
/// inside a retirement callback it is itself receiving (e.g. a future
/// third, runtime-bound subscriber added at C3c) must not corrupt or be
/// skipped by THIS iteration - <c>_retirementNotifications</c> is a
/// plain <see cref="List{T}"/>, so iterating it directly while
/// <see cref="BindRetirementNotification"/> appends to it mid-loop would
/// throw <see cref="InvalidOperationException"/> ("Collection was
/// modified"). <c>ToArray()</c> is the right granularity here (unlike
/// the event stream's <see cref="Volatile"/>-guarded array swap) because
/// binding only ever happens a handful of times at construction, never
/// on a hot per-frame path.
/// </summary>
private void NotifyRetirement(RuntimeEntityKey key)
{
foreach (Action<RuntimeEntityKey> notify in _retirementNotifications.ToArray())
notify(key);
}
internal bool CanAcceptCreate(WorldSession.EntitySpawn incoming)
@ -1003,7 +1022,7 @@ internal sealed class RuntimeInitialCreateResidenceState
lease = entry.Lease;
cancellation = _setPosition.ForgetExactPlacement(
lease.Placement);
_retirementNotification?.Invoke(key);
NotifyRetirement(key);
return true;
}
if (record.Key is { } completedKey
@ -1016,7 +1035,7 @@ internal sealed class RuntimeInitialCreateResidenceState
lease = completed.Lease;
cancellation = _setPosition.ForgetExactPlacement(
lease.Placement);
_retirementNotification?.Invoke(completedKey);
NotifyRetirement(completedKey);
return true;
}
lease = default;
@ -1052,13 +1071,10 @@ internal sealed class RuntimeInitialCreateResidenceState
{
_setPosition.PublishCancellation(cancellations[index]);
}
if (_retirementNotification is { } notify)
{
foreach (Entry entry in active)
notify(entry.Lease.Token.Entity);
foreach (CompletedEntry entry in completed)
notify(entry.Receipt.Token.Entity);
}
foreach (Entry entry in active)
NotifyRetirement(entry.Lease.Token.Entity);
foreach (CompletedEntry entry in completed)
NotifyRetirement(entry.Receipt.Token.Entity);
}
internal RuntimeInitialCreateResidenceOwnershipSnapshot CaptureOwnership() =>
@ -1245,7 +1261,7 @@ internal sealed class RuntimeInitialCreateResidenceState
RuntimePlacementCancellationReceipt cancellation =
_setPosition.ForgetExactPlacement(entry.Lease.Placement);
_setPosition.PublishCancellation(cancellation);
_retirementNotification?.Invoke(key);
NotifyRetirement(key);
}
private void Retire(CompletedEntry entry)
@ -1255,6 +1271,6 @@ internal sealed class RuntimeInitialCreateResidenceState
RuntimePlacementCancellationReceipt cancellation =
_setPosition.ForgetExactPlacement(entry.Lease.Placement);
_setPosition.PublishCancellation(cancellation);
_retirementNotification?.Invoke(key);
NotifyRetirement(key);
}
}