Fix killing-blow damage loss, Continue stranding, and loss-combat discard #246

Closed
nelsong6 wants to merge 1 commit from claude/amazing-wing-eefa07 into main
nelsong6 commented 2026-07-02 10:55:54 -07:00 (Migrated from github.com)

Summary

Three attribution-loss bugs diagnosed from a live Necrobinder run where Death March showed almost no tracked damage, plus hardening from an 8-angle adversarial review of the diff.

1. Killing-blow damage suppression (game-side gap, biggest cause). The game never emits DamageReceivedEntry for a hit that kills the last living enemy: decompiled CreatureCmd.Damage applies HP loss before its IsInProgress && !IsEnding emission gate, and IsEnding flips true the moment no primary enemy lives. In the diagnosed run, 5/5 combat-ending Death March kills had card_played but no damage event, while every mid-combat hit recorded fine — scaling finishers systematically lose their biggest hits. New HookAfterDamageGivenPatch captures the suppressed results via Hook.AfterDamageGiven (which the game explicitly guarantees "must still resolve" for the killing hit), deduped by DamageResult reference against organically observed entries, and routed through the normal Observe pipeline without touching the game's own history.

2. Run stranding on Continue. Every main-menu Continue re-fires RunStarted with the same _startTime; OnRunStarted minted a fresh RunData each time, stranding all committed stats in orphaned files (the diagnosed run split across six). It now resumes the tracked run in memory, or adopts the newest in-progress on-disk record after a game restart, via a shared AdoptRunLocked — with pending rank-restore queues so identity binds correctly whether the deck repopulates before or after RunStarted, and pruning of the ghost aggregates minted by pre-RunStarted CardEnterDeckPatch stamps.

3. Loss-combat discard. On a loss, RunManager.OnEnded fires synchronously from the killing action and the fatal combat's CombatEnded fires only afterwards — after OnRunEnded had already nulled the buffer. Losses now promote the fatal combat's pending stats (abandon still discards; wins already promote via CombatEnded).

Review hardening (8 finder angles + verification): fixed a pre-existing relic Activations double-count (merge consolidated into MergeRelicAggregateInto — every relic's activations were doubled at promotion); ghost-emptiness compares structurally against a bare arrival stamp instead of a hand-kept field list; CaptureInstanceNumbersByDeckRank includes still-queued rank restores so a save during adoption can't orphan stats; resume paths filter to in-progress records at header-scan level (no game-over-screen resurrection); suppressed-damage capture stops once the run record is gone (no junk-file minting in the post-death window); FindByGameStartTime bounds its scan instead of JSON-parsing the whole runs directory on every run start.

Runtime facts (suppression gate, Hook.AfterDamageGiven reliability, Continue re-fire semantics, loss ordering) recorded in docs/sts2-runtime-primer.md and AGENTS.md per the primer's maintenance contract.

Test plan

  • dotnet test Tests/SpireLens.Core.Tests — 237/237 pass (14 new: killing-blow dedup contract, ghost-aggregate pruning boundaries, pending-combat promotion merge incl. the Activations regression).
  • Live verification (killing-blow capture + Continue resume) rides the standard llm-verify phase: scenario with a scaling finisher killing the last enemy, then quit-to-menu → Continue asserting tooltip totals survive.

🤖 Generated with Claude Code

## Summary Three attribution-loss bugs diagnosed from a live Necrobinder run where Death March showed almost no tracked damage, plus hardening from an 8-angle adversarial review of the diff. **1. Killing-blow damage suppression (game-side gap, biggest cause).** The game never emits `DamageReceivedEntry` for a hit that kills the last living enemy: decompiled `CreatureCmd.Damage` applies HP loss *before* its `IsInProgress && !IsEnding` emission gate, and `IsEnding` flips true the moment no primary enemy lives. In the diagnosed run, 5/5 combat-ending Death March kills had `card_played` but no damage event, while every mid-combat hit recorded fine — scaling finishers systematically lose their biggest hits. New `HookAfterDamageGivenPatch` captures the suppressed results via `Hook.AfterDamageGiven` (which the game explicitly guarantees "must still resolve" for the killing hit), deduped by `DamageResult` reference against organically observed entries, and routed through the normal `Observe` pipeline without touching the game's own history. **2. Run stranding on Continue.** Every main-menu Continue re-fires `RunStarted` with the same `_startTime`; `OnRunStarted` minted a fresh `RunData` each time, stranding all committed stats in orphaned files (the diagnosed run split across six). It now resumes the tracked run in memory, or adopts the newest in-progress on-disk record after a game restart, via a shared `AdoptRunLocked` — with pending rank-restore queues so identity binds correctly whether the deck repopulates before or after `RunStarted`, and pruning of the ghost aggregates minted by pre-RunStarted `CardEnterDeckPatch` stamps. **3. Loss-combat discard.** On a loss, `RunManager.OnEnded` fires synchronously from the killing action and the fatal combat's `CombatEnded` fires only afterwards — after `OnRunEnded` had already nulled the buffer. Losses now promote the fatal combat's pending stats (abandon still discards; wins already promote via `CombatEnded`). **Review hardening** (8 finder angles + verification): fixed a pre-existing relic `Activations` double-count (merge consolidated into `MergeRelicAggregateInto` — every relic's activations were doubled at promotion); ghost-emptiness compares structurally against a bare arrival stamp instead of a hand-kept field list; `CaptureInstanceNumbersByDeckRank` includes still-queued rank restores so a save during adoption can't orphan stats; resume paths filter to in-progress records at header-scan level (no game-over-screen resurrection); suppressed-damage capture stops once the run record is gone (no junk-file minting in the post-death window); `FindByGameStartTime` bounds its scan instead of JSON-parsing the whole runs directory on every run start. Runtime facts (suppression gate, `Hook.AfterDamageGiven` reliability, Continue re-fire semantics, loss ordering) recorded in `docs/sts2-runtime-primer.md` and `AGENTS.md` per the primer's maintenance contract. ## Test plan - `dotnet test Tests/SpireLens.Core.Tests` — 237/237 pass (14 new: killing-blow dedup contract, ghost-aggregate pruning boundaries, pending-combat promotion merge incl. the Activations regression). - Live verification (killing-blow capture + Continue resume) rides the standard llm-verify phase: scenario with a scaling finisher killing the last enemy, then quit-to-menu → Continue asserting tooltip totals survive. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
nelsong6 commented 2026-07-03 10:33:35 -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!246
No description provided.