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

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