Files

5.2 KiB

Capture immutable world state at a completed simulation boundary

Task ID: S01-03 Role: sol_implementer Status: READY

1. Context and baseline

Exclusive checkout /home/faumaray/Projects/stoneheart_at_home-worktrees/s01, system/s01-simulation at 68f91a2, verified S01-02. World owns complete data, execution mode/pool/caches; WorldSaveCodec reads and validates that data. M01-P2/F3 and upstream Void/Library #5 cover immutable caller-built snapshots.

2. Objective and deliverables

Provide NEW World::capture() const -> std::shared_ptr for const renderer/serializer/snapshot users. Held snapshots preserve all observable data after subsequent live mutations, or when live World is destroyed.

3. Scope and non-goals

World snapshot representation and focused tests, no coordinator, UI, checkpoint, rules or generic atomic snapshot mirror. No byte roundtrip/allocation of a worker during capture. Capture must be called by owner at finished command/tick barrier.

4. Files to inspect

Inspect world.hpp, world.cpp, world_save.cpp, worker_pool.*, tests/{replay,executor,core}_tests.cpp, benchmarks/colony.cpp. Identify all persistent fields, visible counters, worker and transient cache state, const views and nested paths/inventory containers.

5. Write ownership and coordination

Write scope: engine/include/settlement/core/world.hpp; engine/src/world.cpp; tests/snapshot_tests.cpp; CMakeLists.txt; docs/plan/systems/S01.md No editing other worktrees, Git or Serena state. You are not alone and other agents own runtime, rules, persistence, dispatch. Preserve S01-02 exactly apart from necessary representation changes.

6. Implementation or investigation approach

Group copyable logical World data in a single copyable representation such that future gameplay fields naturally join one copy. Keep executor, worker callbacks and cache out of captures (cache independent of future behavior; if a read-only getter exposes hit or path counters, preserve its observed value). Preserve source worker_count() reporting where practical, and forbid mutable snapshot access by type. Favor private or internal state and simple direct World access; no hand-maintained second serializer, dozens of copy assignments or per-capture thread starts. Reuse existing WorldSaveCodec public behavior. Validate current construction/layout/implicit move caller compatibility.

7. Interfaces and data contracts

NEW public std::shared_ptr World::capture() const. Propagate normal allocation failures to the owner, source remains untouched, no mutation or pointer aliases to source vectors/agents. Existing factories, modes and format13 unchanged. Include upstream #5 link plus replacement criterion where publication is discussed.

8. Dependencies and integration

Root will plug capture into single-owner publication, sampled under one owner, snapshots can cross renderer/I/O/threads. This feature can compile from 68f91a2 without S16 or S19. No alternate restore API unless natural and actually required.

9. Edge cases security and performance

Snapshot retains owned nested inventories/routes/reservations, current pause, workshop, hidden sequence/revision/counters and profiling data needed by reads. Capture while a task is running is outside caller contract. Pools/hooks not allocated/retained by read-only view. Test held snapshot can be read on a worker while source advances without using sleeps as ordering controls. Bound benchmark scope to actually measured World/runs.

10. Acceptance criteria

  1. compare canonical bytes immediately and after source changes/destruction incl mid-carry fixture; assert stable views/counters/pause. 2. Capture+serialize on actual const read path; callback ownership released with live world even if snapshot lives. 3. Cover 2/6 and serial or existing replay tests for legacy behavior. 4. Measure capture cost at 50/500 residents in x64 Wine and report exactly what was measured, no native claim.

11. Verification commands and evidence

Source /tmp/stoneheart-verify.KoZwE4o8/env.sh. From YOUR worktree configure cmake -S . -B /tmp/stoneheart-milestones.xprJ2SVp/capture-build -G Ninja --toolchain "$SETTLEMENT_VERIFY/cross.cmake" -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Release -DFETCHCONTENT_SOURCE_DIR_VOID_LIBRARY:PATH="$SETTLEMENT_VERIFY/candidate/_deps/void_library-src". Build with cmake --build --parallel 6, run ctest --test-dir --output-on-failure and your targeted tests. Evidence required. Run wine /settlement_core_tests.exe --tag snapshot, git diff --check; evidence including benchmark protocol and measurements. Separate output files from S01-02 logs.

12. Constraints and stop conditions

Do not alter formats, owner scheduling or save/LAN fixtures. No unrequested generic server/runtime framework. Stop if renderer has mutating access disguised as const or impossible copy semantics. Escalate after two failed repairs of the same defect.

13. Authorization and decisions

Parent owns all commits and pushes. User approved roadmap; planner/preflight accepted independent copies at owner barrier. This is the first S01 immutable-publication component.

14. Return format

Return S01-03 READY/BLOCKED, exact API/files, fields/cache/executor boundary, actual tests/counts, measurements, limitations and contact on any compatibility risk. No children.