Audit fixes batch 4: run-identity stranding, healing race, handler guards #265

Closed
nelsong6 wants to merge 6 commits from claude/audit-fixes-batch4 into main
nelsong6 commented 2026-07-03 10:02:40 -07:00 (Migrated from github.com)

Fourth batch from the audit. Stacks on #264. Confirmed correctness + resilience fixes; 244/244 tests pass against the live game DLL.

Run-identity stranding (#255)

  • Lazy run creation now stamps GameStartTime (finding #11). The 8 copy-pasted _currentRun ??= new RunData {...} sites minted a run without GameStartTime, so a later Continue/hot-reload couldn't match it → the same stranding class the adoption work fixed for the main path. Unified into one EnsureLazyCurrentRunLocked() helper that always stamps it.
  • RecordUpgrade no longer mints a phantom run during save deserialization (finding #58). The game fires UpgradeInternal on template cards while loading a save (_currentRun null); the mint ran before the "have we seen this card?" gate, creating a junk in_progress run that OnRunStarted then saved. The gate now runs first.

Healing-finalize race (#254, findings #19/#50)

GetOrCreateRelicAggregateForHealingLocked used GetOrCreateRelicAggregateLocked, which does _pendingCombat ??= new — so when the pool-thread heal finalize lost the race with OnCombatEnded's promote+null, the lost-healing tail landed in an orphan buffer discarded at the next combat (stranded on a run's final victorious combat). It now routes to the committed run aggregate when there's no live pending combat, and persists that late write.

Exception-discipline hot spots (#261, findings #70 / #143 open half)

The terminal run-end funnel (RunHistoryUtilitiesCreateEntryPatch.Postfix — previously the one patch with no try/catch) and the three event-subscribed lifecycle handlers (OnRunStarted/OnCombatSetUp/OnCombatEnded) now run under an always-on Error-logging guard, so a tracker throw can't propagate into the game's own run/combat dispatch. The full PatchGuard convention across all patches remains #261.

🤖 Generated with Claude Code

Fourth batch from the audit. Stacks on #264. Confirmed correctness + resilience fixes; 244/244 tests pass against the live game DLL. ## Run-identity stranding ([#255](https://github.com/romaine-life/spirelens/issues/255)) - **Lazy run creation now stamps `GameStartTime`** (finding #11). The 8 copy-pasted `_currentRun ??= new RunData {...}` sites minted a run *without* `GameStartTime`, so a later Continue/hot-reload couldn't match it → the same stranding class the adoption work fixed for the main path. Unified into one `EnsureLazyCurrentRunLocked()` helper that always stamps it. - **`RecordUpgrade` no longer mints a phantom run during save deserialization** (finding #58). The game fires `UpgradeInternal` on template cards while loading a save (`_currentRun` null); the mint ran *before* the "have we seen this card?" gate, creating a junk `in_progress` run that `OnRunStarted` then saved. The gate now runs first. ## Healing-finalize race ([#254](https://github.com/romaine-life/spirelens/issues/254), findings #19/#50) `GetOrCreateRelicAggregateForHealingLocked` used `GetOrCreateRelicAggregateLocked`, which does `_pendingCombat ??= new` — so when the pool-thread heal finalize lost the race with `OnCombatEnded`'s promote+null, the lost-healing tail landed in an orphan buffer discarded at the next combat (stranded on a run's final victorious combat). It now routes to the committed run aggregate when there's no live pending combat, and persists that late write. ## Exception-discipline hot spots ([#261](https://github.com/romaine-life/spirelens/issues/261), findings #70 / #143 open half) The terminal run-end funnel (`RunHistoryUtilitiesCreateEntryPatch.Postfix` — previously the one patch with no try/catch) and the three event-subscribed lifecycle handlers (`OnRunStarted`/`OnCombatSetUp`/`OnCombatEnded`) now run under an always-on Error-logging guard, so a tracker throw can't propagate into the game's own run/combat dispatch. The full `PatchGuard` convention across all patches remains #261. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
nelsong6 commented 2026-07-03 10:33:41 -07:00 (Migrated from github.com)

Superseded by #267, which consolidates this and the rest of the audit work onto current main (these branches all conflicted after #247 landed). Closing in favor of the single mergeable PR.

Superseded by #267, which consolidates this and the rest of the audit work onto current main (these branches all conflicted after #247 landed). Closing in favor of the single mergeable PR.

Pull request closed

Sign in to join this conversation.
No reviewers
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!265
No description provided.