Integrate geometry worker through CultMesh

This commit is contained in:
Meta Vens 2026-07-22 04:01:20 +01:00
commit 9758940b35
5 changed files with 424 additions and 10 deletions

View file

@ -4,7 +4,7 @@ Plan: `docs/cultmath-gamecult-geometry-migration-plan.md` (locked)
Started: 2026-07-22
Status: Stages 0-4 complete; Stage 5 in progress
Status: Stages 0-5 complete; Stage 6 in progress
## Objective
@ -59,8 +59,8 @@ Demotions:
| 2. Primitive deletion and v2 schemas | Complete | C# and Geometry-owned Rust emit identical v2 bytes and record keys for all four roots |
| 3. Planetary transfer | Complete | Managed, HLSL, CMPT, Unity, web, tool, docs, tests, and package authority moved; CultMath owners deleted |
| 4. Mine `vg-csg` | Complete | Geometry-owned Rust kernel passes correctness, parity, performance, formatting, and warning-denied lint gates |
| 5. CultCache/CultNet/CultMesh integration | In progress | Provider/dataflow mapped; typed commit-path smoke remains |
| 6. Consumer cutover/release | Pending | Requires local candidate feed and downstream passes |
| 5. CultCache/CultNet/CultMesh integration | Complete | One provider commit path persists, watches, replicates, and probes typed geometry state |
| 6. Consumer cutover/release | In progress | Fensalir/Aetheria exact cutover surfaces mapped; consumer edits and release receipts remain |
| 7. Delete obsolete authorities/audit | Pending | Requires every prior stage gate |
## Verification Receipts
@ -244,13 +244,32 @@ a broader stage gate.
passes 67/67 plus doc tests; rustfmt and warning-denied Clippy pass.
- The authority transfer commits are CultLib `756f5a33`, CultMath `6a16260`,
and the post-transfer label cleanup `99c893bd`. The Rust absorption commit is
recorded after this progress update is committed.
CultLib `6b44f969`.
### Stage 5 receipts
- `CultGeometryWorkerProvider` owns the build invocation and output commit
sequence. Direct calls and the `gamecult.geometry.worker.build` CultMesh
operation share `BuildAsync`; compute is injected through the persistence-free
`ICultGeometryBuildPipeline` port.
- Domain/request reads and selected-cut, artifact, and observational worker-state
writes use `CultNetDatabase` typed APIs. Watches and raw MessagePack envelopes
are consequences of that commit path rather than parallel publishers.
- The development probe derives owner, v2 schema, request/cut keys, selected
nodes, artifact identities, content hashes, and served assembly version from
persisted documents. Mutating worker display state cannot overwrite geometry
outputs or forge the served version.
- Worker state registers through the generated CultDocument registry. Focused
provider tests pass 4/4 and the full GameCult.Geometry suite passes 31/31.
- Rust raw-envelope duplication was deliberately omitted: CultNet owns that
protocol. Existing C#/Rust exact v2 document bytes and record keys remain the
cross-runtime geometry witness.
## Next Actions
1. Add the Geometry-owned worker provider with `CultNetDatabase.PutAsync` as
the single commit/publication primitive for direct and operation-handle use.
2. Prove domain/request to selected-cut/artifact persistence, raw envelope
replication, worker-state observation, and typed dev-probe agreement.
3. Add exact C#/Rust raw-envelope parity without growing a second networking
stack or a load-bearing JSON projection.
1. Cut Fensalir's C# and HLSL planetary surfaces atomically to
GameCult.Geometry, including shader resolver and parity harnesses.
2. Replace Aetheria Freeze's remaining `CultVec*` fixtures with CultMath values
under an exact serialization witness, then regenerate Unity project files.
3. Rebuild coordinated CultMath and Geometry candidates and run the named
downstream parity corpus before publication.

View file

@ -0,0 +1,87 @@
using System;
using GameCult.Caching;
using MessagePack;
namespace GameCult.Geometry
{
public static class CultGeometryWorkerSchemaVersions
{
public const string State = "gamecult.geometry.worker_state.v1";
}
[MessagePackObject]
[CultDocument("gamecult.geometry.worker_state", CultGeometryWorkerSchemaVersions.State)]
public sealed class CultGeometryWorkerState
{
[Key(0), CultName]
public string WorkerId { get; set; } = string.Empty;
[Key(1)]
public string Phase { get; set; } = string.Empty;
[Key(2), CultReference(typeof(CultGeometryBuildRequest))]
public string ActiveRequestKey { get; set; } = string.Empty;
[Key(3), CultReference(typeof(CultGeometrySelectedCutManifest))]
public string LastSelectedCutKey { get; set; } = string.Empty;
[Key(4)]
public string[] LastArtifactKeys { get; set; } = Array.Empty<string>();
[Key(5)]
public string LastError { get; set; } = string.Empty;
[Key(6)]
public string UpdatedAt { get; set; } = string.Empty;
[Key(7)]
public string ServedPackageVersion { get; set; } = string.Empty;
public static CultRecordKey CreateRecordKey(string workerId)
{
if (string.IsNullOrWhiteSpace(workerId)) throw new ArgumentException("Value must be non-empty.", nameof(workerId));
return new CultRecordKey("geometry:worker:" + workerId);
}
}
[MessagePackObject]
public sealed class CultGeometryBuildCommand
{
[Key(0)]
public string RequestKey { get; set; } = string.Empty;
}
[MessagePackObject]
public sealed class CultGeometryBuildReceipt
{
[Key(0)]
public string RequestKey { get; set; } = string.Empty;
[Key(1)]
public string SelectedCutKey { get; set; } = string.Empty;
[Key(2)]
public string[] ArtifactKeys { get; set; } = Array.Empty<string>();
[Key(3)]
public string[] ContentHashes { get; set; } = Array.Empty<string>();
}
public sealed class CultGeometryBuildOutput
{
public CultGeometrySelectedCutManifest SelectedCut { get; init; } = new();
public CultGeometryChunkArtifact[] Artifacts { get; init; } = Array.Empty<CultGeometryChunkArtifact>();
}
public sealed class CultGeometryDevelopmentProbe
{
public string Owner { get; init; } = string.Empty;
public string SchemaVersion { get; init; } = string.Empty;
public string SourceRecordKey { get; init; } = string.Empty;
public string SelectedCutKey { get; init; } = string.Empty;
public string[] SelectedNodes { get; init; } = Array.Empty<string>();
public string[] ArtifactKeys { get; init; } = Array.Empty<string>();
public string[] ContentHashes { get; init; } = Array.Empty<string>();
public string ServedPackageVersion { get; init; } = string.Empty;
}
}

View file

@ -0,0 +1,124 @@
using System;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using GameCult.Caching;
using GameCult.Mesh;
using GameCult.Networking;
namespace GameCult.Geometry
{
public interface ICultGeometryBuildPipeline
{
Task<CultGeometryBuildOutput> BuildAsync(
CultGeometryDomainDocument domain,
CultGeometryBuildRequest request);
}
/// <summary>Owns geometry worker commands and the authoritative output commit path.</summary>
public sealed class CultGeometryWorkerProvider
{
public const string Owner = "GameCult.Geometry";
public const string BuildOperationId = "gamecult.geometry.worker.build";
private readonly string _workerId;
private readonly CultNetDatabase _database;
private readonly ICultGeometryBuildPipeline _pipeline;
public CultGeometryWorkerProvider(
string workerId,
CultNetDatabase database,
ICultGeometryBuildPipeline pipeline)
{
_workerId = string.IsNullOrWhiteSpace(workerId)
? throw new ArgumentException("Value must be non-empty.", nameof(workerId))
: workerId;
_database = database ?? throw new ArgumentNullException(nameof(database));
_pipeline = pipeline ?? throw new ArgumentNullException(nameof(pipeline));
BuildOperation = new CultMeshOperationHandle<CultGeometryBuildCommand, CultGeometryBuildReceipt>(
BuildOperationId,
(command, _) => BuildAsync(command));
}
public CultMeshOperationHandle<CultGeometryBuildCommand, CultGeometryBuildReceipt> BuildOperation { get; }
public CultRecordKey WorkerStateKey => CultGeometryWorkerState.CreateRecordKey(_workerId);
public async Task<CultGeometryBuildReceipt> BuildAsync(CultGeometryBuildCommand command)
{
if (command == null) throw new ArgumentNullException(nameof(command));
if (string.IsNullOrWhiteSpace(command.RequestKey))
throw new ArgumentException("Request key must be non-empty.", nameof(command));
var requestKey = new CultRecordKey(command.RequestKey);
var request = await RequireAsync<CultGeometryBuildRequest>(requestKey).ConfigureAwait(false);
var domain = await RequireAsync<CultGeometryDomainDocument>(new CultRecordKey(request.DomainKey)).ConfigureAwait(false);
var output = await _pipeline.BuildAsync(domain, request).ConfigureAwait(false)
?? throw new InvalidOperationException("Geometry build pipeline returned no output.");
output.SelectedCut.RequestKey = requestKey.Value;
var cutKey = CultGeometrySelectedCutManifest.CreateRecordKey(output.SelectedCut);
await _database.PutAsync(cutKey, output.SelectedCut).ConfigureAwait(false);
var artifactKeys = new string[output.Artifacts.Length];
for (var index = 0; index < output.Artifacts.Length; index++)
{
var artifact = output.Artifacts[index];
artifact.CutKey = cutKey.Value;
artifact.SelectedCutId = output.SelectedCut.CutId;
var artifactKey = CultGeometryChunkArtifact.CreateRecordKey(artifact);
await _database.PutAsync(artifactKey, artifact).ConfigureAwait(false);
artifactKeys[index] = artifactKey.Value;
}
var receipt = new CultGeometryBuildReceipt
{
RequestKey = requestKey.Value,
SelectedCutKey = cutKey.Value,
ArtifactKeys = artifactKeys,
ContentHashes = artifactKeys.Select(ContentHashFromKey).ToArray()
};
await _database.PutAsync(WorkerStateKey, new CultGeometryWorkerState
{
WorkerId = _workerId,
Phase = "completed",
ActiveRequestKey = requestKey.Value,
LastSelectedCutKey = cutKey.Value,
LastArtifactKeys = artifactKeys,
UpdatedAt = DateTimeOffset.UtcNow.ToString("O"),
ServedPackageVersion = PackageVersion
}).ConfigureAwait(false);
return receipt;
}
public async Task<CultGeometryDevelopmentProbe> ProbeAsync()
{
var state = await RequireAsync<CultGeometryWorkerState>(WorkerStateKey).ConfigureAwait(false);
var cut = await RequireAsync<CultGeometrySelectedCutManifest>(new CultRecordKey(state.LastSelectedCutKey)).ConfigureAwait(false);
return new CultGeometryDevelopmentProbe
{
Owner = Owner,
SchemaVersion = CultGeometrySchemaVersions.SelectedCut,
SourceRecordKey = state.ActiveRequestKey,
SelectedCutKey = state.LastSelectedCutKey,
SelectedNodes = cut.SelectedNodes,
ArtifactKeys = state.LastArtifactKeys,
ContentHashes = state.LastArtifactKeys.Select(ContentHashFromKey).ToArray(),
ServedPackageVersion = PackageVersion
};
}
private async Task<T> RequireAsync<T>(CultRecordKey key) where T : class =>
await _database.GetAsync<T>(key).ConfigureAwait(false)
?? throw new InvalidOperationException($"Required geometry document '{key.Value}' was not found.");
private static string ContentHashFromKey(string key) =>
key[(key.LastIndexOf(':') + 1)..];
private static string PackageVersion =>
typeof(CultGeometryWorkerProvider).Assembly
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion
?? typeof(CultGeometryWorkerProvider).Assembly.GetName().Version?.ToString()
?? "unknown";
}
}

View file

@ -13,6 +13,8 @@
<ItemGroup>
<ProjectReference Include="..\GameCult.Caching\GameCult.Caching.csproj" />
<ProjectReference Include="..\GameCult.Caching.MessagePack\GameCult.Caching.MessagePack.csproj" />
<ProjectReference Include="..\GameCult.Mesh\GameCult.Mesh.csproj" />
<ProjectReference Include="..\GameCult.Networking\GameCult.Networking.csproj" />
<PackageReference Include="CultMath" Version="$(CultMathVersion)" />
<PackageReference Include="MessagePack" Version="3.1.7" />
<PackageReference Include="System.Text.Json" Version="9.0.10" />

View file

@ -0,0 +1,182 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using CultMath;
using FluentAssertions;
using GameCult.Caching;
using GameCult.Mesh;
using GameCult.Networking;
using NUnit.Framework;
using R3;
namespace GameCult.Geometry.Tests
{
public sealed class CultGeometryWorkerProviderTests
{
[Test]
public async Task BuildOperation_UsesTheDirectCommitPath_AndPublishesTypedState()
{
using var database = CreateDatabase("geometry-worker");
var (domain, request) = await SeedAsync(database);
var provider = new CultGeometryWorkerProvider("worker-1", database, new FakePipeline());
var artifactChanges = new List<CultNetDatabaseChange<CultGeometryChunkArtifact>>();
using var subscription = database.Watch<CultGeometryChunkArtifact>()
.Subscribe(change => artifactChanges.Add(change));
var receipt = await provider.BuildOperation.InvokeAsync(
new CultGeometryBuildCommand { RequestKey = CultGeometryBuildRequest.CreateRecordKey(request).Value },
"test-runtime");
receipt.RequestKey.Should().Be(CultGeometryBuildRequest.CreateRecordKey(request).Value);
receipt.ArtifactKeys.Should().ContainSingle();
receipt.ContentHashes.Should().ContainSingle();
artifactChanges.Should().ContainSingle(change => change.Key.Value == receipt.ArtifactKeys[0]);
(await database.GetAsync<CultGeometrySelectedCutManifest>(new CultRecordKey(receipt.SelectedCutKey)))
.Should().NotBeNull();
(await database.GetAsync<CultGeometryChunkArtifact>(new CultRecordKey(receipt.ArtifactKeys[0])))
.Should().NotBeNull();
var state = await database.GetAsync<CultGeometryWorkerState>(provider.WorkerStateKey);
state.Should().NotBeNull();
state!.ActiveRequestKey.Should().Be(receipt.RequestKey);
state.LastSelectedCutKey.Should().Be(receipt.SelectedCutKey);
domain.DomainId.Should().Be("domain-1");
}
[Test]
public async Task DirectAndOperationBuilds_DeriveTheSameCanonicalOutputKeys()
{
using var database = CreateDatabase("geometry-direct-operation");
var (_, request) = await SeedAsync(database);
var provider = new CultGeometryWorkerProvider("worker-1", database, new FakePipeline());
var command = new CultGeometryBuildCommand
{
RequestKey = CultGeometryBuildRequest.CreateRecordKey(request).Value
};
var direct = await provider.BuildAsync(command);
var operation = await provider.BuildOperation.InvokeAsync(command, "test-runtime");
operation.SelectedCutKey.Should().Be(direct.SelectedCutKey);
operation.ArtifactKeys.Should().Equal(direct.ArtifactKeys);
operation.ContentHashes.Should().Equal(direct.ContentHashes);
}
[Test]
public async Task Artifact_RawEnvelopeReplicates_AndWorkerStateCannotOverrideProbeTruth()
{
using var source = CreateDatabase("geometry-source");
var (_, request) = await SeedAsync(source);
var provider = new CultGeometryWorkerProvider("worker-1", source, new FakePipeline());
var receipt = await provider.BuildAsync(new CultGeometryBuildCommand
{
RequestKey = CultGeometryBuildRequest.CreateRecordKey(request).Value
});
var artifactKey = new CultRecordKey(receipt.ArtifactKeys[0]);
var artifact = await source.GetAsync<CultGeometryChunkArtifact>(artifactKey);
artifact.Should().NotBeNull();
var put = source.Documents.CreateRawDocumentPutMessage(
"geometry-artifact",
new CultRecordHandle<CultGeometryChunkArtifact>(artifactKey),
artifact!,
new CultNetDocumentMessageOptions { SourceRuntimeId = "geometry-source", SourceRole = "geometry-worker" });
put.Document.PayloadEncoding.Should().Be("messagepack");
var targetCache = new CultCache();
var replicated = await source.Documents.ApplyRawDocumentPutMessageAsync<CultGeometryChunkArtifact>(targetCache, put);
CultGeometryChunkArtifact.CreateRecordKey(replicated).Should().Be(artifactKey);
await source.PutAsync(provider.WorkerStateKey, new CultGeometryWorkerState
{
WorkerId = "worker-1",
Phase = "lying-status",
ActiveRequestKey = receipt.RequestKey,
LastSelectedCutKey = receipt.SelectedCutKey,
LastArtifactKeys = receipt.ArtifactKeys,
ServedPackageVersion = "false-version"
});
var probe = await provider.ProbeAsync();
probe.Owner.Should().Be(CultGeometryWorkerProvider.Owner);
probe.SchemaVersion.Should().Be(CultGeometrySchemaVersions.SelectedCut);
probe.SelectedCutKey.Should().Be(receipt.SelectedCutKey);
probe.ContentHashes.Should().Equal(receipt.ContentHashes);
probe.ServedPackageVersion.Should().NotBe("false-version");
(await source.GetAsync<CultGeometryChunkArtifact>(artifactKey))!.ChunkId.Should().Be("chunk-1");
}
[Test]
public void WorkerState_RegistersThroughTheGeneratedDocumentRegistry()
{
var descriptor = new CultCache().Registry.GetRequired<CultGeometryWorkerState>();
descriptor.SchemaVersion.Should().Be(CultGeometryWorkerSchemaVersions.State);
descriptor.SchemaName.Should().Be("gamecult.geometry.worker_state");
}
private static CultNetDatabase CreateDatabase(string runtimeId)
{
var cache = new CultCache();
return new CultNetDatabase(cache, new CultNetDatabaseOptions
{
RuntimeId = runtimeId,
DocumentRegistry = new CultNetDocumentRegistry(cache.Registry)
});
}
private static async Task<(CultGeometryDomainDocument Domain, CultGeometryBuildRequest Request)> SeedAsync(
CultNetDatabase database)
{
var domain = new CultGeometryDomainDocument
{
DomainId = "domain-1",
RootKey = "root",
SourceRuntime = "test",
Root = new CultGeometryDomainNode { Name = "root", Kind = "root" }
};
var domainKey = CultGeometryDomainDocument.CreateRecordKey(domain);
var request = new CultGeometryBuildRequest
{
RequestId = "request-1",
DomainKey = domainKey.Value,
WorkerGroup = "test",
ViewportHeightPixels = 1080,
VerticalFovRadians = 1,
TargetError = 0.01f,
TriangleBudget = 100,
ColliderBudget = 100
};
await database.PutAsync(domainKey, domain);
await database.PutAsync(CultGeometryBuildRequest.CreateRecordKey(request), request);
return (domain, request);
}
private sealed class FakePipeline : ICultGeometryBuildPipeline
{
public Task<CultGeometryBuildOutput> BuildAsync(
CultGeometryDomainDocument domain,
CultGeometryBuildRequest request)
{
return Task.FromResult(new CultGeometryBuildOutput
{
SelectedCut = new CultGeometrySelectedCutManifest
{
CutId = "cut-1",
SelectedNodes = [domain.Root.Name]
},
Artifacts =
[
new CultGeometryChunkArtifact
{
ChunkId = "chunk-1",
BoundsMin = float3.zero,
BoundsMax = new float3(1, 1, 1),
SourceDomainKeys = [request.DomainKey],
RenderMesh = new CultGeometryTriangleMesh()
}
]
});
}
}
}
}