fix(physics): C4 route 7 — child cell propagation moves from a render tick into Runtime

Retail re-cells children when their parent crosses a cell, recursively, to
unbounded depth. acdream did it from a RENDER tick, so headless parented
children were cell-less forever and the canonical cell had two writers. This
slice makes Runtime the sole authority and demotes App's tick to
presentation-only. Contract:
docs/research/2026-08-04-c4-route-7-contract.md; the research that unblocked
it is docs/research/2026-08-04-retail-parent-cell-propagation.md (ca96ea5e).

Retail: SetPositionInternal @0x00515330 branches on `this->cell == curr_cell`
@0x0051536d; the changed branch reaches change_cell @0x00513390, whose
delegates leave_cell @0x00510f50 and enter_cell @0x00510ed0 self-recurse over
children and write the FULL identity (add_object @0x00510ee2, objcell_id
@0x00510f1e, part-array cell id @0x00510f2b, cell pointer @0x00510f35).
change_cell itself has no child loop.

THE TRAP, recorded because it nearly shipped: the depth-1 loop
@0x0051539c-0x005153d8 is the SAME-CELL fast path (objcell_id and part-array
id only, deliberately not the cell pointer), NOT the propagation. An
implementer who finds it first concludes "depth-1, id-only" and strands every
equipped item at a landblock boundary — the #184 class. The clincher against
that reading: update_object @0x00515d10 early-returns on `parent != 0`
@0x00515d40, so a child never runs its own physics tick and parent
propagation is the ONLY mechanism maintaining its cell.

Route 7 performs NO placement (DoPickupEvent @0x00452240 = unset_parent +
leave_world; DoParentEvent @0x00452290 = set_parent + SetPlacementFrame), so
it arms ConstrainTo nowhere — the leash rule INVERTS relative to routes
2/4/5, and both reviewers confirmed nothing arms.

Propagation is an ITERATIVE WORKLIST, not recursion. The first implementation
recursed with a depth-64 cap; both reviews independently found the cap left a
truncated tail at a stale NON-ZERO cell — permanently unrecoverable, logged
only under a probe flag, and on the withdraw path exactly the #184 shape
AP-142 clause (a) exists to reject. Shipping a fresh #184 instance inside the
slice that fixes stranded children was not acceptable, so the cap was removed
rather than tuned. The worklist retires the cap, the constant, its register
clause, and the failure mode together. Termination: every record on the stack
is already at the target pair, so nothing can be pushed twice and a hostile
A->B->A cycle collapses without a visited set.

The child write deliberately bypasses the public RuntimeEntityDirectory
.SetFullCell and calls the record method directly. This is LOAD-BEARING:
the public method re-enters PropagateFullCellToChildren, which opens with
_propagationWorklist.Clear() — routing children through it mid-drain would
wipe the shared stack and silently drop every unprocessed sibling. Any future
side effect added to the public SetFullCell must be mirrored by hand at that
call site.

Deliberate divergence, recorded not disguised: retail's removal path leaves
children with a null cell pointer but a STALE nonzero objcell_id @0x005133c1.
acdream does not reproduce it, because FullCellId != 0 is the liveness
predicate at 45+ sites — faithful porting would mark dead children live.
AP-142 records this; clause (d) records that acdream cannot gate propagation
on HasPartArray the way enter_cell gates on part_array @0x00510ed8, because
the flag's only writers are graphical and headless never sets it — the reason
is Slice J LAYERING, not a semantic difference (retail's part_array is itself
a mesh-construction product, single assignment site makeAnimObject
@0x0050e930 -> CPartArray::CreateSetup @0x0050e93e).

D7 adopts retail's unset_parent-before-leave_world order @0x0045227f ->
@0x00452286, applied to BOTH pickup paths including the dormant executor
replay. Its inertness was verified by reverting it and finding all 12
propagation tests still green — reported honestly rather than papered over
with a manufactured test, and independently confirmed by both reviewers.

ClassifyLeaveWorld and its request/cause types are DELETED: retail has no
classification here, and method-per-cause IS the retail dispatch shape.
Wiring it would have forced a vacuous teleport-sequence predicate with the
#307 shape.

Two review rounds plus a coordinator-required third pass; 5 MAJORs. One was a
handoff failure worth recording: enter_cell's part_array guard was correctly
identified as load-bearing by the research, dropped by the contract when it
enumerated the writes, and inherited as an omission by the code — a right
finding that evaporated across two handoffs with nobody re-reading the source.
Another was a test that survived deleting the entire behaviour it claimed to
pin, because its assertion read a field written unconditionally one line
earlier.

NoProjection is structurally unreachable from TickChild (TryResolveExactAttachment
performs a strictly stronger form of the same guard one call earlier). Kept as
a fail-safe, unit-tested directly, and documented in two places rather than
wrapped in a fabricated end-to-end test.

Headless regression test — the direct gate for this defect, which FAILED
before this work because no code path existed:
RuntimeLiveEntitySessionControllerTests
.DirectSink_D5_StandaloneParentEventCommitsChildToParentsExactCell.

Probe: ACDREAM_PROBE_CHILD_CELL=1 emits [child-cell] lines at all four write
sites (attach / headless-attach / propagate / withdraw / delete). TEMPORARY.

Complete Release suite MEASURED at 11,079 passed / 4 skipped / 0 failed
(baseline 11,063 at cff52c44, +16). An allocation flake appeared once under
load and was proven NOT this slice by reachability — RuntimeCollisionReportingState
contains zero SetFullCell and zero ParentAttachments references.

STILL OWED: the two-client connected gate (equip/unequip, carry across
landblock boundaries, pickup, loot, reconnect) with ACDREAM_PROBE_CHILD_CELL=1,
and a session counts only if [child-cell] cause=propagate lines appear.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-08-04 23:53:05 +02:00
parent 19ebf043e3
commit cd3129e9d6
24 changed files with 4500 additions and 105 deletions

View file

@ -313,6 +313,112 @@ public sealed class RuntimeLiveEntitySessionControllerTests
projection.LastPositionDisposition);
}
/// <summary>
/// C4 route 7 headless gate (D5) — the direct regression test for the
/// route-6 scoping's stranded-equipped-child defect: a committed
/// child's canonical FullCellId must equal its parent's, driven purely
/// through <see cref="RuntimeLiveEntitySessionController.OnParentUpdated"/>
/// with no App/graphical layer involved. Fails without D1/D2/D5.
/// </summary>
[Fact]
public void DirectSink_D5_StandaloneParentEventCommitsChildToParentsExactCell()
{
using StartedRuntime started = StartRuntime();
GameRuntime runtime = started.Runtime;
CommitLandblockCollision(runtime, 0x01010000u);
CommitLandblockCollision(runtime, 0x01020000u);
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();
const uint parentGuid = 0x70000020u;
const uint childGuid = 0x70000021u;
sink.Spawned(SpawnAt(parentGuid, incarnation: 1, 0x01010001u));
drive.DriveAll();
DrainPlacementFifo(runtime);
sink.Spawned(SpawnAt(childGuid, incarnation: 1, 0x01020001u));
drive.DriveAll();
DrainPlacementFifo(runtime);
Assert.True(runtime.EntityObjects.Entities.TryGetActive(
parentGuid, out RuntimeEntityRecord parent));
Assert.True(runtime.EntityObjects.Entities.TryGetActive(
childGuid, out RuntimeEntityRecord child));
Assert.NotEqual(0u, parent.FullCellId);
// Distinct starting cells — equality below can only come from D5's
// commit, never from coincidence.
Assert.NotEqual(parent.FullCellId, child.FullCellId);
sink.ParentUpdated(new ParentEvent.Parsed(
parentGuid,
childGuid,
ParentLocation: 0u,
PlacementId: 0u,
ParentInstanceSequence: 1,
ChildPositionSequence: 2));
Assert.Equal(parent.FullCellId, child.FullCellId);
Assert.NotEqual(0u, child.FullCellId);
}
/// <summary>
/// D5 companion: the deferred flavor — a standalone ParentEvent naming a
/// parent whose own CreateObject has not arrived yet must commit once
/// that guid becomes addressable (<c>OnSpawned</c>'s
/// <c>RetryChildrenWaitingForParent</c>).
/// </summary>
[Fact]
public void DirectSink_D5_DeferredParentEventCommitsOnceTheParentBecomesAddressable()
{
using StartedRuntime started = StartRuntime();
GameRuntime runtime = started.Runtime;
CommitLandblockCollision(runtime, 0x01010000u);
CommitLandblockCollision(runtime, 0x01020000u);
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();
const uint parentGuid = 0x70000022u;
const uint childGuid = 0x70000023u;
sink.Spawned(SpawnAt(childGuid, incarnation: 1, 0x01020001u));
drive.DriveAll();
DrainPlacementFifo(runtime);
Assert.True(runtime.EntityObjects.Entities.TryGetActive(
childGuid, out RuntimeEntityRecord child));
uint childOriginalCell = child.FullCellId;
// The ParentEvent arrives BEFORE the parent's own CreateObject.
sink.ParentUpdated(new ParentEvent.Parsed(
parentGuid,
childGuid,
ParentLocation: 0u,
PlacementId: 0u,
ParentInstanceSequence: 1,
ChildPositionSequence: 2));
Assert.Equal(childOriginalCell, child.FullCellId);
sink.Spawned(SpawnAt(parentGuid, incarnation: 1, 0x01010001u));
drive.DriveAll();
DrainPlacementFifo(runtime);
Assert.True(runtime.EntityObjects.Entities.TryGetActive(
parentGuid, out RuntimeEntityRecord parent));
Assert.Equal(parent.FullCellId, child.FullCellId);
Assert.NotEqual(0u, child.FullCellId);
}
/// <summary>
/// C3c-R1 review F6: the drive controller outlives its session routes,
/// so "session reset precedes a new route" is an asserted latch, not a
@ -639,10 +745,22 @@ public sealed class RuntimeLiveEntitySessionControllerTests
private static WorldSession.EntitySpawn Spawn(
uint guid,
ushort incarnation)
ushort incarnation) =>
SpawnAt(guid, incarnation, 0x01010001u);
/// <summary>
/// C4 route 7 D5 gate: <see cref="Spawn"/> parametrized over the wire
/// landblock, so a parent and a child can be seeded at DISTINCT cells —
/// equality after the D5 commit can then only come from the
/// propagation write, never from a coincidental shared default.
/// </summary>
private static WorldSession.EntitySpawn SpawnAt(
uint guid,
ushort incarnation,
uint landblockId)
{
var position = new CreateObject.ServerPosition(
0x01010001u,
landblockId,
10f,
10f,
5f,