07-debuggable-state/06-logging-checkpoints-replay.md
Logging, checkpoints, and replay
Logging, checkpoints, and replay
Good state architecture enables powerful debugging tools such as action logs, checkpoints, and replay.
These capabilities allow developers and LLMs to inspect how the system reached a certain state and reproduce issues reliably.
Action logs
When actions are explicit and reducers are predictable, the system can keep a log of actions that occurred.
An action log helps answer:
- what happened before the bug appeared
- which actions changed the state
- whether a reducer behaved incorrectly
Action logs are much more useful when action names and payloads are clear.
Checkpoints
Checkpoints allow the system to capture a snapshot of state at a specific moment.
This can be used to:
- compare state before and after a sequence of actions
- restore the application to a known state
- isolate bugs introduced by recent changes
Checkpoints are especially useful during debugging sessions.
Replay
Replay means reapplying actions from the log to reconstruct how the state evolved.
With replay, developers can:
- reproduce a bug exactly
- test whether a fix changes the behavior
- inspect intermediate state transitions
Replay works best when reducers are pure and state transitions are deterministic.
Requirements for good replay
To support reliable replay:
- reducers must be pure
- actions must contain enough data to reproduce transitions
- API calls should not directly mutate state
This ensures that replaying the same actions leads to the same state.
Final rule
Design reducers and actions so the state history can be inspected and replayed. This makes debugging dramatically easier for both humans and LLMs.