Repository navigation
feat(conductor): persist scene state across restarts - #13
Merged
vdmo merged 1 commit intoOct 1, 2026
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #12 — this reuses the
Clistruct andmain.rsflow #12 introduced, so it's based on that branch, notmain. 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 viarun_state_snapshot_loop(every 2s, skipped when nothing's changed since the last one — compared viaSceneState::timestamp, which every mutation already updates).snapshot_state_now()takes one final snapshot on graceful shutdown.main.rsas--state-file/PCHI_STATE_FILE(defaultpchi_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— cleanSIGINT(the actual Ctrl+C path) and confirmed the final-snapshot log line; restarted the same binary pointed at the same state file and confirmedResumed scene state from ... (last updated ...)with the exact prior timestamp🤖 Generated with Claude Code