From 53d2f117800de3b582f7668d9867d7025b07a30d Mon Sep 17 00:00:00 2001 From: soul Date: Tue, 10 Nov 2026 14:35:10 +0000 Subject: [PATCH] Contracts: extra slots are read-only, not ignored Co-Authored-By: Claude Sonnet 5.5 --- .../Contracts/cultcache-persistence-format.md | 11 ++++++++--- .../Contracts/cultcache-schema-compatibility.md | 13 ++++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/GameCult.Caching/Contracts/cultcache-persistence-format.md b/src/GameCult.Caching/Contracts/cultcache-persistence-format.md index 93faf63f..851d261e 100644 --- a/src/GameCult.Caching/Contracts/cultcache-persistence-format.md +++ b/src/GameCult.Caching/Contracts/cultcache-persistence-format.md @@ -202,6 +202,12 @@ flatten, remove, commit) is refused with the typed schema conflict before anythi Declaring its id compatible on any registered type makes it writable and is the consent to the loss: the next write stores it under the writing type's own id and sheds the slots. +A record whose payload carries a slot past the slots its reader declares, at any depth (nested object, list +element, union arm, unit arm), is read-only the same way, whatever id it is stored under. The one consent +is the declaration above, and it reaches only depth-0 slots the schema comparison reports ignored under a +listed compatible id: a mark anywhere else, or at depth 0 under the reader's own id, is not consented to. +`CultCache.IsWritable(key)` answers the same question the staging refusal asks. + The rule is checked again where the write lands, under the store's lock: a write or removal at a key whose durable record is not owned, because another writer rewrote it after this cache loaded, is refused typed, and the record is reloaded as the store holds it, read-only when a type can @@ -535,15 +541,14 @@ Read directly when: Allowed when: - persisted schema has missing slots that the local schema can default -- persisted schema has extra slots the local reader can safely ignore or preserve - slot meanings remain compatible -Soft migration should emit warnings, not silent shrugs. +A persisted schema with extra slots the local reader lacks is not soft: the record is read-only (see the ownership +rule above). Soft migration should emit warnings, not silent shrugs. Typical warnings: - missing slot defaulted -- unknown extra slot ignored - nullable/default behavior widened - field preserved but not surfaced natively diff --git a/src/GameCult.Caching/Contracts/cultcache-schema-compatibility.md b/src/GameCult.Caching/Contracts/cultcache-schema-compatibility.md index dc7e7bea..c638050e 100644 --- a/src/GameCult.Caching/Contracts/cultcache-schema-compatibility.md +++ b/src/GameCult.Caching/Contracts/cultcache-schema-compatibility.md @@ -107,10 +107,21 @@ persisted slots honestly: - persisted schema id differs, but the embedded catalog points to a compatible local schema id -- persisted slot is missing locally and can be ignored +- persisted slot is missing locally and the record is read-only until its id is declared compatible + (see Extra slots are read-only, below) - local slot is missing in persisted data and can fall back to the local default value +Extra slots are read-only. A record whose payload carries a slot past the slots its reader declares, at any +depth (the record, a nested object, a list element, a union arm, a unit arm), is loaded read-only: it is +served, `CultStoredDocument.UnreadSlots` names the first type read with extra slots and both counts, and +`CultCache.IsWritable(key)` is false. A staged write or removal of it is refused with +`CultSchemaConflictException` (`UnreadSlots` set; the message names the type and the counts, never a slot +value). A missing trailing slot keeps its default and stays writable; a non-nil value in a retired gap below +the highest key is not extra. Declaring an id compatible consents only to depth-0 slots the schema comparison +reports ignored under that id; any other mark (nested, list element, arm, unit arm, or depth 0 under the +reader's own id) keeps the record read-only whatever is declared. + The cache emits a typed migration report with: - exact vs compatible-drift classification