Stop a finished run getting a second, empty record #300
No reviewers
Labels
No labels
4-29
bug
documentation
duplicate
enhancement
flow improvement
good first issue
help wanted
invalid
investigating
issue-agent
issue-agent-blocked
issue-agent-complete
issue-agent-pr-open
issue-agent-runner-nelsonlaptop
issue-agent-runner-nelsonpc
issue-agent-runner-nelsonpc-user
issue-agent-running
needs-verification
next to do
question
queue
recon
relics-stats-onboarding
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
romaine-life/spirelens!300
Loading…
Reference in a new issue
No description provided.
Delete branch "claude/fix-duplicate-run-record"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Symptom
Run history showed all-zero card stats for a real, completed run. Hovering
Glacier reported
Played 0/0,in deck 0, everything zero — while correctlyshowing
Received floor 25, came upgraded +1.Two independent defects
Creation.
OnRunEndeddeliberately nulls_currentRun. But ~40Record*/getter paths funnel throughEnsureLazyCurrentRunLocked, whichre-creates it on demand and cannot distinguish "no run yet" — the legitimate
hot-loaded-mid-run case it exists for — from "run just ended". One post-run
event resurrects the finished game as a second, empty record, stamped with the
same
game_start_timeread from the still-liveRunManager.Observed on disk: a win at floor 49, then 9 ms later an
in_progressrecord withnull character/ascension/floor, 0 events, and 106 freshly renumbered card
aggregates carrying real
floor_addedmetadata but zero counters. NoRunStartedlog line, confirming it did not come from the run-start path.Resolution.
FindHistoricalByGameStartTimesorted by newest write time andreturned the first
game_start_timematch. The stray is written after the realrecord, so newest-mtime picked the empty one.
Fix
Guard the write, not the ~40 call sites. A finished game's record is written
exactly once, by
OnRunEnded.SaveCurrentRunnow refuses to persist a recordwhose
game_start_timebelongs to an already-terminal run. A resurrectedinstance may still accumulate in memory; it is discarded at the next run start
and never reaches disk.
Rank duplicates instead of taking the first match. Finished beats
in-progress, because a game run cannot un-finish. Then higher floor, which
separates a real run from an empty stand-in. Write time only breaks remaining
ties. This half recovers runs whose duplicate is already on disk, with no file
cleanup, and logs a warning so a duplicate stays visible rather than being
silently resolved.
Both halves are pure functions (
RunTracker.IsResurrectedEndedRun,RunStorage.SelectBestRunFileCandidate) with unit coverage: every terminaloutcome, the ended run writing itself, a genuinely new run, the legitimate lazy
mint, missing start time, and each tier of the ranking.
Verification
Deployed and hot-reloaded; the live lookup now resolves the real run:
No new Harmony targets, so hot reload is sufficient — no restart. Unit tests were
not run, per the repo user-owned verification rule.
Not fixed here
The underlying design smell remains: run lifecycle is created as a side effect
from ~40 scattered call sites, two of which are read-only getters
(
GetMutablePotionHistoryLocked,GetMutableMaxHpHistoryLocked) — reading statscan create a run. Lifecycle should have exactly one owner. That refactor is
larger than this fix and deliberately left separate.