[P1] Run-identity stamping/reset gaps on lazy-create, upgrade-deserialize, and abandon paths #255

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

Priority: P1. From the 2026-07-02 audit. Several paths re-trigger the run-stranding / phantom-run class the repo recently fixed for the main Continue path. Verify each against current code before fixing (some were not re-verified due to a verification cap).

  • Lazy combat-end run never stamps GameStartTime (RunTracker.cs:~1246): the _currentRun ??= new RunData in OnCombatEnded omits GameStartTime, so a later continue can't match it and mints a fresh parallel run.
  • CardUpgradePatch lazy _currentRun ??= new (RunTracker.cs:~3625) can mint a junk run during save deserialization that OnRunStarted then finalizes and saves as a phantom in_progress file. Move the TryGetInstanceId gate above the mint; audit RecordShivGenerated for the same shape.
  • RunHistoryUtilitiesCreateEntryPatch discards its SerializableRun parameter (patch:32), so OnRunEnded stamps whatever _currentRun happens to be in memory. The main-menu Abandon path never stamps outcome (defeats issue #10), and a cross-run abandon can corrupt a resumable run. Bind the run identity through OnRunEnded and stamp by identity match / on-disk lookup.
  • Run-boundary reset never clears _pendingRelicHeals / _pendingWhiteBeastPotionRewards — out-of-combat relic state leaks across runs.

Each is a small, localized fix; group them because they share the "run identity is stamped/reset inconsistently across lazy-create, deserialize, and abandon paths" root cause. Add fixtures pinning: a continue after a lazy combat-end resumes rather than strands; a deserialize-triggered upgrade does not create a phantom saved run; abandon stamps the correct run's outcome.

**Priority: P1.** From the 2026-07-02 audit. Several paths re-trigger the run-stranding / phantom-run class the repo recently fixed for the main Continue path. **Verify each against current code before fixing** (some were not re-verified due to a verification cap). - **Lazy combat-end run never stamps `GameStartTime`** (`RunTracker.cs:~1246`): the `_currentRun ??= new RunData` in `OnCombatEnded` omits `GameStartTime`, so a later continue can't match it and mints a fresh parallel run. - **CardUpgradePatch lazy `_currentRun ??= new`** (`RunTracker.cs:~3625`) can mint a junk run during save deserialization that `OnRunStarted` then finalizes and **saves** as a phantom `in_progress` file. Move the `TryGetInstanceId` gate above the mint; audit `RecordShivGenerated` for the same shape. - **`RunHistoryUtilitiesCreateEntryPatch` discards its `SerializableRun` parameter** (patch:32), so `OnRunEnded` stamps whatever `_currentRun` happens to be in memory. The main-menu Abandon path never stamps outcome (defeats issue #10), and a cross-run abandon can corrupt a resumable run. Bind the run identity through `OnRunEnded` and stamp by identity match / on-disk lookup. - **Run-boundary reset never clears `_pendingRelicHeals` / `_pendingWhiteBeastPotionRewards`** — out-of-combat relic state leaks across runs. Each is a small, localized fix; group them because they share the "run identity is stamped/reset inconsistently across lazy-create, deserialize, and abandon paths" root cause. Add fixtures pinning: a continue after a lazy combat-end resumes rather than strands; a deserialize-triggered upgrade does not create a phantom saved run; abandon stamps the correct run's outcome.
nelsong6 commented 2026-07-03 09:34:26 -07:00 (Migrated from github.com)

Uncapped audit pass — additional confirmed lifecycle paths:

  • OnCombatEnded's mid-run lazy RunData never stamps GameStartTime, re-triggering stranding on Continue/hot-reload and letting SaveCurrentRun's freeze guard absorb a new run's deck (#11, HIGH).
  • RecordUpgrade/RecordShivGenerated's _currentRun ??= new RunData mints a junk run during save-deserialization that OnRunStarted finalizes and SAVES as a phantom in_progress file (#58, HIGH) — replace with if (_currentRun==null) return.
  • RunHistoryUtilitiesCreateEntryPatch.Postfix discards the SerializableRun identity, so main-menu Abandon stamps the wrong/no run (#67, #70, HIGH) — thread run.StartTime through OnRunEnded and stamp the abandoned file directly.
  • The adoption/queue-claim machinery and FindByGameStartTime have zero tests (#114).
**Uncapped audit pass — additional confirmed lifecycle paths:** - `OnCombatEnded`'s mid-run lazy `RunData` never stamps `GameStartTime`, re-triggering stranding on Continue/hot-reload and letting `SaveCurrentRun`'s freeze guard absorb a new run's deck (#11, HIGH). - `RecordUpgrade`/`RecordShivGenerated`'s `_currentRun ??= new RunData` mints a junk run during save-deserialization that `OnRunStarted` finalizes and SAVES as a phantom `in_progress` file (#58, HIGH) — replace with `if (_currentRun==null) return`. - `RunHistoryUtilitiesCreateEntryPatch.Postfix` discards the `SerializableRun` identity, so main-menu Abandon stamps the wrong/no run (#67, #70, HIGH) — thread `run.StartTime` through `OnRunEnded` and stamp the abandoned file directly. - The adoption/queue-claim machinery and `FindByGameStartTime` have zero tests (#114).
nelsong6 commented 2026-07-03 10:03:03 -07:00 (Migrated from github.com)

Addressed in #265: lazy run creation now stamps GameStartTime via a shared EnsureLazyCurrentRunLocked() helper (all 8 sites), and RecordUpgrade gates on TryGetInstanceId before minting so a template card during save deserialization can't create a phantom run. Remaining in this issue: RecordShivGenerated/SovereignBlade generated paths (same shape, lower frequency — now GameStartTime-stamped but not gate-reordered) and the RunHistoryUtilitiesCreateEntryPatch SerializableRun identity thread-through (#67), and adoption/FindByGameStartTime test coverage (#114).

Addressed in #265: lazy run creation now stamps GameStartTime via a shared EnsureLazyCurrentRunLocked() helper (all 8 sites), and RecordUpgrade gates on TryGetInstanceId before minting so a template card during save deserialization can't create a phantom run. Remaining in this issue: RecordShivGenerated/SovereignBlade generated paths (same shape, lower frequency — now GameStartTime-stamped but not gate-reordered) and the RunHistoryUtilitiesCreateEntryPatch SerializableRun identity thread-through (#67), and adoption/FindByGameStartTime test coverage (#114).
nelsong6 commented 2026-07-05 15:45:07 -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#255
No description provided.