Store readability: one typed refusal, one full reader, one store shape

CultStoreUnreadableException (a NotSupportedException) is the one refusal for a store file this runtime cannot read, thrown
by the single-file reader, the rewriting paths and CultMesh's reads, with the cause as the inner exception. The reader is exactly
one array of three slots (or an empty array): a header alone and an extra top-level slot are refused instead of read as empty or
skipped. CultMesh's older-catalog fallback is the same reader with the older entry reader, so it also requires one array.

Vectors: bad-body, header-only, missing-schema, variant-slot, extra-top-slot in the readability set, and a legacy-catalog store
with and without bytes after it for CultMesh. The persistence contract says what is true.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-30 04:06:44 +02:00
commit 436eed73e4
23 changed files with 186 additions and 84 deletions

View file

@ -230,14 +230,20 @@ rest, so a file already declared `v3` stays `v3` when it merges onto it. A direc
store's manifest says `cultcache.store.v5.directory-content-addressed-pages` under the
same rule, and `v4` otherwise.
A single-file store is exactly one MessagePack array. Every runtime refuses a file that is
truncated, has bytes after the array (a second store appended included), is not an array, or
whose first slot is not a header it reads; it refuses these on open and on rewrite alike. A
zero-byte file is an empty store. A flush or a commit replaces a file only when the
A single-file store is exactly one MessagePack array of three slots: the header, the schema
catalog and the records. Every runtime refuses a file that is truncated, has bytes after the
array (a second store appended included), is not an array, has fewer or more than three slots
(a header alone included), whose first slot is not a header it reads, or whose catalog or
records it cannot decode (a record with more slots than its header allows, a variant record
it does not read). A runtime never skips a slot it does not understand. It refuses on open
and on rewrite alike, because the rewrite asks the same full reader as the open. A zero-byte
file and an empty array are an empty store. A flush or a commit replaces a file only when the
runtime's own reader opens it, so one verdict covers open, flush and commit, and a file the
runtime cannot read is left as it is. Rust, TypeScript and Python also open the legacy
envelope array (an array of `key`/`type`/`payload`/`storedAt` maps) and replace it; C# has
no legacy reader and refuses it. The shared byte vectors and each runtime's verdict are
runtime cannot read is left as it is. Each runtime refuses with one typed error:
`CultStoreUnreadableException` (C#), `StoreUnreadableError` (Rust, TypeScript, Python), with
the underlying cause attached. Rust, TypeScript and Python also open the legacy envelope
array (an array of `key`/`type`/`payload`/`storedAt` maps) and replace it; C# has no legacy
reader and refuses it. The shared byte vectors and each runtime's verdict are
`tests/vectors/document-variants-c2a/readability/manifest.txt`.
## Variant Records

View file

@ -3419,8 +3419,9 @@ namespace GameCult.Caching
/// <summary>
/// This store's one reader of a non-empty store file, and so its one verdict on whether the file may be replaced: open,
/// flush and commit all ask it. It must throw for anything that is not exactly one store this runtime reads (a
/// truncated file, bytes after the store, a format it does not know), so a rewrite never overwrites a file it cannot see.
/// flush and commit all ask it. It must throw <see cref="CultStoreUnreadableException"/> for anything that is not exactly one
/// store this runtime reads (a truncated file, bytes after the store, a missing or extra slot, a format or record it does
/// not know), so a rewrite never overwrites a file it cannot see.
/// </summary>
protected abstract CultPersistedStoreSnapshot DeserializeSnapshot(byte[] data);

View file

@ -0,0 +1,18 @@
using System;
namespace GameCult.Caching
{
/// <summary>
/// A store file this runtime cannot read: not exactly one complete store (truncated, bytes after it, a value that is not a
/// store, a missing or extra top-level slot), a format or record it does not know, or a body it cannot decode. Open, flush,
/// commit and CultMesh's single-file reads all refuse a file with this one exception, and a refused file is left as it was.
/// The underlying cause, where there is one, is the inner exception.
/// </summary>
public sealed class CultStoreUnreadableException : NotSupportedException
{
public CultStoreUnreadableException(string message, Exception? innerException = null)
: base(message, innerException)
{
}
}
}