Own run failure in the daemon

This commit is contained in:
Meta Vens 2026-07-16 23:42:27 +01:00
commit 8abdf3ac62
13 changed files with 205 additions and 16 deletions

View file

@ -1397,7 +1397,9 @@ internal sealed class AetheriaDaemonYmirSmokeChecks
var cockpitRun = new AetheriaRuntimeRunCheckpointCommit
{
RunId = "cockpit-destruction-smoke", CurrentZoneIndex = 0,
CurrentEntityKey = "zone.0.entity.0", Zones = [cockpitZone]
CurrentEntityKey = AetheriaRuntimeRunCheckpointCommit.EntityRecordKey(
"cockpit-destruction-smoke", 0, cockpitTarget.EntityIndex),
Zones = [cockpitZone]
};
AetheriaRuntimeDaemonSimulation.Step(cockpitRun, new AetheriaRuntimeDaemonIntentState(), 0.1,
@ -1412,6 +1414,63 @@ internal sealed class AetheriaDaemonYmirSmokeChecks
.Select(value => value.Kind).ToArray();
RequireEqual("equipment.destroyed,entity.destroyed", string.Join(",", chronology),
"equipment destruction feedback must precede the cause-specific entity destruction fact");
RequireEqual(AetheriaRuntimeRunLifecycle.Failed, cockpitRun.LifecyclePhase,
"destruction of the controlled entity must end the daemon-owned run");
RequireEqual("cockpit-destroyed", cockpitRun.TerminalReason,
"the run terminal reason must preserve the fossil cause of death");
RequireEqual(1L, cockpitRun.TerminalFrameId,
"the run terminal frame must be committed with the lethal transaction");
RequireEqual("", cockpitRun.CurrentEntityKey,
"the failed run must release its controlled entity after recording the terminal cause");
RequireEqual(1, cockpitRun.GameEvents.Count(value => value.Kind == "run.failed" &&
value.Reason == "cockpit-destroyed"),
"the lethal transaction must publish one durable run failure fact");
var restartedRun = MessagePack.MessagePackSerializer.Deserialize<AetheriaRuntimeRunCheckpointCommit>(
MessagePack.MessagePackSerializer.Serialize(cockpitRun));
restartedRun.Zones[0].Entities[0].VelocityX = 10;
var sourcePosition = restartedRun.Zones[0].Entities[0].PositionX;
var rejectedAfterFailure = MovementCommand("move-after-run-failure", "zone.0.entity.0", 1, 0);
using var restartedPhysics = NewPhysics();
var restarted = AetheriaRuntimeDaemonTickRunner.Tick(
Path.Combine(Path.GetTempPath(), "aetheria-failed-run-restart.cc"),
restartedRun,
new AetheriaRuntimeDaemonTickOptions
{
FrameId = 2,
FixedDeltaSeconds = 0.1,
SimulationTimeSeconds = 0.2,
ObservedCommands = [rejectedAfterFailure],
WorldPhysics = restartedPhysics,
BuildPublications = false
});
Require(restarted.OperationResult.RejectedCommandIds.Contains("move-after-run-failure"),
"a terminal run must reject later gameplay commands after restart");
RequireNear(sourcePosition, restartedRun.Zones[0].Entities[0].PositionX, 0.000001,
"a terminal run must not advance surviving world bodies after restart");
RequireEqual(1, restartedRun.GameEvents.Count(value => value.Kind == "run.failed"),
"restart must not replay the run failure transition");
var failedSurface = AetheriaRuntimeDaemonGameSurfaceBuilder.Build(
restarted.Frame,
new AetheriaRuntimeDaemonHealthDocument(),
AetheriaRuntimeDaemonCommandBoundaryDocument.Create("daemon"));
var failedWorld = Flatten(failedSurface.Surface.Root)
.Single(node => node.Id == "aetheria.daemon.game.world");
RequireEqual("terminal", failedWorld.Props["presentationMode"],
"the generic Eve world must receive a terminal presentation lever");
RequireEqual("false", failedWorld.Props["movementEnabled"],
"the generic Eve world must not advertise movement after run failure");
RequireEqual("cockpit-destroyed", failedWorld.Props["runTerminalReason"],
"the generic Eve world must receive the authoritative terminal cause");
Require(AetheriaRuntimeStateRefResolver.TryResolveDaemonStateRef(
restarted.Frame,
new AetheriaRuntimeDaemonHealthDocument(),
AetheriaRuntimeDaemonCommandBoundaryDocument.Create("daemon"),
AetheriaRuntimeDaemonStateRefs.CurrentRunLifecycle,
out var projectedLifecycle) &&
projectedLifecycle == AetheriaRuntimeRunLifecycle.Failed,
"Eve state bindings must resolve the daemon-owned run lifecycle without client inference");
}
private static void DestructionDropsLootExactlyOnce()
@ -1465,6 +1524,8 @@ internal sealed class AetheriaDaemonYmirSmokeChecks
"each durable pickup must publish one drop event");
RequireEqual(1, run.GameEvents.Count(value => value.Kind == "entity.destroyed"),
"destruction chronology must publish exactly once");
RequireEqual(AetheriaRuntimeRunLifecycle.Active, run.LifecyclePhase,
"destroying a non-controlled entity must not counterfeit a run failure");
var surface = AetheriaRuntimeDaemonGameSurfaceBuilder.Build(
new AetheriaRuntimeDaemonFrameDocument { FrameId = 1, Run = run },

View file

@ -96,6 +96,8 @@ internal static class AetheriaDaemonZoneGenerator
ZoneKeys = [zoneKey.ToString()],
GenerationSeed = GenerationSeed,
CurrentEntityKey = entityKeys[1],
LifecyclePhase = AetheriaRuntimeRunLifecycle.Active,
TerminalFrameId = -1,
UpdatedAtUtc = now
}).ConfigureAwait(false);

View file

@ -246,15 +246,15 @@ static async Task<AetheriaRuntimeDaemonTickResult> TickAsync(
await ApplySimulationClockCommandsAsync(node, ingressState, simulationClockCommands).ConfigureAwait(false);
}
var simulationStepCount = terminus ? ingressState.TakeTerminusSimulationSteps() : 1;
var advanceSimulation = simulationStepCount > 0;
if (terminus && !advanceSimulation)
var advanceSimulation = simulationStepCount > 0 && AetheriaRuntimeRunLifecycle.IsActive(run);
if (terminus && !advanceSimulation && AetheriaRuntimeRunLifecycle.IsActive(run))
{
authorizedCommands = authorizedCommands
.Where(command => !AetheriaRuntimeDaemonOperations.RequiresSimulationStep(command.Kind))
.ToArray();
}
var simulationTimeSeconds = (currentFrame?.SimulationTimeSeconds ?? 0) +
(simulationStepCount * fixedDeltaSeconds);
((advanceSimulation ? simulationStepCount : 0) * fixedDeltaSeconds);
TracePhase("tick-inputs");
var result = AetheriaRuntimeDaemonTickRunner.Tick(
@ -2590,6 +2590,11 @@ static async Task<AetheriaRuntimeRunCheckpointCommit?> ReadRuntimeRunCheckpointA
.ToArray(),
GenerationSeed = run.GenerationSeed,
CurrentEntityKey = run.CurrentEntityKey ?? "",
LifecyclePhase = string.IsNullOrWhiteSpace(run.LifecyclePhase)
? AetheriaRuntimeRunLifecycle.Active
: run.LifecyclePhase,
TerminalReason = run.TerminalReason ?? "",
TerminalFrameId = run.TerminalFrameId,
Credits = 1000000
};
}

View file

@ -241,6 +241,15 @@ public sealed class AetheriaRunState
[Key(12)]
[CultReference(typeof(AetheriaEntitySnapshot))]
public string CurrentEntityKey { get; set; } = "";
[Key(13)]
public string LifecyclePhase { get; set; } = "active";
[Key(14)]
public string TerminalReason { get; set; } = "";
[Key(15)]
public long TerminalFrameId { get; set; } = -1;
}
[CultDocument("aetheria.zone_state", "aetheria.zone_state.v1")]

View file

@ -62,6 +62,9 @@ namespace GameCult.Aetheria.State.Verse
"card",
new[] { ("title", "Current Entity") },
Metric("aetheria.daemon.game.player.run", "Run", run.RunId, AetheriaRuntimeDaemonStateRefs.CurrentRunId),
Metric("aetheria.daemon.game.player.lifecycle", "Run State", run.LifecyclePhase, AetheriaRuntimeDaemonStateRefs.CurrentRunLifecycle),
Metric("aetheria.daemon.game.player.terminal_reason", "Terminal Reason", run.TerminalReason, AetheriaRuntimeDaemonStateRefs.CurrentRunTerminalReason),
Metric("aetheria.daemon.game.player.terminal_frame", "Terminal Frame", run.TerminalFrameId.ToString(CultureInfo.InvariantCulture), AetheriaRuntimeDaemonStateRefs.CurrentRunTerminalFrameId),
Metric("aetheria.daemon.game.player.zone", "Zone", run.CurrentZoneIndex.ToString(CultureInfo.InvariantCulture), AetheriaRuntimeDaemonStateRefs.CurrentZoneIndex),
Metric("aetheria.daemon.game.player.key", "Entity Key", run.CurrentEntityKey, AetheriaRuntimeDaemonStateRefs.CurrentEntityKey),
Metric("aetheria.daemon.game.player.name", "Name", entityName, AetheriaRuntimeDaemonStateRefs.CurrentEntityName),
@ -670,9 +673,14 @@ namespace GameCult.Aetheria.State.Verse
["excludedRenderChannels"] = "map",
["playerEntityId"] = playerEntityId,
["cameraTargetEntityId"] = cameraTargetEntityId,
["subjectVisible"] = isDocked ? "false" : "true",
["movementEnabled"] = isDocked ? "false" : "true",
["presentationMode"] = isDocked ? "docked" : "world",
["subjectVisible"] = AetheriaRuntimeRunLifecycle.IsActive(run) && !isDocked && playerEntityIndex >= 0 ? "true" : "false",
["movementEnabled"] = !AetheriaRuntimeRunLifecycle.IsActive(run) || isDocked ? "false" : "true",
["runLifecycle"] = run.LifecyclePhase ?? "",
["runTerminalReason"] = run.TerminalReason ?? "",
["runTerminalFrameId"] = run.TerminalFrameId.ToString(CultureInfo.InvariantCulture),
["presentationMode"] = !AetheriaRuntimeRunLifecycle.IsActive(run)
? "terminal"
: isDocked ? "docked" : "world",
["movementCommand"] = CommandName(AetheriaRuntimeDaemonCommandKinds.SetMoveVector),
["lookCommand"] = CommandName(AetheriaRuntimeDaemonCommandKinds.SetLookDirection),
["lookModel"] = "planar-yaw.v1",

View file

@ -69,6 +69,12 @@ namespace GameCult.Aetheria.State.Verse
if (command == null || string.IsNullOrWhiteSpace(command.CommandId))
continue;
if (!AetheriaRuntimeRunLifecycle.IsActive(run))
{
rejected.Add(command.CommandId);
continue;
}
if (ApplyOne(run, command, context))
applied.Add(command.CommandId);
else

View file

@ -25,7 +25,7 @@ namespace GameCult.Aetheria.State.Verse
double simulationTimeSeconds = 0,
int simulationStepIndex = 0)
{
if (run == null || deltaSeconds <= 0)
if (run == null || deltaSeconds <= 0 || !AetheriaRuntimeRunLifecycle.IsActive(run))
return;
if (worldPhysics == null)
throw new ArgumentNullException(nameof(worldPhysics));
@ -1707,9 +1707,16 @@ namespace GameCult.Aetheria.State.Verse
entity.Contacts = (entity.Contacts ?? Array.Empty<AetheriaRuntimeEntityContactCommit>())
.Where(contact => contact != null && contact.TargetEntityIndex != target.EntityIndex).ToArray();
}
if (run.CurrentZoneIndex == zone.ZoneIndex && TryParseEntityIndex(run.CurrentEntityKey, out var currentIndex) &&
currentIndex == target.EntityIndex)
var controlledEntityDestroyed =
run.CurrentZoneIndex == zone.ZoneIndex &&
TryParseEntityIndex(run.CurrentEntityKey, out var currentIndex) &&
currentIndex == target.EntityIndex;
var runFailed = false;
if (controlledEntityDestroyed)
{
runFailed = AetheriaRuntimeRunLifecycle.Fail(run, target.CauseOfDeath, frameId);
run.CurrentEntityKey = "";
}
AetheriaRuntimeGameEvents.Append(run, new AetheriaRuntimeGameEventCommit
{
@ -1719,6 +1726,22 @@ namespace GameCult.Aetheria.State.Verse
ItemKey = weaponItemKey, Reason = target.CauseOfDeath,
PositionX = target.PositionX, PositionZ = target.PositionZ
});
if (runFailed)
{
AetheriaRuntimeGameEvents.Append(run, new AetheriaRuntimeGameEventCommit
{
EventId = $"run:{run.RunId}:failed",
Kind = "run.failed",
FrameId = frameId,
ZoneIndex = zone.ZoneIndex,
SourceEntityIndex = sourceEntityIndex,
TargetEntityIndex = target.EntityIndex,
SubjectKey = run.RunId,
Reason = target.CauseOfDeath,
PositionX = target.PositionX,
PositionZ = target.PositionZ
});
}
}
private static AetheriaRuntimeLoadoutItemCommit CloneItem(AetheriaRuntimeLoadoutItemCommit item) => new()

View file

@ -14,6 +14,9 @@ namespace GameCult.Aetheria.State.Verse
public const string FrameRejectedCommands = Prefix + "/frame/rejectedCommands";
public const string CurrentRunId = Prefix + "/current/runId";
public const string CurrentRunLifecycle = Prefix + "/current/runLifecycle";
public const string CurrentRunTerminalReason = Prefix + "/current/runTerminalReason";
public const string CurrentRunTerminalFrameId = Prefix + "/current/runTerminalFrameId";
public const string CurrentZoneIndex = Prefix + "/current/zoneIndex";
public const string CurrentEntityKey = Prefix + "/current/entityKey";
public const string CurrentEntityName = Prefix + "/current/entityName";

View file

@ -151,7 +151,9 @@ namespace GameCult.Aetheria.State.Verse
.ToArray(),
operationResult.Intents);
}
var simulationStepCount = options.AdvanceSimulation ? Math.Max(1, options.SimulationStepCount) : 0;
var simulationStepCount = options.AdvanceSimulation && AetheriaRuntimeRunLifecycle.IsActive(operationResult.Run)
? Math.Max(1, options.SimulationStepCount)
: 0;
for (var simulationStep = 0; simulationStep < simulationStepCount; simulationStep++)
{
var stepTime = options.SimulationTimeSeconds -

View file

@ -218,6 +218,15 @@ namespace GameCult.Aetheria.State.Verse
public IReadOnlyList<AetheriaRuntimePickupContactReceiptCommit> PickupContactReceipts { get; set; } =
Array.Empty<AetheriaRuntimePickupContactReceiptCommit>();
[Key(17)]
public string LifecyclePhase { get; set; } = AetheriaRuntimeRunLifecycle.Active;
[Key(18)]
public string TerminalReason { get; set; } = "";
[Key(19)]
public long TerminalFrameId { get; set; } = -1;
public AetheriaRuntimeLoadoutTemplateCommit CreateLoadoutTemplate(string entityKey)
{
return TryParseEntityKey(entityKey, out var zoneIndex, out var entityIndex)
@ -462,6 +471,29 @@ namespace GameCult.Aetheria.State.Verse
[Key(13)] public double AuxiliaryValue { get; set; }
}
public static class AetheriaRuntimeRunLifecycle
{
public const string Active = "active";
public const string Failed = "failed";
public static bool IsActive(AetheriaRuntimeRunCheckpointCommit? run) =>
run != null && string.Equals(run.LifecyclePhase, Active, StringComparison.Ordinal);
public static bool Fail(
AetheriaRuntimeRunCheckpointCommit? run,
string reason,
long frameId)
{
if (!IsActive(run))
return false;
run!.LifecyclePhase = Failed;
run.TerminalReason = reason ?? "";
run.TerminalFrameId = frameId;
return true;
}
}
[MessagePackObject]
public sealed class AetheriaRuntimeShotReceiptCommit
{

View file

@ -56,6 +56,15 @@ namespace GameCult.Aetheria.State.Verse
case AetheriaRuntimeDaemonStateRefs.CurrentRunId:
value = run.RunId ?? "";
return true;
case AetheriaRuntimeDaemonStateRefs.CurrentRunLifecycle:
value = run.LifecyclePhase ?? "";
return true;
case AetheriaRuntimeDaemonStateRefs.CurrentRunTerminalReason:
value = run.TerminalReason ?? "";
return true;
case AetheriaRuntimeDaemonStateRefs.CurrentRunTerminalFrameId:
value = run.TerminalFrameId.ToString(CultureInfo.InvariantCulture);
return true;
case AetheriaRuntimeDaemonStateRefs.CurrentZoneIndex:
value = run.CurrentZoneIndex.ToString(CultureInfo.InvariantCulture);
return true;

View file

@ -2829,6 +2829,33 @@ technology keys has been deleted. A future Starbridge mode must enter through
the active daemon game-mode owner and typed catalogs; a dormant document seeder
is not a game mode.
Run-lifecycle ownership is deliberately narrower than a quest system:
- Owner: the daemon run checkpoint owns whether the run is `active` or
terminal. The fossil supplied a failure transition on destruction of the
controlled entity; it did not supply a victory transition.
- Inputs: the controlled entity key and the daemon's committed destruction
transaction, including its cause and frame.
- Outputs: lifecycle phase, terminal reason, terminal frame, one durable
`run.failed` fact, command rejection, and a frozen world after the lethal
frame.
- Derived state: docked, travelling, fighting, mining, looting, and refitting
remain projections of authoritative world facts. They are not durable run
phases and cannot advance the lifecycle.
- Forbidden writers: Unity death callbacks, Eve surfaces, command payloads,
health documents, and menu navigation cannot end, revive, or complete a run.
- Shared paths: every lethal hull, cockpit, heatstroke, and hypothermia path
must pass through the same daemon destruction commit. New Game replaces the
run through the existing daemon session bootstrap; Continue reads the latest
checkpoint.
- Cut line: clearing `CurrentEntityKey` is no longer the implicit lifecycle
decision. It remains the controlled-entity consequence of the explicit
failure commit.
- Verification layer: daemon smoke kills the controlled entity, serializes the
terminal checkpoint, restarts it, proves later commands are rejected and
simulation is frozen, and inspects the Eve surface state bindings. Completion
remains unimplemented until a source-backed game-mode rule owns it.
Ymir restart ownership is deliberately private and asymmetric:
- Owner: `AetheriaYmirPersistenceCoordinator` owns reconstruction durability;

View file

@ -15,7 +15,7 @@ validation proves contract shape, not wiring, exclusivity, lowering, or parity.
| Organ | Original authority/evidence | Target owner | Eve contract | Runtime lowering | Current status | Required proof |
|---|---|---|---|---|---|---|
| Run/session state | `ServerShared`, `ActionGameManager` | Aetheria daemon/CultCache | provider/session advertisement | all clients | owner-exists; wired; projected; not proven | restart and multi-client convergence |
| Run/session state | `ServerShared`, `ActionGameManager` | Aetheria daemon/CultCache | provider/session advertisement plus run lifecycle bindings | all clients | active/failed lifecycle is daemon-owned and restart-stable: controlled-entity destruction commits the fossil cause, terminal frame, one `run.failed` fact, releases control, rejects later gameplay commands, and freezes the world; Eve receives terminal presentation/input levers without becoming an owner. Docked, travelling, fighting, mining, looting, and refitting remain derived world conditions rather than counterfeit durable phases | full-daemon death/restart witness, multi-client convergence, and a source-backed game-mode completion rule; the fossil supplied no victory transition |
| Entity identity/loadout | `ServerShared/Entity*` | daemon | typed entity and inventory surfaces | EveUnity/Electron | owner-exists; wired; projected; not proven | loadout round trip and reconnect |
| Loadout generation | map/faction availability, item cost, hull hardpoints and role constraints | daemon using canonical galaxy, faction knowledge/economy and typed catalog | generated loadout plus provenance/availability facts | Eve inspection and refit surfaces | daemon now uses the fossil candidate filter and seeded weighted selection: manufacturer must be present and allied, ally weight decays by home-zone graph distance, price uses the authored exponent, and hardpoints require matching semantic type, rotated footprint containment, and controller role; the April 2021 catalog fossil restores the distinct common `Longinus`, rare AetherDrive-compatible `LonginusX`, and `Djinni` rows with their original IDs, shapes, hardpoints, prices, drag, and prefabs, plus missing Thruster rows required to fill their authored mounts; typed `rarity:rare` tags apply a 0.05 generation multiplier to `LonginusX` and AetherDrive equipment; the generator owns one mutable CultMath stream, fixing the readonly-struct defensive-copy bug that restarted every weighted draw; placement rotation survives durable state and reconnect; generation fills the largest compatible footprint before economic weighting; cargo/capacitor plus station docking equipment must fit remaining hull space; stations pack faction-available inventory largest-first; ordinary ships begin without invented scenario cargo; every generated entity persists a source/selection receipt that reaches Eve as `loadout.item` semantics | multi-zone generated-world parity and exact root-to-zone stream sequencing against the fossil |
| Flight intent | `Ship`, `Thruster`, `AetherDrive`, input paths | daemon actuator simulation + Ymir integration | analog local helm/look/tractor plus actuator state | generic Eve input and scene lowerers | direct faction-speed velocity ownership is deleted; daemon persists local strafe/forward helm and desired look, allocates ordinary directional thruster banks by authored rotation, derives torque from hull/item placement, compensates lateral torque, gates execution through the shared energy ledger, deposits equipment-cell heat, publishes plume visibility and actuator state, applies hull drag, and gives resulting velocity/direction to Ymir. Autonomous tasks translate world travel into the same local helm axes and issue look commands instead of mutating heading. AetherDrive rotor/coupling simulation is additive and explicitly non-default: common `Longinus` and `Djinni` hulls use ordinary thrusters; the rare `LonginusX` replaces those mounts with the single rare `Traction` AetherDrive path | hardpoint-transform direction parity, exact behavior execution ordering, CultMath/float32 parity harness, live production-frequency evidence, generic thrust/turn feedback lowering, and live handling screenshots |
@ -113,10 +113,12 @@ These are source-confirmed ownership failures, not feature backlog:
layers without leaking Unity masks into portable state. Entity presentation
graphs, attachment sockets, map products, and richer effect composition are
not yet first-class contracts.
5. **The game loop has no single daemon owner.** Exploration, discovery,
encounter, loot, docking, trade, refit, narrative, boss progression,
completion, failure, and continue exist as pieces rather than one explicit
run-state machine.
5. **Run completion and boss/narrative progression have no source-backed
owner.** Active play, failure, and Continue now share the daemon checkpoint;
exploration, encounter, loot, docking, trade, and refit remain correctly
derived from world facts. The fossil contains boss placement and an exit
zone, but no victory transition, so completion must be owned by an explicit
game mode rather than inferred from reaching a zone.
6. **Unity spatial feedback remains insufficiently fenced.** The daemon now
requires Ymir for world advancement, but the Unity bridge/query path still
needs a negative proof that presentation transforms cannot write spatial