What problem does it solve?
Long-running Golem agents accumulate large oplogs from heartbeats, polling loops, and frequent state changes, making recovery slow because every restart replays the full history. This Skill guides you through enabling snapshot-based recovery and implementing custom snapshot save/load functions in MoonBit, so recovery starts from the latest snapshot and manual component updates between incompatible versions become possible.
Core Features & Use Cases
- Automatic JSON Snapshotting: Derive
ToJson and @json.FromJson on the agent struct and set #derive.agent(snapshotting="every_n(N)") for zero-effort JSON-based persistence.
- Custom Binary Snapshots: Implement the
Snapshottable trait with save_snapshot and load_snapshot methods for custom serialization, versioning, and cross-version migration.
- Oplog Compaction: Periodic snapshots compact the oplog so recovery replays only entries after the latest snapshot instead of the full history.
- Use Case: A counter agent that increments every few seconds builds a huge oplog over weeks; enabling
every_n(1) snapshotting with a custom 8-byte binary format keeps recovery fast and supports safe updates between incompatible component versions.
Quick Start
Add snapshot-based recovery to my MoonBit Golem agent by deriving ToJson and FromJson and enabling every_n snapshotting on the agent struct.