Skip to content

feat(conductor): persist scene state across restarts - #13

Merged
vdmo merged 1 commit into
feat/runtime-rules-and-dashboard-authfrom
feat/scene-state-persistence
Oct 1, 2026
Merged

vdmo merged 1 commit into
feat/runtime-rules-and-dashboard-authfrom
feat/scene-state-persistence

Conversation

@vdmo

@vdmo vdmo commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Stacked on #12 — this reuses the Cli struct and main.rs flow #12 introduced, so it's based on that branch, not main. Review/merge #12 first.

Summary

Scene state (SceneState) was in-memory only: any restart, planned or crashed, started from blank — even though the governance log already survives restarts fine. This closes that gap:

  • SceneState::save_snapshot/load_snapshot: atomic write (temp file + rename — a crash mid-write can never corrupt the snapshot already on disk). A missing or corrupt snapshot logs a warning and starts fresh rather than blocking startup — this is a resilience convenience, not the safety-critical record (that's still the governance log, which already fsyncs every signed receipt, untouched here).
  • PCHIConductor::with_state_file(path): loads an existing snapshot immediately if present, then enables periodic snapshotting via run_state_snapshot_loop (every 2s, skipped when nothing's changed since the last one — compared via SceneState::timestamp, which every mutation already updates). snapshot_state_now() takes one final snapshot on graceful shutdown.
  • Wired into main.rs as --state-file / PCHI_STATE_FILE (default pchi_scene_state.json, always on — same posture as the governance log's own default-local-file behavior) and into the Ctrl+C shutdown path.

Test plan

  • cargo test --workspace — 45/45 passing (40 existing + 5 new)
  • cargo clippy --workspace --all-targets -- -D warnings — clean
  • Live smoke test against the real binary, not just unit tests: sent a control parameter over real UDP, confirmed the periodic snapshot picked it up on disk; sent real SIGINT (the actual Ctrl+C path) and confirmed the final-snapshot log line; restarted the same binary pointed at the same state file and confirmed Resumed scene state from ... (last updated ...) with the exact prior timestamp

🤖 Generated with Claude Code

Scene state was in-memory only — a restart (planned or crashed) always
started from a blank SceneState, even though the governance log already
survives restarts fine. A venue running this overnight had no way to
come back up mid-show without losing "where things were."

- SceneState::save_snapshot/load_snapshot: atomic write (temp file +
  rename, so a crash mid-write never corrupts the snapshot already on
  disk), and a missing/corrupt snapshot logs a warning and starts fresh
  rather than failing startup — this is a resilience convenience, not
  the safety-critical record (that's still the governance log, which
  already fsyncs every signed receipt, untouched by this change).
- PCHIConductor::with_state_file(path): loads an existing snapshot right
  now if present, then enables periodic snapshotting via the new
  run_state_snapshot_loop (every 2s, skipped when nothing changed since
  the last one). snapshot_state_now() takes one final snapshot on
  graceful shutdown, so a planned restart loses nothing regardless of
  where in the interval it happened.
- Wired into main.rs as --state-file / PCHI_STATE_FILE, defaulting to
  pchi_scene_state.json (always on, same posture as the governance
  log's own default-local-file behavior) — and into the Ctrl+C shutdown
  path.

Verified live against the real binary, not just unit tests: set a
control parameter over real UDP, confirmed the periodic snapshot picked
it up on disk, sent SIGINT (the real Ctrl+C path), confirmed the final-
snapshot log line, restarted the same binary pointed at the same file,
and confirmed "Resumed scene state from ... (last updated ...)" with
the exact prior timestamp.

5 new tests (40 -> 45 total): 4 for SceneState's save/load, including a
corrupt-file case, plus one full restart-resume cycle through
PCHIConductor itself (set a value, snapshot, construct a fresh
conductor pointed at the same file, confirm it resumes the value).
clippy clean.

Stacked on #12 (reuses its Cli struct and main.rs flow) — review/merge
after that one.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@vdmo
vdmo merged commit f6b0734 into feat/runtime-rules-and-dashboard-auth Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant