Reuse unchanged compiled runtime catalog

This commit is contained in:
Meta Vens 2026-07-20 00:56:46 +01:00
commit 466d2bc8ab
4 changed files with 63 additions and 16 deletions

View file

@ -5858,9 +5858,12 @@ internal sealed class AetheriaDaemonYmirSmokeChecks
DockingMaxSizeY = 12
}).GetAwaiter().GetResult();
AetheriaDaemonNativeCatalog.EnsureAsync(node).GetAwaiter().GetResult();
Require(AetheriaDaemonNativeCatalog.EnsureAsync(node).GetAwaiter().GetResult(),
"daemon-native catalog must report its first materialization");
node.FlushAsync().GetAwaiter().GetResult();
node.RefreshRuntimeCatalogAsync().GetAwaiter().GetResult();
Require(!AetheriaDaemonNativeCatalog.EnsureAsync(node).GetAwaiter().GetResult(),
"daemon-native catalog must not rewrite an unchanged generated revision");
var catalog = node.RuntimeCatalog().Latest();
var hull = catalog.FindItem(AetheriaDaemonNativeCatalog.DockyardHullItemKey);
var bay = catalog.FindItem(AetheriaDaemonNativeCatalog.DockyardBayItemKey);

View file

@ -1,8 +1,11 @@
using Aetheria.State;
using Aetheria.State.Documents;
using MessagePack;
using System.Security.Cryptography;
internal static class AetheriaDaemonNativeCatalog
{
private const string NativeCatalogRevisionTag = "native-catalog-revision:1";
private const string ZenithHullLegacyId = "82efc0a5-1ba5-4ff3-a281-b2e6e247521d";
private const string MediumDockingBayLegacyId = "3e930a2c-ac72-4385-98aa-1c5b0b90db46";
private const string DockyardHullLegacyId = "ca098005-8cc8-47f4-be99-7bc842805359";
@ -11,7 +14,7 @@ internal static class AetheriaDaemonNativeCatalog
public static string DockyardHullItemKey => ItemKey(DockyardHullLegacyId);
public static string DockyardBayItemKey => ItemKey(DockyardBayLegacyId);
public static async Task EnsureAsync(AetheriaStateNode node)
public static async Task<bool> EnsureAsync(AetheriaStateNode node)
{
ArgumentNullException.ThrowIfNull(node);
@ -26,14 +29,23 @@ internal static class AetheriaDaemonNativeCatalog
.ConfigureAwait(false)
?? throw new InvalidDataException("The daemon-native dockyard requires the canonical medium docking bay.");
await node.MutableDocument<AetheriaItemDefinition>(
AetheriaCatalogKeys.ItemDefinitionFromLegacyId(DockyardHullLegacyId))
.ReplaceAsync(CreateDockyardHull(zenith))
.ConfigureAwait(false);
await node.MutableDocument<AetheriaItemDefinition>(
AetheriaCatalogKeys.ItemDefinitionFromLegacyId(DockyardBayLegacyId))
.ReplaceAsync(CreateDockyardBay(mediumBay))
.ConfigureAwait(false);
var expectedHull = CreateDockyardHull(zenith);
var expectedBay = CreateDockyardBay(mediumBay);
var hullDocument = node.MutableDocument<AetheriaItemDefinition>(
AetheriaCatalogKeys.ItemDefinitionFromLegacyId(DockyardHullLegacyId));
var bayDocument = node.MutableDocument<AetheriaItemDefinition>(
AetheriaCatalogKeys.ItemDefinitionFromLegacyId(DockyardBayLegacyId));
var existingHull = await hullDocument.ReadAsync().ConfigureAwait(false);
var existingBay = await bayDocument.ReadAsync().ConfigureAwait(false);
var hullCurrent = HasGenerationTags(existingHull, expectedHull.Tags);
var bayCurrent = HasGenerationTags(existingBay, expectedBay.Tags);
if (!hullCurrent)
await hullDocument.ReplaceAsync(expectedHull).ConfigureAwait(false);
if (!bayCurrent)
await bayDocument.ReplaceAsync(expectedBay).ConfigureAwait(false);
return !hullCurrent || !bayCurrent;
}
private static AetheriaItemDefinition CreateDockyardHull(AetheriaItemDefinition source)
@ -77,6 +89,8 @@ internal static class AetheriaDaemonNativeCatalog
hull.Tags = Tags(
source.Tags,
"origin:aetheria-daemon",
NativeCatalogRevisionTag,
SourceFingerprintTag(source),
"station-role:dockyard",
"docking-capacity:12",
$"presentation-hull-item:{ItemKey(ZenithHullLegacyId)}");
@ -89,10 +103,32 @@ internal static class AetheriaDaemonNativeCatalog
bay.Description = "A medium docking bay packaged for a dedicated station docking hardpoint.";
bay.HardpointType = "DockingBay";
bay.Price = checked(source.Price * 2);
bay.Tags = Tags(source.Tags, "origin:aetheria-daemon", "station-role:dockyard");
bay.Tags = Tags(
source.Tags,
"origin:aetheria-daemon",
NativeCatalogRevisionTag,
SourceFingerprintTag(source),
"station-role:dockyard");
return bay;
}
private static bool HasGenerationTags(AetheriaItemDefinition? existing, IEnumerable<string> expectedTags)
{
if (existing == null)
return false;
var expectedGenerationTags = expectedTags.Where(tag =>
tag.StartsWith("native-catalog-revision:", StringComparison.Ordinal) ||
tag.StartsWith("native-source-sha256:", StringComparison.Ordinal));
return expectedGenerationTags.All(tag => existing.Tags.Contains(tag, StringComparer.Ordinal));
}
private static string SourceFingerprintTag(AetheriaItemDefinition source)
{
var payload = MessagePackSerializer.Serialize(source);
return "native-source-sha256:" + Convert.ToHexString(SHA256.HashData(payload)).ToLowerInvariant();
}
private static AetheriaItemDefinition Copy(AetheriaItemDefinition source, string legacyId, string name) => new()
{
Name = name,

View file

@ -78,13 +78,17 @@ using var soaPublisher = new AetheriaRuntimeDaemonSoaFramePublisher(
await EnsureWorldDocumentAsync(node).ConfigureAwait(false);
TraceStartup("world-document");
await EnsureTradeValuePolicyAsync(node, startedAtUtc).ConfigureAwait(false);
var persistedRuntimeCatalog = await node.Database
.GetAsync<AetheriaRuntimeCatalogSnapshot>(AetheriaStateNode.RuntimeCatalogKey)
.ConfigureAwait(false);
var tradePolicyChanged = await EnsureTradeValuePolicyAsync(node, startedAtUtc).ConfigureAwait(false);
TraceStartup("trade-policy");
await AetheriaDaemonNativeCatalog.EnsureAsync(node).ConfigureAwait(false);
var nativeCatalogChanged = await AetheriaDaemonNativeCatalog.EnsureAsync(node).ConfigureAwait(false);
TraceStartup("native-catalog");
await node.FlushAsync().ConfigureAwait(false);
TraceStartup("initial-flush");
await node.RefreshRuntimeCatalogAsync().ConfigureAwait(false);
if (persistedRuntimeCatalog == null || tradePolicyChanged || nativeCatalogChanged)
await node.RefreshRuntimeCatalogAsync().ConfigureAwait(false);
TraceStartup("runtime-catalog");
await EnsurePlayableRunDocumentsAsync(node, options, startedAtUtc).ConfigureAwait(false);
TraceStartup("playable-run");
@ -2832,17 +2836,18 @@ static async Task EnsureWorldDocumentAsync(AetheriaStateNode node)
}).ConfigureAwait(false);
}
static async Task EnsureTradeValuePolicyAsync(AetheriaStateNode node, string now)
static async Task<bool> EnsureTradeValuePolicyAsync(AetheriaStateNode node, string now)
{
var tradeValuePolicy = node.MutableDocument<AetheriaTradeValuePolicy>(AetheriaStateNode.TradeValuePolicyKey);
var existing = await tradeValuePolicy.ReadAsync().ConfigureAwait(false);
if (existing != null)
return;
return false;
await tradeValuePolicy.ReplaceAsync(
AetheriaRuntimeStateMapper.ToTradeValuePolicy(
AetheriaRuntimeTradeValueSettings.Default,
now)).ConfigureAwait(false);
return true;
}
static async Task EnsurePlayableRunDocumentsAsync(

View file

@ -3622,6 +3622,9 @@ The runtime catalog has one compiled-state owner:
and surface refreshes cannot silently recompile or replace the catalog.
- Shared paths: import, daemon-native catalog augmentation, and the explicit Eve
catalog-refresh command use the same compile-and-publish primitive.
Daemon-native generated items carry a generator revision and a hash of their
authored source item; unchanged generations do not rewrite source records or
force recompilation on restart.
- Cut line: runtime reads and catalog-surface watches no longer reopen the
CultCache store or subscribe to daemon-frame changes.
- Verification layer: state verification requires the typed record/watch path