Defer relic classification normalization until the game's model database exists #321
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!321
Loading…
Reference in a new issue
No description provided.
Delete branch "claude/strange-wiles-445c7a"
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?
The bug
RelicClassificationStore.Initialize()enumeratedModelDb.AllRelicsfromCoreMain.Initialize(). On a cold start that runs too early, and the enumeration threw:ModelDb.AllRelicsreachesAllCharactersbefore it touches a single relic, andModelDb.Get<T>()uses a raw dictionary indexer — hence aKeyNotFoundExceptionon a character key during a relic enumeration.Why it only happens at startup
The game loads mods before it builds the model database, on purpose (so
ModelDbandLocManagerpick up mod injections). The observed stack trace:ModelDb.Init()is one step later, inOneTimeInitialization.ExecuteEssential. A Core hot reload re-entersCoreMain.Initialize()long after that, so it always succeeds — which is exactly why a normal player session permanently ran an unreconciled store while every dev session that pressed F5 got the correct one. The bug was invisible in dev.What it cost
The enumeration was wrapped in a log-only try/catch, so the session continued with the reconciliation pass skipped:
CombatIds— andSetCombatRelevantUntilTurngates onCombatIds.Contains(relicId), so the compendium's "hide after turn N" control would silently refuse to stick for any relic a game update added;The relic bar's own hide/show decisions were not affected: they read
NonCombatIdsandCombatRelevantUntilTurns, both populated straight from the document. This is a latent-correctness fix — it pays off the next time MegaCrit adds or renames a relic.The fix
IsLiveRelicDatabaseReady()probes withModelDb.Contains(typeof(Ironclad))— the same key, butContainsKeyanswersfalseon an empty database instead of throwing. Probing rather than catching matters: a catch would cost one throw per relic on the bar-refresh path for as long as the database stayed empty.Initialize()attempts normalization and, when it is too early, says so in its log line rather than logging an error.EnsureReady(), which reconciles on the first read or write. The relic-bar filter therefore normalizes before it answers rather than reading a degraded store.NormalizeClassifications(...)over the collections it is handed, and only persist when the pass actually changed something.Verification
Built, deployed, and hot-reloaded into the running game.
--- HOT RELOAD DONE ---,Core.Initialize complete,Patch install: 428 classes patched, 0 failed/skipped, noCore.Initialize threw, and the load line printed without the deferred-normalization suffix — the new code ran and took the database-ready branch. No restart required: no Harmony target was added or changed.Adds
RelicClassificationNormalizationTests(7 cases). One asserts the readiness probe reports not-ready instead of throwing against an uninitializedModelDb— the test host is the cold-start state, so that case pins the exact branch that was broken. Per the repo's user-owned verification rule the suite was not run; both projects compile clean.Documents the ordering trap in
docs/sts2-runtime-primer.mdunder "Core Loads Before The Game's Model Database Exists", with a pointer fromdocs/architecture.md.