Compare commits

..
Author SHA1 Message Date
Libby
b36cf5ed91 cultcache-py: convert keeps the source store's header; README and CHANGELOG state the format limits exactly; stale references fixed
All checks were successful
CultMesh portability and performance / ubuntu-latest reactive semantics and leases (pull_request) Successful in 24m50s
Soul pass on #179: a v3 source converted to v1 (now carried, pinned by the v3-base vector and
mutation-checked); README states the one-digit JSON exception once and the object-slot byte
difference from C#; CHANGELOG records the entry-type codec inheritance, the doubled walk and the
accepted JSON depth refusal; the store-reader docstring and test name no longer overstate
'codec alone'; stale payload_decoder/_refuse_past_depth_limit references fixed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-17 02:21:05 +00:00
Libby
2267c81866 cultcache-py: define_document_type defaults to MessagePack payloads; a definition's PayloadCodec owns its format; convert writes a new store (py-msgpack-default)
Some checks failed
CultMesh portability and performance / ubuntu-latest reactive semantics and leases (pull_request) Has been cancelled
Ports hands/py-msgpack-default (20 commits) onto main as one squash. Main's one-value
payload read (bytes after the first value refused by count, depth first, plain
ValueError), update-with-retry, stamp hardening and store lock/commit path are kept;
the codec replaces payload_encoder/payload_decoder. JSON_PAYLOAD_CODEC reads 0.3
stores; convert(source, destination, definitions) rewrites them to a new store.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-17 02:06:35 +00:00
3 changed files with 4 additions and 79 deletions

View file

@ -13,7 +13,6 @@ only in git history.
### Changed ### Changed
- `CultCache::delete::<T>` of a key nothing holds now refuses, as `put` and `is_writable` do, when `T` has no home store ("No backing store is registered…") or when a store carries a foreign record at the key or another registered type holds it (before: `Ok(false)`).
- `is_stored_at_stamp(&str)` (new, public) is the one shape a peer's `storedAt` must parse as, pinned by `tests/vectors/stored-at-stamp` (RFC 3339 `YYYY-MM-DDThh:mm:ss`, a 1 to 9 digit fraction, `Z` or `+hh:mm`/`-hh:mm`; uppercase `T`/`Z`, a real date, seconds 00-59, years 0001-9999), hand-checked because `chrono`'s RFC 3339 reader takes other shapes. `put_raw_envelope` and `put_prepared_batch` refuse a `stored_at` that is not a stamp (before: only a blank one) and mint nothing (variants:ruling:raw-put-without-stamp-refused). - `is_stored_at_stamp(&str)` (new, public) is the one shape a peer's `storedAt` must parse as, pinned by `tests/vectors/stored-at-stamp` (RFC 3339 `YYYY-MM-DDThh:mm:ss`, a 1 to 9 digit fraction, `Z` or `+hh:mm`/`-hh:mm`; uppercase `T`/`Z`, a real date, seconds 00-59, years 0001-9999), hand-checked because `chrono`'s RFC 3339 reader takes other shapes. `put_raw_envelope` and `put_prepared_batch` refuse a `stored_at` that is not a stamp (before: only a blank one) and mint nothing (variants:ruling:raw-put-without-stamp-refused).
- The single-file store's `push`, `push_all` and `commit_if` stamp a replacing write strictly later than the record it replaces at the same key (a staged stamp stands only when it parses and is strictly later; otherwise the stamp is minted as the replaced stamp plus one microsecond, or now if later), with no identical-content exception, as C# does. A stamp with no successor (the replaced stamp is at year 9999's last microsecond) refuses the write and writes nothing, as C# `MintStoredAt` does. `commit_if` replaces only the record of the entry's own type under the key, so a retype is refused as `push` refuses it. The cache holds the stamp the store wrote. The redb stores and the store-level exact-envelope writes (`compare_and_swap_entry` and its family) still write the caller's envelope unchanged. - The single-file store's `push`, `push_all` and `commit_if` stamp a replacing write strictly later than the record it replaces at the same key (a staged stamp stands only when it parses and is strictly later; otherwise the stamp is minted as the replaced stamp plus one microsecond, or now if later), with no identical-content exception, as C# does. A stamp with no successor (the replaced stamp is at year 9999's last microsecond) refuses the write and writes nothing, as C# `MintStoredAt` does. `commit_if` replaces only the record of the entry's own type under the key, so a retype is refused as `push` refuses it. The cache holds the stamp the store wrote. The redb stores and the store-level exact-envelope writes (`compare_and_swap_entry` and its family) still write the caller's envelope unchanged.
- The single-file store re-checks for a link once the store lock is held (every write and the try-exchange), so a link put at the path while a writer waited on the lock is refused with `StoreLinkedError` and the lock released, as C# does, instead of being replaced. Pinned by a test that puts the link while a second holder owns the lock. - The single-file store re-checks for a link once the store lock is held (every write and the try-exchange), so a link put at the path while a writer waited on the lock is refused with `StoreLinkedError` and the lock released, as C# does, instead of being replaced. Pinned by a test that puts the link while a second holder owns the lock.

View file

@ -3487,8 +3487,6 @@ impl CultCache {
/// The one decode behind every write entry and [`CultCache::is_writable`]: the held envelope at `(type_id, key)` /// The one decode behind every write entry and [`CultCache::is_writable`]: the held envelope at `(type_id, key)`
/// read under the registered type's mark. /// read under the registered type's mark.
/// Each write over a held key pays one full typed decode of the held payload (about 40% of a `put` of a 200,000-element
/// record, measured in release); this cost is accepted deliberately, with no cached mark, so the check keeps no second state.
fn held_finding(&self, type_id: &str, key: &str) -> Result<HeldFinding> { fn held_finding(&self, type_id: &str, key: &str) -> Result<HeldFinding> {
let Some(definition) = self.definitions.get(type_id) else { let Some(definition) = self.definitions.get(type_id) else {
bail!("No entry type registered for CultCache envelope type {type_id:?}"); bail!("No entry type registered for CultCache envelope type {type_id:?}");
@ -3987,22 +3985,15 @@ impl CultCache {
self.require_loaded()?; self.require_loaded()?;
self.require_entry_type::<T>()?; self.require_entry_type::<T>()?;
self.refuse_unread_slots(T::TYPE, key)?; self.refuse_unread_slots(T::TYPE, key)?;
let home = self.home_index(T::TYPE)?;
let id = entry_id_parts(T::TYPE, key); let id = entry_id_parts(T::TYPE, key);
let Some(entry) = self.entries.get(&id).cloned() else { let Some(entry) = self.entries.get(&id).cloned() else {
// The retype judge a write runs: a foreign record or another registered type holding the key refuses the removal. if let Some((_, foreign)) = self.foreign.iter().find(|(_, foreign)| foreign.key == key) {
let probe = CultCacheEnvelope { return Err(foreign_conflict(foreign, T::TYPE));
key: key.to_string(), }
r#type: T::TYPE.to_string(),
payload: Vec::new(),
stored_at: String::new(),
schema_id: None,
};
self.refuse_retype(&self.entries, &self.foreign, &probe)?;
return Ok(false); return Ok(false);
}; };
let released = self.projected_slots(&entry)?; let released = self.projected_slots(&entry)?;
if let Some(home) = home { if let Some(home) = self.home_index(T::TYPE)? {
self.stores[home].store.delete(&entry)?; self.stores[home].store.delete(&entry)?;
} }
self.entries.remove(&id); self.entries.remove(&id);

View file

@ -477,21 +477,6 @@ fn is_writable_is_false_for_a_type_with_no_home_store() {
assert!(cache.is_writable(SlotUnit::TYPE, "k").unwrap()); assert!(cache.is_writable(SlotUnit::TYPE, "k").unwrap());
} }
// For a homeless type, is_writable, put and delete of an unheld key agree: removal is refused like the write, not answered false.
#[test]
fn delete_of_an_unheld_key_of_a_type_with_no_home_store_is_refused_like_the_put() {
let dir = tempfile::tempdir().unwrap();
let mut cache = registered();
cache.add_backing_store(SingleFileMessagePackBackingStore::new(dir.path().join("s.cc")), [SlotUnit::TYPE]).unwrap();
cache.pull_all_backing_stores().unwrap();
assert!(!cache.is_writable(UnionSurface::TYPE, "k").unwrap());
let error = cache.delete::<UnionSurface>("k").unwrap_err();
assert!(error.to_string().contains("No backing store is registered"), "{error:#}");
// A homed type's unheld delete is still a plain false.
assert!(cache.is_writable(SlotUnit::TYPE, "k").unwrap());
assert!(!cache.delete::<SlotUnit>("k").unwrap());
}
#[test] #[test]
fn load_soa_refuses_a_same_length_replacement_of_a_marked_record() { fn load_soa_refuses_a_same_length_replacement_of_a_marked_record() {
use cultcache_rs::CultCacheSoaTable; use cultcache_rs::CultCacheSoaTable;
@ -554,53 +539,3 @@ fn a_store_with_marked_records_and_a_tail_is_refused_and_its_cache_writes_nothin
} }
assert_eq!(std::fs::read(&path).unwrap(), before); assert_eq!(std::fs::read(&path).unwrap(), before);
} }
// Attaching a store to a cache whose load was refused must keep the refusal: the write refusal still names why the load
// failed, not merely that the cache has not pulled. (Only a pulled cache falls back to unpulled when a store is attached.)
#[test]
fn a_store_attached_after_a_refused_load_keeps_the_refusal_reason() {
use cultcache_rs::CacheBackingStore;
use cultcache_rs::CultCacheLoadRefused;
let (_held, dir, path) = held_marked_and_clean();
let mut tailed = vector("union-surface.msgpack");
tailed.push(0xc0);
SingleFileMessagePackBackingStore::new(&path).push(&envelope("tailed", tailed)).unwrap();
let mut cache = registered();
cache.add_generic_backing_store(SingleFileMessagePackBackingStore::new(&path)).unwrap();
assert!(cache.pull_all_backing_stores().is_err());
cache.add_backing_store(SingleFileMessagePackBackingStore::new(dir.path().join("routed.cc")), [SlotUnit::TYPE]).unwrap();
let error = cache.put("new", &constructed()).unwrap_err();
let refused = error.downcast_ref::<CultCacheLoadRefused>().unwrap_or_else(|| panic!("{error:#}"));
assert!(refused.reason.contains("bytes after"), "refusal reason lost: {}", refused.reason);
}
// A key held by another registered type, or carried as a foreign record: put, is_writable and typed delete all refuse, and
// delete refuses with the put's conflict (delete used to answer Ok(false)). This agreement is for those two cases; for a
// type with no home store delete's home-store error comes before the retype judge, and both still refuse.
#[test]
fn delete_of_a_key_held_by_another_registered_type_is_refused_like_the_put() {
let (mut cache, _dir, _path) = held_marked_and_clean();
assert!(!cache.is_writable(SlotUnit::TYPE, "clean").unwrap());
let put = cache.put("clean", &SlotUnit { name: "n".into(), outcome: UnitOutcome::Denied }).unwrap_err();
let delete = cache.delete::<SlotUnit>("clean").unwrap_err();
let (put, delete) = (conflict(&put), conflict(&delete));
assert_eq!(delete.record_key, "clean");
assert_eq!(delete.record_key, put.record_key);
assert_eq!(delete.schema_names, put.schema_names);
assert!(delete.schema_names.contains(&UnionSurface::TYPE.to_string()), "{:?}", delete.schema_names);
assert!(cache.snapshot_envelopes().iter().any(|held| held.key == "clean" && held.r#type == UnionSurface::TYPE));
// A foreign record at the key: only UnionSurface registered, the store's unit-arm record is foreign here.
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("extra-slot-store.cc");
std::fs::write(&path, without_variant_row(&vector("extra-slot-store.cc"))).unwrap();
let mut cache = CultCache::new();
cache.register_entry_type::<UnionSurface>().unwrap();
cache.add_generic_backing_store(SingleFileMessagePackBackingStore::new(&path)).unwrap();
cache.pull_all_backing_stores().unwrap();
assert!(!cache.is_writable(UnionSurface::TYPE, "unit-arm").unwrap());
let put = cache.put("unit-arm", &constructed()).unwrap_err();
let delete = cache.delete::<UnionSurface>("unit-arm").unwrap_err();
assert_eq!(conflict(&delete).record_key, "unit-arm");
assert_eq!(conflict(&delete).schema_names, conflict(&put).schema_names);
}