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

@ -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