[P1] Repair path zeroes damage aggregates the writer stamped with a null Receiver #254

Closed
opened 2026-07-03 02:30:52 -07:00 by nelsong6 · 3 comments
nelsong6 commented 2026-07-03 02:30:52 -07:00 (Migrated from github.com)

Priority: P1. From the 2026-07-02 audit. Confirmed.

Problem

RepairOffensiveDamageAggregatesFromEvents (RunTracker.cs:~5486) zeroes all offensive aggregates and rebuilds them only from damage_received events whose Receiver starts with "MONSTER.". But the writer, RecordDamageFromCard, stamps Receiver = entry.Receiver.Monster?.Id — which is null when the receiver has no Monster — while GetEnemyId uses a MONSTER.UNKNOWN fallback. The two paths disagree.

This repair runs on every hot-reload / continue (AdoptRunLocked(..., repairAggregates: true)), so a card that damaged a Monster-null creature has its damage and kills permanently wiped on the next resume — the exact stat-stranding class the recent adoption work set out to fix.

Fix

  • Make the writer stamp Receiver via the same MONSTER.UNKNOWN fallback that GetEnemyId uses (or, alternatively, skip the repair entirely when any damage_received event lacks a Receiver, so it can't silently drop data).
  • Related: ally / Osty receivers should route to an absorbed-damage bucket, not the offensive branch (ties into the Osty receiver-guard already fixed in PR #248).

Test

Add a fixture to RunTrackerRepairTests with a Monster-null-receiver damage_received event and assert the repair preserves (does not wipe) the aggregate's damage/kills.

**Priority: P1.** From the 2026-07-02 audit. Confirmed. ## Problem `RepairOffensiveDamageAggregatesFromEvents` (`RunTracker.cs:~5486`) zeroes all offensive aggregates and rebuilds them **only** from `damage_received` events whose `Receiver` starts with `"MONSTER."`. But the writer, `RecordDamageFromCard`, stamps `Receiver = entry.Receiver.Monster?.Id` — which is **null** when the receiver has no `Monster` — while `GetEnemyId` uses a `MONSTER.UNKNOWN` fallback. The two paths disagree. This repair runs on **every** hot-reload / continue (`AdoptRunLocked(..., repairAggregates: true)`), so a card that damaged a `Monster`-null creature has its damage and kills **permanently wiped** on the next resume — the exact stat-stranding class the recent adoption work set out to fix. ## Fix - Make the writer stamp `Receiver` via the same `MONSTER.UNKNOWN` fallback that `GetEnemyId` uses (or, alternatively, skip the repair entirely when any `damage_received` event lacks a `Receiver`, so it can't silently drop data). - Related: ally / Osty receivers should route to an absorbed-damage bucket, not the offensive branch (ties into the Osty receiver-guard already fixed in PR #248). ## Test Add a fixture to `RunTrackerRepairTests` with a `Monster`-null-receiver `damage_received` event and assert the repair preserves (does not wipe) the aggregate's damage/kills.
nelsong6 commented 2026-07-03 09:34:25 -07:00 (Migrated from github.com)

Uncapped audit pass — sibling of the null-Receiver bug (confirmed): FinalizeRelicHealing runs on a TaskScheduler.Default ContinueWith racing the main-thread CombatEnded promotion; if promotion wins, GetOrCreateRelicAggregateForHealingLocked resurrects a fresh _pendingCombat (RunTracker.cs:3200) and the TotalHealingLost tail is silently discarded at the next OnCombatSetUp — stranded permanently on the run's final victorious combat (#50). Fix: route by live _pendingCombat==null to the committed run aggregate; persist when the tail landed in the run.

**Uncapped audit pass — sibling of the null-Receiver bug (confirmed):** `FinalizeRelicHealing` runs on a `TaskScheduler.Default` `ContinueWith` racing the main-thread `CombatEnded` promotion; if promotion wins, `GetOrCreateRelicAggregateForHealingLocked` resurrects a fresh `_pendingCombat` (`RunTracker.cs:3200`) and the `TotalHealingLost` tail is silently discarded at the next `OnCombatSetUp` — stranded permanently on the run's final victorious combat (#50). Fix: route by live `_pendingCombat==null` to the committed run aggregate; persist when the tail landed in the run.
nelsong6 commented 2026-07-03 10:03:04 -07:00 (Migrated from github.com)

Addressed in #265: GetOrCreateRelicAggregateForHealingLocked now routes to the committed run aggregate (GetOrCreateRelicAggregateForCurrentContextLocked) instead of GetOrCreateRelicAggregateLocked, which did _pendingCombat ??= new and resurrected an orphan buffer when the pool-thread finalize lost the race with combat-end promotion. The late direct-to-run write is now persisted. The broader repair-path Receiver asymmetry (#4/#12) remains open here.

Addressed in #265: GetOrCreateRelicAggregateForHealingLocked now routes to the committed run aggregate (GetOrCreateRelicAggregateForCurrentContextLocked) instead of GetOrCreateRelicAggregateLocked, which did `_pendingCombat ??= new` and resurrected an orphan buffer when the pool-thread finalize lost the race with combat-end promotion. The late direct-to-run write is now persisted. The broader repair-path Receiver asymmetry (#4/#12) remains open here.
nelsong6 commented 2026-07-05 15:45:08 -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#254
No description provided.