Catalog writers merge entries that share an id; every reader resolves an id by its owner first

Entries that share a schema id are one schema seen by different writers, so the writer lists every id any of them lists, in any
order: C# single-file and directory (CultSchemaCatalogEntry.MergeById), TypeScript and Python. Rust synthesises one entry per id and
has no such merge. An id that one entry owns and another lists as compatible names the owner in Rust, TypeScript, Python and the TS
inspector, as C# already did (own-id-over-compatible-v3). Also: a directory manifest in an unreadable format is the typed refusal
naming it, cultnet-py applies and reports a record under the local schema id, and Rust's error prints its cause once.
Vectors for the Mesh layout discriminator: a nil and an integer at catalog slot 5.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-30 08:17:59 +02:00
commit f96a0e7f7a
20 changed files with 290 additions and 48 deletions

View file

@ -251,11 +251,11 @@ public sealed class DirectoryMessagePackBackingStore : CacheBackingStore
currentIndex[key] = ToIndexRecord(stored);
}
var catalogCandidates = currentManifest.SchemaCatalog
.Concat(_durableCatalog)
.Concat(Entries.Values.Select(entry => entry.Descriptor.ToCatalogEntry()))
.GroupBy(entry => entry.SchemaId, StringComparer.Ordinal)
.Select(group => group.Last())
var catalogCandidates = CultSchemaCatalogEntry.MergeById(
currentManifest.SchemaCatalog
.Concat(_durableCatalog)
.Concat(Entries.Values.Select(entry => entry.Descriptor.ToCatalogEntry())),
preferLast: true)
.ToArray();
var usedSchemaIds = currentIndex.Values.Select(record => record.SchemaId).ToHashSet(StringComparer.Ordinal);
var targetCatalog = catalogCandidates
@ -464,8 +464,9 @@ public sealed class DirectoryMessagePackBackingStore : CacheBackingStore
if (!string.Equals(snapshot.FormatVersion, IndexedFormatVersion, StringComparison.Ordinal) &&
!string.Equals(snapshot.FormatVersion, IndexedFormatVersionWithIds, StringComparison.Ordinal))
{
throw new InvalidOperationException(
$"Directory store {_manifestFile.FullName} is {snapshot.FormatVersion}; only {IndexedFormatVersion} and {IndexedFormatVersionWithIds} are readable.");
throw new CultStoreUnreadableException(
$"Directory store {_manifestFile.FullName} is {snapshot.FormatVersion}; only {IndexedFormatVersion} and {IndexedFormatVersionWithIds} are readable.",
_manifestFile.FullName);
}
return snapshot;

View file

@ -28,6 +28,33 @@ namespace GameCult.Caching
public string[] CompatibleSchemaIds { get; set; } = Array.Empty<string>();
public CultSchemaMemberCatalogEntry[] Members { get; set; } = Array.Empty<CultSchemaMemberCatalogEntry>();
// One entry per schema id, whatever order the candidates come in: entries that share an id are one schema seen by different
// writers, so the entry written lists every id any of them lists, and its other fields are the first's (or the last's).
internal static IEnumerable<CultSchemaCatalogEntry> MergeById(IEnumerable<CultSchemaCatalogEntry> entries, bool preferLast = false)
{
foreach (var group in entries.GroupBy(entry => entry.SchemaId, StringComparer.Ordinal))
{
var members = group.ToArray();
var chosen = preferLast ? members[^1] : members[0];
if (members.Length == 1)
{
yield return chosen;
continue;
}
yield return new CultSchemaCatalogEntry
{
SchemaId = chosen.SchemaId,
SchemaName = chosen.SchemaName,
SchemaVersion = chosen.SchemaVersion,
ContentHash = chosen.ContentHash,
CanonicalSchemaJson = chosen.CanonicalSchemaJson,
CompatibleSchemaIds = members.SelectMany(entry => entry.CompatibleSchemaIds).Distinct(StringComparer.Ordinal).ToArray(),
Members = chosen.Members
};
}
}
}
public sealed class CultSchemaMemberCatalogEntry
@ -3637,9 +3664,7 @@ namespace GameCult.Caching
var snapshot = new CultPersistedStoreSnapshot
{
FormatVersion = HeaderFor(holdsElementIds, existingHeader, wholeStore, directoryStore: false, holdsVariants: ordered.Any(record => record.Variant != null)),
SchemaCatalog = catalog
.GroupBy(entry => entry.SchemaId, StringComparer.Ordinal)
.Select(group => group.First())
SchemaCatalog = CultSchemaCatalogEntry.MergeById(catalog)
// An entry stays while it publishes a schema id some record carries, as its own id or a compatible one.
.Where(entry => used.Contains(entry.SchemaId) || entry.CompatibleSchemaIds.Any(used.Contains))
.OrderBy(entry => entry.SchemaName, StringComparer.Ordinal)

View file

@ -7,6 +7,7 @@
<ItemGroup>
<InternalsVisibleTo Include="GameCult.Caching.Tests" />
<InternalsVisibleTo Include="GameCult.Mesh" />
<InternalsVisibleTo Include="GameCult.Caching.MessagePack" />
</ItemGroup>
<ItemGroup>