CultLib/packages/cultcache-py/CHANGELOG.md

9.7 KiB

Changelog

Unreleased

Added

  • read_payload_tree(type_name, payload, decoder=None): the exported owner of the one-value, depth-first payload read that decode_payload uses, for payloads read outside a definition (cultnet-py's witness bundle decode needs it, so cultnet-py now requires cultcache-py>=0.4.0). The manifest version is 0.4.0, the minor these Unreleased breaking changes imply, set in this change so the workspace install resolves the new bound; the ## Unreleased heading becomes ## [0.4.0] when it is tagged.

Changed

  • msgpack is a hard dependency, as pyproject.toml declared it. The optional-import fallbacks and the cultcache-py[msgpack] extra they named (which never existed) are gone: a missing msgpack is an ImportError at import.
  • The single-file store's push, push_all and delete take the cross-process lock on <path>.lock (flock; LockFileEx over the whole file on Windows) across the read and the replace, waiting up to lock_timeout seconds (30 by default, TimeoutError after), and exclude the C#, Rust and TypeScript runtimes' writers. The staged file is <path>.tmp-<pid>-<uuid>, fsynced before the replace, with a directory fsync after it off Windows. A fixed <path>.tmp is no longer used.

Breaking

  • A record whose payload carries a slot past its reader's declared slots, at any depth (the document, a nested record, a list element, a union arm, a unit arm), is read, held read-only, and every write or removal of its key (put, put_global, update, put_envelope, put_envelopes, delete, delete_global) is refused with SchemaConflictError before any store is touched (cultlib-gaps:ruling:extra-trailing-slots). Reading dropped those slots silently and the next write shed them. SchemaConflictError.unread_slots is an UnreadSlots(type_name, slot_count, declared_count, occurrences, depth0_only) and the message names the type and both counts, never a slot value. A depth-0 mark is consented, and the record writable, only when the record is stored under an id the document lists in compatible_schema_ids and that id's catalog entry has slots past the document's, covering the mark's slot count (cultlib-gaps:ruling:slot-mark-consent); a nested mark, or a mark under the document's own id, keeps the record read-only whatever is declared. Missing trailing slots keep their declared defaults. An untouched marked record keeps its stored bytes through every other write. Added CultCache.is_writable(document, key) (advisory; the write still decides: it also answers False for a foreign-carried key, for a key held as a type the document does not own, and for a global document at a non-global key; delete asks the same judges, so removing a key held as another type is refused with SchemaConflictError unless the document owns that record's schema id (its own or one it lists compatible), in which case the removal removes that record, its file row and its lookups, as a write of the key would replace it; it returned silently and removed nothing), DocumentDefinition.decode_payload_marked, and UnreadSlots. A document with a custom decode (no slot codec) never marks. A store holding a variant record is still unreadable here. Implies a minor bump while the version is 0.x (0.3.0 to 0.4.0): code that wrote back a record from a newer writer now gets SchemaConflictError.

  • A payload is one MessagePack value: DocumentDefinition.decode_payload refuses bytes after it, by count, with ValueError <type> payload has N bytes after its first MessagePack value (refused on read). (never the bytes, never the depth refusal; a payload that ends early stays the decoder's), as the C# reference does (tests/vectors/union-parity/bytes-after-outcomes.msgpack). It raised msgpack.ExtraData (a ValueError, so only a caller naming msgpack.ExtraData is affected); this is a minor-version bump while pre-1.0. The refused set is unchanged. Cache loads, get and every definition built on the MessagePack decoder go through it; a user payload_decoder that raises ExtraData is refused the same way. Depth is judged first, so a value nested past 256 with a tail is the depth refusal, as in C#.

  • A cache holds one record per key whatever its type (variants:ruling:cache-refuses-retype). A put, put_envelope, put_envelopes or put_global of a second type under a key the cache holds, or under a key a store carries foreign, is refused with SchemaConflictError naming the key, even with no store, and changes nothing; retype a key by deleting it, then putting the new type. A write may replace another registered type's record only when the written type owns its schema id (declares it or lists it compatible) and both types share one home store. A load that reads one key from two stores, whatever the types, is refused with CultCacheError naming the key and both types, and admits nothing. A store that holds a record no registered type claims now loads and is carried: the cache does not serve it, the store keeps its bytes through every write, delete or put at its key is refused with SchemaConflictError, and registering a type that declares its schema id claims it at the next load. It raised CultCacheError "Unknown persisted document type". Two global types share the key __global__, so a second global type in one cache is now refused, and a store that already holds two global types at __global__ (a JSONL store written by caches that never pulled could produce one) no longer loads: the pull raises CultCacheError and admits nothing. C# refuses a second persisted global on pull the same way (cultcache-store-composition.md, "Globals never invented"); repair such a file by deleting one of the two records with the runtime that wrote it.

  • Added foreign_records() and the frozen ForeignRecord(key, schema_id, schema_name, stored_at), sorted by key in UTF-16 code-unit order. stores.retyped and stores.written_owns lose their underscore: the cache judge and the single-file store's commit guard ask one predicate.

  • A single-file store holding two records under one key is unreadable: the v1 reader and the legacy envelope-array reader refuse it with StoreUnreadableError (a key is compared by its exact code points, no case folding or normalisation). A catalog slot whose canonical schema is not a string is refused the same way. A store that loaded before can now be refused: repair it with the runtime that wrote the duplicate.

  • A put or push_all that would land a second type under a key the store holds is refused with SchemaConflictError, and the file is left as it was. Retype a key by deleting it, then putting the new type. A write replaces the record at a key only when the written type owns it: its catalog entry declares the stored schema id (its own, or one it lists compatible), so a renamed type that lists the old id compatible may replace the record, or it has the stored record's schema name. This runtime does not compare shapes, so a same-name type is never refused for dropping persisted slots as C# refuses it.

  • Writes of the same type replace by key: the last record wins, in a batch as in the file.

  • indexes are unique, as C# [CultIndex]: a write, load or register_index that leaves two records of a type holding one non-blank value under one alias is refused (CultCacheError) naming both keys and the alias, and writes nothing. Index text is the C# canonical text (True/False, integers as digits, floats as the exact expansion, blank values never indexed), so an empty or whitespace string is no longer a value. A new roles map names the many-row selection aliases (never indexed for lookup, same catalog index_alias). Classify every indexes key per the README before updating. The verdict is the contract, the text is informational.

  • A single-file store written as cultcache.store.v3 is read and written: a store the C# runtime marked v3 (it holds a record with an element id: an owned list element with a [CultElementId] member) keeps its header here, and is carried through every rewrite with its ids; this runtime never drops the mark. A runtime from before this change refuses a v3 store by name. Rolling back to an older release after a store has been written as v3 is one-way: there is no carry-back, so restore from a copy taken before upgrading.

  • A write over a file the reader refuses (StoreUnreadableError, from push, push_all and delete) refuses and leaves the file as it is. A flush used to replace such a file. A write set cannot merge with a disk it cannot read, so the file is repaired or removed by its owner before the store writes again.

  • Added StoreUnreadableError (a ValueError) for a store file this runtime cannot read, and SchemaConflictError (a ValueError) for a write the catalog cannot describe. A store is exactly three slots; a schema is never recovered from a record's payload.

  • The single-file writer derives the catalog from the records it writes: one entry per carried schema id, the registered entry over an arrived one, written as chosen and never merged. A cache stamps a record with its registered schema's id.

  • Every registration refusal is now a SchemaConflictError, a ValueError, where it was a CultCacheError, a RuntimeError: registering a document type or a schema name twice no longer raises what except CultCacheError or except RuntimeError catches.

  • Two documents that own one schema id are refused at registration (SchemaConflictError). 2.0.1 accepted them. A document may still list another's id as compatible.

  • A loaded record resolves by its schema id first: the document that owns the id, else the one document that lists it as compatible; several listers and no owner refuse the record with SchemaConflictError. The record's type name resolves it only when its schema id names no registered document. 2.0.1 resolved by the record's type name alone.