Card transformation on upgrade (new ref, orphans stats) #18

Closed
opened 2026-04-20 08:14:07 -07:00 by nelsong6 · 1 comment
nelsong6 commented 2026-04-20 08:14:07 -07:00 (Migrated from github.com)

Observation

Hovering an upgraded Astral Pulse (Regent card, "Deal 14 damage to ALL enemies" base, +4 on upgrade) showed:

  • Display: `Astral Pulse+ #2`
  • Lineage: `Received starting deck` + `Upgraded floor 7 → +1`

Before the upgrade there was ONE Astral Pulse in the deck, tracked as `#1`. After a single campfire upgrade it jumped to `#2` — implying a fresh CardModel ref was created during the upgrade rather than the existing one being mutated in place.

Stats on `#1` are now orphaned (card no longer in the deck under that id), and the user sees a fresh-looking `#2` aggregate.

Contrast: Shining Strike campfire upgrade (confirmed working)

Same test with Shining Strike #1 at a campfire:

```
card_upgraded: CARD.SHINING_STRIKE#1 level=1 floor=9 rawHash=45035823 canonicalHash=45035823 deckVerNull=True inDeck=True floorAddedToDeck=2
```

Same ref before/after, stayed `#1`. Works as expected.

Hypothesis: card-specific transformation behavior

Both `AstralPulse.cs` and `ShiningStrike.cs` have identical `OnUpgrade` structure (just `DynamicVars.Damage.UpgradeValueBy(N)`). So the new-ref creation isn't visible in the card-level source. It's likely triggered by a command/flow somewhere in the campfire code path for specific cards.

Data we need to catch it

Next time this happens, the `card_upgraded` log line (diagnostic already always-on) will include:

  • `rawHash` vs `canonicalHash` — if they differ, it's a clone being upgraded
  • `deckVerNull` — whether the upgraded ref has a DeckVersion back-pointer
  • `inDeck` — whether the upgraded ref is in `player.Deck.Cards` at the moment of upgrade

A reproduction of the bug should show a `#N` jump AND a specific combination of these fields that differs from the Shining Strike control case.

Fix sketch (when reproducible)

  1. In `RecordUpgrade`, if `inDeck == false` at upgrade time, treat as a transformation candidate.
  2. Queue the ref for post-upgrade matching: once the upgrade completes, scan `player.Deck.Cards` for a card with matching def_id that WASN'T there before.
  3. If a single match pops, migrate `_instanceNumbers[old_ref] → _instanceNumbers[new_ref]` (preserve the number), and merge aggregate entries (`#1_old` stats → `#1_new`).
  4. If zero or multiple matches, give up gracefully — accept the fresh number.

Priority

Medium. Most cards upgrade in-place (confirmed via Shining Strike). Transformation-on-upgrade is card-specific and relatively rare. Stats don't migrate cleanly for those cards currently, but they're still tracked (just under a new instance number).

## Observation Hovering an upgraded Astral Pulse (Regent card, \"Deal 14 damage to ALL enemies\" base, +4 on upgrade) showed: - Display: \`Astral Pulse+ #2\` - Lineage: \`Received starting deck\` + \`Upgraded floor 7 → +1\` Before the upgrade there was ONE Astral Pulse in the deck, tracked as \`#1\`. After a single campfire upgrade it jumped to \`#2\` — implying a fresh CardModel ref was created during the upgrade rather than the existing one being mutated in place. Stats on \`#1\` are now orphaned (card no longer in the deck under that id), and the user sees a fresh-looking \`#2\` aggregate. ## Contrast: Shining Strike campfire upgrade (confirmed working) Same test with Shining Strike #1 at a campfire: \`\`\` card_upgraded: CARD.SHINING_STRIKE#1 level=1 floor=9 rawHash=45035823 canonicalHash=45035823 deckVerNull=True inDeck=True floorAddedToDeck=2 \`\`\` Same ref before/after, stayed \`#1\`. Works as expected. ## Hypothesis: card-specific transformation behavior Both \`AstralPulse.cs\` and \`ShiningStrike.cs\` have identical \`OnUpgrade\` structure (just \`DynamicVars.Damage.UpgradeValueBy(N)\`). So the new-ref creation isn't visible in the card-level source. It's likely triggered by a command/flow somewhere in the campfire code path for specific cards. ## Data we need to catch it Next time this happens, the \`card_upgraded\` log line (diagnostic already always-on) will include: - \`rawHash\` vs \`canonicalHash\` — if they differ, it's a clone being upgraded - \`deckVerNull\` — whether the upgraded ref has a DeckVersion back-pointer - \`inDeck\` — whether the upgraded ref is in \`player.Deck.Cards\` at the moment of upgrade A reproduction of the bug should show a \`#N\` jump AND a specific combination of these fields that differs from the Shining Strike control case. ## Fix sketch (when reproducible) 1. In \`RecordUpgrade\`, if \`inDeck == false\` at upgrade time, treat as a transformation candidate. 2. Queue the ref for post-upgrade matching: once the upgrade completes, scan \`player.Deck.Cards\` for a card with matching def_id that WASN'T there before. 3. If a single match pops, migrate \`_instanceNumbers[old_ref] → _instanceNumbers[new_ref]\` (preserve the number), and merge aggregate entries (\`#1_old\` stats → \`#1_new\`). 4. If zero or multiple matches, give up gracefully — accept the fresh number. ## Priority Medium. Most cards upgrade in-place (confirmed via Shining Strike). Transformation-on-upgrade is card-specific and relatively rare. Stats don't migrate cleanly for those cards currently, but they're still tracked (just under a new instance number).
nelsong6 commented 2026-04-20 18:40:37 -07:00 (Migrated from github.com)

Closing this as resolved.

This no longer reproduces after the per-instance identity refactor shipped in commit 9a4a44e3f5ae5583083f3821ff4e4ca5b2b3dd35 (Add per-card stats tooltip and removed card tracking).

What changed:

  • upgrade / hover / removal paths are now read-only lookups instead of places that can lazily mint fresh instance numbers
  • upgrade attribution resolves against the canonical deck ref in RunTracker.RecordUpgrade
  • per-instance numbering is now only created from real deck-entry / combat-observation paths, which removed the phantom-card / wrong-instance behavior that was behind this class of bug

At this point the upgrade-transform case is behaving correctly in current testing, so there is no active orphaned-stats issue to chase here.

Closing this as resolved. This no longer reproduces after the per-instance identity refactor shipped in commit `9a4a44e3f5ae5583083f3821ff4e4ca5b2b3dd35` (`Add per-card stats tooltip and removed card tracking`). What changed: - upgrade / hover / removal paths are now read-only lookups instead of places that can lazily mint fresh instance numbers - upgrade attribution resolves against the canonical deck ref in `RunTracker.RecordUpgrade` - per-instance numbering is now only created from real deck-entry / combat-observation paths, which removed the phantom-card / wrong-instance behavior that was behind this class of bug At this point the upgrade-transform case is behaving correctly in current testing, so there is no active orphaned-stats issue to chase here.
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#18
No description provided.