[Medium] [Bug] Enchanting tick pipeline uses live store instead of snapshot — race condition #362
Reference in New Issue
Block a user
Delete Branch "%!s()"
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?
Severity: Medium
File:
src/lib/game/stores/pipelines/enchanting-tick.ts(multiple lines)Description:
The entire purpose of the tick pipeline (per
tick-pipeline.ts) is to snapshot all state once, compute, then batch-write. ButprocessEnchantingTicks()callsuseCraftingStore.getState()anduseCraftingStore.setState()throughout, which reads/writes the live store state rather than using thectxsnapshot.Impact: State corruption during tick processing. The design progress, preparation progress, and application progress could be read mid-update, leading to double-progress, lost progress, or inconsistent state.
Fix needed: Refactor
processEnchantingTicksto read from thectxsnapshot and return writes to be applied by the pipeline, rather than directly accessing the store.Fixed: Refactored processEnchantingTicks to return writes via the TickWrites pattern instead of calling useCraftingStore.setState() directly. The gameStore caller now merges enchantingResult.writes.crafting into the pipeline writes.