[P1] Unify run/API JSON wire format + fix RemovedSnapshot props data-loss (IncludeFields) #259

Closed
opened 2026-07-03 09:33:36 -07:00 by nelsong6 · 2 comments
nelsong6 commented 2026-07-03 09:33:36 -07:00 (Migrated from github.com)

Priority: P1. From the 2026-07-02 uncapped audit pass. Contains an actual data-loss member. No existing issue owns storage/API serialization coherence.

Data loss — RemovedSnapshot props (finding #94, confirmed)

RunStorage.Options (Core/RunStorage.cs:29-34) does not set IncludeFields = true. SerializableCard.SavedProperties stores its data in public fields, so a removed card's props/enchantment serialize as {} and rehydrate empty on reload — the removed-card overlay loses upgrade/enchant state. Fix: IncludeFields = true (matches the game's MegaCritSerializerContext). No fixture pins the removed_snapshot round-trip (#95, #119) — which is exactly why this went unnoticed; add one that carries non-empty props.

Wire-format divergence — public API (findings #96, #86, confirmed)

SpireLensApiRegistry.cs:20 serializes with a bare new JsonSerializerOptions() → PascalCase, nulls written — a shape incompatible with every on-disk run file and every test option set (all snake_case + WhenWritingNull). Any API consumer reads a different shape than the run files. It also serializes live RunData without holding _lock, racing OnCombatEnded promotion (#86).

Fix: expose one canonical RunStorage.Options (internal static) and route the API through a lock-held RunTracker.SerializeCurrentRunJson().

Secondary hardening (same file, lower severity)

  • ReadHeader full-file-parses per probe on the main thread (#97).
  • RunsDir has no test seam; SaveAsync's synchronous serialize sits outside the try/catch (#98).
  • Non-nullable legacy-default ints render 0 as fact on pre-instance_numbers_by_def files (#99) — consider nullable for genuinely-absent fields.
  • On load, treat a malformed <run_id>.json as recoverable from a leftover .json.tmp (pairs with the atomic-write change already in PR #248).
**Priority: P1.** From the 2026-07-02 uncapped audit pass. Contains an actual data-loss member. No existing issue owns storage/API serialization coherence. ## Data loss — RemovedSnapshot props (finding #94, confirmed) `RunStorage.Options` (`Core/RunStorage.cs:29-34`) does **not** set `IncludeFields = true`. `SerializableCard.SavedProperties` stores its data in public **fields**, so a removed card's props/enchantment serialize as `{}` and rehydrate empty on reload — the removed-card overlay loses upgrade/enchant state. Fix: `IncludeFields = true` (matches the game's `MegaCritSerializerContext`). No fixture pins the `removed_snapshot` round-trip (#95, #119) — which is exactly why this went unnoticed; add one that carries non-empty props. ## Wire-format divergence — public API (findings #96, #86, confirmed) `SpireLensApiRegistry.cs:20` serializes with a bare `new JsonSerializerOptions()` → **PascalCase, nulls written** — a shape incompatible with every on-disk run file and every test option set (all snake_case + `WhenWritingNull`). Any API consumer reads a different shape than the run files. It also serializes live `RunData` **without holding `_lock`**, racing `OnCombatEnded` promotion (#86). Fix: expose one canonical `RunStorage.Options` (internal static) and route the API through a lock-held `RunTracker.SerializeCurrentRunJson()`. ## Secondary hardening (same file, lower severity) - `ReadHeader` full-file-parses per probe on the main thread (#97). - `RunsDir` has no test seam; `SaveAsync`'s synchronous serialize sits outside the try/catch (#98). - Non-nullable legacy-default ints render `0` as fact on pre-`instance_numbers_by_def` files (#99) — consider nullable for genuinely-absent fields. - On load, treat a malformed `<run_id>.json` as recoverable from a leftover `.json.tmp` (pairs with the atomic-write change already in PR #248).
nelsong6 commented 2026-07-03 10:03:07 -07:00 (Migrated from github.com)

Addressed in #264: RunStorage.Options now sets IncludeFields=true (SerializableCard stores data in public fields, so removed-card props/enchantment were serializing as {} and rehydrating empty), and Options is now internal so tests consume the canonical config. The public-API wire-format unification (#96/#86) and the ReadHeader/RunsDir hardening remain open here.

Addressed in #264: RunStorage.Options now sets IncludeFields=true (SerializableCard stores data in public fields, so removed-card props/enchantment were serializing as {} and rehydrating empty), and Options is now internal so tests consume the canonical config. The public-API wire-format unification (#96/#86) and the ReadHeader/RunsDir hardening remain open here.
nelsong6 commented 2026-07-05 15:45:01 -07:00 (Migrated from github.com)

Closing during repository issue cleanup. If this becomes active work again, we can reopen or recreate it as a fresh, specific task.

Closing during repository issue cleanup. If this becomes active work again, we can reopen or recreate it as a fresh, specific task.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
romaine-life/spirelens#259
No description provided.