Problem
reserve_resource() and release_resource() in scripts/main.gd (lines 2502, 2508) mutate state.reserved_resources, but persist() (line 2439) does not include it in the save payload:
func persist() -> void:
# ... saves resources, builds, workers, goals, etc.
# reserved_resources is NEVER written to the save
GameState.save_game(state)
Wait — actually persist() calls GameState.save_game(state) which serializes the entire state dict. But reserved_resources is initialized lazily in reserve_resource():
func reserve_resource(resource: String, amount: int = 1) -> void:
if not state.has("reserved_resources"):
state["reserved_resources"] = {}
# ...
The issue is that _clean_stale_reservations() (line 1518) runs every tick and can reset reserved_resources. If the game saves mid-tick (after cleanup but before reservation is re-established), the saved state may have stale or empty reservations.
More critically: on load, if reserved_resources is missing from the save (old saves), it defaults to {}. Any in-flight reservations from the previous session are lost, which means two workers could be assigned to the same resource tile because the reservation count is zero.
Fix
- Ensure
reserved_resources is explicitly included in the persist payload
- On load (
bootstrap_state or similar), validate that reserved_resources exists and re-sync it by scanning active worker tasks
- Add a test that saves with active reservations, loads, and verifies the reservations persist
Acceptance criteria
Problem
reserve_resource()andrelease_resource()inscripts/main.gd(lines 2502, 2508) mutatestate.reserved_resources, butpersist()(line 2439) does not include it in the save payload:Wait — actually
persist()callsGameState.save_game(state)which serializes the entirestatedict. Butreserved_resourcesis initialized lazily inreserve_resource():The issue is that
_clean_stale_reservations()(line 1518) runs every tick and can resetreserved_resources. If the game saves mid-tick (after cleanup but before reservation is re-established), the saved state may have stale or empty reservations.More critically: on load, if
reserved_resourcesis missing from the save (old saves), it defaults to{}. Any in-flight reservations from the previous session are lost, which means two workers could be assigned to the same resource tile because the reservation count is zero.Fix
reserved_resourcesis explicitly included in the persist payloadbootstrap_stateor similar), validate thatreserved_resourcesexists and re-sync it by scanning active worker tasksAcceptance criteria
reserved_resourcessurvives save/load cycletests/test_reservations.gdcovering save/load