fix(runtime): give the no-window host a post-merge canonical cell commit (D1, AD-60/AD-64, AP-146/#320)

C5b (735f0a72) made the steady-state accepted-Position merge stop writing
residency. That is retail-correct — HandleReceivedPosition @0x00453FD0 reads
the wire objcell_id into a local and never assigns the object's cell — and it
stays. What C5b did not account for is that its replacement writers both live
in AcDream.App: the OnPosition prologue rebucket (AD-60's W2) and the
post-routing wire-cell adopt (W3, AP-135).

The two hosts run parallel, non-shared inbound routes. LiveEntitySessionController
-> LiveEntityNetworkUpdateController.OnPosition is graphical-only;
RuntimeLiveEntitySessionController.OnPositionUpdated is the no-window route and
is constructed only at HeadlessSessionHost.cs:682. So AcDream.Headless had NO
post-merge cell writer at all. Every remote's FullCellId was written at
create/placement and then frozen for the session — and RuntimeEntityObjectViews
.Snapshot projects exactly that field as RuntimeEntitySnapshot.CellId, i.e. every
bot's entire world view. The local player lost one of AP-146's three refresh
edges, which matters beyond cosmetics: RuntimeSetPositionState
.IsAffectedCollisionResident reads FullCellId to pick which bodies a landblock
retirement parks, so a bot running A->B without teleporting would have retired A
while parking a body physically in B.

The fix, in three parts:

1. RuntimeEntityObjectLifetime.CommitWireCellRebucket — a new Runtime owner for
   the committed VALUE, extracted verbatim from LiveEntityRuntime
   .RebucketLiveEntity. This is also the root-cause fix for the layering
   inversion the review found: AD-60 was documenting its own correctness by
   naming an App class the Runtime assembly cannot reference. Behaviour on the
   graphical side is unchanged — record.FullCellId is a proxy for
   record.Canonical.FullCellId, which is the record the callee reads, and the
   commit is still CommitRebucket. Verified load-bearing for BOTH hosts:
   sabotaging the preserve branch reddens the graphical
   LiveEntityRuntimeTests.CanonicalOnlyRebucket_DoesNotOverwriteAuthoritativeFullCell
   as well as the new headless assertion.

2. RuntimeLiveEntitySessionController.TryCommitAcceptedWireCell — the no-window
   W2, under the same reachability rules the graphical route applies: Rejected
   writes nothing (the shape the App authority gate produces by returning false);
   a bound-projectile packet writes nothing (routed by the graphical host through
   the canonical projectile placement owner, which returns before W2); an active
   initial-create residence writes nothing (RebucketLiveEntity's own early
   return — while the lease is live the SetPosition conductor is the sole cell
   authority); a local ForcePosition writes only when the accepted-Position drive
   declined it (NotApplicable), because a handled force is
   placement-receipt-authoritative. W2/W3 themselves are untouched.

3. On the committed value (the landblock-vs-cell trap). RebucketLiveEntity's
   preserve branch fires on a LANDBLOCK-shaped id — low 16 bits 0xFFFF — and
   exists for LocalPlayerProjectionController.Project, the per-frame local
   movement caller that emits exactly that shape. An inbound wire objcell_id is
   never landblock-shaped, so on the accepted-Position route the branch is not
   taken and the exact wire cell is committed. That is what W2 commits today and
   what this now commits; the no-window host has no per-frame caller at all.

Ordering is matched, not improved on: the force drive submits its placement
before the commit, so its first submit still reads the pre-commit FullCellId —
AP-138's amended route-2 CurrentCellId measurement.

Bookkeeping in this commit:
- AD-60 corrected. Its surviving-channel enumeration presented "the local force
  path, the missile arm" as exhaustive; the entire no-window host belonged in it.
  23aa62f2's W2/W3-redundancy measurement is preserved verbatim.
- AP-146 and #320 amended the same way — their three-edge list was written from
  the graphical host and silently assumed both hosts shared it. The no-window
  host had two of three; it now has all three.
- AD-64 filed: the reachability decision is now expressed once per host. The
  value is single-sourced; the gate set is not.
- #324 filed: unifying the two session controllers is the genuinely correct fix
  and is campaign-sized (presentation recovery, hydration, the equipped-child
  renderer, and the remote/projectile routing arms only one host has). Not
  attempted here, per the fix brief.

Gates. Release build 0 errors. Complete suite 11,141 passed / 4 skipped /
0 failed, against the 11,134 / 4 / 0 baseline at 23aa62f2 — net +7, exactly the
7 tests added. Eight sabotages verified, each red on at least one discriminating
test and green when reverted: remote commit removed (2 Runtime + the end-to-end
Headless test); local ordinary commit removed; local NotApplicable-force commit
removed; force commit made unconditional; residence gate removed; missile gate
removed; Rejected gate removed; preserve branch broken (red on both hosts).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-08-05 22:36:31 +02:00
parent 23aa62f292
commit ff100cf33f
8 changed files with 746 additions and 22 deletions

View file

@ -24,6 +24,68 @@ What does NOT go here:
- Every session: scan OPEN issues at start; promote/close anything we touched during the session before ending.
- Promoting to a Phase: mark as `DONE (promoted to Phase X)` + commit SHA where the Phase entry landed.
## #324 — The graphical and no-window hosts run parallel, non-shared inbound entity routes
**Status:** OPEN
**Severity:** MEDIUM (no live symptom today; it is the structure that PRODUCED
D1, and it will produce the next one)
**Filed:** 2026-08-05, in the C5b architecture-review D1 fix commit, per that
fix's brief ("if the correct answer is to unify the two session controllers,
say so and file it rather than attempting it here")
**Component:** runtime / session routing / host structure
**Description.** Two inbound entity routes exist and neither is derived from
the other:
- graphical: `src/AcDream.App/Net/LiveEntitySessionController.cs`
`LiveEntityNetworkUpdateController.OnPosition` (and siblings)
- no-window: `src/AcDream.Runtime/Session/RuntimeLiveEntitySessionController.cs`
(`OnPositionUpdated` and siblings), constructed only at
`src/AcDream.Headless/Hosting/HeadlessSessionHost.cs:682`
They share the canonical Runtime owners underneath (Slice J's whole point) but
NOT the routing decisions on top: which packet shapes reach which owner, in
what order, under what gates. Every canonical rule expressed in the graphical
route's control flow has to be re-derived by hand for the other, and nothing
enforces that it was.
**Why this is filed as its own issue rather than fixed inline.** This is the
structural cause of defect D1 from the C5b architecture review (both reviewers
found it independently). C5b made the steady-state Position merge stop writing
residency — retail-correct — and moved the write to the `OnPosition`
prologue rebucket. That rebucket is graphical-only, so the no-window host
silently lost canonical cell tracking for every entity: remotes froze at their
placement cell for the whole session, and the local player lost one of
AP-146's three refresh edges. Nothing failed; the host just stopped being
right. The D1 fix gives the no-window route its own commit over a shared
Runtime value owner and files the residual duplication at AD-64 — it does not
remove the class.
**What unification has to reconcile (why it is campaign-sized, not a slice):**
1. The graphical route performs presentation recovery the no-window route has
no analogue for (`RequiresSpatialProjectionRecovery`, the equipped-child
`ChildUnparentDisposition` arm, `LiveEntityHydrationController`).
2. The graphical route performs remote contact routing, far-snap/teleport
placement arms, and projectile routing; the no-window route performs none
of them and returns early for `!isLocal`. Unifying means deciding whether
the no-window host GAINS those arms (a behaviour change with its own gate)
or whether the shared route is parameterized over them.
3. Ordering constraints are load-bearing and already documented as
measurements, not intentions — AP-138's route-2 first-submit
`CurrentCellId` observation depends on the force drive submitting BEFORE
the wire-cell commit, and AD-60/AP-147 on the merge publishing before the
rebucket. A unified route must preserve each, per host.
4. `LiveEntityRuntime`'s spatial/presentation half and its canonical half are
currently interleaved in one method (`RebucketLiveEntity`); the D1 fix
split out the canonical value derivation, but the residence gate, the
object-clock enter-world rebase, and the visibility publication are still
entangled with the bucket move.
**Acceptance:** one route object owns the inbound decision set for both hosts,
with presentation and routing supplied as collaborators; AD-64 is deleted in
the same commit; the eight D1 sabotages still discriminate.
## #320 — The local player's canonical cell does not track ordinary movement (follow-up from #319)
**Status:** OPEN
@ -61,6 +123,33 @@ survey: a local **ForcePosition** returns before that tail, so its residency
is now placement-receipt-authoritative — a refused or contended force writes
no cell at all (retail's own shape; AD-62).
**Corrected 2026-08-05 by the C5b architecture review's D1 fix.** The
three-edge enumeration above was written from the graphical host and silently
assumed both hosts shared it. They do not. `AcDream.App` and
`AcDream.Headless` run parallel, non-shared inbound routes
(`LiveEntitySessionController``LiveEntityNetworkUpdateController.OnPosition`
versus `RuntimeLiveEntitySessionController.OnPositionUpdated`), and C5b's
replacement writer lived only in the former — so the no-window host had only
TWO of the three edges, login activation and the teleport/portal commit, and
its remotes' cells were frozen from placement onward as well. That is fixed:
`RuntimeLiveEntitySessionController.TryCommitAcceptedWireCell` now commits the
same value through a shared Runtime owner,
`RuntimeEntityObjectLifetime.CommitWireCellRebucket`, which is also where the
landblock-preserve branch this issue's item 1 is about now lives (it moved
verbatim out of `LiveEntityRuntime.cs:935-938`; update that citation when
reading item 1). The reachability duplication the fix leaves behind is filed
at AD-64, and controller unification at #324.
**What this changes for item 6, the unresolved first verification step.** It
does not answer it, but it removes a strictly-worse case that was hiding
underneath it: before the fix, a no-window bot lacked the inbound-Position
edge entirely, so a bot running A→B without ever teleporting kept
`FullCellId` at A for the whole session — retiring A would park a body that
is physically in B, and retiring B would miss it. Both hosts now refresh at
ACE's 5-10 Hz Position cadence. The question item 6 actually asks — whether a
stale-cell landblock retirement can sweep a spatial-root local player — is
unchanged and still open.
**Why this is not #319's blast radius.** #319's fix makes a player-parented
equipped child inherit the parent's (the player's) canonical cell EXACTLY —
an equality invariant, not a freshness one. The child is stale-but-equal

File diff suppressed because one or more lines are too long

View file

@ -932,17 +932,21 @@ public sealed class LiveEntityRuntime : ILiveEntityRadarSource
bool visible = _spatial.IsLiveEntityProjectionResident(key);
record.IsSpatiallyVisible = visible;
RefreshPresentation(record);
uint committedFullCell =
(spatialCellOrLandblockId & 0xFFFFu) != 0xFFFFu
? spatialCellOrLandblockId
: record.FullCellId;
uint committedLandblock = spatialCellOrLandblockId == 0
? 0u
: (spatialCellOrLandblockId & 0xFFFF0000u) | 0xFFFFu;
if (!_entityObjects.CommitRebucket(
// D1 (C5b architecture review): the committed-value derivation that
// used to be inline here — the landblock-shaped-id preserve branch
// and the canonical-landblock mask — moved VERBATIM into
// RuntimeEntityObjectLifetime.CommitWireCellRebucket so the
// no-window host can commit the same value from its own route
// instead of having no post-merge cell writer at all. Behaviour is
// unchanged: `record.FullCellId` is a proxy for
// `record.Canonical.FullCellId` (see this class's own property),
// which is the record the callee reads, and the commit itself is
// still CommitRebucket. AP-146/#320's "LiveEntityRuntime.cs:935-938
// preserves the prior canonical cell" citation now resolves to that
// method.
if (!_entityObjects.CommitWireCellRebucket(
record.Canonical,
committedFullCell,
committedLandblock))
spatialCellOrLandblockId))
{
ThrowAfterCommittedProjectionChange(
serverGuid,

View file

@ -1943,15 +1943,28 @@ public sealed class RuntimeEntityObjectLifetime : IDisposable
// The snapshot's Position field itself IS still refreshed; only the
// derived FullCellId write is withheld.
//
// Two wire-cell writers deliberately SURVIVE this change, downstream
// of the merge and outside the classification window: the OnPosition
// prologue rebucket (LiveEntityNetworkUpdateController ->
// LiveEntityRuntime.RebucketLiveEntity -> CommitRebucket, which is
// also the local player's own cell-freshness path, AP-146/#320) and
// the post-routing wire-cell adopt for non-placing arms
// (TryAdoptWireCellAfterRouting, filed at AP-135). Neither is gated
// here: gating the prologue rebucket would freeze the local player's
// Wire-cell writers deliberately SURVIVE this change, downstream of
// the merge and outside the classification window. The canonical one
// is CommitWireCellRebucket, in this class: BOTH inbound routes call
// it after the merge, and it is also the local player's own
// cell-freshness path (AP-146/#320). Neither route gates it here:
// gating the prologue rebucket would freeze the local player's
// canonical cell between teleports.
//
// CORRECTED 2026-08-05 at the C5b architecture review (D1). This
// comment used to enumerate the survivors as two App classes —
// LiveEntityNetworkUpdateController -> LiveEntityRuntime and
// TryAdoptWireCellAfterRouting (AP-135) — which was both a layering
// inversion (a Runtime file documenting its own correctness by
// naming classes this assembly cannot reference) and, worse, WRONG:
// it described the graphical host as though it were the only host.
// The no-window route (RuntimeLiveEntitySessionController) had
// neither writer, so it had no post-merge cell writer at all and
// every entity's FullCellId froze at its placement value for the
// session. The graphical route's post-routing adopt still exists and
// is still filed at AP-135; the no-window route has no remote
// contact routing and therefore no analogue of it. AD-60 and AD-64
// carry the complete channel list.
Entities.RefreshSnapshot(
canonical,
snapshot,
@ -2028,6 +2041,72 @@ public sealed class RuntimeEntityObjectLifetime : IDisposable
() => canonical.SpatialAuthorityVersion == spatialVersion);
}
/// <summary>
/// D1 (C5b architecture review): the CANONICAL half of the wire-cell
/// rebucket (AD-60's W2), expressed once, in Runtime, for every host.
///
/// <para>
/// <b>Why this exists.</b> C5b made the steady-state merge stop writing
/// residency (<c>RefreshSnapshot(..., refreshPosition: false)</c> in
/// <see cref="TryApplyPosition"/>) and left the graphical
/// <c>OnPosition</c> prologue rebucket
/// (<c>LiveEntityNetworkUpdateController</c> →
/// <c>LiveEntityRuntime.RebucketLiveEntity</c>) as the replacement
/// writer. That writer lives in <c>AcDream.App</c>, so the no-window
/// host had NO post-merge cell writer at all: a headless remote's
/// <see cref="RuntimeEntityRecord.FullCellId"/> was written at
/// create/placement and then frozen for the session, and the local
/// player lost one of AP-146's three refresh edges. The derivation was
/// also the reason AD-60 documented itself by naming an App class this
/// assembly cannot reference — a layering inversion. Both are fixed by
/// owning the rule here and letting each host's route call it.
/// </para>
///
/// <para>
/// <b>The landblock-vs-cell rule (verbatim from the graphical site it
/// was extracted from).</b> <paramref name="spatialCellOrLandblockId"/>
/// is overloaded. A LANDBLOCK-shaped id — low 16 bits <c>0xFFFF</c>,
/// which is what <c>LocalPlayerProjectionController.Project</c> emits
/// for ordinary per-frame movement — deliberately PRESERVES the exact
/// cell and updates only the canonical landblock; writing the coarser
/// value would destroy a resolved EnvCell. Any other id is an exact
/// cell and is committed as-is. An inbound wire <c>objcell_id</c> is
/// always cell-shaped (ACE never sends <c>0xFFFF</c> in the low half),
/// so on the accepted-Position route this always commits the exact wire
/// cell — the preserve branch is there for the per-frame local caller,
/// which no-window hosts do not have. <c>0</c> is passed through
/// unchanged (cell 0 + landblock 0), the withdrawal shape.
/// </para>
///
/// <para>
/// This method deliberately carries NO gates. Which packets may reach a
/// wire-cell commit is the caller's decision and differs per host route
/// (the graphical route returns ahead of it for the local force arm,
/// the missile arm, and an active initial-create residence); duplicating
/// those tests here would double-gate one host and silently widen the
/// other.
/// </para>
/// </summary>
public bool CommitWireCellRebucket(
RuntimeEntityRecord canonical,
uint spatialCellOrLandblockId,
Action<RuntimeEntityRecord>? acknowledgeProjection = null)
{
ArgumentNullException.ThrowIfNull(canonical);
uint committedFullCell =
(spatialCellOrLandblockId & 0xFFFFu) != 0xFFFFu
? spatialCellOrLandblockId
: canonical.FullCellId;
uint committedLandblock = spatialCellOrLandblockId == 0
? 0u
: (spatialCellOrLandblockId & 0xFFFF0000u) | 0xFFFFu;
return CommitRebucket(
canonical,
committedFullCell,
committedLandblock,
acknowledgeProjection);
}
public bool CommitWithdrawal(
RuntimeEntityRecord canonical,
Action<RuntimeEntityRecord>? acknowledgeProjection = null)

View file

@ -237,9 +237,26 @@ public sealed class RuntimeLiveEntitySessionController
out _,
out AcceptedPhysicsTimestamps timestamps);
if (!known
|| !isLocal
|| disposition is PositionTimestampDisposition.Rejected)
{
// Rejected writes nothing anywhere — the same shape the
// graphical authority gate produces by returning false from
// LiveEntityInboundAuthorityGate.TryAcceptPosition, which is
// ahead of every wire-cell writer.
return;
}
if (!isLocal)
{
// D1 (C5b architecture review): the no-window host's half of
// AD-60's W2. The graphical route commits the accepted wire
// cell for EVERY classification that reaches its generic tail,
// remotes included; this route used to return here, so a
// headless remote's FullCellId was written once at
// create/placement and then frozen for the whole session —
// and RuntimeEntityObjectViews.Snapshot feeds exactly that
// field to every bot's RuntimeEntitySnapshot.CellId.
TryCommitAcceptedWireCell(update);
return;
}
@ -307,6 +324,20 @@ public sealed class RuntimeLiveEntitySessionController
// fallback this disposition always had — it must still
// run, exactly as every other disposition's fallback
// does below.
//
// D1: ... and so does the wire-cell commit. A force the
// drive HANDLED (Committed/DeferredCell) is
// placement-receipt-authoritative for residency, and a
// Rejected/Contention force leaves the last committed
// cell alone (AD-62's shapes) — both are exactly why
// the graphical route returns ahead of W2 on every
// status except NotApplicable. Ordering matters as well
// as reachability: the drive submits its placement
// BEFORE this point, so its first submit reads the
// pre-commit FullCellId, which is the source landblock
// — AP-138's amended route-2 measurement, matched here
// rather than accidentally improved on.
TryCommitAcceptedWireCell(update);
_worldProjection?.ProjectPosition(
record,
isLocalPlayer: true,
@ -315,6 +346,7 @@ public sealed class RuntimeLiveEntitySessionController
}
else
{
TryCommitAcceptedWireCell(update);
_worldProjection?.ProjectPosition(
record,
isLocalPlayer: true,
@ -324,6 +356,63 @@ public sealed class RuntimeLiveEntitySessionController
TryCompletePortal();
}
/// <summary>
/// D1 (C5b architecture review): commits the accepted wire cell to
/// canonical residency for a no-window host, under the same
/// reachability rules the graphical <c>OnPosition</c> route applies to
/// AD-60's W2. The committed VALUE is
/// <see cref="RuntimeEntityObjectLifetime.CommitWireCellRebucket"/>'s —
/// one rule, shared by both hosts, including its landblock-vs-cell
/// branch.
///
/// <para>
/// Two gates mirror callers the graphical route has and this one does
/// not. <b>The initial-create residence</b> is
/// <c>LiveEntityRuntime.RebucketLiveEntity</c>'s own early return
/// (<c>MaterializationResidence is AwaitRuntimePlacement &amp;&amp;
/// HasActiveInitialCreateResidence</c>): while the lease is live,
/// Runtime's <c>SetPosition</c> conductor is the sole cell authority.
/// Only the residence half is tested here, because it IS the whole
/// test on this side — the App enum's <c>AwaitRuntimePlacement</c> value
/// exists to mark records that took the residence route, which is every
/// record a projection-backed direct host registers, and a content-less
/// direct host opens no lease at all
/// (<see cref="OnSpawned"/>). <b>A missile packet</b> is routed by the
/// graphical host through the canonical projectile placement owner and
/// returns before W2; the predicate below is the exact conjunction that
/// route's own null-classification arm uses
/// (<c>LiveEntityNetworkUpdateController.OnPosition</c>, the
/// <c>isMissilePacket</c> ternary), which its D-P1 comment records as
/// equivalent to the classifier's <c>ProjectileAuthoritative</c>
/// operation kind. Committing a wire cell for a projectile here would
/// invent residency a placement route owns.
/// </para>
/// </summary>
private void TryCommitAcceptedWireCell(
WorldSession.EntityPositionUpdate update)
{
if (!Entities.Entities.TryGetActive(
update.Guid,
out RuntimeEntityRecord canonical)
|| Entities.TryGetInitialCreateResidence(canonical, out _)
|| IsMissilePacket(canonical, update.Guid))
{
return;
}
_ = Entities.CommitWireCellRebucket(
canonical,
update.Position.LandblockId);
}
private bool IsMissilePacket(
RuntimeEntityRecord canonical,
uint guid) =>
guid != _runtime.PlayerIdentity.ServerGuid
&& (canonical.FinalPhysicsState & PhysicsStateFlags.Missile) != 0
&& canonical.Projectile is { } projectile
&& ReferenceEquals(canonical.PhysicsBody, projectile.Body);
private void OnVectorUpdated(VectorUpdate.Parsed update) =>
_ = Entities.TryApplyVector(
update,

View file

@ -1936,6 +1936,125 @@ public sealed class HeadlessSessionHostTests
}
}
/// <summary>
/// D1 (C5b architecture review), the local-player FORCE arm — both
/// directions of the reachability rule, driven through the real
/// <see cref="RuntimeLiveEntitySessionController"/> sink.
///
/// <para>
/// The graphical <c>OnPosition</c> route returns ahead of AD-60's W2
/// for every force status EXCEPT <c>NotApplicable</c>, and falls
/// through to it on that one. So: a force the drive HANDLED
/// (<c>Committed</c> here) is placement-receipt-authoritative and this
/// route must leave residency at the cell the placement RESOLVED, not
/// re-stamp the wire cell over it; a force the drive did NOT handle
/// (no drive at all — the login-window / route-1 shape) must still
/// refresh the cell, because nothing else will.
/// </para>
/// </summary>
[Theory]
[InlineData(true)]
[InlineData(false)]
public void LocalForcePosition_CommitsTheWireCellOnlyWhenTheDriveDeclined(
bool driveHandlesIt)
{
var operations = new FixtureSessionOperations();
using var credential = new HeadlessCredentialSecret(
"fixture",
"password");
using var host = new HeadlessSessionHost(
Descriptor(),
credential,
new HeadlessDiagnosticWriter(TextWriter.Null),
operations);
GameRuntime runtime = host.Runtime;
Assert.Equal(
RuntimeSessionStartStatus.Connected,
host.Start().Status);
const uint player = 0x50000004u;
runtime.PlayerIdentity.ServerGuid = player;
runtime.EntityObjects.Physics.SetPosition.BeginCollisionGeneration(
0xA9B40000u, 1UL);
AddFlatLandblock(runtime.EntityObjects.Physics.Engine);
runtime.EntityObjects.Physics.SetPosition.CommitCollisionGeneration(
0xA9B40000u, 1UL, ready: true);
RuntimeFirstEntryDriveController firstEntry =
CreateFirstEntryDrive(runtime);
RuntimeEntityRecord record = runtime.EntityObjects
.RegisterEntityWithInitialResidence(
Spawn(player),
isLocalPlayer: true)
.Canonical!;
Assert.True(runtime.EntityObjects.ApplyAcceptedSpawn(
record,
record.CreateIntegrationVersion,
record.Snapshot,
replaceGeneration: false));
var collision = new FixtureCollisionNeighborhood();
var projection = new HeadlessSessionWorldProjection(
runtime,
collision,
firstEntry);
projection.ProjectSpawn(record, isLocalPlayer: true);
PlayerMovementController controller =
Assert.IsType<PlayerMovementController>(
runtime.MovementOwner.Controller);
controller.SeedPlacementForTest(
new Vector3(48f, 49f, 50f),
0xA9B40001u,
new Vector3(48f, 49f, 50f));
// The residence must be closed before the ordinary post-residence
// rules apply at all (the conductor is the sole cell authority
// while it is open — asserted separately in the Runtime suite).
Assert.False(runtime.EntityObjects.TryGetInitialCreateResidence(
record,
out _));
using var session = new WorldSession(
new IPEndPoint(IPAddress.Loopback, 9000));
var entities = new RuntimeLiveEntitySessionController(
runtime,
session,
log: null,
projection,
driveHandlesIt ? CreateAcceptedPositionDrive(runtime) : null);
LiveEntitySessionSink sink = entities.CreateSink();
// A wire cell that is NOT the cell a placement at (72,73) resolves
// to, so "committed the wire cell" and "kept the placement's own
// resolved cell" are distinguishable values rather than the same
// number arrived at two ways.
const uint wireCell = 0xA9B40002u;
sink.PositionUpdated(new WorldSession.EntityPositionUpdate(
player,
new CreateObject.ServerPosition(
wireCell, 72f, 73f, 50f, 1f, 0f, 0f, 0f),
Velocity: null,
PlacementId: null,
IsGrounded: true,
InstanceSequence: 1,
PositionSequence: 2,
TeleportSequence: 0,
ForcePositionSequence: 1));
if (driveHandlesIt)
{
// The placement committed and resolved its OWN cell — measured
// 0xA9B4001C, the outdoor landcell that actually contains
// (72, 73) in this flat landblock, which is neither the wire
// cell nor the spawn cell. This route added nothing on top of
// it.
Assert.Equal(new Vector3(72f, 73f, 50.005f), controller.Position);
Assert.Equal(0xA9B4001Cu, record.FullCellId);
Assert.NotEqual(wireCell, record.FullCellId);
}
else
{
Assert.Equal(wireCell, record.FullCellId);
Assert.Equal(0xA9B4FFFFu, record.CanonicalLandblockId);
}
}
private static void AddFlatLandblock(PhysicsEngine engine)
{
var heights = new byte[81];

View file

@ -351,6 +351,65 @@ public sealed class HeadlessSessionIsolationTests
host.Runtime.CaptureOwnership().IsConverged));
}
/// <summary>
/// D1 (C5b architecture review), end to end through a real
/// <see cref="HeadlessSessionHost"/>: a bot's view of a remote must
/// track the server, not freeze at the cell the remote was created in.
///
/// <para>
/// C5b made the steady-state accepted-Position merge stop writing
/// residency and left the replacement writers (AD-60's W2/W3) in
/// <c>AcDream.App</c>. This host has neither, so before the fix
/// <c>RuntimeEntityRecord.FullCellId</c> — the field
/// <c>RuntimeEntityObjectViews.Snapshot</c> projects as
/// <c>RuntimeEntitySnapshot.CellId</c>, i.e. every bot's world view —
/// was written once at create and then never again for the life of the
/// session, however far the server said the remote walked.
/// </para>
/// </summary>
[Fact]
public void RemoteSteadyStatePositionAdvancesTheBotVisibleCell()
{
const uint playerGuid = 0x50000001u;
const uint remoteGuid = 0x70000031u;
var operations = new FixtureOperations(playerGuid);
using HeadlessSessionHost host = CreateHost(0, operations);
Assert.Equal(
RuntimeSessionStartStatus.Connected,
host.Start().Status);
WorldSession session = operations.ActiveSession(host.SessionId);
session.GameActionCapture = _ => { };
SpawnInto(session, remoteGuid, 1f);
Assert.True(host.Runtime.Entities.TryGet(
remoteGuid,
out RuntimeEntitySnapshot created));
Assert.Equal(0x01010001u, created.CellId);
// An ordinary broadcast Position: no teleport channel, no force
// channel — the exact packet shape C5b stopped committing.
const uint movedCell = 0x01010025u;
EventDelegate<Action<WorldSession.EntityPositionUpdate>>(
session,
nameof(session.PositionUpdated))(
new WorldSession.EntityPositionUpdate(
remoteGuid,
Position(2f) with { LandblockId = movedCell },
Velocity: null,
PlacementId: null,
IsGrounded: true,
InstanceSequence: 1,
PositionSequence: 2,
TeleportSequence: 0,
ForcePositionSequence: 0));
Assert.True(host.Runtime.Entities.TryGet(
remoteGuid,
out RuntimeEntitySnapshot moved));
Assert.Equal(movedCell, moved.CellId);
Assert.Equal(movedCell, moved.Position!.Value.ObjCellId);
}
private static HeadlessSessionHost CreateHost(
int index,
FixtureOperations operations,

View file

@ -493,6 +493,290 @@ public sealed class RuntimeLiveEntitySessionControllerTests
drive.DetachRoute(route);
}
/// <summary>
/// D1 (C5b architecture review) — THE discriminating test for the
/// no-window host's missing post-merge cell writer. C5b made the
/// steady-state merge withhold the wire cell and left the replacement
/// writers (AD-60's W2/W3) in <c>AcDream.App</c>, which this route does
/// not have and cannot reach. Before the fix a headless remote's
/// <c>FullCellId</c> was written at create/placement and then frozen for
/// the whole session, no matter how far the server said it walked, and
/// <c>RuntimeEntityObjectViews.Snapshot</c> feeds exactly that field to
/// every bot's <c>RuntimeEntitySnapshot.CellId</c>.
/// </summary>
[Fact]
public void AcceptedRemotePosition_AdvancesCanonicalResidencyInANoWindowHost()
{
using StartedRuntime started = StartRuntime();
GameRuntime runtime = started.Runtime;
CommitLandblockCollision(runtime, 0x01010000u);
RuntimeFirstEntryDriveController drive = CreateDrive(runtime);
using var session = new WorldSession(
new IPEndPoint(IPAddress.Loopback, 9000),
new FixtureTransport());
var controller = new RuntimeLiveEntitySessionController(
runtime,
session,
worldProjection: new FixtureWorldProjection());
LiveEntitySessionSink sink = controller.CreateSink();
WorldSession.EntitySpawn spawn =
SpawnAt(0x70000020u, incarnation: 1, 0x01010001u);
sink.Spawned(spawn);
DrainFirstEntry(runtime, drive);
Assert.True(runtime.EntityObjects.Entities.TryGetActive(
spawn.Guid,
out RuntimeEntityRecord remote));
uint placedCell = remote.FullCellId;
Assert.NotEqual(0u, placedCell);
// A steady-state Position that crosses into another cell of the SAME
// landblock — no teleport channel, no force channel, so this is the
// ordinary accepted-Position merge, the exact packet shape C5b
// stopped writing residency for.
const uint movedCell = 0x01010013u;
Assert.NotEqual(movedCell, placedCell);
sink.PositionUpdated(PositionUpdate(
spawn.Guid,
movedCell,
positionX: 40f,
positionSequence: 2));
Assert.Equal(movedCell, remote.FullCellId);
Assert.Equal(0x0101FFFFu, remote.CanonicalLandblockId);
// The bot-visible projection, which is the observable this defect
// actually broke.
Assert.True(runtime.Entities.TryGet(
spawn.Guid,
out RuntimeEntitySnapshot view));
Assert.Equal(movedCell, view.CellId);
}
/// <summary>
/// D1's local-player half. AP-146 enumerates three edges that refresh
/// the local player's canonical cell; C5b moved the inbound-Position
/// one out of the merge and into an App-only writer, so a no-window
/// host lost it entirely. The consequence is not cosmetic:
/// <c>RuntimeSetPositionState.IsAffectedCollisionResident</c> reads
/// <c>FullCellId</c> to decide which bodies a landblock retirement
/// parks, so a bot that runs A-&gt;B without teleporting would have
/// retired A while parking a body that is physically in B.
/// </summary>
[Fact]
public void AcceptedLocalPlayerPosition_AdvancesCanonicalResidencyInANoWindowHost()
{
using StartedRuntime started = StartRuntime();
GameRuntime runtime = started.Runtime;
const uint playerGuid = 0x50000020u;
runtime.PlayerIdentity.ServerGuid = playerGuid;
CommitLandblockCollision(runtime, 0x01010000u);
RuntimeFirstEntryDriveController drive = CreateDrive(runtime);
using var session = new WorldSession(
new IPEndPoint(IPAddress.Loopback, 9000),
new FixtureTransport());
var controller = new RuntimeLiveEntitySessionController(
runtime,
session,
worldProjection: new FixtureWorldProjection());
LiveEntitySessionSink sink = controller.CreateSink();
sink.Spawned(SpawnAt(playerGuid, incarnation: 1, 0x01010001u));
DrainFirstEntry(runtime, drive);
Assert.True(runtime.EntityObjects.Entities.TryGetActive(
playerGuid,
out RuntimeEntityRecord player));
uint placedCell = player.FullCellId;
Assert.NotEqual(0u, placedCell);
const uint movedCell = 0x01010021u;
Assert.NotEqual(movedCell, placedCell);
sink.PositionUpdated(PositionUpdate(
playerGuid,
movedCell,
positionX: 55f,
positionSequence: 2));
Assert.Equal(movedCell, player.FullCellId);
Assert.Equal(0x0101FFFFu, player.CanonicalLandblockId);
}
/// <summary>
/// D1's negative half, stated as three separate rules rather than one
/// aggregate assertion.
///
/// <para>
/// (a) A <c>Rejected</c> disposition writes NOTHING — the shape the
/// graphical route gets for free by returning false from
/// <c>LiveEntityInboundAuthorityGate.TryAcceptPosition</c> ahead of
/// every wire-cell writer. (b) An active initial-create residence
/// suppresses the commit, mirroring
/// <c>LiveEntityRuntime.RebucketLiveEntity</c>'s own early return:
/// while the lease is live, Runtime's SetPosition conductor is the sole
/// cell authority and a wire cell must not pre-empt it. (c) A
/// LANDBLOCK-shaped id preserves the exact cell instead of coarsening
/// it — the rule fact 4 of this fix's brief warned about, asserted
/// directly against the shared derivation.
/// </para>
/// </summary>
[Fact]
public void WireCellCommit_HonoursRejection_Residence_AndTheLandblockPreserveRule()
{
using StartedRuntime started = StartRuntime();
GameRuntime runtime = started.Runtime;
CommitLandblockCollision(runtime, 0x01010000u);
RuntimeFirstEntryDriveController drive = CreateDrive(runtime);
using var session = new WorldSession(
new IPEndPoint(IPAddress.Loopback, 9000),
new FixtureTransport());
var controller = new RuntimeLiveEntitySessionController(
runtime,
session,
worldProjection: new FixtureWorldProjection());
LiveEntitySessionSink sink = controller.CreateSink();
WorldSession.EntitySpawn spawn =
SpawnAt(0x70000021u, incarnation: 1, 0x01010001u);
// (b) The residence is open between Spawned and the drive's drain.
sink.Spawned(spawn);
Assert.True(runtime.EntityObjects.Entities.TryGetActive(
spawn.Guid,
out RuntimeEntityRecord remote));
Assert.True(runtime.EntityObjects.TryGetInitialCreateResidence(
remote,
out _));
uint duringResidence = remote.FullCellId;
sink.PositionUpdated(PositionUpdate(
spawn.Guid,
0x01010031u,
positionX: 12f,
positionSequence: 2));
Assert.Equal(duringResidence, remote.FullCellId);
DrainFirstEntry(runtime, drive);
uint placedCell = remote.FullCellId;
Assert.NotEqual(0u, placedCell);
// (a) A stale position sequence is Rejected by the timestamp gate.
sink.PositionUpdated(PositionUpdate(
spawn.Guid,
0x01010041u,
positionX: 13f,
positionSequence: 1));
Assert.Equal(placedCell, remote.FullCellId);
// (c) The landblock-shaped id preserves the exact cell.
Assert.True(runtime.EntityObjects.CommitWireCellRebucket(
remote,
0x0202FFFFu));
Assert.Equal(placedCell, remote.FullCellId);
Assert.Equal(0x0202FFFFu, remote.CanonicalLandblockId);
}
/// <summary>
/// D1's missile gate. The graphical route sends a BOUND projectile's
/// accepted Position to the canonical projectile placement owner and
/// returns before AD-60's W2, so no wire cell is committed for it; the
/// no-window route must not invent one. An UNBOUND Missile-flagged
/// record takes the ordinary remote tail in both hosts — the same
/// distinction <see cref="Entities.RuntimeProjectilePositionKindTests"/>
/// pins on the classifier, asserted here on the residency write.
/// </summary>
[Fact]
public void BoundProjectilePosition_CommitsNoWireCell_UnboundMissileDoes()
{
using StartedRuntime started = StartRuntime();
GameRuntime runtime = started.Runtime;
using var session = new WorldSession(
new IPEndPoint(IPAddress.Loopback, 9000),
new FixtureTransport());
// Content-less direct host: legacy registration, no residence lease,
// so the packet reaches the wire-cell decision with nothing else in
// the way.
var controller = new RuntimeLiveEntitySessionController(
runtime,
session);
LiveEntitySessionSink sink = controller.CreateSink();
const uint boundGuid = 0x70000041u;
const uint unboundGuid = 0x70000042u;
sink.Spawned(SpawnAt(boundGuid, incarnation: 1, 0x01010001u));
sink.Spawned(SpawnAt(unboundGuid, incarnation: 1, 0x01010001u));
Assert.True(runtime.EntityObjects.Entities.TryGetActive(
boundGuid,
out RuntimeEntityRecord bound));
Assert.True(runtime.EntityObjects.Entities.TryGetActive(
unboundGuid,
out RuntimeEntityRecord unbound));
foreach (RuntimeEntityRecord missile in new[] { bound, unbound })
{
runtime.EntityObjects.Entities.SetFinalPhysicsState(
missile,
missile.FinalPhysicsState | PhysicsStateFlags.Missile);
}
var body = new PhysicsBody
{
Position = new System.Numerics.Vector3(10f, 10f, 5f),
Orientation = System.Numerics.Quaternion.Identity,
LastUpdateTime = 1d,
State = bound.FinalPhysicsState,
TransientState = TransientStateFlags.Active,
};
body.SnapToCell(0x01010001u, body.Position, body.Position);
runtime.EntityObjects.Entities.SetPhysicsBody(bound, body);
runtime.EntityObjects.Physics.BindProjectile(
bound,
body,
new ProjectileCollisionSphere(
System.Numerics.Vector3.Zero,
0.1f,
1f));
Assert.NotNull(bound.Projectile);
Assert.Null(unbound.Projectile);
const uint movedCell = 0x01010051u;
sink.PositionUpdated(PositionUpdate(
boundGuid,
movedCell,
positionX: 30f,
positionSequence: 2));
sink.PositionUpdated(PositionUpdate(
unboundGuid,
movedCell,
positionX: 30f,
positionSequence: 2));
Assert.Equal(0x01010001u, bound.FullCellId);
Assert.Equal(movedCell, unbound.FullCellId);
}
private static WorldSession.EntityPositionUpdate PositionUpdate(
uint guid,
uint cellId,
float positionX,
ushort positionSequence) =>
new(
guid,
new CreateObject.ServerPosition(
cellId,
positionX,
10f,
5f,
1f,
0f,
0f,
0f),
Velocity: null,
PlacementId: null,
IsGrounded: true,
InstanceSequence: 1,
PositionSequence: positionSequence,
TeleportSequence: 0,
ForcePositionSequence: 0);
/// <summary>
/// C3c: initial-residence admission requires a live session generation
/// (RuntimeInitialCreateResidenceState.CanAcceptCreate), so these direct