golem-atomic-block-moonbit

Implement atomic operations, idempotency controls, and retry policies in MoonBit Golem agents.

1.5k|212|Updated Nov 24, 2023
One-click install
npx skills add https://github.com/golemcloud/golem --skill golem-atomic-block-moonbit
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golem-atomic-block-moonbit
Source: https://github.com/golemcloud/golem/tree/main/golem-skills/skills/moonbit/golem-atomic-block-moonbit
Command: npx skills add https://github.com/golemcloud/golem --skill golem-atomic-block-moonbit

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Golem agents are durable by default, but grouping multiple external side effects (HTTP calls, payments, cross-agent calls) so they replay together after a crash requires explicit control. This Skill explains how to use the MoonBit @api package to manage atomic operations, idempotence mode, oplog commits, idempotency keys, and retry policies correctly.

Core Features & Use Cases

  • Atomic Operations: Wrap two or more external side effects with @api.with_atomic_operation (or mark_begin_operation/mark_end_operation) so recovery replays the whole group instead of resuming mid-block.
  • Idempotence Mode: Understand that idempotence defaults to true for all HTTP requests, and opt out per-call with @api.with_idempotence_mode(false, ...) for non-idempotent side effects like payments.
  • Retry Policies & Durability Keys: Override retry behavior with @api.with_retry_policy, generate durable idempotency keys via @api.generate_idempotency_key, and wait for oplog replication with @api.oplog_commit.
  • Use Case: When placing an order that reserves inventory and charges a customer, wrap both external calls in an atomic block so a crash between them triggers replay of both calls rather than leaving a partial state.

Quick Start

Show me how to wrap an inventory reservation and a payment charge in an atomic operation in my MoonBit Golem agent so both replay together after a crash.

Frequently Asked Questions about golem-atomic-block-moonbit

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I group external side effects atomically in a MoonBit Golem agent?

Use @api.with_atomic_operation from the golemcloud/golem_sdk/api package to wrap two or more external calls so recovery replays the entire block after a crash. For manual control, call @api.mark_begin_operation and @api.mark_end_operation around the calls.

Are POST requests retried by default in Golem agents?

Yes. Idempotence mode defaults to true, so every outgoing HTTP request including POST, PUT, PATCH, and DELETE is treated as idempotent and works with status-code-keyed retry policies out of the box. You only opt out per-call with @api.with_idempotence_mode(false, ...).

When should I not use with_atomic_operation in Golem?

Do not use it for in-memory state mutations, since oplog replay already rebuilds state deterministically, and do not use it to shrink the oplog or speed up recovery. For large oplogs or slow replay, use snapshot-based recovery instead.

How do I generate an idempotency key for payment APIs in MoonBit?

Call @api.generate_idempotency_key() to get a durable @types.Uuid that persists across agent restarts, or @api.generate_idempotency_key_string() for a string. Pass it to external payment APIs for exactly-once processing.

How do I override the retry policy for a block of MoonBit code?

Use @api.with_retry_policy with a @api.RetryPolicy struct specifying max_attempts, min_delay, max_delay, multiplier, and max_jitter_factor around the flaky operation. For manual control, use @api.get_retry_policy and @api.set_retry_policy.