From 0479304d0b84aec8623dfea0a88897c4a5f98557 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 30 Sep 2026 01:56:03 +0200 Subject: [PATCH 1/7] Geometry: reference members are CultRecordRef, not [CultReference] strings e420410f (D11) refuses a reference member whose CLR shape the cache cannot walk; many:false needs CultRecordRef. CultGeometryBuildRequest.DomainKey, CultGeometrySelectedCutManifest.RequestKey and CultGeometryChunkArtifact.CutKey were strings marked [CultReference], so registering the geometry catalog threw and 7 geometry tests failed on main. All three are record keys of another document, so the members become CultRecordRef (the attribute is dropped, the type declares the reference). The msgpack formatter writes a CultRecordRef as its key string, so the wire bytes and the fingerprint inputs are unchanged. Co-Authored-By: Claude Sonnet 5.5 --- .../CultGeometryDocuments.cs | 15 +++++------- .../GeometryDocumentTests.cs | 24 +++++++++++++++++-- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/GameCult.Geometry/CultGeometryDocuments.cs b/src/GameCult.Geometry/CultGeometryDocuments.cs index 306b5849..0da8af90 100644 --- a/src/GameCult.Geometry/CultGeometryDocuments.cs +++ b/src/GameCult.Geometry/CultGeometryDocuments.cs @@ -153,8 +153,7 @@ namespace GameCult.Geometry public string RequestId { get; set; } = string.Empty; [Key(1)] - [CultReference(typeof(CultGeometryDomainDocument))] - public string DomainKey { get; set; } = string.Empty; + public CultRecordRef DomainKey { get; set; } [Key(2)] [CultIndex] @@ -200,7 +199,7 @@ namespace GameCult.Geometry { if (request == null) throw new ArgumentNullException(nameof(request)); return new CultRecordKey("geometry:request:" + StableHash( - request.DomainKey, + request.DomainKey.Key.Value, request.WorkerGroup, StableVector(request.CameraPosition), StableVector(request.FrustumMin), @@ -228,8 +227,7 @@ namespace GameCult.Geometry public string CutId { get; set; } = string.Empty; [Key(1)] - [CultReference(typeof(CultGeometryBuildRequest))] - public string RequestKey { get; set; } = string.Empty; + public CultRecordRef RequestKey { get; set; } [Key(2)] public string[] SelectedNodes { get; set; } = Array.Empty(); @@ -247,7 +245,7 @@ namespace GameCult.Geometry { if (cut == null) throw new ArgumentNullException(nameof(cut)); return new CultRecordKey("geometry:cut:" + StableHash( - cut.RequestKey, + cut.RequestKey.Key.Value, cut.CutId, StableArray(cut.SelectedNodes), StableArray(cut.DeferredChildRequests), @@ -313,8 +311,7 @@ namespace GameCult.Geometry public string ChunkId { get; set; } = string.Empty; [Key(1)] - [CultReference(typeof(CultGeometrySelectedCutManifest))] - public string CutKey { get; set; } = string.Empty; + public CultRecordRef CutKey { get; set; } [Key(2)] [CultIndex] @@ -357,7 +354,7 @@ namespace GameCult.Geometry { if (chunk == null) throw new ArgumentNullException(nameof(chunk)); return new CultRecordKey("geometry:chunk:" + StableHash( - chunk.CutKey, + chunk.CutKey.Key.Value, chunk.ChunkId, chunk.SelectedCutId, StableArray(chunk.SourceDomainKeys), diff --git a/tests/GameCult.Geometry.Tests/GeometryDocumentTests.cs b/tests/GameCult.Geometry.Tests/GeometryDocumentTests.cs index 8741f891..2576c295 100644 --- a/tests/GameCult.Geometry.Tests/GeometryDocumentTests.cs +++ b/tests/GameCult.Geometry.Tests/GeometryDocumentTests.cs @@ -104,7 +104,7 @@ namespace GameCult.Geometry.Tests var domainKey = CultGeometryDomainDocument.CreateRecordKey(domain); var request = new CultGeometryBuildRequest { - DomainKey = domainKey.Value, + DomainKey = new CultRecordRef(domainKey), WorkerGroup = "ragnarok-column-workers", CameraPosition = [36f, -42f, 30f], FrustumMin = [-75f, -75f, -30f], @@ -129,6 +129,26 @@ namespace GameCult.Geometry.Tests first.Value.Should().StartWith("geometry:request:"); } + // The geometry documents reference each other by record key. The reference members are + // CultRecordRef so the cache can walk them, and they stay a bare msgpack string on the wire. + [Test] + public void GeometryReferences_AreWalkableByTheCache_AndStayStringsOnTheWire() + { + var cache = new CultCache(); + var descriptor = cache.Registry.GetRequired(); + descriptor.DeclaredMembers.Should().Contain(m => m.MemberName == "DomainKey" && m.IsReference && !m.IsMany); + + var chunk = SampleChunk(); + var references = cache.Registry.GetRequired().ReferencesOf(chunk, "CutKey").ToArray(); + references.Should().ContainSingle().Which.Target.Value.Should().Be("geometry:cut:test"); + + var payload = CultDocumentMessagePackSerialization.SerializeUntyped(chunk, typeof(CultGeometryChunkArtifact)); + var reader = new MessagePackReader(payload); + reader.ReadArrayHeader(); + reader.ReadString().Should().Be(chunk.ChunkId); + reader.ReadString().Should().Be("geometry:cut:test"); + } + [Test] public void ChunkArtifact_RoundTrips_ThroughCultCacheMessagePack() { @@ -382,7 +402,7 @@ namespace GameCult.Geometry.Tests return new CultGeometryChunkArtifact { ChunkId = "chunk/ragnarok-column/column-00", - CutKey = "geometry:cut:test", + CutKey = new CultRecordRef(new CultRecordKey("geometry:cut:test")), SelectedCutId = "cut-test", BoundsMin = [-1f, -1f, 0f], BoundsMax = [1f, 1f, 1f], From ef8f76a0d4baa5483067c7f617f1d79ad26f4178 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 30 Sep 2026 02:15:47 +0200 Subject: [PATCH 2/7] Geometry: register the cache's CultRecordRef formatter with the MessagePack generator The MessagePack source generator emitted a broken formatter reference for the CultRecordRef reference members. Declaring CultRecordRefFormatter<> a known formatter makes the generated resolver defer to the cache's own. Co-Authored-By: Claude Sonnet 5.5 --- src/GameCult.Geometry/CultGeometryDocuments.cs | 4 ++++ src/GameCult.Geometry/GameCult.Geometry.csproj | 1 + 2 files changed, 5 insertions(+) diff --git a/src/GameCult.Geometry/CultGeometryDocuments.cs b/src/GameCult.Geometry/CultGeometryDocuments.cs index 0da8af90..5d9ddaa9 100644 --- a/src/GameCult.Geometry/CultGeometryDocuments.cs +++ b/src/GameCult.Geometry/CultGeometryDocuments.cs @@ -7,6 +7,10 @@ using GameCult.Caching; using MessagePack; using static GameCult.Geometry.CultGeometryDocuments; +// The generator emits a resolver for these [MessagePackObject] documents; without this it would try to +// generate a formatter for the CultRecordRef reference members instead of using the cache's. +[assembly: MessagePackKnownFormatter(typeof(CultRecordRefFormatter<>))] + namespace GameCult.Geometry { /// diff --git a/src/GameCult.Geometry/GameCult.Geometry.csproj b/src/GameCult.Geometry/GameCult.Geometry.csproj index c10c2ecf..c1588906 100644 --- a/src/GameCult.Geometry/GameCult.Geometry.csproj +++ b/src/GameCult.Geometry/GameCult.Geometry.csproj @@ -10,6 +10,7 @@ + From e35b0092042aecc902854cd4cfbcb8f48b0266fb Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 30 Sep 2026 02:15:56 +0200 Subject: [PATCH 3/7] Geometry: fix the Caching.MessagePack project reference path The previous commit lost its backslashes. Co-Authored-By: Claude Sonnet 5.5 --- src/GameCult.Geometry/GameCult.Geometry.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GameCult.Geometry/GameCult.Geometry.csproj b/src/GameCult.Geometry/GameCult.Geometry.csproj index c1588906..cc66cba9 100644 --- a/src/GameCult.Geometry/GameCult.Geometry.csproj +++ b/src/GameCult.Geometry/GameCult.Geometry.csproj @@ -10,7 +10,7 @@ - + From 9ea134aca948ae864e51638526421caa966ee947 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 30 Sep 2026 02:25:27 +0200 Subject: [PATCH 4/7] Geometry: name the cache formatter on each CultRecordRef member The MessagePack source generator cannot resolve CultRecordRef on its own and emitted a broken formatter reference; MessagePackKnownFormatter on the open generic did not change that. An explicit MessagePackFormatter per member is the same formatter the cache resolver uses, so the wire stays a key string. Co-Authored-By: Claude Sonnet 5.5 --- src/GameCult.Geometry/CultGeometryDocuments.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/GameCult.Geometry/CultGeometryDocuments.cs b/src/GameCult.Geometry/CultGeometryDocuments.cs index 5d9ddaa9..1ce73bdb 100644 --- a/src/GameCult.Geometry/CultGeometryDocuments.cs +++ b/src/GameCult.Geometry/CultGeometryDocuments.cs @@ -7,10 +7,6 @@ using GameCult.Caching; using MessagePack; using static GameCult.Geometry.CultGeometryDocuments; -// The generator emits a resolver for these [MessagePackObject] documents; without this it would try to -// generate a formatter for the CultRecordRef reference members instead of using the cache's. -[assembly: MessagePackKnownFormatter(typeof(CultRecordRefFormatter<>))] - namespace GameCult.Geometry { /// @@ -157,6 +153,7 @@ namespace GameCult.Geometry public string RequestId { get; set; } = string.Empty; [Key(1)] + [MessagePackFormatter(typeof(CultRecordRefFormatter))] public CultRecordRef DomainKey { get; set; } [Key(2)] @@ -231,6 +228,7 @@ namespace GameCult.Geometry public string CutId { get; set; } = string.Empty; [Key(1)] + [MessagePackFormatter(typeof(CultRecordRefFormatter))] public CultRecordRef RequestKey { get; set; } [Key(2)] @@ -315,6 +313,7 @@ namespace GameCult.Geometry public string ChunkId { get; set; } = string.Empty; [Key(1)] + [MessagePackFormatter(typeof(CultRecordRefFormatter))] public CultRecordRef CutKey { get; set; } [Key(2)] From fd34d4573e757ba845e0c975c1197b814d7152bf Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 30 Sep 2026 02:30:43 +0200 Subject: [PATCH 5/7] Geometry tests: import System.Linq for the reference walk test Co-Authored-By: Claude Sonnet 5.5 --- tests/GameCult.Geometry.Tests/GeometryDocumentTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/GameCult.Geometry.Tests/GeometryDocumentTests.cs b/tests/GameCult.Geometry.Tests/GeometryDocumentTests.cs index 2576c295..b5f63775 100644 --- a/tests/GameCult.Geometry.Tests/GeometryDocumentTests.cs +++ b/tests/GameCult.Geometry.Tests/GeometryDocumentTests.cs @@ -10,6 +10,7 @@ using R3; using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text.Json; using System.Threading.Tasks; From 6a87e53c23d2f1d9689f74ec5d17482b5fc0f347 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 30 Sep 2026 02:38:41 +0200 Subject: [PATCH 6/7] Publication map: record Cut 4 Soul follow-ups (crash-safe log store prerequisite) Co-Authored-By: Claude Opus 5.5 --- docs/cultcache-publication-cut.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/cultcache-publication-cut.md b/docs/cultcache-publication-cut.md index 06aa47db..ed281978 100644 --- a/docs/cultcache-publication-cut.md +++ b/docs/cultcache-publication-cut.md @@ -813,4 +813,16 @@ Recorded, not forked: a gap (`ApplyShardSnapshotResponseAsync` `:675-736`). It predates this campaign. - **AetheriaEve `Program.cs:3722`.** It reads a committed write's `InvalidOperationException` as a denial. Under Q-P5 A, Cut 4's log failures cannot reach it. Observer and `OnUpdate` exceptions still can, so the Cuts 1-2 - recording stands. \ No newline at end of file + recording stands.- **Cut 4 Soul, recorded 2026-09-30 (Self), not fixed in Cut 4:** + - **File log store is not crash-safe (hard prerequisite).** `CultNetFileShardMutationLogStore.Append` and + `CompactThrough` use `File.WriteAllBytes` (truncate, rewrite, no temp+rename, no fsync). A failure mid-write + truncates the log; every later append burns a sequence and a restart cannot construct the database. It also + rewrites the whole file per append, which Cut 4 now does under the cache gate (2.2 ms per write at 100 + entries, 33 ms at 950, a 2.49 s stall). An atomic, append-only store must land before any live daemon + enables durable shard logs. Today only AetheriaEve's offline tools do; the live Aetheria daemon passes + `enableDurableShardLogs: false`. + - **A slow log append blocks cache readers** (`CultCache.Get` takes the gate). Accepted with a note in the + store's XML doc. + - **Crash between the store write and the log append** leaves the log lagging the store, and nothing detects + it; a restarted primary reuses that sequence (A2's divergence reached by a plain kill). The spec called this + lag detectable; for a crash it is not. From 486244b60f0cb43ba7d409cf9f0748f873819d43 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 30 Sep 2026 02:46:29 +0200 Subject: [PATCH 7/7] Caching: JSON converter and MessagePack formatter for CultPhasor The Phacelle merge added the public CultMath value type CultPhasor without its Caching adapters, failing the every-public-type tests. Register it the way CultCellular is: {"cos","sin"} objects in JSON (which also gives the dictionary-key form) and a [cos, sin] array in MessagePack. The adapters are Caching code and stay MIT; only CultPhasor.cs itself is MPL-2.0. Co-Authored-By: Claude Sonnet 5.5 --- .../CultMathJson.cs | 11 +++++++++-- .../CultMathResolver.cs | 17 ++++++++++++++++- src/GameCult.Caching.MessagePack/README.md | 1 + .../GameCult.Caching.Tests/CultMathJsonTests.cs | 3 +++ .../CultMathSerializationTests.cs | 5 +++++ 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/GameCult.Caching.MessagePack/CultMathJson.cs b/src/GameCult.Caching.MessagePack/CultMathJson.cs index 438c6150..0e65bf22 100644 --- a/src/GameCult.Caching.MessagePack/CultMathJson.cs +++ b/src/GameCult.Caching.MessagePack/CultMathJson.cs @@ -14,7 +14,7 @@ namespace GameCult.Caching.MessagePack; /// The canonical System.Text.Json shape of every public CultMath value type, the JSON twin of /// . Vectors, quaternions and colors are objects keyed by their /// field names ({"x":1,"y":2}), matrices are arrays of row objects, rect is -/// {"min":..,"max":..}, and CultCellular is {"nearest":..,"edge":..,"id":..}. +/// {"min":..,"max":..}, CultCellular is {"nearest":..,"edge":..,"id":..}, and CultPhasor is {"cos":..,"sin":..}. /// Property names are fixed: PropertyNamingPolicy does not rename them, and /// PropertyNameCaseInsensitive makes reading case-insensitive. /// @@ -481,7 +481,7 @@ public static class CultMathJson Add(UIntScalar.Instance, new Fields(("state", Val())), a => new Random { state = a[0] }, (v, a) => a[0] = v.state), - // Compositions: matrices are arrays of row objects, rect is {min, max}, CultCellular is {nearest, edge, id}. + // Compositions: matrices are arrays of row objects, rect is {min, max}, CultCellular is {nearest, edge, id}, CultPhasor is {cos, sin}. Add(f, new Rows(2, Xy()), a => new float2x2(a[0], a[1], a[2], a[3]), (v, a) => { a[0] = v[0].x; a[1] = v[0].y; a[2] = v[1].x; a[3] = v[1].y; }), @@ -507,6 +507,13 @@ public static class CultMathJson a[4] = v.edge.x; a[5] = v.edge.y; a[6] = v.edge.z; a[7] = v.edge.w; a[8] = v.id; }), + Add(f, new Fields(("cos", Xyzw()), ("sin", Xyzw())), + a => new CultPhasor(new float4(a[0], a[1], a[2], a[3]), new float4(a[4], a[5], a[6], a[7])), + (v, a) => + { + a[0] = v.cos.x; a[1] = v.cos.y; a[2] = v.cos.z; a[3] = v.cos.w; + a[4] = v.sin.x; a[5] = v.sin.y; a[6] = v.sin.z; a[7] = v.sin.w; + }), }; var map = new Dictionary(); diff --git a/src/GameCult.Caching.MessagePack/CultMathResolver.cs b/src/GameCult.Caching.MessagePack/CultMathResolver.cs index 803b3873..8383a464 100644 --- a/src/GameCult.Caching.MessagePack/CultMathResolver.cs +++ b/src/GameCult.Caching.MessagePack/CultMathResolver.cs @@ -180,7 +180,7 @@ public sealed class CultMathResolver : IFormatterResolver return value; }), - // Compositions: matrices are rows, rect is [min, max], CultCellular is [nearest, edge, id]. + // Compositions: matrices are rows, rect is [min, max], CultCellular is [nearest, edge, id], CultPhasor is [cos, sin]. Shape((ref MessagePackWriter w, float2x2 v) => { w.WriteArrayHeader(2); PutFloat2(ref w, v[0]); PutFloat2(ref w, v[1]); }, (ref MessagePackReader r) => { @@ -221,6 +221,21 @@ public sealed class CultMathResolver : IFormatterResolver } return value; }), + Shape((ref MessagePackWriter w, CultPhasor v) => { w.WriteArrayHeader(2); PutFloat4(ref w, v.cos); PutFloat4(ref w, v.sin); }, + (ref MessagePackReader r) => + { + var value = default(CultPhasor); + for (int i = 0, n = r.ReadArrayHeader(); i < n; i++) + { + switch (i) + { + case 0: value.cos = GetFloat4(ref r); break; + case 1: value.sin = GetFloat4(ref r); break; + default: r.Skip(); break; + } + } + return value; + }), }; var map = new Dictionary(); diff --git a/src/GameCult.Caching.MessagePack/README.md b/src/GameCult.Caching.MessagePack/README.md index fdf91ab2..ccd8f568 100644 --- a/src/GameCult.Caching.MessagePack/README.md +++ b/src/GameCult.Caching.MessagePack/README.md @@ -93,6 +93,7 @@ registered ahead of these wins. | `float2x2`, `float3x3` | array of row vectors (row-major) | array of row objects | | `rect` | `[min, max]` of `float2` | `{"min":{..},"max":{..}}` | | `CultCellular` | `[nearest, edge, id]` | `{"nearest":{..},"edge":{..},"id":..}` | +| `CultPhasor` | `[cos, sin]` of `float4` | `{"cos":{..},"sin":{..}}` | Floats are MessagePack float32 (`0xCA`), doubles float64 (`0xCB`), integers the shortest MessagePack integer. diff --git a/tests/GameCult.Caching.Tests/CultMathJsonTests.cs b/tests/GameCult.Caching.Tests/CultMathJsonTests.cs index 87e5b742..90d739be 100644 --- a/tests/GameCult.Caching.Tests/CultMathJsonTests.cs +++ b/tests/GameCult.Caching.Tests/CultMathJsonTests.cs @@ -43,6 +43,8 @@ namespace GameCult.Caching.Tests Json(new rect(5f, 7f, -1f, -2f)).Should().Be("""{"min":{"x":-1,"y":-2},"max":{"x":5,"y":7}}"""); Json(new CultCellular(new float4(1f, 2f, 3f, 4f), new float4(5f, 6f, 7f, 8f), 0.25f)).Should().Be( """{"nearest":{"x":1,"y":2,"z":3,"w":4},"edge":{"x":5,"y":6,"z":7,"w":8},"id":0.25}"""); + Json(new CultPhasor(new float4(1f, 2f, 3f, 4f), new float4(5f, 6f, 7f, 8f))).Should().Be( + """{"cos":{"x":1,"y":2,"z":3,"w":4},"sin":{"x":5,"y":6,"z":7,"w":8}}"""); } [Test] @@ -66,6 +68,7 @@ namespace GameCult.Caching.Tests RoundTrip(new float3x3(1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f)); RoundTrip(new rect(-1f, -2f, 5f, 7f)); RoundTrip(new CultCellular(new float4(1, 2, 3, 4), new float4(5, 6, 7, 8), 0.25f)); + RoundTrip(new CultPhasor(new float4(1, 2, 3, 4), new float4(5, 6, 7, 8))); } [Test] diff --git a/tests/GameCult.Caching.Tests/CultMathSerializationTests.cs b/tests/GameCult.Caching.Tests/CultMathSerializationTests.cs index 32531679..98f126af 100644 --- a/tests/GameCult.Caching.Tests/CultMathSerializationTests.cs +++ b/tests/GameCult.Caching.Tests/CultMathSerializationTests.cs @@ -101,6 +101,7 @@ namespace GameCult.Caching.Tests RoundTrip(new float3x3(1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f)); RoundTrip(new rect(-1f, -2f, 5f, 7f)); RoundTrip(new CultCellular(new float4(1, 2, 3, 4), new float4(5, 6, 7, 8), 0.25f)); + RoundTrip(new CultPhasor(new float4(1, 2, 3, 4), new float4(5, 6, 7, 8))); } [Test] @@ -132,6 +133,10 @@ namespace GameCult.Caching.Tests "94CA3F800000CA40000000CA40400000CA40800000" + "94CA40A00000CA40C00000CA40E00000CA41000000" + "CA3E800000"); + Hex(new CultPhasor(new float4(1f, 2f, 3f, 4f), new float4(5f, 6f, 7f, 8f))).Should().Be( + "92" + + "94CA3F800000CA40000000CA40400000CA40800000" + + "94CA40A00000CA40C00000CA40E00000CA41000000"); } [Test]