[Medium] [Bug] Enchanting tick pipeline uses live store instead of snapshot — race condition #362

Closed
opened 2026-06-10 19:27:47 +02:00 by Anexim · 1 comment
Owner

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. But processEnchantingTicks() calls useCraftingStore.getState() and useCraftingStore.setState() throughout, which reads/writes the live store state rather than using the ctx snapshot.

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 processEnchantingTicks to read from the ctx snapshot and return writes to be applied by the pipeline, rather than directly accessing the store.

**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. But `processEnchantingTicks()` calls `useCraftingStore.getState()` and `useCraftingStore.setState()` throughout, which reads/writes the **live** store state rather than using the `ctx` snapshot. **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 `processEnchantingTicks` to read from the `ctx` snapshot and return writes to be applied by the pipeline, rather than directly accessing the store.
Anexim added the ai:todo label 2026-06-10 19:27:47 +02:00
n8n-gitea was assigned by Anexim 2026-06-10 19:27:47 +02:00
Anexim added ai:done and removed ai:todo labels 2026-06-11 11:38:08 +02:00
Author
Owner

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.

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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Anexim/Mana-Loop#362