Both worktrees were removed afterwards; re-running needs that worktree recreated with the
two-line deletion.
| Id | Question | Result |
|---|---|---|
| Q1 | Does the real catalog open read-only with `ItemData` key 3 removed? | Opens. `LastSchemaMigrationReports`: 180 reports, 115 with `IgnoredExtraSlots` = {3}. 115 items, 102 crafted, 37 products; duplicate/maker/role counts as in §1.5. |
| Q2 | Does a `[CultGlobal]` ledger holding `Dictionary<int, Lot>` with a nested `[Union]` origin and `CultRecordRef` fields round-trip in the run store, committed in one batch with a `SavedZone`? | `GetGlobal` before any write: null. After commit and reopen: `next 4; lots 3; key global:sha256:8660…; zones 1`, all three cases intact (`Attributed` faction, `Produced` station 12 facility 1 inputs 3, `Extracted` zone 4). `batch.Remove(key)` then reopen: null. |
| Q2' | Can `Produced.Station` be a `CultRecordKey`? | No: `FormatterNotRegisteredException: GameCult.Caching.CultRecordKey is not registered in resolver` at commit. `int` works (Q2). See fork N1. |
| Q3 | Does one writable commit re-upserting every `ItemData` clear the drift? | `rewrote 115`; bytes 12,686,267 -> 12,683,061; reopen: 0 reports with ignored slots, 115 items. |
| Q4 | Does a key-11 field on a subclass serialize identically to the same key on the base? | `equal True len 14`. |
Not probed: CultCache Studio's rendering of the ledger (operator check); Unity compile
(batchmode in each cut).
## 3. Authority map
**Lot properties and provenance.**
- Owner: `ProvenanceLedger`, one run-scoped `[CultGlobal]` document. In play, the live
instance is `ItemManager.Lots`.
- Inputs: the lot-minting functions `ItemManager.CreateLot(...)`, which read the product
(maker, design, `Roles` spreads) or the console's design, plus `ItemManager.Random`
and `GameplaySettings.Tiers`.
- Outputs: `Lot { Design, Origin, Quality, Roles }` by `LotId` (an `int`, first id 1, never
reused within a run).
- Derived state:
-`CraftedItemInstance.Data` is no longer an independent value. It is copied from
`Lot.Design` by the one instance mint, `ItemManager.CreateInstance(int lot)`, and
stays on the instance because `ItemsOfType`, stacking and every `GetData` key off it.
- Stats, wear, price and tier are derived from the lot through `ItemManager.GetLot`.
-`EquippedItem` and `ConsumableItemEffect` cache the `Lot` reference at construction.
That is safe because lots are immutable and the live ledger is never pruned.
- Brand is derived by `ItemManager.Brand` and never stored.
- Forbidden writers:
-`CraftedItemInstance.Quality`, `.Ingredients` and `.Product`: deleted.
-`LoadoutGenerator.CopyBuild`: deleted; a matching hardpoint mints from the same lot.
-`ItemManager.Instantiate` and `Unpack(instantiate)`: deleted, because they re-rolled
quality and dropped provenance.
-`ItemData.Manufacturer`: deleted.
- Nothing outside `ItemManager.CreateLot` constructs a `Lot` or assigns its fields.
Tests may construct lots directly.
- Shared paths: NPC and station generation (`LoadoutGenerator`), preset materialization
(`Loadouts.Materialize`), starting ship and `spawnturret` (the generator, no re-mint)
and console `give` all mint through `CreateLot` -> `CreateInstance(lot)`. Loot, buying
and pickup move instance values; their lot rides along.
- Deletion line: in Cut B, the three instance fields and `CopyBuild` go before the ledger
gains a reader.
**Ledger persistence and GC.**
- Owner: `RunSave`.
- Inputs: the live ledger and the `SavedZone`s being committed.
- Outputs:
-`RunSave.Lots(cache)` is the only reader of the stored ledger. It returns the stored
global, or a new empty ledger when there is none.
-`RunSave.Commit(cache, game, zones, lots)` writes `lots.Reachable(roots)` in the same
single-store batch as the zones and the game.
-`RunSave.Clear` removes the ledger through `RunTypes`.
- GC roots: every `CraftedItemInstance` in every committed `SavedZone.Contents.Entities`.
An entity yields its hull, equipment, cargo bays, docking bays, cargo and docking-bay
contents, and its `Children`, recursively (`EntitySerializer.Items(pack)`). Closure
follows `Produced.Facility` and `Produced.Inputs`. Zones never generated have no
contents and contribute nothing.
- Deliberately not roots: floor `ItemPickup`s. `PackZone` never captures them
(`Zone.cs:108-119`), so they vanish on reload anyway, and their lots go with them.
- Invariants:
- GC prunes **only the written copy**. The live ledger keeps unreachable lots, because a
floor pickup can still be collected after a save.
- The written copy keeps `NextLot`, so ids are never reused within a run.
- A root naming an absent lot throws. That is corruption, and it must be loud.
- Forbidden writers: nothing else calls `GetGlobal<ProvenanceLedger>` or upserts one.
`ZoneGenerator`'s staged-upsert pattern (`ZoneGenerator.cs:99-108`) is not used for
lots: the ledger is live simulation state, captured at commit like entities.
- Lifecycle: the run begins with a scene load (§1.6), whose `Start` reads
`RunSave.Lots(CultCache)`. New Game has already cleared the run store (`MainMenu.cs:112`),
so it gets an empty ledger. Continue gets the stored one. Death clears the run store
(`ActionGameManager.cs:1090`); the next run reloads the scene.
An unset maker means `Brand` returns no maker and no product.
-`PropertiesPanel.cs:371-372`: for a `CraftedItemInstance`, a "Manufacturer" stat reads
`Brand(...).Maker.Name`, and is omitted when there is no maker; the "GameCult" fallback
goes. When `Product` is non-null, add the product `Name` and `Description` as
properties. This is the first flavour text the player sees. A `SimpleCommodity` shows
no brand. `ItemData.Manufacturer` is still read here until this edit; Cut C deletes
the field.
-`tools/AetherDb/Program.cs`:
-`:395` passes `new ProvenanceLedger()`.
-`census` adds a "`(maker, design)` with more than one product" section, the Brand
rule's check.
-`save` (`:353-378`) reads `RunSave.Lots(db.Cache)` and prints, per run, the lot
count, crafted instances, instances whose lot is absent, and instances whose `Data`
differs from `Lot.Design`. This is the only headless check of a real played save.
- Tests. Each is paired with the mutation that must kill it; Soul applies each mutation
and sees red.
- Every `new ItemManager(` in tests passes `new ProvenanceLedger()` (10 in
`LoadoutTests`, 1 in `RunSaveTests`). `RunSaveTests.cs:43,60,61,76,86,94,112` pass a
ledger to `Commit`. The record counts in `RepeatedSavesKeepRecordCountConstant`
(`:48-49`) and `ClearRemovesEveryRunRecord` rise by one for the ledger global.
| Test | File | Asserts | Mutations that must kill it |
|---|---|---|---|
| `MaterializedLotsSurviveSaveAndReload` | `LoadoutTests` | `Materialize` a `HandBuilt` ship; pack it into a zone; `Commit` via `Open()`; reopen. Every crafted instance resolves in `RunSave.Lots`, `Data == Lot.Design`, the origin is `Attributed` with the product's maker, and `Quality` equals the pre-save lot's. | `Commit` omits the ledger upsert; `CreateInstance(int)` leaves `Lot` 0; `CreateLot(product)` writes `default` faction; `ProvenanceLedger` absent from `RunTypes` (the commit throws unrouted) |
| `CommitKeepsOnlyReachableLots` | `RunSaveTests` | Hand-built ledger. Lot 1 is on a hull. Lot 3 is `Produced { Facility 4, Inputs [5] }` in a docked child ship's docking-bay contents. Lots 2 and 6 are unreferenced. `NextLot` is 7. After commit and reopen, the stored lots are {1, 3, 4, 5} with `NextLot` 7, and the live ledger still holds 2 and 6. | `Reachable` returns `this`; closure skips `Inputs` or `Facility`; `Reachable` prunes in place; the written copy resets `NextLot`; `Items` skips `Children` or `DockingBayContents` |
| `MatchingHardpointsShareALot` | `LoadoutTests` | A fixture hull, 4x4 with two identical Sensors hardpoints, plus a capacitor gear and product (`FillInterior` requires one, `LoadoutGenerator.cs:250-253`). `GenerateShipLoadout` with galaxy null: both hardpoint units carry the same `Lot`. | the matching-hardpoint branch calls `CreateInstance(entry.product)` |
| `FirstAvailableProductInKeyOrderBuildsTheSlot` (rewritten, `:289-312`) | `LoadoutTests` | `lamp-z` and `lamp-a` get two new makers; each case asserts `items.Brand(unit).Product.Name` | `Brand` ignores the maker; `Materialize` drops key order |
| `StatsReadTheLot` | `LoadoutTests` | A Lamp lot with `Quality .2` and `Roles [lens .9]`: `Evaluate` with `FromRole "lens"`, `Min 0`, `Max 1`, `QualityExponent 1` gives .9; with no role it gives .2; `GetTier` reads .2 | `Evaluate` reads `Quality` for a role stat; `QualityForRole` falls back wrongly |
- Verification:
- The three headless commands of Cut A are green, with 34 tests (29 + 5 new, 1 rewritten).
- Unity batchmode has no `error CS`.
-`AetherDb loadout 1` output equals the HEAD capture (0 hulls failed); only the
quality roll sequence changed.
-`AetherDb census` equals HEAD, plus the empty duplicate section.
- Negative greps:
-`rg -n "\bIngredients\b|\.Product\b|CopyBuild|item\.Quality\b|EquippableItem\.Quality\b|Item\.QualityForRole|EquippableItem\.QualityForRole" Assets/Scripts tools tests` is empty.
-`rg -n "new Attributed" Assets/Scripts tools` matches only `ItemManager.cs`, the
site the generator cut replaces.
-`rg -n "GetGlobal<ProvenanceLedger>" Assets tools tests` matches only
`SavedGame.cs`.
-`rg -n "new Lot\b|\.Origin =|\.Roles\.Add" Assets/Scripts` matches only
`ItemManager.cs`.
-`rg -n "new (EquippableItem|CompoundCommodity|ConsumableItem)\b" Assets/Scripts tools`
matches only `ItemManager.CreateInstance(int)`, the one writer of a crafted
instance's `Data`. Tests may construct instances by hand.
### Cut C: remove the design's manufacturer and rewrite the catalog
Subtraction, plus a data rewrite.
- Deletes: `ItemData.cs:280-281` (`Manufacturer`, key 3), with a one-line retired-key
comment.
- Readers switch:
-`tools/AetherDb/Program.cs:54`: census makers come from the product selling each
| B | `ItemInstance` 26 (19 fields and method, 7 moved `RoleFill`); `ItemManager` ~62 (`:126-187`); `CopyBuild` 8; `PropertiesPanel` 2 | `Provenance.cs` ~90; `ItemManager` ~45; `RunSave` ~12; `Items` ~15; `Entity` ~6; `LoadoutGenerator` ~3; `PropertiesPanel` ~8; `AetherDb` ~20; tests ~170 | +1 run schema `aetheria.provenanceledger` (global); `CraftedItemInstance` keys 2, 9, 10 retired, key 11 added; the run store gains 1 record |
| C | `ItemData` 2; census 1 | census ~4; stores test fixture ±2; 1 retire comment | `ItemData` key 3 retired in the 7 concrete schemas that hold records; the catalog loses slot 3 on 115 records (-3,206 bytes) |
Net source excluding tests: about -620 / +200. Tests: about +170. `TradeMenuDebug` is
most of the deletion; without it the provenance change is close to net +100. That buys a
typed provenance graph, derived brand display and per-lot stats, and it removes three
per-unit fields and two re-mint paths.
## 9. Risks and rejected paths
Risks:
- **Continue with an old run store throws** on the first lot lookup. That is accepted
under "saves are discarded". No `run.cc` exists in the tree today; the operator
deletes any stray one before the smoke.
- **The live ledger grows** by unreachable lots within a session: failed
materializations, consumed consumables, destroyed ships' unlooted gear. That is bounded
by what generation mints: the substrate probe counts about 16k instances for a whole
galaxy, and `CopyBuild` sharing lowers the lot count. It is pruned on every write.
- **The ledger is one document.** The single-file store already rewrites its whole view
per commit (substrate §4), so the ledger adds bytes, not a new rewrite pattern.
- **Studio rendering of `Dictionary<int, Lot>` with union values** is unprobed; it is an
operator check.
- **Cut A's unconditional `Temperature`/`Armor` restore** is argued from source, not
tested.
Rejected paths:
- Staging lots into the cache as zone generation stages orbits. That would make the cache
the live owner and let `Clear` race a live `ItemManager`; lots are simulation state,
captured at commit.
- Pruning the live ledger at commit, which would break pickups collected after a save.
- A nullable lot or a "no provenance" branch in readers (F0 (b)).
- Keeping `Product` on the lot "for display": that is branding stored.
- A save-format version gate for old run stores.
- A typed `LotId` struct.
- A committed `AetherDb` catalog-rewrite command for a one-time rewrite.
- Moving `Data` off the instance so the lot is its only design authority. Every
`ItemsOfType`, stacking and `GetData` path keys off `ItemInstance.Data`, and
`SimpleCommodity` has no lot. Instead, `Data` is written only from `Lot.Design` at mint,